FSN#32922 Rewrite. Function-style, custom_fields ondersteunen

svn path=/Website/trunk/; revision=25630
This commit is contained in:
Jos Groot Lipman
2015-07-13 15:01:15 +00:00
parent acc394dc5c
commit 11cac95d55

View File

@@ -18,6 +18,7 @@
<!-- #include file="model_issueobjects.inc"-->
<!-- #include file="model_notes.inc"-->
<!-- #include file="model_orders.inc"-->
<!-- #include file="./model_custom_fields.inc"-->
<%
function fnextendedStatus (oRs, field, model)
@@ -26,15 +27,16 @@ function fnextendedStatus (oRs, field, model)
return xstatus;
}
model_issues =
function model_issues(mld_key, params)
{
module: "MLD",
table: "mld_melding",
// aliasprefix: "", // Deze prefix wordt voor fields.name gezet.
primary: "mld_melding_key",
records_name: "issues",
record_name: "issue",
fields: {"id" : { dbs: "mld_melding_key", typ: "key", filter: "exact" },
params = params || {};
this.module = "MLD";
this.table = "mld_melding";
this.primary = "mld_melding_key";
this.records_name = "issues";
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" },
"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" },
@@ -54,9 +56,9 @@ model_issues =
"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" }
},
includes: {
"issueobjects": {
};
this.includes =
{ "issueobjects": {
model: model_issueobjects,
joinfield: "mld_melding_key",
single_only: false
@@ -79,10 +81,13 @@ model_issues =
{
return " mld_melding.mld_melding_key = mld_opdr.mld_melding_key(+) ";
}
}
},
},
"custom_fields" : { model: new model_custom_fields("MLD", "mld_melding_key", { readman: true, readuse: true }),
joinfield: "flexparentkey"
}
};
REST_GET: function _GET(params)
this.REST_GET = function _GET(params)
{
var scope = params.filter.scope || "fe";
var autfunction = { fe : "WEB_MLDUSE", fo : "WEB_MLDFOF", bo : "WEB_MLDBOF", mi : "WEB_MLDBAC" } [scope];
@@ -93,7 +98,7 @@ model_issues =
var alg3d = false;
var prs3d = false;
var query = api2.sqlfields(params, model_issues );
var query = api2.sqlfields(params, this );
query.wheres.push("mld_melding.fac_activiteit_key IS NULL");
if (scope == "fe")
@@ -150,7 +155,7 @@ model_issues =
query.wheres.push("prs_perslid.prs_afdeling_key = prs_v_afdeling_boom.prs_afdeling_key");
}
var wheres = api2.sqlfilter(params, model_issues);
var wheres = api2.sqlfilter(params, this);
query.wheres = query.wheres.concat(wheres);
var sql = "SELECT " + query.selects.join(", ")
@@ -173,14 +178,14 @@ model_issues =
(alg3d && prs3d ? 2 : prs3d ? 1 : 0)
);
sql += " ORDER BY mld_melding_key";
sql += " ORDER BY mld_melding_key"; // Order by nodig voor includes
var json = api2.sql2json (params, sql, model_issues );
var json = api2.sql2json (params, sql, this );
return json;
},
};
_pre_analyze_fields: function (params, jsondata) /* analyseer inkomende jsondata voor POST */
function _pre_analyze_fields (params, jsondata) /* analyseer inkomende jsondata voor POST */
{
params.data = {};
var issuetype = api2.get_jdata_refkey(jsondata.issue.issuetype);
@@ -348,18 +353,18 @@ model_issues =
delete jsondata.issue.issuetype;
delete jsondata.issue.location;
}
},
};
_analyze_fields: function (fields, params, jsondata) /* analyseer inkomende data, common voor PUT en POST */
function _analyze_fields (fields, params, jsondata) /* analyseer inkomende data, common voor PUT en POST */
{
},
};
_validate_fields: function (fields, params, jsondata) /* valideer fields, alle constraints die niet door de database worden afgevangen */
function _validate_fields (fields, 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
},
};
_validate_close: function (params, jsondata, the_key) /* uit: mld_close_save.asp */
function _validate_close (params, jsondata, the_key) /* uit: mld_close_save.asp */
{
var mld_key = the_key;
var this_mld = mld.func_enabled_melding(mld_key);
@@ -418,9 +423,9 @@ model_issues =
msgError = "Issue can not be closed";
api2.error(500, msgError);
}
},
};
REST_PUT: function (params, jsondata, the_key) /* update call */
this.REST_PUT = function (params, jsondata, the_key) /* update call */
{
if (!jsondata.issue.id) jsondata.issue.id = the_key;
var scope = params.filter.scope || "fe";
@@ -430,13 +435,17 @@ model_issues =
// Hier kom je niet meer terecht als bovenstaande autorisatiecheck niet tot succes leidt.
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.
model_issues._pre_analyze_fields(params, jsondata);
var fields = api2.update_fields(params, model_issues, jsondata); // Build updater
model_issues._analyze_fields(fields, params, jsondata);
model_issues._validate_fields(fields, params, jsondata);
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);
var wheres = [" mld_melding_key = " + mld_key];
var mldUpd = buildTrackingUpdate("mld_melding", wheres.join(" AND " ), fields, { noValidateToken: true });
@@ -451,7 +460,7 @@ model_issues =
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, model_issues, jsondata, mld_key);
var mldtrack = api2.process_includes(params, this, jsondata, mld_key);
// update nog tracken
if (mld_key > 0)
@@ -467,9 +476,9 @@ model_issues =
return { key: mld_key };
},
};
REST_POST: function (params, jsondata) /* new call */
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];
@@ -477,14 +486,14 @@ model_issues =
// Hier kom je niet meer terecht als bovenstaande autorisatiecheck niet tot succes leidt.
params.isNew = true;
model_issues._pre_analyze_fields(params, jsondata);
this._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, model_issues, jsondata); // Build updater
model_issues._analyze_fields(fields, params, jsondata);
model_issues._validate_fields(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);
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") };
@@ -506,10 +515,10 @@ model_issues =
params.data.module = "MLD"; // model_notes moet weten bij wekle module de notes horen.
return { key: new_key };
},
};
//JGL: Even uitgeschakeld want beetje raar en in ieder geval krijgt hij geen jsondata meer
xxxREST_DELETE: function (params, the_key) /* delete call */
this.xxxREST_DELETE = function (params, the_key) /* delete call */
{
// Een melding wordt niet verwijderd maar wordt afgesloten.
var scope = params.filter.scope || "fe";
@@ -518,7 +527,7 @@ model_issues =
// Hier kom je niet meer terecht als bovenstaande autorisatiecheck niet tot succes leidt.
model_issues._validate_close(params, jsondata, the_key);
this._validate_close(params, jsondata, the_key);
// De melding en eventuele opdrachten mogen afgemeld worden.
// Ik had nog graag een L("lcl_mld_final_remark") toe willen voegen aan de melding, maar er is geen jsondata bij DELETE.
@@ -532,5 +541,18 @@ model_issues =
// De melding zelf afmelden.
mld.setmeldingstatus(the_key, 5);
}
if (mld_key > 0)
{
params.filter = params.filter || {};
params.filter.id = opdr_key;
if (! ("include" in params) )
params.include = { include: ["custom_fields"]};
var xxx_array = this.REST_GET(params);
if (!xxx_array.length)
shared.record_not_found();
this.data = xxx_array[0];
}
}
%>