FSN#32922 model herzien savepoint
svn path=/Website/trunk/; revision=25682
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
<!-- #include file="model_notes.inc"-->
|
||||
<!-- #include file="model_orders.inc"-->
|
||||
<!-- #include file="./model_custom_fields.inc"-->
|
||||
<!-- #include file="./model_tracking.inc"-->
|
||||
<%
|
||||
|
||||
function fnextendedStatus (oRs, field, model)
|
||||
@@ -38,7 +39,7 @@ function model_issues(mld_key, params)
|
||||
this.record_name = "issue";
|
||||
this.fields =
|
||||
{"id" : { dbs: "mld_melding_key", typ: "key", filter: "exact" },
|
||||
"name" : { dbs: "mld_melding_id", typ: "varchar", sql: "ins_srtdiscipline.ins_srtdiscipline_prefix||mld_melding.mld_melding_key", filter: "exact" },
|
||||
"name" : { dbs: "mld_melding_id", typ: "varchar", sql: "ins_srtdiscipline.ins_srtdiscipline_prefix||mld_melding.mld_melding_key", filter: "exact", readonly: true },
|
||||
"contact" : { dbs: "prs_perslid_key", typ: "key", foreign: "prs_perslid", label: L("lcl_mld_name"), track: true, filter: "exact" },
|
||||
"requestor" : { dbs: "prs_perslid_key_voor", typ: "key", foreign: "prs_perslid", label: L("lcl_mld_call_for"), track: true, filter: "exact" },
|
||||
"issuedate" : { dbs: "mld_melding_datum", typ: "datetime", label: L("lcl_mld_date_time"), track: true, filter: "range" },
|
||||
@@ -56,13 +57,16 @@ function model_issues(mld_key, params)
|
||||
"room" : { dbs: "alg_v_allonroerendgoed.alg_ruimte_key", typ: "key", foreign: "alg_ruimte", label: L("lcl_room"), track: true, filter: "exact" },
|
||||
"terrain" : { dbs: "alg_v_allonroerendgoed.alg_terreinsector_key", typ: "key", foreign: "alg_terreinsector", label: L("lcl_room"), track: true, filter: "exact" },
|
||||
"xstatus" : { dbs: "mld_melding_status",
|
||||
val: fnextendedStatus, typ: "key", foreign: mld.getmldstatustext, label: L("lcl_extended_status"), track: true, filter: "exact" }
|
||||
val: fnextendedStatus, typ: "key", foreign: mld.getmldstatustext, label: L("lcl_extended_status"), track: true, filter: "exact", readonly: true }
|
||||
};
|
||||
this.includes =
|
||||
{ "issueobjects": {
|
||||
model: model_issueobjects,
|
||||
joinfield: "mld_melding_key",
|
||||
single_only: false
|
||||
joinfield: "mld_melding_key"
|
||||
},
|
||||
"tracking": {
|
||||
model: new model_tracking(),
|
||||
joinfield: "fac_tracking_refkey"
|
||||
},
|
||||
"notes": {
|
||||
model: model_notes,
|
||||
@@ -180,6 +184,8 @@ function model_issues(mld_key, params)
|
||||
);
|
||||
|
||||
sql += " ORDER BY mld_melding_key"; // Order by nodig voor includes
|
||||
if (query.orderbys.length)
|
||||
sql += ", " + query.orderbys.join(", ");
|
||||
|
||||
var json = api2.sql2json (params, sql, this );
|
||||
|
||||
@@ -189,9 +195,9 @@ function model_issues(mld_key, params)
|
||||
function _pre_analyze_fields (params, jsondata) /* analyseer inkomende jsondata voor POST */
|
||||
{
|
||||
params.data = {};
|
||||
var issuetype = api2.get_jdata_refkey(jsondata.issue.issuetype);
|
||||
var account = api2.get_jdata_refkey(jsondata.issue.account);
|
||||
var mld_key = jsondata.issue.id;
|
||||
var issuetype = api2.get_jdata_refkey(jsondata.issuetype);
|
||||
var account = api2.get_jdata_refkey(jsondata.account);
|
||||
var mld_key = jsondata.id;
|
||||
|
||||
if (params.isNew)
|
||||
{ // analyseer inkomende jsondata voor POST
|
||||
@@ -200,7 +206,7 @@ function model_issues(mld_key, params)
|
||||
//
|
||||
// Voor een nieuwe melding moet er een geldige stdmelding zijn.
|
||||
msgError = "Missing issuetype";
|
||||
if (jsondata.issue.issuetype)
|
||||
if (jsondata.issuetype)
|
||||
{
|
||||
msgError = "Invalid issuetype";
|
||||
var sql_stdm = "SELECT sm.mld_stdmelding_omschrijving"
|
||||
@@ -239,16 +245,16 @@ function model_issues(mld_key, params)
|
||||
msgError = "Account could not be validated";
|
||||
api2.error(500, msgError);
|
||||
}
|
||||
jsondata.issue.account = kpkey;
|
||||
jsondata.account = kpkey;
|
||||
params.data.is_kto_antwoord = stdm_info.is_kto_antwoord;
|
||||
//
|
||||
|
||||
//
|
||||
if (!jsondata.issue.contact) jsondata.issue.contact = user_key; // Als er geen aanvrager opgegeven is, dan de huidige gebruiker invullen.
|
||||
if (!jsondata.contact) jsondata.contact = user_key; // Als er geen aanvrager opgegeven is, dan de huidige gebruiker invullen.
|
||||
// Als de setting niet is gezet is "Melding voor" gelijk aan contactpersoon.
|
||||
if (S("mld_allow_for_others") == 0)
|
||||
{
|
||||
jsondata.issue.requestor = jsondata.issue.contact;
|
||||
jsondata.requestor = jsondata.contact;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -258,15 +264,15 @@ function model_issues(mld_key, params)
|
||||
+ " FROM mld_melding"
|
||||
+ " WHERE mld_melding_key = " + mld_key;
|
||||
var oRs = Oracle.Execute(sql);
|
||||
jsondata.issue.issuetype = oRs("mld_stdmelding_key").Value;
|
||||
jsondata.issuetype = oRs("mld_stdmelding_key").Value;
|
||||
oRs.Close();
|
||||
|
||||
}
|
||||
//
|
||||
//
|
||||
var stdm_info = mld.mld_stdmeldinginfo(jsondata.issue.issuetype);
|
||||
var stdm_info = mld.mld_stdmeldinginfo(jsondata.issuetype);
|
||||
// Startdatum: indien niet meegegeven, neem dan sysdate
|
||||
var startdate = (jsondata.issue.issuedate ? jsondata.issue.issuedate : new Date);
|
||||
var startdate = (jsondata.issuedate ? jsondata.issuedate : new Date);
|
||||
var startwerkdag = parseFloat(S("fac_t_startofworkday"));
|
||||
var startwerkdag_uur = Math.floor(startwerkdag);
|
||||
var startwerkdag_min = (startwerkdag - Math.floor(startwerkdag)) * 60;
|
||||
@@ -321,18 +327,18 @@ function model_issues(mld_key, params)
|
||||
}
|
||||
else
|
||||
{
|
||||
// startdate = jsondata.issue.issuedate;
|
||||
// startdate = jsondata.issuedate;
|
||||
}
|
||||
}
|
||||
// jsondata.issue.issuedate = startdate;
|
||||
// jsondata.issuedate = startdate;
|
||||
// De einddatum is de meegegeven einddatum, maar als die niet wordt meegegeven regelt de trigger dat wel, dus DAN MOET IK HEM NIET MEEGEVEN
|
||||
//
|
||||
|
||||
// Onroerendgoed_keys wordt de verfijnste van de opgegeven plaats
|
||||
var locatiekey = (jsondata.issue.location ? jsondata.issue.location : -1);
|
||||
var gebouwkey = (jsondata.issue.building ? jsondata.issue.building : -1);
|
||||
var verdiepingkey = (jsondata.issue.floor ? jsondata.issue.floor : -1);
|
||||
var ruimtekey = (jsondata.issue.room ? jsondata.issue.room : -1);
|
||||
var locatiekey = (jsondata.location ? jsondata.location : -1);
|
||||
var gebouwkey = (jsondata.building ? jsondata.building : -1);
|
||||
var verdiepingkey = (jsondata.floor ? jsondata.floor : -1);
|
||||
var ruimtekey = (jsondata.room ? jsondata.room : -1);
|
||||
var alg_onroerendgoed_keys = -1;
|
||||
|
||||
if (!S("mld_plaats_is_locatie_only"))
|
||||
@@ -348,19 +354,19 @@ function model_issues(mld_key, params)
|
||||
|
||||
if (!params.isNew)
|
||||
{ // Verwijder voor PUT wat niet gewijzigd mag worden.
|
||||
delete jsondata.issue.name;
|
||||
delete jsondata.issue.contact;
|
||||
delete jsondata.issue.requestor;
|
||||
delete jsondata.issue.issuetype;
|
||||
delete jsondata.issue.location;
|
||||
delete jsondata.name;
|
||||
delete jsondata.contact;
|
||||
delete jsondata.requestor;
|
||||
delete jsondata.issuetype;
|
||||
delete jsondata.location;
|
||||
}
|
||||
};
|
||||
|
||||
function _analyze_fields (fields, params, jsondata) /* analyseer inkomende data, common voor PUT en POST */
|
||||
function _analyze_fields (dbfields, params, jsondata) /* analyseer inkomende data, common voor PUT en POST */
|
||||
{
|
||||
};
|
||||
|
||||
function _validate_fields (fields, params, jsondata) /* valideer fields, alle constraints die niet door de database worden afgevangen */
|
||||
function _validate_fields (dbfields, params, jsondata) /* valideer fields, alle constraints die niet door de database worden afgevangen */
|
||||
{
|
||||
// als einddatum ingevuld is moet deze groter/gelijk zijn aan de begindatum
|
||||
};
|
||||
@@ -426,82 +432,65 @@ function model_issues(mld_key, params)
|
||||
}
|
||||
};
|
||||
|
||||
this.REST_PUT = function (params, jsondata, the_key) /* update call */
|
||||
this.REST_PUT = function (params, jsondata, the_key) /* update issue */
|
||||
{
|
||||
if (!jsondata.issue.id) jsondata.issue.id = the_key;
|
||||
var scope = params.filter.scope || "fe";
|
||||
var autfunction = { fe : "WEB_MLDUSE", fo : "WEB_MLDFOF", bo : "WEB_MLDBOF", mi : "WEB_MLDBAC" } [scope];
|
||||
params.authparams = user.checkAutorisation(autfunction, null, null, true); /* pessimistic */
|
||||
if (jsondata[this.record_name])
|
||||
jsondata = jsondata[this.record_name]; // dereference
|
||||
|
||||
// Hier kom je niet meer terecht als bovenstaande autorisatiecheck niet tot succes leidt.
|
||||
if (!jsondata.id) jsondata.id = the_key;
|
||||
|
||||
var mld_key = the_key;
|
||||
var old_mld = new model_issues(mld_key);
|
||||
var this_mld = mld.func_enabled_melding(mld_key);
|
||||
|
||||
user.auth_required_or_abort(this_mld.canChange); // Geen wijzigingen toestaan bij onvoldoende rechten.
|
||||
|
||||
|
||||
|
||||
this._pre_analyze_fields(params, jsondata);
|
||||
var fields = api2.update_fields(params, this, jsondata); // Build updater
|
||||
this._analyze_fields(fields, params, jsondata);
|
||||
this._validate_fields(fields, params, jsondata);
|
||||
_pre_analyze_fields(params, jsondata);
|
||||
var dbfields = api2.update_fields(params, this, jsondata); // Build updater
|
||||
_analyze_fields(dbfields, params, jsondata);
|
||||
_validate_fields(dbfields, params, jsondata);
|
||||
|
||||
var wheres = [" mld_melding_key = " + mld_key];
|
||||
var mldUpd = buildTrackingUpdate("mld_melding", wheres.join(" AND " ), fields, { noValidateToken: true });
|
||||
var mldUpd = buildTrackingUpdate("mld_melding", wheres.join(" AND " ), dbfields, { noValidateToken: true });
|
||||
|
||||
// Alle gegevens bijwerken.
|
||||
var sql = "BEGIN "
|
||||
+ mldUpd.sql + ";"
|
||||
+ " END;";
|
||||
|
||||
var err = Oracle.Execute(sql, true);
|
||||
var err = Oracle.Execute(mldUpd.sql, true);
|
||||
if (err.friendlyMsg)
|
||||
abort_with_warning(err.friendlyMsg);
|
||||
|
||||
params.data.module = "MLD"; // model_notes moet weten bij wekle module de notes horen.
|
||||
var mldtrack = api2.process_includes(params, this, jsondata, mld_key);
|
||||
|
||||
// update nog tracken
|
||||
if (mld_key > 0)
|
||||
{
|
||||
shared.trackaction("MLDUPD",
|
||||
mld_key,
|
||||
L("lcl_mld_is_mldupdtrack").format(mld_key) + (mldUpd.trackarray.length > 0? "\n" : "") + mldUpd.trackarray.join("\n"));
|
||||
};
|
||||
|
||||
status = jsondata["status"].id;
|
||||
if (status > 0)
|
||||
mld.setmeldingstatus(mld_key, status, "");
|
||||
|
||||
|
||||
return { key: mld_key };
|
||||
};
|
||||
|
||||
this.REST_POST = function (params, jsondata) /* new call */
|
||||
{
|
||||
var scope = params.filter.scope || "fe";
|
||||
var autfunction = { fe : "WEB_MLDUSE", fo : "WEB_MLDFOF", bo : "WEB_MLDBOF", mi : "WEB_MLDBAC" } [scope];
|
||||
params.authparams = user.checkAutorisation(autfunction, null, null, true); /* pessimistic */
|
||||
if (jsondata[this.record_name])
|
||||
jsondata = jsondata[this.record_name]; // dereference
|
||||
|
||||
// Hier kom je niet meer terecht als bovenstaande autorisatiecheck niet tot succes leidt.
|
||||
params.isNew = true;
|
||||
this._pre_analyze_fields(params, jsondata);
|
||||
_pre_analyze_fields(params, jsondata);
|
||||
|
||||
var this_mld = mld.func_enabled_mld(params.data.mld_ins_discipline_key, "D");
|
||||
user.auth_required_or_abort(this_mld.canFEwrite || this_mld.canFOwrite);
|
||||
//
|
||||
var fields = api2.update_fields(params, this, jsondata); // Build updater
|
||||
this._analyze_fields(fields, params, jsondata);
|
||||
this._validate_fields(fields, params, jsondata);
|
||||
var dbfields = api2.update_fields(params, this, jsondata); // Build updater
|
||||
_analyze_fields(dbfields, params, jsondata);
|
||||
_validate_fields(dbfields, params, jsondata);
|
||||
|
||||
fields["alg"] = { dbs: "mld_alg_onroerendgoed_keys", typ: "key", val: (params.data.alg_onroerendgoed_keys==-1 ? null : params.data.alg_onroerendgoed_keys) };
|
||||
fields["origin"] = { dbs: "mld_meldbron_key", typ: "key", val: S("mld_meldbron_key") };
|
||||
fields["module"] = { dbs: "mld_melding_module", typ: "varchar", val: "MLD" };
|
||||
fields["issue"] = { dbs: "mld_melding_key", typ: "key", seq: "mld_s_mld_melding_key" };
|
||||
dbfields["alg"] = { dbs: "mld_alg_onroerendgoed_keys", typ: "key", val: (params.data.alg_onroerendgoed_keys==-1 ? null : params.data.alg_onroerendgoed_keys) };
|
||||
dbfields["origin"] = { dbs: "mld_meldbron_key", typ: "key", val: S("mld_meldbron_key") };
|
||||
dbfields["module"] = { dbs: "mld_melding_module", typ: "varchar", val: "MLD" };
|
||||
dbfields["issue"] = { dbs: "mld_melding_key", typ: "key", seq: "mld_s_mld_melding_key" };
|
||||
|
||||
var mldIns = buildInsert("mld_melding", fields, { noValidateToken: true });
|
||||
var mldIns = buildInsert("mld_melding", dbfields, { noValidateToken: true });
|
||||
var new_key = mldIns.sequences["mld_melding_key"];
|
||||
var sql = "BEGIN "
|
||||
+ mldIns.sql + ";"
|
||||
@@ -550,7 +539,7 @@ function model_issues(mld_key, params)
|
||||
if (mld_key > 0)
|
||||
{
|
||||
params.filter = params.filter || {};
|
||||
params.filter.id = opdr_key;
|
||||
params.filter.id = mld_key;
|
||||
if (! ("include" in params) )
|
||||
params.include = { include: ["custom_fields"]};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user