Files
Facilitor/APPL/SCF/scaffolding_common.inc
2022-12-15 12:09:44 +00:00

121 lines
4.4 KiB
C++

<% /*
$Revision$
$Id$
File: scaffolding_common.inc
Description: Common voor gewone GUI en mobiel
Parameters:
Context:
*/
var scf =
{
parseDefault: function (def, field)
{
var result = { fixed: false, vmin: null, vmax: null };
var isDatum = (field.typ == "date" || field.typ == "datetime" || field.typ == "time");
if (!def || def.substr(0,1) != ":")
{
if (isDatum)
return result; // fixed datumvelden ondersteunen we (nog) niet.
result.vmin = def;
return result;
}
def = def.substr(1);
if (def.substr(0,1) == "!") // ':!' bevriest waarde
{
result.fixed = true;
def = def.substr(1);
}
if (def.substr(0,1) == "^") // '^' -> 'NOT' de waarde
{
result.not = true;
def = def.substr(1);
}
result.vmin = def;
if (def.substr(0,2) == "M:") // 'M' multiselect
{
def = def.substr(2);
result.vmin = def.split(";");
if (result.not && result.vmin[0] && typeof result.vmin[0] == "string")
result.vmin[0] = "^" + result.vmin[0]; // Plak hem weer terug voor parsing in api2.inc
}
if (field.filter == "range")
{
result.vmin = def.split("-")[0];
result.vmax = def.split("-")[1];
}
var validCode = true;
var codeRegex = /^[ndwmqy][pn]?\d{0,3}$/gi;
if (typeof result.vmin == "string" &&
((result.vmin && !result.vmin.match(codeRegex)) ||
(result.vmax && !result.vmax.match(codeRegex))))
validCode = false;
if (result.not && typeof result.vmin == "string")
result.vmin = "^" + result.vmin; // Plak hem weer terug voor parsing in api2.inc
if (!result.fixed && isDatum && !validCode)
abort_with_warning("Velden van type '{0}' accepteren alleen :!null en :!notnull".format(field.typ));
else if (typeof result.vmin == "string" && result.vmin.toLowerCase() == "null")
result.vmin = "NULL";
else if (typeof result.vmin == "string" && result.vmin.toLowerCase() == "notnull")
result.vmin = "NOT NULL";
else if (isDatum && !validCode)
abort_with_warning("Ongeldig {0}-filter: '{1}'".format(field.typ, safe.html(def)));
else if (typeof result.vmin == "string") // geen array geworden ondertussen?
{
switch (field.typ)
{
case "key":
switch (result.vmin.toLowerCase())
{
case "self":
result.vmin = user_key;
break;
case "location":
result.vmin = user.alg_locatie_key({withcurrent:true});
break;
case "building":
result.vmin = user.alg_gebouw_key({withcurrent:true});
break;
}
break;
case "date":
case "datetime":
result.vmin = defaultDate(result.vmin);
result.vmax = defaultDate(result.vmax);
break;
}
}
return result;
}
}
function scf_transit2url(scf_params)
{
var transit = "";
if ("transit" in scf_params)
{
var tdata = scf_params.transit;
for (trans in tdata)
transit += "&" + trans + "=" + safe.url(tdata[trans]);
}
if (scf_params.search && "transit" in scf_params.search)
{
var tdata = scf_params.search.transit;
for (var i=0; i<tdata.length; i++)
{
var sparam = getQParam(tdata[i],"");
if (sparam != "" && sparam != -1)
{
transit += "&" + tdata[i] + "=" + safe.url(sparam);
}
}
}
return transit;
}
%>