Commit dfb5f4b3 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

core/gadget_global.js: change rules of asBoolean to match python rules

 - no more "false" string false
 - empty arrays are false

"false" string evaluating as false allowed to use ?editable=false
in the URL to force a page to render as non editable. This was probably
used only in the tests. The support of this was moved to the form page
gadget.
parent 092ced8e
......@@ -182,8 +182,8 @@ and handling data send&receive.
is_refresh: options.is_refresh || false
};
// options.editable differs when it comes from the erp5_launcher of FormBox - try to unify it here
if (asBoolean(options.editable)) {
// options.editable differs when it comes from an option in URL param, from erp5_launcher of FormBox - try to unify it here
if (options.editable !== "false" && asBoolean(options.editable)) {
options.editable = 1;
} else {
options.editable = 0;
......
......@@ -47,18 +47,17 @@
}
window.getFirstNonEmpty = getFirstNonEmpty;
/** Convert anything to boolean value correctly (even "false" will be false)*/
/**
* Convert anything to boolean value with rules similar to python.
*/
function asBoolean(obj) {
if (typeof obj === "boolean") {
return obj;
}
if (typeof obj === "string") {
return obj.toLowerCase() === "true" || obj === "1";
}
if (typeof obj === "number") {
return obj !== 0;
return Boolean(obj)
}
return Boolean(obj);
return !isEmpty(obj);
}
window.asBoolean = asBoolean;
......
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