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:
parent
f24606b1ff
commit
3be479446b
1 changed files with 54 additions and 47 deletions
|
@ -3206,9 +3206,15 @@ 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,
|
||||||
|
stackedMap = activeMap && (activeMap.parent !== parent || activeMap.section !== section_id);
|
||||||
|
|
||||||
|
return (stackedMap ? activeMap.save(null, true) : Promise.resolve()).then(L.bind(function() {
|
||||||
|
section_id = sref['.name'];
|
||||||
|
|
||||||
|
var m = new CBIMap(parent.config, null, null),
|
||||||
s = m.section(CBINamedSection, section_id, this.sectiontype);
|
s = m.section(CBINamedSection, section_id, this.sectiontype);
|
||||||
|
|
||||||
m.parent = parent;
|
m.parent = parent;
|
||||||
|
@ -3218,6 +3224,14 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
|
||||||
s.tabs = this.tabs;
|
s.tabs = this.tabs;
|
||||||
s.tab_names = this.tab_names;
|
s.tab_names = this.tab_names;
|
||||||
|
|
||||||
|
this.cloneOptions(this, s);
|
||||||
|
|
||||||
|
return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(function() {
|
||||||
|
return m.render();
|
||||||
|
}).then(L.bind(function(nodes) {
|
||||||
|
var title = parent.title,
|
||||||
|
name = null;
|
||||||
|
|
||||||
if ((name = this.titleFn('modaltitle', section_id)) != null)
|
if ((name = this.titleFn('modaltitle', section_id)) != null)
|
||||||
title = name;
|
title = name;
|
||||||
else if ((name = this.titleFn('sectiontitle', section_id)) != null)
|
else if ((name = this.titleFn('sectiontitle', section_id)) != null)
|
||||||
|
@ -3225,13 +3239,7 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
|
||||||
else if (!this.anonymous)
|
else if (!this.anonymous)
|
||||||
title = '%s - %s'.format(parent.title, section_id);
|
title = '%s - %s'.format(parent.title, section_id);
|
||||||
|
|
||||||
this.cloneOptions(this, s);
|
if (stackedMap) {
|
||||||
|
|
||||||
return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(L.bind(m.render, m)).then(L.bind(function(nodes) {
|
|
||||||
var mapNode = this.getActiveModalMap(),
|
|
||||||
activeMap = mapNode ? dom.findClassInstance(mapNode) : null;
|
|
||||||
|
|
||||||
if (activeMap && (activeMap.parent !== parent || activeMap.section !== section_id)) {
|
|
||||||
mapNode.parentNode
|
mapNode.parentNode
|
||||||
.querySelector('h4')
|
.querySelector('h4')
|
||||||
.appendChild(E('span', title ? ' » ' + title : ''));
|
.appendChild(E('span', title ? ' » ' + title : ''));
|
||||||
|
@ -3243,9 +3251,7 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
|
||||||
mapNode.classList.add('hidden');
|
mapNode.classList.add('hidden');
|
||||||
mapNode.parentNode.insertBefore(nodes, mapNode.nextElementSibling);
|
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, [
|
||||||
|
@ -3263,6 +3269,7 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
|
||||||
])
|
])
|
||||||
], 'cbi-modal');
|
], 'cbi-modal');
|
||||||
}
|
}
|
||||||
|
}, this));
|
||||||
}, this)).catch(L.error);
|
}, this)).catch(L.error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue