luci-base: uci.js: merge changes when retrieving entire sections
authorJo-Philipp Wich <jo@mein.io>
Mon, 29 Mar 2021 20:29:36 +0000 (22:29 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 29 Mar 2021 20:35:50 +0000 (22:35 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/uci.js

index cbaeb8c08035248faac3eed3a4317cd3a54f9e84..41e902c5fe2838d2fa0135f558ae031c1acc780e 100644 (file)
@@ -489,8 +489,28 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ {
                }
 
                /* requested an entire section */
-               if (v[conf])
-                       return v[conf][sid];
+               if (v[conf]) {
+                       /* check whether entire section was deleted */
+                       if (d[conf] && d[conf][sid] === true)
+                               return null;
+
+                       var s = v[conf][sid] || null;
+
+                       if (s) {
+                               /* merge changes */
+                               if (c[conf] && c[conf][sid])
+                                       for (var opt in c[conf][sid])
+                                               if (c[conf][sid][opt] != null)
+                                                       s[opt] = c[conf][sid][opt];
+
+                               /* merge deletions */
+                               if (d[conf] && d[conf][sid])
+                                       for (var opt in d[conf][sid])
+                                               delete s[opt];
+                       }
+
+                       return s;
+               }
 
                return null;
        },