FSN#40183 Kopie record maken via scaffolding

svn path=/Website/trunk/; revision=33472
This commit is contained in:
Jos Groot Lipman
2017-04-12 14:08:46 +00:00
parent ddd6d9385d
commit 2c3ef7163f
9 changed files with 70 additions and 11 deletions

View File

@@ -60,7 +60,8 @@ function model_aut_idp(params)
"label": L("aut_idp_secret"),
"typ": "varchar",
"defaultvalue": shared.random(32),
"secret": true
"secret": true,
"clone": false
},
"audience": {
"dbs": "aut_idp_audience",

View File

@@ -52,7 +52,8 @@ function model_cad_legenda()
this.includes = {
"legendvalues": {
"model": new model_cad_legendawaarde(),
"joinfield": "graphiclegenda"
"joinfield": "graphiclegenda",
"enable_update": true
}
};

View File

@@ -12,8 +12,9 @@
*/
%>
<%
function model_fac_usrdata()
function model_fac_usrdata(params)
{
params = params || {};
var tab_key = getQParamInt("customtable", -1);
this.records_name = "customtablevalues";
@@ -24,6 +25,7 @@ function model_fac_usrdata()
this.record_title = L("fac_usrdata");
this.records_title = L("fac_usrdata_m");
this.autfunction = false; // we controleren het zelf
this.fields = {
"id": {

View File

@@ -260,12 +260,14 @@ function model_res_ruimte()
this.includes = {
"physicalrooms": {
"model": new model_res_alg_ruimte(),
"joinfield": "bookingroom"
"joinfield": "bookingroom",
"enable_update": true
},
"bookingconfigurations": {
"model": new model_res_ruimte_opstelling(),
"joinfield": "bookingroom",
"multiadd": "bookingconfiguration"
"multiadd": "bookingconfiguration",
"enable_update": true
}
};

View File

@@ -85,7 +85,7 @@ function model_res_ruimte_opstelling(fnparams)
"columns": [
"id",
"bookingroom",
"roomconfiguration",
"bookingconfiguration",
"capacity",
"isdefault"
]

View File

@@ -29,6 +29,9 @@ function scaffolding_edit(model, scf_params)
if (scf_params.incsetting)
transit += "&" + scf_params.incsetting.joinfield + "=" + getQParamInt(scf_params.incsetting.joinfield);
var cloning = getQParamInt( "scf_clone", 0 ) == 1;
if (cloning)
transit += "&scf_clone=1";
var key = getQParamInt("id", -1);
var multi = getQParamInt("scf_multi", 0) == 1;
@@ -64,6 +67,10 @@ function scaffolding_edit(model, scf_params)
for (var fld in model.fields)
{
var field = model.fields[fld];
if (cloning && (field.clone === false || fld == "id"))
xxx_data[fld] = field.defaultvalue;
if (field.uniquewith)
{
if (!xxx_data.name && !(fld in filter))
@@ -194,7 +201,7 @@ function scaffolding_edit(model, scf_params)
FcltMgr.closeDetail(window, { cancel: true } );
}
<% if (!multi) { %>
<% if (!multi && modal && key > 0) { %>
function scf_history()
{
<%

View File

@@ -17,6 +17,12 @@ function scaffolding_save(model, scf_params)
protectRequest.validateToken();
var key = getQParamInt( "id" );
var multi = getFParamInt( "scf_multi", 0 ) == 1;
var cloning = getQParamInt( "scf_clone", 0 ) == 1;
if (cloning)
{
var clone_key = key;
key = -1;
}
var formfields = [];
for (var fld in model.fields)
@@ -36,6 +42,34 @@ function scaffolding_save(model, scf_params)
params.multiadd = scf_params.incsetting && scf_params.incsetting.multiadd;
var jsondata = api2.form2JSONdata(model, params, formfields);
if (cloning)
{
// Bepaal de mee te nemen includes van de oude data
var incs = [];
for (var inc in model.includes)
{
var include = model.includes[inc];
if (include.enable_update)
incs.push(inc)
}
var olddata = api2.GET(model, clone_key, { include: incs } );
for (var fld in model.fields)
{
var field = model.fields[fld];
if (field.insertonly)
jsondata[fld] = olddata[fld];
}
for (var inc in model.includes)
{
var include = model.includes[inc];
if (include.enable_update)
jsondata[inc] = olddata[inc];
}
__Log("Cloning data:");
__Log(jsondata);
}
params.properties = { extraserie: false,
nameprefix: "k"
};

View File

@@ -157,6 +157,12 @@ function scaffolding_show(model, scf_params)
}
}
function scf_clone()
{
var url = "<%=scf_params.this_path%>?mode=wrap&scf_clone=1&id=<%=key%><%=transit%>"
FcltMgr.openDetail(url);
}
function xxx_delete()
{
FcltMgr.confirm('<%=safe.jsstring(L("lcl_scf_confirm_delete").format(model.record_title, xxx_data.name || xxx_data.id))%>',
@@ -213,6 +219,9 @@ function scaffolding_show(model, scf_params)
if (user.has("WEB_FACFAC") && model["REST_POST"])
buttons.push({ title: L("lcl_scf_export"), action: "scf_export()", icon: "fa-download" });
if (key > 0 && model["REST_POST"])
buttons.push({ title: L("lcl_scf_clone"), action: "scf_clone()", icon: "copy.png" });
if (key > 0 && cnt > 0)
{
buttons.push({title: L("lcl_history") + " ({0})".format(cnt), action:"scf_history()", icon: "fa-history", id: "btn_scf_history" });

View File

@@ -20,6 +20,7 @@ function scaffolding_wrap(model, scf_params)
var transit = scf_transit2url(scf_params);
var key = getQParam("id", -1);
var cloning = getQParamInt( "scf_clone", 0 ) == 1;
FCLTHeader.Requires({plugins:["jQuery", "suggest"], js: ["jquery-ui.js"]})
@@ -32,12 +33,12 @@ function scaffolding_wrap(model, scf_params)
<script type="text/javascript" >
<% if (key > 0)
{ %>
FcltMgr.setTitle("<%=safe.jsstring(scf_title)%>", {hot: false});
FcltMgr.setTitle("<%=(cloning?L("lcl_scf_clonettl") + " ":"") + safe.jsstring(scf_title)%>", {hot: false});
<% } %>
function scfClose(params)
{
<% if (key < 0)
<% if (key < 0 || cloning)
{ %>
if (params.cancel)
{
@@ -58,15 +59,17 @@ function scaffolding_wrap(model, scf_params)
</head>
<body>
<% if (key < 0)
<% if (key < 0 || cloning)
var page = scf_params.this_fullpath + "?mode=edit" + transit; // Maak een nieuw
else
var page = scf_params.this_fullpath + "?mode=show" + transit;
page += "&id=" + key;
if (cloning)
page += "&scf_clone=1"
IFRAMER("scfFrame", page, { FcltClose: "scfClose" } );
if (key > 0)
if (key > 0 && !cloning)
{
if (!scf_params.wrap.no_default_frames)
{