luci-base: form.js: prevent section creation on modal cbi save failure
authorJo-Philipp Wich <jo@mein.io>
Thu, 6 Jun 2019 19:02:04 +0000 (21:02 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 13:36:25 +0000 (15:36 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/form.js

index 9351bae035b07179afb8296f5f760b70c9b74605..c4f3b8aece638fdeea371c25aff35ba01c67a55f 100644 (file)
@@ -120,7 +120,10 @@ var CBIMap = CBINode.extend({
                        .then(uci.save.bind(uci))
                        .then(this.load.bind(this))
                        .then(this.renderContents.bind(this))
-                       .catch(function() { alert('Cannot save due to invalid values') });
+                       .catch(function(e) {
+                               alert('Cannot save due to invalid values')
+                               return Promise.reject();
+                       });
        },
 
        reset: function() {
@@ -1049,13 +1052,14 @@ var CBITableSection = CBITypedSection.extend({
        },
 
        handleModalCancel: function(modalMap, ev) {
-               L.ui.hideModal();
+               return Promise.resolve(L.ui.hideModal());
        },
 
        handleModalSave: function(modalMap, ev) {
-               modalMap.save()
+               return modalMap.save()
                        .then(L.bind(this.map.reset, this.map))
-                       .then(L.ui.hideModal);
+                       .then(L.ui.hideModal)
+                       .catch(function() {});
        },
 
        renderMoreOptionsModal: function(section_id, ev) {
@@ -1139,8 +1143,8 @@ var CBIGridSection = CBITableSection.extend({
        },
 
        handleModalSave: function(/* ... */) {
-               this.super('handleModalSave', arguments);
-               this.addedSection = null;
+               return this.super('handleModalSave', arguments)
+                       .then(L.bind(function() { this.addedSection = null }, this));
        },
 
        handleModalCancel: function(/* ... */) {
@@ -1151,7 +1155,7 @@ var CBIGridSection = CBITableSection.extend({
                        this.addedSection = null;
                }
 
-               this.super('handleModalCancel', arguments);
+               return this.super('handleModalCancel', arguments);
        },
 
        renderUCISection: function(section_id) {