luci-base: uci.js: fix section deletion logic
authorJo-Philipp Wich <jo@mein.io>
Sun, 26 Apr 2020 16:41:19 +0000 (18:41 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 7 May 2020 17:40:49 +0000 (19:40 +0200)
 - Process deletions before additions or changes, allowing user code to
   remove and recreate a section with the same name.

 - Only record section deletions when the section to be removed actually
   existed in the original config or when it was staged for creation
   earlier. This avoids stray ubus not found exception when saving.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 49c6a810e9a705217f4543099d8188f0f3158f6c)

modules/luci-base/htdocs/luci-static/resources/uci.js

index 6bbd1bc37ce192afccab7446136d43891201ddbb..9e81e26ba7d2d9db9103d62181c7511e80b2bf59 100644 (file)
@@ -295,7 +295,8 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ {
         * The ID of the section to remove.
         */
        remove: function(conf, sid) {
-               var n = this.state.creates,
+               var v = this.state.values,
+                   n = this.state.creates,
                    c = this.state.changes,
                    d = this.state.deletes;
 
@@ -303,7 +304,7 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ {
                if (n[conf] && n[conf][sid]) {
                        delete n[conf][sid];
                }
-               else {
+               else if (v[conf] && v[conf][sid]) {
                        if (c[conf])
                                delete c[conf][sid];
 
@@ -785,6 +786,16 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ {
                    pkgs = { },
                    tasks = [];
 
+               if (d)
+                       for (var conf in d) {
+                               for (var sid in d[conf]) {
+                                       var o = d[conf][sid];
+                                       tasks.push(self.callDelete(conf, sid, (o === true) ? null : o));
+                               }
+
+                               pkgs[conf] = true;
+                       }
+
                if (n)
                        for (var conf in n) {
                                for (var sid in n[conf]) {
@@ -817,16 +828,6 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ {
                                pkgs[conf] = true;
                        }
 
-               if (d)
-                       for (var conf in d) {
-                               for (var sid in d[conf]) {
-                                       var o = d[conf][sid];
-                                       tasks.push(self.callDelete(conf, sid, (o === true) ? null : o));
-                               }
-
-                               pkgs[conf] = true;
-                       }
-
                if (r)
                        for (var conf in r)
                                pkgs[conf] = true;