}
}
- section_ids.sort(L.bind(function(a, b) {
+ section_ids.sort(L.bind((a, b) => {
const indexA = (this.data[a]['.index'] != null) ? +this.data[a]['.index'] : 9999;
const indexB = (this.data[b]['.index'] != null) ? +this.data[b]['.index'] : 9999;
if (sectiontype == null || this.data[section_id]['.type'] == sectiontype)
rv.push(this.data[section_id]);
- rv.sort(function(a, b) { return a['.index'] - b['.index'] });
+ rv.sort((a, b) => { return a['.index'] - b['.index'] });
if (typeof(callback) == 'function')
for (let i = 0; i < rv.length; i++)
*/
parse() {
const args = arguments;
- this.children.forEach(function(child) {
+ this.children.forEach((child) => {
child.parse(...args);
});
},
const x = dom.elem(s) ? s : dom.parse(`<div>${s}</div>`);
- x.querySelectorAll('br').forEach(function(br) {
+ x.querySelectorAll('br').forEach((br) => {
x.replaceChild(document.createTextNode('\n'), br);
});
const loadTasks = [ doCheckACL ? callSessionAccess('uci', this.config, 'write') : true ];
const configs = this.parsechain ?? [ this.config ];
- loadTasks.push(...configs.map(L.bind(function(config, i) {
+ loadTasks.push(...configs.map(L.bind((config, i) => {
return i ? L.resolveDefault(this.data.load(config)) : this.data.load(config);
}, this)));
- return Promise.all(loadTasks).then(L.bind(function(res) {
+ return Promise.all(loadTasks).then(L.bind((res) => {
if (res[0] === false)
this.readonly = true;
.then(cb)
.then(this.data.save.bind(this.data))
.then(this.load.bind(this))
- .catch(function(e) {
+ .catch((e) => {
if (!silent) {
ui.showModal(_('Save error'), [
E('p', {}, [ _('An error occurred while saving the form:') ]),
dom.bindClassInstance(mapEl, this);
- return this.renderChildren(null).then(L.bind(function(nodes) {
+ return this.renderChildren(null).then(L.bind((nodes) => {
const initialRender = !mapEl.firstChild;
dom.content(mapEl, null);
if (!initialRender) {
mapEl.classList.remove('flash');
- window.setTimeout(function() {
+ window.setTimeout(() => {
mapEl.classList.add('flash');
}, 1);
}
if (Array.isArray(this.children))
for (let i = 0; i < section_ids.length; i++)
tasks.push(this.loadChildren(section_ids[i])
- .then(Function.prototype.bind.call(function(section_id, set_values) {
+ .then(Function.prototype.bind.call((section_id, set_values) => {
for (let i = 0; i < set_values.length; i++)
this.children[i].cfgvalue(section_id, set_values[i]);
}, this, section_ids[i])));
/** @private */
renderOptions(tab_name, section_id) {
const in_table = (this instanceof CBITableSection);
- return this.renderChildren(tab_name, section_id, in_table).then(function(nodes) {
+ return this.renderChildren(tab_name, section_id, in_table).then((nodes) => {
const optionEls = E([]);
for (let i = 0; i < nodes.length; i++)
optionEls.appendChild(nodes[i]);
/** @override */
cfgsections() {
return this.map.data.sections(this.uciconfig ?? this.map.config, this.sectiontype)
- .map(function(s) { return s['.name'] })
+ .map((s) => { return s['.name'] })
.filter(L.bind(this.filter, this));
},
E('button', {
'class': 'cbi-button cbi-button-add',
'title': btn_title ?? _('Add'),
- 'click': ui.createHandlerFn(this, function(ev) {
+ 'click': ui.createHandlerFn(this, (ev) => {
if (nameEl.classList.contains('cbi-input-invalid'))
return;
]);
if (this.map.readonly !== true) {
- ui.addValidator(nameEl, 'uciname', true, function(v) {
+ ui.addValidator(nameEl, 'uciname', true, (v) => {
const button = createEl.querySelector('.cbi-section-create > .cbi-button-add');
if (v !== '') {
button.disabled = null;
* is true. Optionally supply a name for the new section_id.
*/
/** @private */
- handleClone: function(section_id, put_next, name) {
+ handleClone(section_id, put_next, name) {
let config_name = this.uciconfig || this.map.config;
this.map.data.clone(config_name, this.sectiontype, section_id, put_next, name);
if (typeof(this.extedit) == 'function')
evFn = L.bind(this.extedit, this);
else if (typeof(this.extedit) == 'string')
- evFn = L.bind(function(sid, ev) {
+ evFn = L.bind((sid, ev) => {
location.href = this.extedit.format(sid);
}, this, section_id);
}
if (this.cloneable) {
- var btn_title = this.titleFn('clonebtntitle', section_id);
+ const btn_title = this.titleFn('clonebtntitle', section_id);
dom.append(tdEl.lastElementChild,
E('button', {
n.style.opacity = '';
n.classList.add('flash');
n.parentNode.querySelectorAll('.drag-over-above, .drag-over-below')
- .forEach(function(tr) {
+ .forEach((tr) => {
tr.classList.remove('drag-over-above');
tr.classList.remove('drag-over-below');
});
dragHandle.style.top = `${touchLoc.pageY - (parseInt(dragHandle.style.height) / 2)}px`;
- rowElem.parentNode.querySelectorAll('[draggable]').forEach(function(tr, i, trs) {
+ rowElem.parentNode.querySelectorAll('[draggable]').forEach((tr, i, trs) => {
const trRect = tr.getBoundingClientRect();
const yTop = trRect.top + window.scrollY;
const yBottom = trRect.bottom + window.scrollY;
ev.preventDefault();
if (touchLoc.clientY < 30)
- window.requestAnimationFrame(function() { htmlElem.scrollTop -= 30 });
+ window.requestAnimationFrame(() => { htmlElem.scrollTop -= 30 });
else if (touchLoc.clientY > viewportHeight - 30)
- window.requestAnimationFrame(function() { htmlElem.scrollTop += 30 });
+ window.requestAnimationFrame(() => { htmlElem.scrollTop += 30 });
},
/** @private */
targetElem.getAttribute('data-sid'),
isBelow);
- window.requestAnimationFrame(function() {
+ window.requestAnimationFrame(() => {
const rowRect = rowElem.getBoundingClientRect();
if (rowRect.top < 50)
return saveTasks
.then(L.bind(this.handleModalCancel, this, modalMap, ev, true))
- .catch(function() {});
+ .catch(() => {});
},
/** @private */
let index = 0;
const list = [];
- ev.currentTarget.querySelectorAll('th').forEach(function(other_th, i) {
+ ev.currentTarget.querySelectorAll('th').forEach((other_th, i) => {
if (other_th !== th)
other_th.removeAttribute('data-sort-direction');
else
index = i;
});
- ev.currentTarget.parentNode.querySelectorAll('tr.cbi-section-table-row').forEach(L.bind(function(tr, i) {
+ ev.currentTarget.parentNode.querySelectorAll('tr.cbi-section-table-row').forEach(L.bind((tr, i) => {
const sid = tr.getAttribute('data-sid');
const opt = tr.childNodes[index].getAttribute('data-name');
const val = this.cfgvalue(sid, opt);
- tr.querySelectorAll('.flash').forEach(function(n) {
+ tr.querySelectorAll('.flash').forEach((n) => {
n.classList.remove('flash')
});
]);
}, this));
- list.sort(function(a, b) {
+ list.sort((a, b) => {
return descending
? -L.naturalCompare(a[0], b[0])
: L.naturalCompare(a[0], b[0]);
});
- window.requestAnimationFrame(L.bind(function() {
+ window.requestAnimationFrame(L.bind(() => {
let ref_sid;
let cur_sid;
const activeMap = mapNode ? dom.findClassInstance(mapNode) : null;
const stackedMap = activeMap && (activeMap.parent !== parent || activeMap.section !== section_id);
- return (stackedMap ? activeMap.save(null, true) : Promise.resolve()).then(L.bind(function() {
+ return (stackedMap ? activeMap.save(null, true) : Promise.resolve()).then(L.bind(() => {
section_id = sref['.name'];
let m;
this.cloneOptions(this, s);
- return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(function() {
+ return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(() => {
return m.render();
- }).then(L.bind(function(nodes) {
+ }).then(L.bind((nodes) => {
let title = parent.title;
let name = null;
optionEl.appendChild(E('label', {
'class': 'cbi-value-title',
'for': 'widget.cbid.%s.%s.%s'.format(config_name, section_id, this.option),
- 'click': function(ev) {
+ 'click': (ev) => {
const node = ev.currentTarget;
const elem = node.nextElementSibling.querySelector(`#${node.getAttribute('for')}`) ?? node.nextElementSibling.querySelector(`[data-widget-id="${node.getAttribute('for')}"]`);
* @param {string} [description]
* The description text of the option element.
*/
-var CBIRichListValue = CBIListValue.extend(/** @lends LuCI.form.ListValue.prototype */ {
+const CBIRichListValue = CBIListValue.extend(/** @lends LuCI.form.ListValue.prototype */ {
__name__: 'CBI.RichListValue',
- __init__: function() {
+ __init__() {
this.super('__init__', arguments);
this.widget = 'select';
this.orientation = 'horizontal';
*/
/** @private */
- renderWidget: function(section_id, option_index, cfgvalue) {
- var choices = this.transformChoices();
- var widget = new ui.Dropdown((cfgvalue != null) ? cfgvalue : this.default, choices, {
+ renderWidget(section_id, option_index, cfgvalue) {
+ const choices = this.transformChoices();
+ const widget = new ui.Dropdown((cfgvalue != null) ? cfgvalue : this.default, choices, {
id: this.cbid(section_id),
size: this.size,
sort: this.keylist,
* implemented as a simple ListValue entry.
*
*/
- value: function(value, title, description) {
+ value(value, title, description) {
if (description) {
CBIListValue.prototype.value.call(this, value, E([], [
E('span', { 'class': 'hide-open' }, [ title ]),
dom.content(outputEl, [
E('button', {
'class': 'cbi-button cbi-button-%s'.format(this.inputstyle ?? 'button'),
- 'click': ui.createHandlerFn(this, function(section_id, ev) {
+ 'click': ui.createHandlerFn(this, (section_id, ev) => {
if (this.onclick)
return this.onclick(ev, section_id);
* o.value('choice1', 'The first choice');
* o.value('choice2', 'The second choice');
*
- * m.render().then(function(node) {
+ * m.render().then((node) => {
* document.body.appendChild(node);
* });
* </pre>