luci-mod-system: fix uci led option remove callback 4496/head
authorFlorian Eckert <fe@dev.tdt.de>
Tue, 6 Oct 2020 09:15:45 +0000 (11:15 +0200)
committerFlorian Eckert <fe@dev.tdt.de>
Tue, 6 Oct 2020 09:30:48 +0000 (11:30 +0200)
fixes #4478

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/leds.js

index 9fe1bff55ef7ba632fdc05a9046ba9f85c5c6aec..23feebc005ec1ed0b9c033bfbda99bef1e8e4785 100644 (file)
@@ -88,6 +88,32 @@ return view.extend({
                                var plugin = plugins[i];
                                plugin.form.addFormOptions(s);
                        }
+
+                       var opts = s.getOption();
+
+                       var removeIfNoneActive = function(original_remove_fn, section_id) {
+                               var isAnyActive = false;
+
+                               for (var optname in opts) {
+                                       if (opts[optname].ucioption != this.ucioption)
+                                               continue;
+
+                                       if (!opts[optname].isActive(section_id))
+                                               continue;
+
+                                       isAnyActive = true;
+                                       break;
+                               }
+
+                               if (!isAnyActive)
+                                       original_remove_fn.call(this, section_id);
+                       };
+
+                       for (var optname in opts) {
+                               if (!opts[optname].ucioption || optname == opts[optname].ucioption)
+                                       continue;
+                               opts[optname].remove = removeIfNoneActive.bind(opts[optname], opts[optname].remove);
+                       }
                };
 
                return m.render();