Commit feba703c authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_json_editor: make jslint happy

parent 5c252784
Pipeline #33483 canceled with stage
in 0 seconds
...@@ -45,38 +45,42 @@ ...@@ -45,38 +45,42 @@
JSONEditor.defaults.editors.select.prototype.setValue = function (value, initial) { JSONEditor.defaults.editors.select.prototype.setValue = function (value, initial) {
/* Sanitize value before setting it */ /* Sanitize value before setting it */
let sanitized = this.typecast(value) var sanitized = this.typecast(value),
const inEnum = (this.enum_options.length > 0 && this.enum_values.includes(sanitized)) inEnum = (this.enum_options.length > 0 && this.enum_values.includes(sanitized)),
haveToUseDefaultValue = (!!this.jsoneditor.options.use_default_values || this.schema.default === undefined);
const haveToUseDefaultValue = !!this.jsoneditor.options.use_default_values || typeof this.schema.default !== 'undefined'
if (!this.hasPlaceholderOption && (!inEnum || (initial && !this.isRequired() && !haveToUseDefaultValue))) { if (!this.hasPlaceholderOption && (!inEnum || (initial && !this.isRequired() && !haveToUseDefaultValue))) {
/* NXD: We forcefuly include the value even */ /* NXD: We forcefuly include the value even */
this.theme.setSelectOptions(this.input, this.enum_options.concat([value]), this.enum_display.concat([value]), this.hasPlaceholderOption, this.placeholderOptionText) this.theme.setSelectOptions(this.input,
this.enum_options.concat([value]),
this.enum_display.concat([value]),
this.hasPlaceholderOption,
this.placeholderOptionText);
} }
if (this.value === sanitized) return if (this.value === sanitized) {
return;
}
/* NXD: !this.hasPlaceholderOption seems to be a bug on upstream introduces by: /* NXD: !this.hasPlaceholderOption seems to be a bug on upstream introduces by:
https://github.com/json-editor/json-editor/pull/1499/commits/2f9b1b3a30e64383b92dc4cd7494f55ba089ae66 */ https://github.com/json-editor/json-editor/pull/1499/commits/2f9b1b3a30e64383b92dc4cd7494f55ba089ae66 */
if (inEnum && !this.hasPlaceholderOption) { if (inEnum && !this.hasPlaceholderOption) {
this.input.value = this.enum_options[this.enum_values.indexOf(sanitized)] this.input.value = this.enum_options[this.enum_values.indexOf(sanitized)];
} else if (!inEnum && !this.hasPlaceholderOption) { } else if (!inEnum && !this.hasPlaceholderOption) {
this.input.value = sanitized this.input.value = sanitized;
} else { } else {
this.input.value = '_placeholder_' this.input.value = '_placeholder_';
} }
this.value = sanitized this.value = sanitized;
if (!initial) { if (!initial) {
this.is_dirty = true this.is_dirty = true;
} }
this.onChange() this.onChange();
this.change() this.change();
} };
if (JSONEditor.defaults.editors.select.prototype.original_preBuild === undefined) { if (JSONEditor.defaults.editors.select.prototype.original_preBuild === undefined) {
JSONEditor.defaults.editors.select.prototype.original_preBuild = JSONEditor.defaults.editors.select.prototype.preBuild; JSONEditor.defaults.editors.select.prototype.original_preBuild = JSONEditor.defaults.editors.select.prototype.preBuild;
...@@ -118,16 +122,16 @@ ...@@ -118,16 +122,16 @@
/* The value should be modified but it must be preserve its integrity, /* The value should be modified but it must be preserve its integrity,
it must not be modified even if the type is not the good one */ it must not be modified even if the type is not the good one */
if (this.schema.type === 'boolean' && (value === 'undefined' || value === undefined)) { if (this.schema.type === 'boolean' && (value === 'undefined' || value === undefined)) {
return undefined; return undefined;
} }
if (this.schema.type === 'boolean' && (typeof value == "boolean")) { if (this.schema.type === 'boolean' && (typeof value === "boolean")) {
return value; return value;
} }
if (this.schema.type === 'boolean' && (value === "true" || value === "1")) { if (this.schema.type === 'boolean' && (value === "true" || value === "1")) {
return true; return true;
} }
if (this.schema.type === 'boolean' && (value === "false" || value === "")) { if (this.schema.type === 'boolean' && (value === "false" || value === "")) {
return false; return false;
} }
if (this.schema.type === 'number' && value === "") { if (this.schema.type === 'number' && value === "") {
return undefined; return undefined;
...@@ -140,7 +144,7 @@ ...@@ -140,7 +144,7 @@
} }
if (this.schema.type === 'integer') { if (this.schema.type === 'integer') {
if (parseFloat(value)) { if (parseFloat(value)) {
return Math.floor(parseFloat(value)) return Math.floor(parseFloat(value));
} }
} }
if (this.schema.enum && value === undefined) { if (this.schema.enum && value === undefined) {
...@@ -295,8 +299,8 @@ ...@@ -295,8 +299,8 @@
// editor relies on async load function, so we must return the promise // editor relies on async load function, so we must return the promise
// to finish before continue, otherwise rendering errors wont throw Errors // to finish before continue, otherwise rendering errors wont throw Errors
// in the same stack as expected. // in the same stack as expected.
return editor.promise return editor.promise;
}) });
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
var form_data = {}; var form_data = {};
......
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