Commit c01edfeb authored by Sven Franck's avatar Sven Franck

change prefix from portal_type to id of form

parent 05113df3
...@@ -15,10 +15,6 @@ ...@@ -15,10 +15,6 @@
* Mapping data structure to factory (actions, gadgets, buttons, utilities) * Mapping data structure to factory (actions, gadgets, buttons, utilities)
* @object map * @object map
**/ **/
// NOTE: to use the UI generator with your own data structure, write your
// own map object, which contains all actions, all gadgets and mapping
// methods to convert your data into the JSON configuration needed by
// the factory.
map = {}; map = {};
/** /**
...@@ -700,8 +696,7 @@ ...@@ -700,8 +696,7 @@
// should only be possible if links will be external, but how to set? // should only be possible if links will be external, but how to set?
if (spec.property_dict.link) { if (spec.property_dict.link) {
obj.href = "#" + core + "::" + obj.href = "#" + core + "::" +
item[spec.portal_type_title + "_" + item[spec.property_dict.link_identifier || "id"];
(spec.property_dict.link_identifier || "id")];
} }
// TODO: don't do this based on hardcoded filenames!!! // TODO: don't do this based on hardcoded filenames!!!
...@@ -778,6 +773,7 @@ ...@@ -778,6 +773,7 @@
/** /**
* Map field definition to factory form element * Map field definition to factory form element
* @method mapFormField * @method mapFormField
* @param {string} form_id ID of form to prefix all form fields
* @param {object} spec Form field definition * @param {object} spec Form field definition
* @param {object} overrides Overrides for this field * @param {object} overrides Overrides for this field
* @param {string} value Value to set this field to * @param {string} value Value to set this field to
...@@ -785,9 +781,9 @@ ...@@ -785,9 +781,9 @@
**/ **/
// NOTE: select options must be fetched here, because we are setting // NOTE: select options must be fetched here, because we are setting
// the mapping from (ERP5) custom API to internal API here // the mapping from (ERP5) custom API to internal API here
"mapFormField": function (spec, overrides, passed_value) { "mapFormField": function (form_id, spec, overrides, passed_value) {
var validation_list, class_list, element, type, prevail, clear, config, var validation_list, class_list, element, type, prevail, clear, config,
field_value, skip, use_type, textarea_value; field_value, skip, use_type, textarea_value, alternate_name;
// build config object // build config object
config = {}; config = {};
...@@ -820,6 +816,7 @@ ...@@ -820,6 +816,7 @@
} }
// easy way out if not enabled // easy way out if not enabled
// TODO: should a span still have full structure (label/container)?
if (prevail.properties.enabled === false || if (prevail.properties.enabled === false ||
spec.properties.enabled === false) { spec.properties.enabled === false) {
config = { config = {
...@@ -943,12 +940,16 @@ ...@@ -943,12 +940,16 @@
validation_list = undefined; validation_list = undefined;
} }
// define alternate name here
alternate_name = prevail.widget.alternate_name ||
spec.widget.alternate_name;
// construct config // construct config
// NOTE: type (checkbox, radio...) set in attributes, because can be // NOTE: type (checkbox, radio...) set in attributes, because can be
// null on select/textarea // null on select/textarea
config.type = element; config.type = element;
config.direct = { config.direct = {
"id": (prevail.widget.id || spec.widget.id), "id": form_id + "_" + (prevail.widget.id || spec.widget.id),
"className": class_list + " " + (prevail.widget.css_class || "className": class_list + " " + (prevail.widget.css_class ||
spec.widget.css_class || "") spec.widget.css_class || "")
}; };
...@@ -960,8 +961,7 @@ ...@@ -960,8 +961,7 @@
config.logic = { config.logic = {
"data-vv-validations": validation_list || undefined, "data-vv-validations": validation_list || undefined,
"extra": prevail.widget.extra || spec.widget.extra || undefined, "extra": prevail.widget.extra || spec.widget.extra || undefined,
"name": prevail.widget.alternate_name || "name": alternate_name ? form_id + "_" + alternate_name : null,
spec.widget.alternate_name || null,
"size": prevail.widget.display_width || spec.widget.display_width || "size": prevail.widget.display_width || spec.widget.display_width ||
prevail.widget.size || spec.widget.size || undefined, prevail.widget.size || spec.widget.size || undefined,
"rows": prevail.widget.width || spec.widget.width || undefined, "rows": prevail.widget.width || spec.widget.width || undefined,
...@@ -1515,7 +1515,7 @@ ...@@ -1515,7 +1515,7 @@
element.reset = reset_state; element.reset = reset_state;
element.form = spec.form; element.form = spec.form;
element.fields = field_dict; element.fields = field_dict;
element.id = spec.id; element.reference = spec.id;
} }
target.appendChild(app.setContent(element)); target.appendChild(app.setContent(element));
} }
...@@ -1762,12 +1762,15 @@ ...@@ -1762,12 +1762,15 @@
*/ */
factory.util.wrapInForm = function (spec) { factory.util.wrapInForm = function (spec) {
if (spec.form) { if (spec.form) {
if (spec.reference === undefined && spec.id === undefined) {
util.error({"error": "wrapInForm: Missing form id."});
}
return factory.element( return factory.element(
"form", "form",
{ {
"method": "POST", "method": "POST",
"action": "#", "action": "#",
"id": spec.id, "id": spec.reference || spec.id,
"className": (spec.class_list || "") "className": (spec.class_list || "")
}, },
{"data-ajax": false, "autocomplete": "off"}, {"data-ajax": false, "autocomplete": "off"},
...@@ -2217,9 +2220,10 @@ ...@@ -2217,9 +2220,10 @@
factory.form = function (spec) { factory.form = function (spec) {
var i, j, k, layout, element, container, area, field, overrides, var i, j, k, layout, element, container, area, field, overrides,
position, doc, config, value, stamp, sauce, encode, secure, position, doc, config, value, stamp, sauce, encode, secure,
safety_box, fragment, wrap, item_id, input_config; safety_box, fragment, wrap, item_id, input_config, form_id;
fragment = factory.util.wrapInForm(spec); fragment = factory.util.wrapInForm(spec);
form_id = spec.reference;
secure = spec.property_dict.secure; secure = spec.property_dict.secure;
item_id = spec.data ? (spec.data._id || undefined) : undefined; item_id = spec.data ? (spec.data._id || undefined) : undefined;
...@@ -2228,7 +2232,7 @@ ...@@ -2228,7 +2232,7 @@
// set optional captcha config // set optional captcha config
if (captcha) { if (captcha) {
keys.id = spec.id + "_captcha"; keys.id = form_id + "_captcha";
keys["data-key"] = spec.property_dict.public_key; keys["data-key"] = spec.property_dict.public_key;
} }
...@@ -2281,7 +2285,7 @@ ...@@ -2281,7 +2285,7 @@
{ {
"type": "hidden", "type": "hidden",
"value": spec.property_dict.secret_hash, "value": spec.property_dict.secret_hash,
"id": spec.id + "_not_a_secret" "id": form_id + "_not_a_secret"
}, },
{ {
"data-created": stamp "data-created": stamp
...@@ -2343,7 +2347,12 @@ ...@@ -2343,7 +2347,12 @@
value = doc ? (doc[field.title]) : undefined; value = doc ? (doc[field.title]) : undefined;
// map config to what we need // map config to what we need
input_config = map.utils.mapFormField(config, overrides, value); input_config = map.utils.mapFormField(
form_id,
config,
overrides,
value
);
} }
...@@ -2397,7 +2406,7 @@ ...@@ -2397,7 +2406,7 @@
// pass reference // pass reference
element = spec.children[k]; element = spec.children[k];
if (spec.form) { if (spec.form) {
element.reference = spec.id; element.reference = form_id;
element.item_identifier = item_id; element.item_identifier = item_id;
} }
...@@ -3991,7 +4000,6 @@ ...@@ -3991,7 +4000,6 @@
// spam - thx http://nedbatchelder.com/text/stopbots.html // spam - thx http://nedbatchelder.com/text/stopbots.html
if (anti_spam) { if (anti_spam) {
// fill form in < 1sec = spam // fill form in < 1sec = spam
if (Date.now() - parseInt(anti_spam.getAttribute("data-created"), 10) if (Date.now() - parseInt(anti_spam.getAttribute("data-created"), 10)
> 1000) { > 1000) {
...@@ -4016,7 +4024,13 @@ ...@@ -4016,7 +4024,13 @@
if (test_empty && test_full && test_time) { if (test_empty && test_full && test_time) {
pass = true; pass = true;
} }
// skip spam testing
} else {
pass = true;
} }
// DONE and ...?
if (pass === true) { if (pass === true) {
return valid; return valid;
} }
...@@ -4079,9 +4093,9 @@ ...@@ -4079,9 +4093,9 @@
if (valid === undefined) { if (valid === undefined) {
util.loader("", "validation_dict.general", "ban-circle"); util.loader("", "validation_dict.general", "ban-circle");
// valid form and no spam // form is valid and not "spam"
} else { } else {
replace = form_to_submit.id.split("_")[0] + "_"; replace = form_to_submit.id + "_";
obj = {}; obj = {};
// force portal_type // force portal_type
...@@ -4095,18 +4109,25 @@ ...@@ -4095,18 +4109,25 @@
value = valid[property]; value = valid[property];
// prepare to store // prepare to store
// TODO: add id to captcha fields missing it...
if (property !== "undefined") { if (property !== "undefined") {
// overwrite portal_type if forced // overwrite portal_type if forced
if (config.gadget.state.force_type if (property !== "identifier") {
&& property !== "identifier") { obj[property.replace(replace,"")] = value;
obj[
property.replace(property.split("_")[0],
config.gadget.state.force_type.toLowerCase())
] = value;
} else { } else {
obj[property] = value; obj[property] = value;
} }
// if (config.gadget.state.force_type
// && property !== "identifier") {
// obj[
// property.replace(property.split("_")[0],
// config.gadget.state.force_type.toLowerCase())
// ] = value;
// } else {
// obj[property] = value;
// }
} }
// prepare for form submit // prepare for form submit
...@@ -5472,6 +5493,7 @@ ...@@ -5472,6 +5493,7 @@
pass = reply.pass; pass = reply.pass;
if (reply.response) { if (reply.response) {
// TODO: remove once no need for sample data // TODO: remove once no need for sample data
if (pass.needs_fields) { if (pass.needs_fields) {
delete pass.needs_fields; delete pass.needs_fields;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment