FSN#39638 Bulk bewerken via scaffolding

svn path=/Website/trunk/; revision=32915
This commit is contained in:
Jos Groot Lipman
2017-02-22 20:41:14 +00:00
parent f56446d5a2
commit 402aaa1482
3 changed files with 71 additions and 9 deletions

View File

@@ -31,7 +31,13 @@ function scaffolding_edit(model, scf_params)
transit += "&" + scf_params.incsetting.joinfield + "=" + getQParamInt(scf_params.incsetting.joinfield);
var key = getQParamInt("id", -1);
if (key > 0)
var multi = getQParamInt("scf_multi", 0) == 1;
if (multi)
{
var keys = getQParamIntArray( "id" ); // Vanuit lijst/multi delete
xxx_data = {}; // TODO: vullen met waarden die in alle records gelijk zijn?
}
else if (key > 0)
{
user.auth_required_or_abort(model.REST_PUT || model.REST_DELETE);
var xxx_params = { filter: { id: key } };
@@ -137,7 +143,7 @@ function scaffolding_edit(model, scf_params)
}
api2.setfieldlengths(model); // max lengtes bepalen
if ("hook_pre_edit" in model)
if ("hook_pre_edit" in model && !multi)
model.hook_pre_edit(xxx_data, model.fields);
var modal = model.edit.modal || scf_params.edit && scf_params.edit.modal; // dan doen we een detailrecord altijd modal
@@ -172,6 +178,12 @@ function scaffolding_edit(model, scf_params)
return true; // disable button
}
function scf_cancel()
{
FcltMgr.closeDetail(window, { cancel: true } );
}
<% if (!multi) { %>
function scf_history()
{
<%
@@ -181,11 +193,6 @@ function scaffolding_edit(model, scf_params)
FcltMgr.openDetail("<%= proturl %>", "<%= L("lcl_history") + " " + safe.jsstring(model.record_title) %>");
}
function scf_cancel()
{
FcltMgr.closeDetail(window, { cancel: true } );
}
function scf_delete()
{
FcltMgr.confirm('<%=safe.jsstring(L("lcl_scf_confirm_delete").format(model.record_title, xxx_data.name || xxx_data.id))%>',
@@ -205,6 +212,7 @@ function scaffolding_edit(model, scf_params)
"json");
});
}
<% } %>
window.lastinputid = null;
$(function () {
@@ -249,6 +257,27 @@ function scaffolding_edit(model, scf_params)
{
$('textarea').resize(function () { FcltMgr.resized(window) });
$('textarea').autogrow();
<% if (multi) {
// Overal een vinkje voorzetten
%>
$("input[type=text],input[type=checkbox],select").each(function() {
var cb_name = "scf_multi_" + $(this).attr("name");
var cb = $("<input type='checkbox'>").attr("name", cb_name);
$(this).closest("tr").find("td.label label").prepend(cb);
// Zetten vinkje als je waarde invult
$(this).blur(function () {
$("input[type=checkbox][name=" + cb_name + "]").prop("checked", $(this).val())
});
// Wissen waarde als je vinkje weghaalt
cb.change(function (deze) {
return function () {
if (!$(this).is(":checked"))
$(deze).val("");
}
}(this));
});
<% } %>
FcltMgr.resized(); // Indien labels over meer dan 1 regel staan.
});
</script>
@@ -283,7 +312,7 @@ function scaffolding_edit(model, scf_params)
}
if (model.REST_PUT || key < 0)
buttons.push({title: L("lcl_submit"), action:"scf_submit()", icon: "fa-save", singlepress: true, id: "btn_scf_submit" });
if (modal && model.REST_DELETE && key > 0)
if (modal && model.REST_DELETE && key > 0 && !multi)
buttons.push({title: L("lcl_delete"), action:"scf_delete()", icon: "fa-trash", singlepress: true, id: "btn_scf_delete" });
buttons.push({title: L("lcl_cancel"), action:"scf_cancel()", icon: "fa-undo", id: "btn_scf_cancel" });
if (model.hashints)
@@ -294,6 +323,11 @@ function scaffolding_edit(model, scf_params)
<div id="edit">
<form name="u2" method="post" action="<%=scf_params.this_fullpath%>?mode=save&id=<%=key%><%=transit%>" onsubmit="return false;">
<%
if (multi)
{
Response.Write("<input type='hidden' name='scf_multi' value='1'>");
Response.Write("<input type='hidden' name='scf_multi_id' value='" + keys.join(",") + "'>");
}
var fld_arr = [];
for (var fld in model.fields)
{
@@ -301,6 +335,9 @@ function scaffolding_edit(model, scf_params)
if (field.sql)
continue; // weinig aan te beweken
if (multi)
field.required = false;
if (field.hidden_fld || (field.readonly && !(key > 0)))
{ // Eerst de hidden velden.
scf_RWHIDDENTR(model, fld, xxx_data[fld]);

View File

@@ -120,6 +120,13 @@ function scaffolding_list(model, scf_params)
"json");
}
function scf_multiedit(rowArray, isMulti)
{
var scfKeyString = getKeyString(rowArray);
var url = "<%= default_url %>".format(scfKeyString) + "&scf_multi=1";
FcltMgr.openModalDetail(url, scfKeyString.split(",").length + " " + "<%=safe.jsstring(model.records_title)%>", { callback: scf_reload });
}
// Sorteren door drag-and-drop experiment (niet actief)
// Return a helper with preserved width of cells
var fixHelper = function(e, ui) {
@@ -459,6 +466,9 @@ function scaffolding_list(model, scf_params)
if (model.REST_DELETE)
rst.addAction({ action: "scf_delete", caption: L("lcl_delete"), multi: true, onlyMulti: true, multiOnce: true } );
if (model.REST_PUT && model.edit && model.edit.modal)
rst.addAction({ action: "scf_multiedit", caption: L("lcl_change"), multi: true, onlyMulti: true, multiOnce: true } );
var cnt = rst.processResultset();
%>
</body>

View File

@@ -16,6 +16,7 @@ function scaffolding_save(model, scf_params)
{
protectRequest.validateToken();
var key = getQParamInt( "id" );
var multi = getFParamInt( "scf_multi", 0 ) == 1;
var formfields = [];
for (var fld in model.fields)
@@ -41,7 +42,21 @@ function scaffolding_save(model, scf_params)
if (model.includes && "custom_fields" in model.includes)
jsondata.custom_fields = flexkenmerken2jsondata(params.properties);
if (key > 0)
if (multi)
{
for (var fld in jsondata) // Alle velden waar ons vinkje niet voor stond slaan we niet op
{
var cb_name = "scf_multi_" + fld;
if (getFParam(cb_name, "off") != "on")
delete jsondata[fld];
}
var keys = getFParamIntArray("scf_multi_id");
for (var i = 0; i < keys.length; i++)
{
var restresult = model.REST_PUT(params, jsondata, keys [i]);
}
}
else if (key > 0)
{
if ("hook_pre_put" in model)
model.hook_pre_put(params, jsondata, key);