Files
Facilitor/APPL/API2/model_notes.inc
Jos Groot Lipman f166768b35 FSN#34495 api_notes &module=MLD parameter ondersteunen (effectief zelfs verplicht)
svn path=/Website/trunk/; revision=27376
2015-12-09 15:40:10 +00:00

178 lines
5.4 KiB
PHP

<% /*
$Revision$
$Id$
File: model_notes.inc
Description: notes model.
Parameters:
Context:
Notes: table en fields worden dynamisch per module bepaald
*/
/*
alle notes in 1 view
CREATE OR REPLACE VIEW fac_v_notes
( module, key, parent_key, writer_key, aanmaak, omschrijving)
AS
SELECT 'MLD'
, mld_melding_note_key
, mld_melding_key
, prs_perslid_key
, mld_melding_note_aanmaak
, mld_melding_note_omschrijving
FROM mld_melding_note
UNION
SELECT 'ORD'
, mld_opdr_note_key
, mld_opdr_key
, prs_perslid_key
, mld_opdr_note_aanmaak
, mld_opdr_note_omschrijving
FROM mld_opdr_note
UNION
SELECT 'FIN'
, fin_factuur_note_key
, fin_factuur_key
, prs_perslid_key
, fin_factuur_note_aanmaak
, fin_factuur_note_omschrijving
FROM fin_factuur_note
UNION
SELECT 'CNT'
, cnt_contract_note_key
, cnt_contract_key
, prs_perslid_key
, cnt_contract_note_aanmaak
, cnt_contract_note_omschrijving
FROM cnt_contract_note
UNION
SELECT 'PRJ'
, prj_scenario_note_key
, prj_scenario_key
, prs_perslid_key
, prj_scenario_note_aanmaak
, prj_scenario_note_omschrijving
FROM prj_scenario_note
*/
%>
<!-- #include file="../mld/mld.inc" -->
<!-- #include file="model_objects.inc"-->
<%
function model_notes(module)
{
this.module = module;
// this.table = "fac_v_notes";
this.records_name = "notes";
this.record_name = "note";
var tabel = {}; // De tabel met notes die aangepast moet worden.
switch (module)
{
case "MLD":
{ tabel.naam = "mld_melding_note";
tabel.seq = "mld_s_mld_melding_note_key";
tabel.parent = "mld_melding";
break;
}
case "ORD":
{ tabel.naam = "mld_opdr_note";
tabel.seq = "mld_s_mld_opdr_note_key";
tabel.parent = "mld_opdr";
break;
}
case "FIN":
{ tabel.naam = "fin_factuur_note";
tabel.seq = "fin_s_fin_factuur_note_key";
tabel.parent = "fin_factuur";
break;
}
case "CNT":
{ tabel.naam = "cnt_contract_note";
tabel.seq = "cnt_s_cnt_contract_note_key";
tabel.parent = "cnt_contract";
break;
}
case "PRJ":
{ tabel.naam = "prj_scenario_note";
tabel.seq = "prj_s_prj_scenario_note_key";
tabel.parent = "prj_scenario";
break;
}
default:
api2.error(500, "Missing module parameter");
}
this.table = tabel.naam;
this.primary = tabel.parent + "_note_key";
this.fields =
{ "id" : { dbs: tabel.naam + "_key", typ: "key", seq: tabel.seq, filter: "exact" },
"author" : { dbs: "prs_perslid_key", typ: "key", foreign: "prs_perslid", filter: "exact" },
"description" : { dbs: tabel.naam + "_omschrijving", typ: "varchar", filter: "like" },
"createdate" : { dbs: tabel.naam + "_aanmaak", typ: "datetime" },
// { name: "module", dbs: "module", typ: "varchar", filter: "exact" }
"parent" : { dbs: tabel.parent + "_key", typ: "key", filter: "exact" }
};
this.list = {
"columns": [
"id",
"author",
"description",
"createdate"
]
};
// TODO: REST_GET niet (rechtstreeks) toestaan?
this.REST_GET = function _GET(params)
{
var query = api2.sqlfields(params, this );
var wheres = api2.sqlfilter(params, this);
query.wheres = query.wheres.concat(wheres);
var sql = "SELECT " + query.selects.join(", ")
+ " FROM " + query.tables.join(", ");
if (query.wheres.length)
sql += " WHERE " + query.wheres.join(" AND " );
var json = api2.sql2json (params, sql, this );
return json;
};
this.REST_PUT = function (params, jsondata, the_key) /* update note */
{
// Een note kan alleen worden aangepast door de persoon die hem geschreven heeft.
// Alleen van de meest recente note bij een (melding/opdracht/...) kan de omschrijving worden aangepast.
//
var dbfields = api2.update_fields(params, this, jsondata); // Build updater
var wheres = [ this.id.dbs + " = " + the_key];
wheres.push("prs_perslid = " + user_key);
var xxxUpd = buildTrackingUpdate(this.table, wheres.join(" AND " ), dbfields, { noValidateToken: true });
Oracle.Execute(xxxUpd.sql);
return { key: the_key };
};
this.REST_POST = function (params, jsondata) /* new note */
{
params.isNew = true;
//
var xxxIns = buildInsert(this.table, dbfields, { noValidateToken: true });
var new_key = xxxIns.sequences[xxx_tabel.naam];
Oracle.Execute(xxxIns.sql);
return { key: new_key };
}
// REST_DELETE = function (params, the_key) /* delete note doen we niet */
}
%>