luci-base: form.js: save parent map on opening nested modal map

Before opening (rendering) a nested modal map, make sure to save the parent
modal map in order to persist any structural uci changes, such as newly added
anonymous sections to prevent the nested map from operating on stale values
or ephemeral config section IDs.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2022-05-16 13:10:20 +02:00
parent f24606b1ff
commit 3be479446b

View file

@ -3206,63 +3206,70 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
/** @private */ /** @private */
renderMoreOptionsModal: function(section_id, ev) { renderMoreOptionsModal: function(section_id, ev) {
var parent = this.map, var parent = this.map,
title = parent.title, sref = parent.data.get(parent.config, section_id),
name = null, mapNode = this.getActiveModalMap(),
m = new CBIMap(this.map.config, null, null), activeMap = mapNode ? dom.findClassInstance(mapNode) : null,
s = m.section(CBINamedSection, section_id, this.sectiontype); stackedMap = activeMap && (activeMap.parent !== parent || activeMap.section !== section_id);
m.parent = parent; return (stackedMap ? activeMap.save(null, true) : Promise.resolve()).then(L.bind(function() {
m.section = section_id; section_id = sref['.name'];
m.readonly = parent.readonly;
s.tabs = this.tabs; var m = new CBIMap(parent.config, null, null),
s.tab_names = this.tab_names; s = m.section(CBINamedSection, section_id, this.sectiontype);
if ((name = this.titleFn('modaltitle', section_id)) != null) m.parent = parent;
title = name; m.section = section_id;
else if ((name = this.titleFn('sectiontitle', section_id)) != null) m.readonly = parent.readonly;
title = '%s - %s'.format(parent.title, name);
else if (!this.anonymous)
title = '%s - %s'.format(parent.title, section_id);
this.cloneOptions(this, s); s.tabs = this.tabs;
s.tab_names = this.tab_names;
return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(L.bind(m.render, m)).then(L.bind(function(nodes) { this.cloneOptions(this, s);
var mapNode = this.getActiveModalMap(),
activeMap = mapNode ? dom.findClassInstance(mapNode) : null;
if (activeMap && (activeMap.parent !== parent || activeMap.section !== section_id)) { return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(function() {
mapNode.parentNode return m.render();
.querySelector('h4') }).then(L.bind(function(nodes) {
.appendChild(E('span', title ? ' » ' + title : '')); var title = parent.title,
name = null;
mapNode.parentNode if ((name = this.titleFn('modaltitle', section_id)) != null)
.querySelector('div.right > button') title = name;
.firstChild.data = _('Back'); else if ((name = this.titleFn('sectiontitle', section_id)) != null)
title = '%s - %s'.format(parent.title, name);
else if (!this.anonymous)
title = '%s - %s'.format(parent.title, section_id);
mapNode.classList.add('hidden'); if (stackedMap) {
mapNode.parentNode.insertBefore(nodes, mapNode.nextElementSibling); mapNode.parentNode
.querySelector('h4')
.appendChild(E('span', title ? ' » ' + title : ''));
mapNode.parentNode
.querySelector('div.right > button')
.firstChild.data = _('Back');
mapNode.classList.add('hidden');
mapNode.parentNode.insertBefore(nodes, mapNode.nextElementSibling);
return activeMap.save(null, true).then(function() {
nodes.classList.add('flash'); nodes.classList.add('flash');
}, function() {}); }
} else {
else { ui.showModal(title, [
ui.showModal(title, [ nodes,
nodes, E('div', { 'class': 'right' }, [
E('div', { 'class': 'right' }, [ E('button', {
E('button', { 'class': 'cbi-button',
'class': 'cbi-button', 'click': ui.createHandlerFn(this, 'handleModalCancel', m)
'click': ui.createHandlerFn(this, 'handleModalCancel', m) }, [ _('Dismiss') ]), ' ',
}, [ _('Dismiss') ]), ' ', E('button', {
E('button', { 'class': 'cbi-button cbi-button-positive important',
'class': 'cbi-button cbi-button-positive important', 'click': ui.createHandlerFn(this, 'handleModalSave', m),
'click': ui.createHandlerFn(this, 'handleModalSave', m), 'disabled': m.readonly || null
'disabled': m.readonly || null }, [ _('Save') ])
}, [ _('Save') ]) ])
]) ], 'cbi-modal');
], 'cbi-modal'); }
} }, this));
}, this)).catch(L.error); }, this)).catch(L.error);
} }
}); });