[ADD] form_editor: whitelisting of fields

Automatically whitelist fields added to a website_form through the form
editor.

Ideally fields *removed* from a form should be removed from the
whitelist, but since we don't/can't keep track of the website's form,
there's no way to know if a field is needed by multiple forms and thus
no way to remove them.

Plus that would require way more source-tracking than just whitelisting
all the form's fields, I don't know if snippet widgets can track the
removal of elements from a page (easily anyway).
This commit is contained in:
Xavier Morel
2015-12-01 15:59:31 +01:00
parent 19d9c57512
commit 09ec639661
+17 -1
View File
@@ -352,6 +352,22 @@ odoo.define('website_form_editor', function (require) {
},
clean_for_save: function () {
var model = this.$target.data('model_name');
// because apparently this can be called on the wrong widget and
// we may not have a model, or fields...
if (model) {
// we may be re-whitelisting already whitelisted fields. Doesn't
// really matter.
var fields = this.$target.find('input.form-field[name=email_to], .form-field:not(.o_website_form_custom) :input').map(function (_, node) {
return node.getAttribute('name');
}).get();
if (fields.length) {
// ideally we'd only do this if saving the form
// succeeds... but no idea how to do that
new Model('ir.model.fields').call('formbuilder_whitelist', [model, _.uniq(fields)]);
}
}
// Prevent saving of the error colors // TODO: would be better on Edit
this.$target.find('.has-error').removeClass('has-error');
@@ -482,4 +498,4 @@ odoo.define('website_form_editor', function (require) {
}
});
});
});