Skip to content
Snippets Groups Projects
Commit 9f04f538 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-edit-panel' into 'dev'

ENH: allow to provide a function that creates the form to create_show_form_callback

See merge request !98
parents 554ce493 62e35ff4
Branches
Tags
2 merge requests!103Quick main-release of documentation,!98ENH: allow to provide a function that creates the form to create_show_form_callback
Pipeline #36138 passed
...@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `form_elements.make_form_modal` and * `form_elements.make_form_modal` and
`form_elements.make_scripting_submission_button` functions to create a form `form_elements.make_scripting_submission_button` functions to create a form
modal and an SSS submission button, respectively. modal and an SSS submission button, respectively.
* Allow to supply a function that creates the form instead of a config to
create_show_form_callback
* `BUILD_MODULE_EXT_ENTITY_ACL_USER_MANAGEMENT_BUTTON` build variable with which * `BUILD_MODULE_EXT_ENTITY_ACL_USER_MANAGEMENT_BUTTON` build variable with which
a button to the user management is added to the navbar for users with role a button to the user management is added to the navbar for users with role
administration if `BUILD_MODULE_EXT_ENTITY_ACL=ENABLED`. administration if `BUILD_MODULE_EXT_ENTITY_ACL=ENABLED`.
......
...@@ -65,15 +65,33 @@ var form_panel = new function () { ...@@ -65,15 +65,33 @@ var form_panel = new function () {
}; };
/** /**
* Creates a callback function that toggles the form panel which * Creates a callback function that creates the form inside
* the form panel when called for the first time.
*
* You may supply 'undefined' as form_config and use form_creator
* instead which is supposed to be a function without argument that
* return the form to be added to the panel
*/ */
this.create_show_form_callback = function (panel_id, title, form_config) { this.create_show_form_callback = function (
panel_id, title, form_config, form_creator=undefined
) {
return (e) => { return (e) => {
logger.trace("enter show_form_panel", e); logger.trace("enter show_form_panel", e);
const panel = $(form_panel.get_form_panel(panel_id, title)); const panel = $(form_panel.get_form_panel(panel_id, title));
if (panel.find("form").length === 0) { if (panel.find("form").length === 0) {
const form = form_elements.make_form(form_config); if (form_config != undefined && form_creator!=undefined){
throw new Error("create_show_form_callback takes either a FormConfig or a function that creates the form");
}
var form;
if (form_config != undefined ){
form = form_elements.make_form(form_config);
} else if (form_creator != undefined ){
form = form_creator();
} else {
throw new Error("create_show_form_callback takes a FormConfig or a function that creates the form");
}
panel.append(form); panel.append(form);
$(form).find(".selectpicker").selectpicker(); $(form).find(".selectpicker").selectpicker();
......
...@@ -55,9 +55,18 @@ QUnit.test("create_show_form_callback ", function (assert) { ...@@ -55,9 +55,18 @@ QUnit.test("create_show_form_callback ", function (assert) {
help: help_text, help: help_text,
}, ], }, ],
}; };
const cb = form_panel.create_show_form_callback( panel_id, title, csv_form_config); const cb = form_panel.create_show_form_callback(panel_id, title, csv_form_config);
assert.equal(typeof cb, "function", "function created"); assert.equal(typeof cb, "function", "function created");
cb() cb()
const creator = function() {
return form_elements.make_form(csv_form_config);
}
const cb2 = form_panel.create_show_form_callback(
panel_id, title, undefined, creator
);
assert.equal(typeof cb2, "function", "function created");
cb2()
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment