luci2: add get_first(), set_first() and unset_first() helper to L.UCIContext
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 13 Apr 2014 20:36:16 +0000 (22:36 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 13 Apr 2014 20:36:16 +0000 (22:36 +0200)
luci2/htdocs/luci2/luci2.js

index ea64074c5b21df9a2dba2b832c2096a6b8b37da3..5947791600a9ace955dade058bbd8849ec29a2ce 100644 (file)
@@ -1109,6 +1109,35 @@ function LuCI2()
                        return this.set(conf, sid, opt, undefined);
                },
 
+               get_first: function(conf, type, opt)
+               {
+                       var sid = undefined;
+
+                       L.uci.sections(conf, type, function(s) {
+                               if (typeof(sid) != 'string')
+                                       sid = s['.name'];
+                       });
+
+                       return this.get(conf, sid, opt);
+               },
+
+               set_first: function(conf, type, opt, val)
+               {
+                       var sid = undefined;
+
+                       L.uci.sections(conf, type, function(s) {
+                               if (typeof(sid) != 'string')
+                                       sid = s['.name'];
+                       });
+
+                       return this.set(conf, sid, opt, val);
+               },
+
+               unset_first: function(conf, type, opt)
+               {
+                       return this.set_first(conf, type, opt, undefined);
+               },
+
                _reload: function()
                {
                        var pkgs = [ ];