diff --git a/src/action.js b/src/action.js index 817f814911..1b388ef1ec 100644 --- a/src/action.js +++ b/src/action.js @@ -63,10 +63,10 @@ if (!jQuery.isEmptyObject(action.views)) { params.view_ids = []; params.mode = []; - action.views.forEach(function(x) { - params.view_ids.push(x[0]); - params.mode.push(x[1]); - }); + for (const view of action.views) { + params.view_ids.push(view[0]); + params.mode.push(view[1]); + } } else if (!jQuery.isEmptyObject(action.view_id)) { params.view_ids = [action.view_id[0]]; } @@ -94,10 +94,10 @@ params.search_value = decoder.decode( action.pyson_search_value || '[]'); params.tab_domain = []; - action.domains.forEach(function(element, index) { + for (const element of action.domains) { params.tab_domain.push( [element[0], decoder.decode(element[1]), element[2]]); - }); + } name_prm = jQuery.when(action.name); params.model = action.res_model || data.res_model; params.res_id = action.res_id || data.res_id; diff --git a/src/board.js b/src/board.js index 391cf74b9d..0b6d06baaf 100644 --- a/src/board.js +++ b/src/board.js @@ -42,8 +42,8 @@ new this.xml_parser(this, null, {}).parse(xml.children()[0]); actions_prms = []; - for (var i = 0, len = this.actions.length; i < len; i++) { - actions_prms.push(this.actions[i].action_prm); + for (const action of this.actions) { + actions_prms.push(action.action_prm); } this.actions_prms = jQuery.when.apply(jQuery, actions_prms); }, @@ -57,12 +57,11 @@ } }, active_changed: function(event_action) { - this.actions.forEach(function(action) { - if (action === event_action) { - return; + for (const action of this.actions) { + if (action !== event_action) { + action.update_domain(this.actions); } - action.update_domain(this.actions); - }); + } }, }); @@ -94,10 +93,10 @@ if (!jQuery.isEmptyObject(action.views)) { params.view_ids = []; params.mode = []; - action.views.forEach(function(x) { - params.view_ids.push(x[0]); - params.mode.push(x[1]); - }); + for (const view of action.views) { + params.view_ids.push(view[0]); + params.mode.push(view[1]); + } } else if (!jQuery.isEmptyObject(action.view_id)) { params.view_ids = [action.view_id[0]]; } @@ -120,10 +119,10 @@ params.search_value = decoder.decode( action.pyson_search_value || '[]'); params.tab_domain = []; - action.domains.forEach(function(element, index) { + for (const element of action.domains) { params.tab_domain.push( [element[0], decoder.decode(element[1]), element[2]]); - }); + } params.context_model = action.context_model; params.context_domain = action.context_domain; if (action.limit !== null) { diff --git a/src/common.js b/src/common.js index 19d4faad66..caffb2fd5d 100644 --- a/src/common.js +++ b/src/common.js @@ -109,15 +109,15 @@ i++; } var result = [[]]; - pools.forEach(function(pool) { + for (const pool of pools) { var tmp = []; - result.forEach(function(x) { - pool.forEach(function(y) { + for (const x of result) { + for (const y of pool) { tmp.push(x.concat([y])); - }); - }); + } + } result = tmp; - }); + } return result; }; @@ -667,9 +667,9 @@ Sao.common.selection_mixin.init_selection = function(value, callback) { if (!value) { value = {}; - (this.attributes.selection_change_with || []).forEach(function(e) { + for (const e of (this.attributes.selection_change_with || [])) { value[e] = null; - }); + } } var key = JSON.stringify(value); var selection = this.attributes.selection || []; @@ -758,17 +758,17 @@ }, record.model.session); prm.done(function(result) { var selection = []; - result.forEach(function(x) { + for (const x of result) { selection.push([x.id, x.rec_name]); - }); + } if (this.nullable_widget) { selection.push([null, '']); } var help = {}; if (help_field){ - result.forEach(function(x) { + for (const x of result) { help[x.id] = x[help_field]; - }); + } } this._last_domain = [domain, context]; this._domain_cache[jdomain] = selection; @@ -1554,7 +1554,7 @@ var cur = tokens[0]; var nex = null; var result = []; - tokens.slice(1).forEach(function(nex) { + for (const nex of tokens.slice(1)) { if ((nex == '=') && cur && ~this.OPERATORS.indexOf(cur + nex)) { result.push(cur + nex); @@ -1565,7 +1565,7 @@ } cur = nex; } - }.bind(this)); + } if (cur !== null) { result.push(cur); } @@ -1575,9 +1575,9 @@ var result = []; var current = result; var parent = []; - tokens.forEach(function(token, i) { + for (const token of tokens) { if (current === undefined) { - return; + continue; } if (token == '(') { parent.push(current); @@ -1587,7 +1587,7 @@ } else { current.push(token); } - }); + } return result; }, group: function(tokens) { @@ -1676,24 +1676,24 @@ _group = _group.bind(this); var parts = []; - tokens.forEach(function(token) { + for (const token of tokens) { if (this.is_generator(token)) { - _group(parts).forEach(function(group) { + for (const group of _group(parts)) { if (!Sao.common.compare(group, [null])) { result.push(group); } - }); + } parts = []; result.push(this.group(token)); } else { parts.push(token); } - }.bind(this)); - _group(parts).forEach(function(group) { + } + for (const group of _group(parts)) { if (!Sao.common.compare(group, [null])) { result.push(group); } - }); + } return result; }, is_generator: function(value) { @@ -2653,11 +2653,11 @@ if (domoperator) { result.push(domoperator); } - domains.forEach(function append(domain) { + for (const domain of domains) { if (!jQuery.isEmptyObject(domain)) { result.push(domain); } - }); + } return this.simplify(this.merge(result)); }, unique_value: function(domain) { @@ -3066,20 +3066,20 @@ from = (from < 0) ? 0 : from; var to = Math.round(idx + this.batchnum / 2); var ids = []; - this.tryton_icons.slice(from, to).forEach(function(e) { + for (const e of this.tryton_icons.slice(from, to)) { ids.push(e[0]); - }); + } var read_prm = icon_model.execute('read', [ids, ['name', 'icon']], {}); return read_prm.then(function(icons) { - icons.forEach(function(icon) { + for (const icon of icons) { var img_url = this._convert(icon.icon); this.loaded_icons[icon.name] = img_url; delete this.name2id[icon.name]; this.tryton_icons.splice( find_array([icon.id, icon.name]), 1); - }.bind(this)); + } }.bind(this)); }.bind(this)); return this.register_prm; @@ -4096,9 +4096,8 @@ 'class': 'btn-group', 'role': 'group' }).appendTo(toolbar); - for (var i in buttons) { - var properties = buttons[i]; - var button = jQuery('', { + for (const properties of buttons) { + const button = jQuery('', { 'class': 'btn btn-default', 'type': 'button', 'title': properties.label, @@ -4144,8 +4143,7 @@ }))); }; }; - for (var i in selections) { - var properties = selections[i]; + for (var properties of selections) { var group = jQuery('
', { 'class': 'btn-group', 'role': 'group' diff --git a/src/model.js b/src/model.js index 8cc9c6f6ca..2b0251ec4b 100644 --- a/src/model.js +++ b/src/model.js @@ -81,10 +81,8 @@ position = this.length; } var new_records = []; - var i, len; - for (i = 0, len = ids.length; i < len; i++) { - var id = ids[i]; - var new_record = this.get(id); + for (const id of ids) { + let new_record = this.get(id); if (!new_record) { new_record = new Sao.Record(this.model, id); new_record.group = this; @@ -95,33 +93,29 @@ } // Remove previously removed or deleted records var record_removed = []; - var record; - for (i = 0, len = this.record_removed.length; i < len; i++) { - record = this.record_removed[i]; + for (const record of this.record_removed) { if (!~ids.indexOf(record.id)) { record_removed.push(record); } } this.record_removed = record_removed; var record_deleted = []; - for (i = 0, len = this.record_deleted.length; i < len; i++) { - record = this.record_deleted[i]; + for (const record of this.record_deleted) { if (!~ids.indexOf(record.id)) { record_deleted.push(record); } } this.record_deleted = record_deleted; if (new_records.length && modified) { - new_records.forEach(function(record) { + for (const record of new_records) { record.modified_fields.id = true; - }); + } this.record_modified(); } }; array.get = function(id) { // TODO optimize - for (var i = 0, len = this.length; i < len; i++) { - var record = this[i]; + for (const record of this) { if (record.id == id) { return record; } @@ -226,9 +220,9 @@ }; array.record_modified = function() { if (!this.parent) { - this.screens.forEach(function(screen) { + for (const screen of this.screens) { screen.record_modified(); - }); + } } else { this.parent.modified_fields[this.child_name] = true; this.parent.model.fields[this.child_name].changed(this.parent); @@ -252,16 +246,16 @@ }); var context = this.context; context._timestamp = {}; - records.forEach(function(record) { + for (const record of records) { jQuery.extend(context._timestamp, record.get_timestamp()); - }); + } var record_ids = records.map(function(record) { return record.id; }); return root_group.on_write_ids(record_ids).then(function(reload_ids) { - records.forEach(function(record) { + for (const record of records) { record.destroy(); - }); + } reload_ids = reload_ids.filter(function(e) { return !~record_ids.indexOf(e); }); @@ -288,9 +282,9 @@ deferreds.push(record.save()); }); if (!jQuery.isEmptyObject(this.record_deleted)) { - this.record_deleted.forEach(function(record) { + for (const record of this.record_deleted) { this._remove(record); - }.bind(this)); + } deferreds.push(this.delete_(this.record_deleted)); this.record_deleted.splice(0, this.record_deleted.length); } @@ -308,15 +302,15 @@ }.bind(this)); }; array.reload = function(ids) { - this.children.forEach(function(child) { + for (const child of this.children) { child.reload(ids); - }); - ids.forEach(function(id) { - var record = this.get(id); + } + for (const id of ids) { + const record = this.get(id); if (record && jQuery.isEmptyObject(record.modified_fields)) { record.cancel(); } - }.bind(this)); + } }; array.on_write_ids = function(ids) { var deferreds = []; @@ -346,17 +340,17 @@ return; } var new_ = []; - this.forEach(function(record) { + for (const record of this) { if (record.id < 0) { new_.push(record); } - }); + } if (new_.length && added.length) { this.model.execute('default_get', [added, this.context]) .then(function(values) { - new_.forEach(function(record) { + for (const record of new_) { record.set_default(values, true, false); - }); + } this.record_modified(); }.bind(this)); } @@ -373,11 +367,11 @@ Object.defineProperty(array, 'domain', { get: function() { var domain = []; - this.screens.forEach(function(screen) { + for (const screen of this.screens) { if (screen.attributes.domain) { domain.push(screen.attributes.domain); } - }); + } if (this.parent && this.child_name) { var field = this.parent.model.fields[this.child_name]; return [domain, field.get_domain(this.parent)]; @@ -487,8 +481,7 @@ } else { cmp = function(a, b) { return a < b; }; } - for (var i=0; i < this.length; i++) { - record = this[i]; + for (const record of this) { if (record.get_loaded([field]) || changed || record.id < 0) { if (prev) { index = prev.field_get(field); @@ -656,15 +649,14 @@ if (name == '*') { loading = 'eager'; views = new Set(); - var views_add = function(view) { - views.add(view); - }; for (fname in this.model.fields) { field = this.model.fields[fname]; if ((field.description.loading || 'eager') == 'lazy') { loading = 'lazy'; } - field.views.forEach(views_add); + for (const view of field.views) { + views.add(view); + } } } else { loading = this.model.fields[name].description.loading || 'eager'; @@ -694,8 +686,7 @@ } var fnames_to_fetch = fnames.slice(); var rec_named_fields = ['many2one', 'one2one', 'reference']; - for (var i in fnames) { - fname = fnames[i]; + for (const fname of fnames) { var fdescription = this.model.fields[fname].description; if (~rec_named_fields.indexOf(fdescription.type)) fnames_to_fetch.push(fname + '.rec_name'); @@ -775,9 +766,9 @@ fnames_to_fetch], context, async); var succeed = function(values, exception=false) { var id2value = {}; - values.forEach(function(e, i, a) { + for (const e of values) { id2value[e.id] = e; - }); + } for (var id in id2record) { if (!id2record.hasOwnProperty(id)) { continue; @@ -805,8 +796,8 @@ default_values = { id: id }; - for (var i in fnames_to_fetch) { - default_values[fnames_to_fetch[i]] = null; + for (const fname of fnames_to_fetch) { + default_values[fname] = null; } failed_values.push(default_values); } @@ -1043,27 +1034,27 @@ _get_on_change_args: function(args) { var result = {}; var values = Sao.common.EvalEnvironment(this, 'on_change'); - args.forEach(function(arg) { + for (const arg of args) { var scope = values; - arg.split('.').forEach(function(e) { + for (const e of arg.split('.')) { if (scope !== undefined) { scope = scope[e]; } - }); + } result[arg] = scope; - }); + } return result; }, on_change: function(fieldnames) { var values = {}; - fieldnames.forEach(function(fieldname) { + for (const fieldname of fieldnames) { var on_change = this.model.fields[fieldname] .description.on_change; if (!jQuery.isEmptyObject(on_change)) { values = jQuery.extend(values, this._get_on_change_args(on_change)); } - }.bind(this)); + } if (!jQuery.isEmptyObject(values)) { var changes; try { @@ -1294,11 +1285,11 @@ get_loaded: function(fields) { if (!jQuery.isEmptyObject(fields)) { var result = true; - fields.forEach(function(field) { + for (const field of fields) { if (!(field in this._loaded) && !(field in this.modified_fields)) { result = false; } - }.bind(this)); + } return result; } return Sao.common.compare(Object.keys(this.model.fields).sort(), @@ -1454,8 +1445,7 @@ }, destroy: function() { var vals = Object.values(this._values); - for (var i=0; i < vals.length; i++) { - var val = vals[i]; + for (const val of vals) { if (val && val.hasOwnProperty('destroy')) { val.destroy(); } @@ -1621,9 +1611,9 @@ record, states=['readonly', 'required', 'invisible']) { var state_changes = record.expr_eval( this.description.states || {}); - states.forEach(function(state) { + for (const state of states) { if ((state == 'readonly') && this.description.readonly) { - return; + continue; } if (state_changes[state] !== undefined) { this.get_state_attrs(record)[state] = state_changes[state]; @@ -1631,7 +1621,7 @@ this.get_state_attrs(record)[state] = this.description[state]; } - }.bind(this)); + } if (record.group.readonly || this.get_state_attrs(record).domain_readonly) { this.get_state_attrs(record).readonly = true; @@ -1707,11 +1697,10 @@ var localpart = leftpart.split('.', 1)[1]; var constraintfields = []; if (domain_readonly) { - inversion.localize_domain( - original_domain.slice(1)) - .forEach(function(leaf) { - constraintfields.push(leaf); - }); + for (const leaf of inversion.localize_domain( + original_domain.slice(1))) { + constraintfields.push(leaf); + } } if ((localpart != 'id') || !~constraintfields.indexOf(recordpart)) { @@ -2124,17 +2113,14 @@ if (mode == 'list values') { var context = this.get_context(record); var field_names = {}; - value.forEach(function(val) { - for (var fieldname in val) { - if (!val.hasOwnProperty(fieldname)) { - continue; - } + for (const val of value) { + for (var fieldname of val) { if (!(fieldname in group.model.fields) && (!~fieldname.indexOf('.'))) { field_names[fieldname] = true; } } - }); + } if (!jQuery.isEmptyObject(field_names)) { var args = { 'method': 'model.' + this.description.relation + @@ -2152,19 +2138,17 @@ } if (mode == 'list ids') { var records_to_remove = []; - for (var i = 0, len = group.length; i < len; i++) { - var old_record = group[i]; + for (const old_record of group) { if (!~value.indexOf(old_record.id)) { records_to_remove.push(old_record); } } - for (i = 0, len = records_to_remove.length; i < len; i++) { - var record_to_remove = records_to_remove[i]; + for (const record_to_remove of records_to_remove) { group.remove(record_to_remove, true, true, false, false); } group.load(value, modified || default_); } else { - value.forEach(function(vals) { + for (const vals of value) { var new_record = group.new_(false); if (default_) { // Don't validate as parent will validate @@ -2174,7 +2158,7 @@ new_record.set(vals); group.push(new_record); } - }); + } } }, set: function(record, value, _default=false) { @@ -2204,8 +2188,7 @@ var to_add = []; var to_create = []; var to_write = []; - for (var i = 0, len = group.length; i < len; i++) { - var record2 = group[i]; + for (const record2 of group) { if (~record_removed.indexOf(record2) || ~record_deleted.indexOf(record2)) { continue; @@ -2287,29 +2270,29 @@ if (value instanceof Array) { return this._set_value(record, value, false, true); } + var new_field_names = {}; if (value.add || value.update) { var context = this.get_context(record); fields = record._values[this.name].model.fields; - var new_field_names = {}; var adding_values = []; if (value.add) { - for (var i=0; i < value.add.length; i++) { - adding_values.push(value.add[i][1]); + for (const add of value.add) { + adding_values.push(add[1]); } } - [adding_values, value.update].forEach(function(l) { + for (const l of [adding_values, value.update]) { if (!jQuery.isEmptyObject(l)) { - l.forEach(function(v) { - Object.keys(v).forEach(function(f) { + for (const v of l) { + for (const f of Object.keys(v)) { if (!(f in fields) && (f != 'id') && (!~f.indexOf('.'))) { new_field_names[f] = true; } - }); - }); + } + } } - }); + } if (!jQuery.isEmptyObject(new_field_names)) { var args = { 'method': 'model.' + this.description.relation + @@ -2328,31 +2311,31 @@ var group = record._values[this.name]; if (value.delete) { - value.delete.forEach(function(record_id) { - var record2 = group.get(record_id); + for (const record_id of value.delete) { + const record2 = group.get(record_id); if (record2) { group.remove(record2, false, true, false, false); } - }.bind(this)); + } } if (value.remove) { - value.remove.forEach(function(record_id) { - var record2 = group.get(record_id); + for (const record_id of value.remove) { + const record2 = group.get(record_id); if (record2) { group.remove(record2, true, true, false, false); } - }.bind(this)); + } } if (value.add || value.update) { // First set already added fields to prevent triggering a // second on_change call if (value.update) { - value.update.forEach(function(vals) { + for (const vals of value.update) { if (!vals.id) { - return; + continue; } - var record2 = group.get(vals.id); + const record2 = group.get(vals.id); if (record2) { var vals_to_set = {}; for (var key in vals) { @@ -2362,16 +2345,16 @@ } record2.set_on_change(vals_to_set); } - }); + } } group.add_fields(new_fields); if (value.add) { - value.add.forEach(function(vals) { - var new_record; - var index = vals[0]; - var data = vals[1]; - var id_ = data.id; + for (const vals of value.add) { + let new_record; + const index = vals[0]; + const data = vals[1]; + const id_ = data.id; delete data.id; if (id_) { new_record = group.get(id_); @@ -2381,18 +2364,18 @@ } group.add(new_record, index, false); new_record.set_on_change(data); - }); + } } if (value.update) { - value.update.forEach(function(vals) { + for (const vals of value.update) { if (!vals.id) { - return; + continue; } - var record2 = group.get(vals.id); + const record2 = group.get(vals.id); if (record2) { record2.set_on_change(vals); } - }); + } } } }, @@ -2420,11 +2403,10 @@ var records = group.filter(function(record) { return record.modified; }); - var record2; - jQuery.extend(records, group.record_removed, group.record_deleted) - .forEach(function(record) { + for (const record of jQuery.extend( + records, group.record_removed, group.record_deleted)) { jQuery.extend(timestamps, record.get_timestamp()); - }); + } return timestamps; }, get_eval: function(record) { @@ -2434,9 +2416,7 @@ var record_removed = group.record_removed; var record_deleted = group.record_deleted; - for (var i = 0, len = record._values[this.name].length; i < len; - i++) { - var record2 = group[i]; + for (const record2 of group) { if (~record_removed.indexOf(record2) || ~record_deleted.indexOf(record2)) continue; @@ -2448,9 +2428,7 @@ var result = []; var group = record._values[this.name]; if (group === undefined) return result; - for (var i = 0, len = record._values[this.name].length; i < len; - i++) { - var record2 = group[i]; + for (const record2 of group) { if (!record2.deleted && !record2.removed) result.push(record2.get_on_change_value( [this.description.relation_field || ''])); @@ -2485,9 +2463,7 @@ ldomain = [['id', '=', null]]; } } - for (var i = 0, len = (record._values[this.name] || []).length; - i < len; i++) { - var record2 = record._values[this.name][i]; + for (const record2 of (record._values[this.name] || [])) { if (!record2.get_loaded() && (record2.id >= 0) && !pre_validate) { continue; @@ -2775,8 +2751,7 @@ keys = jQuery.extend([], keys); var update_keys = function(values) { - for (var i = 0, len = values.length; i < len; i++) { - var k = values[i]; + for (const k of values) { this.keys[k.name] = k; } }.bind(this); @@ -2797,10 +2772,10 @@ return this.schema_model.execute('get_keys', [ids], context) .then(function(new_fields) { var names = []; - new_fields.forEach(function(new_field) { + for (const new_field of new_fields) { this.keys[new_field.name] = new_field; names.push(new_field.name); - }.bind(this)); + } return names; }.bind(this)); }, diff --git a/src/pyson.js b/src/pyson.js index 4d65b20b7d..1694b37528 100644 --- a/src/pyson.js +++ b/src/pyson.js @@ -311,8 +311,7 @@ Sao.PYSON.And.eval_ = function(value, context) { var result = true; - for (var i = 0, len = value.s.length; i < len; i++) { - var statement = value.s[i]; + for (const statement of value.s) { result = result && statement; } return result; @@ -335,8 +334,7 @@ Sao.PYSON.Or.eval_ = function(value, context) { var result = false; - for (var i = 0, len = value.s.length; i < len; i++) { - var statement = value.s[i]; + for (const statement of value.s) { result = result || statement; } return result; diff --git a/src/sao.js b/src/sao.js index 77528215ce..3121357d96 100644 --- a/src/sao.js +++ b/src/sao.js @@ -95,9 +95,9 @@ var Sao = {}; // Implementation is not strictly equivalent but works for most // cases var result = []; - value.forEach(function(e) { + for (const e of value) { result.push(e); - }); + } return result; }; } @@ -404,9 +404,9 @@ var Sao = {}; deferreds.push(Sao.common.MODELHISTORY.load_history()); deferreds.push(Sao.common.VIEW_SEARCH.load_searches()); return jQuery.when.apply(jQuery, deferreds).then(function() { - (preferences.actions || []).forEach(function(action_id) { + for (const action_id of (preferences.actions || [])) { Sao.Action.execute(action_id, {}, null, {}); - }); + } Sao.set_title(); var new_lang = preferences.language != Sao.i18n.getLocale(); var prm = jQuery.Deferred(); @@ -465,8 +465,7 @@ var Sao = {}; } } else { url = decodeURIComponent(url); - for (var i = 0; i < Sao.Tab.tabs.length; i++) { - tab = Sao.Tab.tabs[i]; + for (const tab of Sao.Tab.tabs) { if (decodeURIComponent(tab.get_url()) == url) { tab.show(); return; @@ -487,12 +486,12 @@ var Sao = {}; var path, params = {}; if (i >= 0) { path = url.substring(0, i); - url.substring(i + 1).split('&').forEach(function(part) { + for (const part of url.substring(i + 1).split('&')) { if (part) { var item = part.split('=').map(decodeURIComponent); params[item[0]] = item[1]; } - }); + } } else { path = url; } @@ -984,18 +983,18 @@ var Sao = {}; [text, Sao.config.limit, Sao.main_menu_screen.model_name], Sao.main_menu_screen.context) .then(function(s_results) { - var results = []; - for (var i=0, len=s_results.length; i < len; i++) { - results.push({ - 'model': s_results[i][1], - 'model_name': s_results[i][2], - 'record_id': s_results[i][3], - 'record_name': s_results[i][4], - 'icon': s_results[i][5], - }); - } - return results; - }.bind(this)); + var results = []; + for (const result of s_results) { + results.push({ + 'model': result[1], + 'model_name': result[2], + 'record_id': result[3], + 'record_name': result[4], + 'icon': result[5], + }); + } + return results; + }.bind(this)); }, match_selected: function(item) { if (item.model == Sao.main_menu_screen.model_name) { @@ -1175,7 +1174,7 @@ var Sao = {}; .text(Sao.i18n.gettext('Tab shortcuts'))) .appendTo(row); - shortcuts_defs().forEach(function(definition) { + for (const definition of shortcuts_defs()) { var dt = jQuery('').text(definition.label); var dd = jQuery('').append(jQuery('') .text(definition.shortcut)); @@ -1187,7 +1186,7 @@ var Sao = {}; } dt.appendTo(dest_dl); dd.appendTo(dest_dl); - }); + } dialog.modal.on('hidden.bs.modal', function() { jQuery(this).remove(); }); diff --git a/src/screen.js b/src/screen.js index c16cf0b4ac..04608a001a 100644 --- a/src/screen.js +++ b/src/screen.js @@ -101,9 +101,9 @@ this.but_bookmark.click(function() { dropdown_bookmark.empty(); var bookmarks = this.bookmarks(); - for (var i=0; i < bookmarks.length; i++) { - var name = bookmarks[i][1]; - var domain = bookmarks[i][2]; + for (const bookmark of bookmarks) { + const name = bookmark[1]; + const domain = bookmark[2]; jQuery('', { 'role': 'presentation' }) @@ -228,11 +228,11 @@ var completions = this.screen.domain_parser.completion( this.get_text()); this.search_list.empty(); - completions.forEach(function(e) { + for (const e of completions) { jQuery('', { 'value': e.trim() }).appendTo(this.search_list); - }, this); + } }, set_star: function(star) { var img = this.but_star.children('img'); @@ -306,12 +306,12 @@ current_text); var star = this.get_star(); var bookmarks = this.bookmarks(); - for (var i=0; i < bookmarks.length; i++) { - var id = bookmarks[i][0]; - var name = bookmarks[i][1]; - var domain = bookmarks[i][2]; - var access = bookmarks[i][3]; - var text = this.screen.domain_parser.string(domain); + for (const bookmark of bookmarks) { + const id = bookmark[0]; + const name = bookmark[1]; + const domain = bookmark[2]; + const access = bookmark[3]; + const text = this.screen.domain_parser.string(domain); if ((text === current_text) || (Sao.common.compare(domain, current_domain))) { this.set_star(true); @@ -428,10 +428,10 @@ this.search_modal.modal('hide'); var text = ''; var quote = domain_parser.quote.bind(domain_parser); - for (var i = 0; i < this.search_form.fields.length; i++) { - var label = this.search_form.fields[i][0]; - var entry = this.search_form.fields[i][1]; - var value; + for (const field of this.search_form.fields) { + const label = field[0]; + const entry = field[1]; + let value; if ((entry instanceof Sao.ScreenContainer.Between) || (entry instanceof Sao.ScreenContainer.Selection)) { value = entry.get_value(quote); @@ -459,36 +459,17 @@ }); var fields = []; - var field; for (var f in domain_parser.fields) { - field = domain_parser.fields[f]; + const field = domain_parser.fields[f]; if ((field.searchable || field.searchable === undefined) && !field.name.contains('.')) { fields.push(field); } } - var boolean_option = function(input) { - return function(e) { - jQuery('', { - value: e, - text: e - }).appendTo(input); - }; - }; - var selection_option = function(input) { - return function(s) { - jQuery('', { - value: s[1], - text: s[1] - }).appendTo(input); - }; - }; - var prefix = 'filter-' + this.screen.model_name + '-'; this.search_form.fields = []; - for (var i = 0; i < fields.length; i++) { - field = fields[i]; + for (const field of fields) { var form_group = jQuery('', { 'class': 'form-group form-group-sm' }).append(jQuery('', { @@ -506,10 +487,15 @@ 'class': 'form-control input-sm', id: prefix + field.name }); - ['', - Sao.i18n.gettext('True'), - Sao.i18n.gettext('False')].forEach( - boolean_option(input)); + for (const e of [ + '', + Sao.i18n.gettext('True'), + Sao.i18n.gettext('False')]) { + jQuery('', { + value: e, + text: e + }).appendTo(input); + } break; case 'selection': case 'multiselection': @@ -775,12 +761,12 @@ multiple: true, id: id }); - selections.forEach(function(s) { + for (const s of selections) { jQuery('', { value: s[1], text: s[1] }).appendTo(this.el); - }.bind(this)); + } }, get_value: function(quote) { var value = this.el.val(); @@ -1232,12 +1218,11 @@ this.current_record = null; } this.group.add_fields(fields); - var views_add = function(view) { - this.group.model.fields[name].views.add(view); - }.bind(this); for (name in fields_views) { var views = fields_views[name]; - views.forEach(views_add); + for (const view of views) { + this.group.model.fields[name].views.add(view); + } } this.group.exclude_field = this.exclude_field; }, @@ -1250,35 +1235,35 @@ this.set_group(group); }, record_modified: function(display=true) { - this.windows.forEach(function(window_) { + for (const window_ of this.windows) { if (window_.record_modified) { window_.record_modified(); } - }); + } if (display) { return this.display(); } }, record_message: function(position, size, max_size, record_id) { - this.windows.forEach(function(window_) { + for (const window_ of this.windows) { if (window_.record_message) { window_.record_message(position, size, max_size, record_id); } - }); + } }, record_saved: function() { - this.windows.forEach(function(window_) { + for (const window_ of this.windows) { if (window_.record_saved) { window_.record_saved(); } - }); + } }, update_resources: function(resources) { - this.windows.forEach(function(window_) { + for (const window_ of this.windows) { if (window_.update_resources) { window_.update_resources(resources); } - }); + } }, has_update_resources: function() { return this.windows.some(function(window_) { @@ -1345,11 +1330,11 @@ ~['tree', 'graph', 'calendar'].indexOf( this.current_view.view_type)); deferreds.push(search_prm); - for (var i = 0; i < this.views.length; i++) { - if (this.views[i] && - ((this.views[i] == this.current_view) || - this.views[i].el.parent().length)) { - deferreds.push(this.views[i].display()); + for (const view of this.views) { + if (view && + ((view == this.current_view) || + view.el.parent().length)) { + deferreds.push(view.display()); } } } @@ -1639,9 +1624,9 @@ }, unremove: function() { var records = this.current_view.selected_records; - records.forEach(function(record) { + for (const record of records) { record.group.unremove(record); - }); + } }, remove: function(delete_, remove, force_remove, records) { var prm = jQuery.when(); @@ -1658,14 +1643,14 @@ var idx = top_group.indexOf(top_record); var path = top_record.get_path(this.group); return prm.then(function() { - records.forEach(function(record) { + for (const record of records) { record.group.remove(record, remove, true, force_remove, false); - }); + } // trigger changed only once records[0].group.record_modified(); var prms = []; if (delete_) { - records.forEach(function(record) { + for (const record of records) { if (record.group.parent) { prms.push(record.group.parent.save(false)); } @@ -1678,7 +1663,7 @@ record.group.record_removed.indexOf(record), 1); } // TODO destroy - }); + } } if (idx > 0) { var record = top_group[idx - 1]; @@ -1767,11 +1752,11 @@ // take only the first definition if (!(name in dom_fields)) { dom_fields[name] = fields[name]; - ['string', 'factor'].forEach(function(attr) { + for (const attr of ['string', 'factor']) { if (node.getAttribute(attr)) { dom_fields[name][attr] = node.getAttribute(attr); } - }); + } } var symbol = node.getAttribute('symbol'); if (symbol && !(symbol in dom_fields)) { @@ -1789,27 +1774,25 @@ } // Add common fields - [ + const common_fields = new Map([ ['id', Sao.i18n.gettext('ID'), 'integer'], ['create_uid', Sao.i18n.gettext('Created by'), 'many2one'], ['create_date', Sao.i18n.gettext('Created at'), 'datetime'], ['write_uid', Sao.i18n.gettext('Modified by'), 'many2one'], ['write_date', Sao.i18n.gettext('Modified at'), 'datetime'] - ] .forEach(function(e) { - var name = e[0]; - var string = e[1]; - var type = e[2]; - if (!(name in fields)) { - fields[name] = { - 'string': string, - 'name': name, - 'type': type - }; - if (type == 'datetime') { - fields[name].format = '"%H:%M:%S"'; - } - } - }); + ]); + for (const [name, string, type] of common_fields) { + if (!(name in fields)) { + fields[name] = { + 'string': string, + 'name': name, + 'type': type + }; + if (type == 'datetime') { + fields[name].format = '"%H:%M:%S"'; + } + } + } domain_parser = new Sao.common.DomainParser(fields, this.context); this._domain_parser[view_id] = domain_parser; @@ -1820,9 +1803,9 @@ var change_with = props.selection_change_with; if (!jQuery.isEmptyObject(change_with)) { var values = {}; - change_with.forEach(function(p) { + for (const p of change_with) { values[p] = null; - }); + } selection = this.model.execute(props.selection, [values], undefined, false); } else { @@ -1857,32 +1840,30 @@ var domain_parser = new Sao.common.DomainParser(fields_desc); var fields = []; var invalid_fields = record.invalid_fields(); - Object.keys(invalid_fields).sort().forEach( - function(field) { - var invalid = invalid_fields[field]; - var string = record.model.fields[field].description.string; - if ((invalid == 'required') || - (Sao.common.compare(invalid, - [[field, '!=', null]]))) { - fields.push(Sao.i18n.gettext( - '"%1" is required.', string)); - } else if (invalid == 'domain') { - fields.push(Sao.i18n.gettext( - '"%1" is not valid according to its domain.', - string)); - } else if (invalid == 'children') { - fields.push(Sao.i18n.gettext( - 'The values of "%1" are not valid.', string)); + for (const field of Object.keys(invalid_fields).sort()) { + var invalid = invalid_fields[field]; + var string = record.model.fields[field].description.string; + if ((invalid == 'required') || + (Sao.common.compare(invalid, [[field, '!=', null]]))) { + fields.push(Sao.i18n.gettext( + '"%1" is required.', string)); + } else if (invalid == 'domain') { + fields.push(Sao.i18n.gettext( + '"%1" is not valid according to its domain.', + string)); + } else if (invalid == 'children') { + fields.push(Sao.i18n.gettext( + 'The values of "%1" are not valid.', string)); + } else { + if (domain_parser.stringable(invalid)) { + fields.push(domain_parser.string(invalid)); } else { - if (domain_parser.stringable(invalid)) { - fields.push(domain_parser.string(invalid)); - } else { - fields.push(Sao.i18n.gettext( - '"%1" is not valid according to its domain.'), - string); - } + fields.push(Sao.i18n.gettext( + '"%1" is not valid according to its domain.'), + string); } - }); + } + } if (fields.length > 5) { fields.splice(5, fields.length); fields.push('...'); @@ -1922,7 +1903,7 @@ return []; } var buttons = this.current_view.get_buttons(); - selected_records.forEach(function(record) { + for (const record of selected_records) { buttons = buttons.filter(function(button) { if (button.attributes.type === 'instance') { return false; @@ -1931,7 +1912,7 @@ button.attributes.states || {}); return !(states.invisible || states.readonly); }); - }); + } return buttons; }, button: function(attributes) { @@ -1963,9 +1944,8 @@ record.validate(fields); }.bind(this); }.bind(this); - for (var i = 0; i < selected_records.length; i++) { - var record = selected_records[i]; - var domain = record.expr_eval( + for (const record of selected_records) { + const domain = record.expr_eval( (attributes.states || {})).pre_validate || []; prms.push(record.validate(fields, false, domain)); } @@ -1996,10 +1976,10 @@ this.context).then(function(changes) { record.set_on_change(changes); record.set_modified(); - record.group.root_group.screens.forEach( - function(screen) { - screen.display(); - }); + for (const screen of + record.group.root_group.screens) { + screen.display(); + } }); } else { return record.save(false).then(function() { @@ -2248,8 +2228,8 @@ return view.display(selected_nodes, expanded_nodes); } else { if (!jQuery.isEmptyObject(selected_nodes)) { - for (var i = 0; i < selected_nodes[0].length; i++) { - var new_record = this.group.get(selected_nodes[0][i]); + for (const id of selected_nodes[0]) { + const new_record = this.group.get(id); if (!new_record) { break; } else { diff --git a/src/session.js b/src/session.js index dd20fa9048..6fda9bb474 100644 --- a/src/session.js +++ b/src/session.js @@ -286,12 +286,12 @@ el = dialog.database_input; } else { el = dialog.database_select; - databases.forEach(function(database) { + for (const database of databases) { el.append(jQuery('', { 'value': database, 'text': database })); - }); + } } el.prop('readonly', databases.length == 1); el.show(); diff --git a/src/tab.js b/src/tab.js index 38fe763dd5..a8676f6f46 100644 --- a/src/tab.js +++ b/src/tab.js @@ -376,8 +376,7 @@ if (attributes.context === undefined) { attributes.context = {}; } - for (var i = 0; i < Sao.Tab.tabs.length; i++) { - var other = Sao.Tab.tabs[i]; + for (const other of Sao.Tab.tabs) { if (other.compare(attributes)) { tablist.find('a[href="#' + other.id + '"]') .tab('show')[0].scrollIntoView(); @@ -609,18 +608,17 @@ }); var kw_plugins = []; - Sao.Plugins.forEach(function(plugin) { - plugin.get_plugins(screen.model.name).forEach( - function(spec) { - var name = spec[0], - func = spec[1], - keyword = spec[2] || 'action'; - if (keyword != menu_action[0]) { - return; - } + for (const plugin of Sao.Plugins) { + for (const spec of plugin.get_plugins( + screen.model.name)) { + var name = spec[0], + func = spec[1], + keyword = spec[2] || 'action'; + if (keyword == menu_action[0]) { kw_plugins.push([name, func]); - }); - }); + } + } + } if (kw_plugins.length) { menu.append(jQuery('', { 'role': 'separator', @@ -861,12 +859,12 @@ return this.screen.search_filter( this.screen.screen_container.search_entry.val()) .then(function() { - this.screen.group.forEach(function(record) { + for (const record of this.screen.group) { if (record.id == record_id) { this.screen.current_record = record; set_cursor = true; } - }.bind(this)); + } return set_cursor; }.bind(this)); } @@ -975,15 +973,15 @@ .then(function(data) { data = data[0]; var message = ''; - fields.forEach(function(field) { - var key = field[0]; - var label = field[1]; - var value = data; - var keys = key.split('.'); - var name = keys.splice(-1); - keys.forEach(function(key) { + for (const field of fields) { + const key = field[0]; + const label = field[1]; + let value = data; + const keys = key.split('.'); + const name = keys.splice(-1); + for (const key of keys) { value = value[key + '.'] || {}; - }); + } value = (value || {})[name] || '/'; if (value && value.isDateTime) { value = Sao.common.format_datetime( @@ -991,7 +989,7 @@ value); } message += label + ' ' + value + '\n'; - }); + } message += Sao.i18n.gettext('Model: ') + this.screen.model.name; Sao.common.message.run(message); }.bind(this)); @@ -1063,14 +1061,14 @@ set_buttons_sensitive: function(revision) { if (!revision) { var access = Sao.common.MODELACCESS.get(this.screen.model_name); - [['new_', access.create], - ['save', access.create || access.write], - ['delete_', access.delete], - ['copy', access.create], - ['import', access.create], - ].forEach(function(e) { - var name = e[0]; - var access = e[1]; + const accesses = new Map([ + ['new_', access.create], + ['save', access.create || access.write], + ['delete_', access.delete], + ['copy', access.create], + ['import', access.create], + ]); + for (const [name, access] of accesses) { if (this.buttons[name]) { this.buttons[name].prop('disabled', !access); } @@ -1078,17 +1076,17 @@ this.menu_buttons[name] .toggleClass('disabled', !access); } - }.bind(this)); + } } else { - ['new_', 'save', 'delete_', 'copy', 'import'].forEach( - function(name) { - if (this.buttons[name]) { - this.buttons[name].prop('disabled', true); - } - if (this.menu_buttons[name]) { - this.menu_buttons[name].addClass('disabled'); - } - }.bind(this)); + for (const name of [ + 'new_', 'save', 'delete_', 'copy', 'import']) { + if (this.buttons[name]) { + this.buttons[name].prop('disabled', true); + } + if (this.menu_buttons[name]) { + this.menu_buttons[name].addClass('disabled'); + } + } } }, attach: function(evt) { @@ -1239,24 +1237,22 @@ var window_ = new Sao.Window.Attachment(record, function() { this.refresh_resources(true); }.bind(this)); - files.forEach(function(file) { - Sao.common.get_file_data(file, function(data, filename) { - window_.add_data(data, filename); - }); - }); + for (const file of files) { + Sao.common.get_file_data(file, window_.add_data); + } jQuery.when.apply(jQuery, uris).then(function() { function empty(value) { return Boolean(value); } - for (var i = 0; i < arguments.length; i++) { - arguments[i].split('\r\n') + for (const argument of arguments) { + argument.split('\r\n') .filter(empty) .forEach(window_.add_uri, window_); } }); jQuery.when.apply(jQuery, texts).then(function() { - for (var i = 0; i < arguments.length; i++) { - window_.add_text(arguments[i]); + for (const argument of arguments) { + window_.add_text(argument); } }); if (evt.dataTransfer.items) { @@ -1371,8 +1367,7 @@ .then(function(toolbars) { var prints = toolbars.print.filter(is_report); var emails = {}; - for (var i = 0; i < toolbars.emails.length; i++) { - var email = toolbars.emails[i]; + for (const email of toolbars.emails) { emails[email.name] = email.id; } record.rec_name().then(function(rec_name) { @@ -1476,9 +1471,9 @@ } } var buttons = ['print', 'relate', 'email', 'save', 'attach']; - buttons.forEach(function(button_id){ - var button = this.buttons[button_id]; - var can_be_sensitive = button._can_be_sensitive; + for (const button_id of buttons) { + const button = this.buttons[button_id]; + let can_be_sensitive = button._can_be_sensitive; if (can_be_sensitive === undefined) { can_be_sensitive = true; } @@ -1494,7 +1489,7 @@ can_be_sensitive &= !this.screen.readonly; } set_sensitive(button_id, position && can_be_sensitive); - }.bind(this)); + } set_sensitive('switch_', this.screen.number_of_views > 1); set_sensitive('delete_', this.screen.deletable); set_sensitive('previous', position > (this.screen.offset + 1)); diff --git a/src/view.js b/src/view.js index 80740d01e2..5d7b4031e5 100644 --- a/src/view.js +++ b/src/view.js @@ -20,8 +20,7 @@ this.state_widgets = []; var attributes = xml.children()[0].attributes; this.attributes = {}; - for (var i = 0, len = attributes.length; i < len; i++) { - var attribute = attributes[i]; + for (const attribute of attributes) { this.attributes[attribute.name] = attribute.value; } screen.set_on_write(this.attributes.on_write); @@ -102,8 +101,7 @@ }, _node_attributes: function(node) { var node_attrs = {}; - for (var i = 0; i < node.attributes.length; i++) { - var attribute = node.attributes[i]; + for (var attribute of node.attributes) { node_attrs[attribute.name] = attribute.value; } @@ -112,22 +110,24 @@ field = this.field_attrs[node_attrs.name] || {}; } - ['readonly', 'homogeneous'].forEach(function(name) { + for (const name of ['readonly', 'homogeneous']) { if (node_attrs[name]) { node_attrs[name] = node_attrs[name] == 1; } - }); - ['yexpand', 'yfill', 'xexpand', 'xfill', 'colspan', - 'position', 'height', 'width'].forEach(function(name) { - if (node_attrs[name]) { - node_attrs[name] = Number(node_attrs[name]); - } - }); - ['xalign', 'yalign'].forEach(function(name) { + } + for (const name of [ + 'yexpand', 'yfill', + 'xexpand', 'xfill', + 'colspan', 'position', 'height', 'width']) { if (node_attrs[name]) { node_attrs[name] = Number(node_attrs[name]); } - }); + } + for (const name of ['xalign', 'yalign']) { + if (node_attrs[name]) { + node_attrs[name] = Number(node_attrs[name]); + } + } if (!jQuery.isEmptyObject(field)) { if (!node_attrs.widget) { @@ -141,17 +141,17 @@ node_attrs.help = field.help; } - ['relation', 'domain', 'selection', 'string', 'states', + for (const name of [ + 'relation', 'domain', 'selection', 'string', 'states', 'relation_field', 'views', 'invisible', 'add_remove', 'sort', 'context', 'size', 'filename', 'autocomplete', 'translate', 'create', 'delete', 'selection_change_with', 'schema_model', 'required', 'help_selection', 'help_field', - 'order', 'symbol', 'monetary', - ].forEach(function(name) { - if ((name in field) && (!(name in node_attrs))) { - node_attrs[name] = field[name]; - } - }); + 'order', 'symbol', 'monetary']) { + if ((name in field) && (!(name in node_attrs))) { + node_attrs[name] = field[name]; + } + } } return node_attrs; }, diff --git a/src/view/calendar.js b/src/view/calendar.js index c179120808..72dc289906 100644 --- a/src/view/calendar.js +++ b/src/view/calendar.js @@ -5,9 +5,9 @@ Sao.View.CalendarXMLViewParser = Sao.class_(Sao.View.XMLViewParser, { _parse_calendar: function(node, attributes) { - [].forEach.call(node.childNodes, function(child) { + for (const child of node.childNodes) { this.parse(child); - }.bind(this)); + } var view_week; if (this.view.screen.model.fields[attributes.dtstart] @@ -138,10 +138,9 @@ model_access.write); var description = []; - for (var i = 1; i < this.fields.length; i++) { + for (const field of this.fields) { description.push( - this.screen.model.fields[this.fields[i]].get_client( - record)); + this.screen.model.fields[field].get_client( record)); } description = description.join('\n'); if (date_start) { @@ -191,9 +190,9 @@ prm.then(function() { this.group.forEach(function(record) { var record_promisses = []; - this.fields.forEach(function(name) { + for (const name of this.fields) { record_promisses.push(record.load(name)); - }); + } var prm = jQuery.when.apply(jQuery, record_promisses).then( function(){ this.insert_event(record); diff --git a/src/view/form.js b/src/view/form.js index 41ea1c1a9f..f38bb7c7e6 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -42,9 +42,9 @@ function eval_pyson(value){ if (container) { this._containers.push(container); } - [].forEach.call(node.childNodes, function(child) { + for (const child of node.childNodes) { this.parse(child); - }.bind(this)); + } if (container) { this._containers.pop(); } @@ -308,13 +308,12 @@ function eval_pyson(value){ var record = this.record; var field; var depends; - var name; var promesses = []; if (record) { // Force to set fields in record // Get first the lazy one from the view to reduce number of requests var field_names = new Set(this.get_fields()); - for (name in record.model.fields) { + for (const name in record.model.fields) { field = record.model.fields[name]; if (~field.views.has(this.view_id)) { field_names.add(name); @@ -322,14 +321,14 @@ function eval_pyson(value){ } var fields = []; - field_names.forEach(function(fname) { + for (const fname of field_names) { field = record.model.fields[fname]; fields.push([ fname, field.description.loading || 'eager' == 'eager', field.views.size, ]); - }); + } fields.sort(function(a, b) { if (!a[1] && b[1]) { return -1; @@ -339,18 +338,15 @@ function eval_pyson(value){ return a[2] - b[2]; } }); - fields.forEach(function(e) { - var name = e[0]; + for (const e of fields) { + const name = e[0]; promesses.push(record.load(name)); - }); + } } - var display = function(widget) { - widget.display(); - }; return jQuery.when.apply(jQuery,promesses) .done(function() { var record = this.record; - for (name in this.widgets) { + for (const name in this.widgets) { var widgets = this.widgets[name]; field = null; if (record) { @@ -359,7 +355,9 @@ function eval_pyson(value){ if (field) { field.set_state(record); } - widgets.forEach(display); + for (const widget of widgets) { + widget.display(); + } } }.bind(this)) .done(function() { @@ -378,14 +376,13 @@ function eval_pyson(value){ set_value: function() { var record = this.record; if (record) { - var set_value = function(widget) { - widget.set_value(record, this); - }; for (var name in this.widgets) { if (name in record.model.fields) { var widgets = this.widgets[name]; var field = record.model.fields[name]; - widgets.forEach(set_value, field); + for (const widget of widgets) { + widget.set_value(record, field); + } } } } @@ -404,8 +401,8 @@ function eval_pyson(value){ get modified() { for (var name in this.widgets) { var widgets = this.widgets[name]; - for (var i=0; i < widgets.length; i++) { - if (widgets[i].modified) { + for (const widget of widgets) { + if (widget.modified) { return true; } } @@ -594,7 +591,6 @@ function eval_pyson(value){ var widths = []; var col = this.col; var has_expand = false; - var i, j; var parent_max_width = 0.9; this.el.parents('td').each(function() { @@ -607,7 +603,7 @@ function eval_pyson(value){ var get_xexpands = function(row) { row = jQuery(row); var xexpands = []; - i = 0; + let i = 0; row.children().map(function() { var cell = jQuery(this); var colspan = Math.min(Number(cell.attr('colspan')), col); @@ -638,19 +634,19 @@ function eval_pyson(value){ return b.length - a.length; } }); - rows.forEach(function(row) { + for (let row of rows) { row = jQuery(row); var xexpands = get_xexpands(row); - var width = 100 / xexpands.length; - xexpands.forEach(function(e) { + const width = 100 / xexpands.length; + for (const e of xexpands) { var cell = e[0]; - i = e[1]; - var colspan = Math.min(Number(cell.attr('colspan')), col); + let i = e[1]; + const colspan = Math.min(Number(cell.attr('colspan')), col); var current_width = 0; - for (j = 0; j < colspan; j++) { + for (let j = 0; j < colspan; j++) { current_width += widths[i + j] || 0; } - for (j = 0; j < colspan; j++) { + for (let j = 0; j < colspan; j++) { if (!current_width) { widths[i + j] = width / colspan; } else if (current_width > width) { @@ -663,22 +659,22 @@ function eval_pyson(value){ } } } - }); + } if (!jQuery.isEmptyObject(xexpands)) { has_expand = true; } - }); - rows.forEach(function(row) { + } + for (let row of rows) { row = jQuery(row); - i = 0; - row.children().map(function() { - var cell = jQuery(this); - var colspan = Math.min(Number(cell.attr('colspan')), col); + let i = 0; + for (let cell of row.children()) { + cell = jQuery(cell); + const colspan = Math.min(Number(cell.attr('colspan')), col); if (cell.hasClass('xexpand') && (cell.children(':not(.tooltip)').css('display') != 'none')) { - var width = 0; - for (j = 0; j < colspan; j++) { + let width = 0; + for (let j = 0; j < colspan; j++) { width += widths[i + j] || 0; } cell.css('width', width + '%'); @@ -704,8 +700,8 @@ function eval_pyson(value){ } } i += colspan; - }); - }); + } + } if (has_expand && (!this.el.closest('td').length || this.el.closest('td').hasClass('xexpand'))) { @@ -1400,7 +1396,7 @@ function eval_pyson(value){ }.bind(this)); }, write: function(widget, dialog) { - this.languages.forEach(function(lang) { + for (const lang of this.languages) { var input = jQuery('[data-lang-id=' + lang.id + ']'); if (!input.attr('readonly')) { var current_language = widget.model.session.context. @@ -1421,7 +1417,7 @@ function eval_pyson(value){ }; Sao.rpc(args, widget.model.session, false); } - }.bind(this)); + } widget.record.cancel(); widget.view.display(); this.close(dialog); @@ -1564,11 +1560,11 @@ function eval_pyson(value){ } else { selection = []; } - selection.forEach(function(e) { + for (const e of selection) { jQuery('', { 'value': e }).appendTo(this.datalist); - }.bind(this)); + } } // Set size @@ -2091,13 +2087,13 @@ function eval_pyson(value){ set_selection: function(selection, help) { var select = this.select; select.empty(); - selection.forEach(function(e) { + for (const e of selection) { select.append(jQuery('', { 'value': JSON.stringify(e[0]), 'text': e[1], 'title': help[e[0]], })); - }); + } }, display_update_selection: function() { var record = this.record; @@ -2109,8 +2105,8 @@ function eval_pyson(value){ } var value = field.get(record); var prm, found = false; - for (var i = 0, len = this.selection.length; i < len; i++) { - if (this.selection[i][0] === value) { + for (const option of this.selection) { + if (option[0] === value) { found = true; break; } @@ -2883,13 +2879,13 @@ function eval_pyson(value){ set_selection: function(selection, help) { var select = this.select; select.empty(); - selection.forEach(function(e) { + for (const e of selection) { select.append(jQuery('', { 'value': e[0], 'text': e[1], 'title': help[e[0]], })); - }); + } }, get modified() { if (this.record && this.field) { @@ -3322,10 +3318,9 @@ function eval_pyson(value){ } }, _sequence: function() { - for (var i=0, len = this.screen.views.length; i < len; i++) { - var view = this.screen.views[i]; + for (const view of this.screen.views) { if (view.view_type == 'tree') { - var sequence = view.attributes.sequence; + const sequence = view.attributes.sequence; if (sequence) { return sequence; } @@ -4556,9 +4551,9 @@ function eval_pyson(value){ }, translate_dialog: function(languages) { var options = {}; - languages.forEach(function(language) { + for (const language of languages) { options[language.name] = language.code; - }); + } Sao.common.selection(Sao.i18n.gettext("Choose a language"), options) .done(function(language) { window.open(this.uri(language), '_blank', 'noreferrer,noopener'); @@ -4709,7 +4704,7 @@ function eval_pyson(value){ .then(function(new_names) { this.send_modified(); var focus = false; - new_names.forEach(function(name) { + for (const name of new_names) { if (!(name in this.fields)) { this.add_line(name); if (!focus) { @@ -4717,7 +4712,7 @@ function eval_pyson(value){ focus = true; } } - }.bind(this)); + } }.bind(this)); }, remove: function(key, modified=true) { @@ -5023,13 +5018,13 @@ function eval_pyson(value){ return a[1].localeCompare(b[1]); }); } - selection.forEach(function(e) { + for (const e of selection) { select.append(jQuery('', { 'value': JSON.stringify(e[0]), 'text': e[1], 'title': this.definition.help_selection[e[0]], })); - }.bind(this)); + } }, set_readonly: function(readonly) { this._readonly = readonly; diff --git a/src/view/graph.js b/src/view/graph.js index ad234cd958..821b592dec 100644 --- a/src/view/graph.js +++ b/src/view/graph.js @@ -12,8 +12,7 @@ }, _node_attributes: function(node) { var node_attrs = {}; - for (var i = 0, len = node.attributes.length; i < len; i++) { - var attribute = node.attributes[i]; + for (const attribute of node.attributes) { node_attrs[attribute.name] = attribute.value; } if (node_attrs.name) { @@ -25,9 +24,9 @@ return node_attrs; }, _parse_graph: function(node, attributes) { - [].forEach.call(node.childNodes, function(child) { + for (const child of node.childNodes) { this.parse(child); - }.bind(this)); + } var Widget = Sao.View.GraphXMLViewParser.WIDGETS[ attributes.type || 'vbar']; var widget = new Widget(this.view, this._xfield, this._yfields); @@ -35,13 +34,13 @@ this.view.widgets.root = widget; }, _parse_x: function(node, attributes) { - for (var i = 0; i < node.children.length; i++) { - this._xfield = this._node_attributes(node.children[i]); + for (const child of node.children) { + this._xfield = this._node_attributes(child); } }, _parse_y: function(node, attributes) { - for (var i = 0; i < node.children.length; i++) { - this._yfields.push(this._node_attributes(node.children[i])); + for (const child of node.children) { + this._yfields.push(this._node_attributes(child)); } } }); @@ -142,16 +141,13 @@ } }.bind(this); }.bind(this); - var load_field = function(record) { - return function(fname) { - prms.push(record.load(fname)); - }; - }; var r_prms = []; for (i = 0, len = group.length; i < len; i++) { record = group[i]; - fields2load.forEach(load_field(group[i])); + for (const fname of fields2load) { + prms.push(record.load(fname)); + } r_prms.push( jQuery.when.apply(jQuery, prms).then(set_data(i))); } diff --git a/src/view/list_form.js b/src/view/list_form.js index bfd45b1c71..e5dd6b6f8e 100644 --- a/src/view/list_form.js +++ b/src/view/list_form.js @@ -79,11 +79,9 @@ return frame; }, get selected_records() { - var view_form, records = []; - var frame; - for (var i = 0; i < this._view_forms.length; i++) { - view_form = this._view_forms[i]; - frame = view_form.el.parent(); + var records = []; + for (const view_form of this._view_forms) { + const frame = view_form.el.parent(); if (frame.hasClass('list-group-item-selected')) { records.push(view_form.record); } @@ -116,10 +114,9 @@ to = tmp; } - var select_form = function(form) { + for (const form of this._view_forms.slice(from, to + 1)) { form.el.parent().addClass('list-group-item-selected'); - }; - this._view_forms.slice(from, to + 1).forEach(select_form); + } }, _select_row: function(event_) { var current_view_form; @@ -127,9 +124,9 @@ var view_form = this._view_forms[view_form_idx]; if (event_.shiftKey) { - for (var i=0; i < this._view_forms.length; i++) { - if (this._view_forms[i].record === this.record) { - current_view_form = this._view_forms[i]; + for (const other_view_form of this._view_forms) { + if (other_view_forms.record === this.record) { + current_view_form = other_view_form; break; } } diff --git a/src/view/tree.js b/src/view/tree.js index 1ad33791d9..901053c7f7 100644 --- a/src/view/tree.js +++ b/src/view/tree.js @@ -5,11 +5,11 @@ if ('IntersectionObserver' in window) { var moreObserver = new IntersectionObserver(function(entries, observer) { - entries.forEach(function(entry) { + for (const entry of entries) { if (entry.isIntersecting) { jQuery(entry.target).trigger('click'); } - }); + } }, { rootMargin: '0px 0px 50px 0px', }); @@ -53,9 +53,9 @@ Sao.View.TreeXMLViewParser = Sao.class_(Sao.View.XMLViewParser, { _parse_tree: function(node, attributes) { - [].forEach.call(node.childNodes, function(child) { + for (const child of node.childNodes) { this.parse(child); - }.bind(this)); + } }, _parse_field: function(node, attributes) { var name = attributes.name; @@ -81,19 +81,15 @@ if ('icon' in attributes) { column.prefixes.push(new Sao.View.Tree.Affix(attributes)); } - var affix, affix_attributes; - var affixes = node.childNodes; - for (var i = 0; i < affixes.length; i++) { - affix = affixes[i]; - affix_attributes = {}; - for (var j = 0, len = affix.attributes.length; j < len; j++) { - var attribute = affix.attributes[j]; + for (const affix of node.childNodes) { + let affix_attributes = {}; + for (const attribute of affix.attributes) { affix_attributes[attribute.name] = attribute.value; } if (!affix_attributes.name) { affix_attributes.name = name; } - var list; + let list; if (affix.tagName == 'prefix') { list = column.prefixes; } else { @@ -224,7 +220,7 @@ }.bind(this)); } - this.columns.forEach(function(column, i) { + for (const column of this.columns) { col = jQuery('