luci-base: form.js: rework stacked modal CBI map logic

Only stack a new modal CBI map on top of the currently displayed modal one
if the related map or section differs. This prevents misbehavior when
switching the protocol of interfaces.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2022-05-05 23:07:13 +02:00
parent c40dd71b84
commit f2fa59e89a

View file

@ -3149,6 +3149,7 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
s = m.section(CBINamedSection, section_id, this.sectiontype); s = m.section(CBINamedSection, section_id, this.sectiontype);
m.parent = parent; m.parent = parent;
m.section = section_id;
m.readonly = parent.readonly; m.readonly = parent.readonly;
s.tabs = this.tabs; s.tabs = this.tabs;
@ -3188,20 +3189,24 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
} }
return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(L.bind(m.render, m)).then(L.bind(function(nodes) { return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(L.bind(m.render, m)).then(L.bind(function(nodes) {
var modalMap = this.getActiveModalMap(); var mapNode = this.getActiveModalMap(),
activeMap = mapNode ? dom.findClassInstance(mapNode) : null;
if (modalMap) { if (activeMap && (activeMap.parent !== parent || activeMap.section !== section_id)) {
modalMap.parentNode mapNode.parentNode
.querySelector('h4') .querySelector('h4')
.appendChild(E('span', title ? ' » ' + title : '')); .appendChild(E('span', title ? ' » ' + title : ''));
modalMap.parentNode mapNode.parentNode
.querySelector('div.right > button') .querySelector('div.right > button')
.firstChild.data = _('Back'); .firstChild.data = _('Back');
modalMap.classList.add('hidden'); mapNode.classList.add('hidden');
modalMap.parentNode.insertBefore(nodes, modalMap.nextElementSibling); mapNode.parentNode.insertBefore(nodes, mapNode.nextElementSibling);
nodes.classList.add('flash');
return activeMap.save(null, true).then(function() {
nodes.classList.add('flash');
}, function() {});
} }
else { else {
ui.showModal(title, [ ui.showModal(title, [