X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci2%2Fui.git;a=blobdiff_plain;f=luci2%2Fhtdocs%2Fluci2%2Fluci2.js;h=45584e70485269a0e5a09b3897b6aac3f836d22f;hp=6f40b777bafe88952af5cd0dfb8a20dde116ef24;hb=4bb42cc51fbf15038be9548c002c3a3d6b2a296f;hpb=7172e2c4e2e8176d02d7d6c790c8ebececc383e4 diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index 6f40b77..45584e7 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -3860,20 +3860,23 @@ function LuCI2() if (n > 0) $('#changes') - .empty() - .show() - .append($('') - .attr('href', '#') - .addClass('label') - .addClass('notice') - .text(_luci2.trcp('Pending configuration changes', '1 change', '%d changes', n).format(n)) - .click(function(ev) { - _luci2.ui.dialog(_luci2.tr('Staged configuration changes'), html, { style: 'close' }); - ev.preventDefault(); - })); + .click(function(ev) { + _luci2.ui.dialog(_luci2.tr('Staged configuration changes'), html, { + style: 'confirm', + confirm: function() { + _luci2.uci.apply().then( + function(code) { alert('Success with code ' + code); }, + function(code) { alert('Error with code ' + code); } + ); + } + }); + ev.preventDefault(); + }) + .children('span') + .show() + .text(_luci2.trcp('Pending configuration changes', '1 change', '%d changes', n).format(n)); else - $('#changes') - .hide(); + $('#changes').children('span').hide(); }); }, @@ -4963,6 +4966,7 @@ function LuCI2() this.instance = { }; this.dependencies = [ ]; this.rdependency = { }; + this.events = { }; this.options = _luci2.defaults(options, { placeholder: '', @@ -5018,6 +5022,11 @@ function LuCI2() return i.top; }, + active: function(sid) + { + return (this.instance[sid] && !this.instance[sid].disabled); + }, + ucipath: function(sid) { return { @@ -5157,14 +5166,30 @@ function LuCI2() } if (rv) + { for (var field in d.self.rdependency) d.self.rdependency[field].toggle(d.sid); + d.self.section.tabtoggle(d.sid); + } + return rv; }, validator: function(sid, elem, multi) { + var evdata = { + self: this, + sid: sid, + elem: elem, + multi: multi, + inst: this.instance[sid], + opt: this.options.optional + }; + + for (var evname in this.events) + elem.on(evname, evdata, this.events[evname]); + if (typeof(this.options.datatype) == 'undefined' && $.isEmptyObject(this.rdependency)) return elem; @@ -5172,13 +5197,13 @@ function LuCI2() if (typeof(this.options.datatype) == 'string') { try { - vstack = _luci2.cbi.validation.compile(this.options.datatype); + evdata.vstack = _luci2.cbi.validation.compile(this.options.datatype); } catch(e) { }; } else if (typeof(this.options.datatype) == 'function') { var vfunc = this.options.datatype; - vstack = [ function(elem) { + evdata.vstack = [ function(elem) { var rv = vfunc(this, elem); if (rv !== true) validation.message = rv; @@ -5186,16 +5211,6 @@ function LuCI2() }, [ elem ] ]; } - var evdata = { - self: this, - sid: sid, - elem: elem, - multi: multi, - vstack: vstack, - inst: this.instance[sid], - opt: this.options.optional - }; - if (elem.prop('tagName') == 'SELECT') { elem.change(evdata, this._ev_validate); @@ -5225,7 +5240,7 @@ function LuCI2() return (i.disabled || i.error.text() == ''); }, - depends: function(d, v) + depends: function(d, v, add) { var dep; @@ -5270,7 +5285,11 @@ function LuCI2() if ($.isEmptyObject(dep)) return this; - this.dependencies.push(dep); + if (!add || !this.dependencies.length) + this.dependencies.push(dep); + else + for (var i = 0; i < this.dependencies.length; i++) + $.extend(this.dependencies[i], dep); return this; }, @@ -5300,7 +5319,7 @@ function LuCI2() break; } } - else if (typeof(cmp) == 'string') + else if (typeof(cmp) == 'string' || typeof(cmp) == 'number') { if (val != cmp) { @@ -5345,6 +5364,12 @@ function LuCI2() } return false; + }, + + on: function(evname, evfunc) + { + this.events[evname] = evfunc; + return this; } }); @@ -5464,7 +5489,7 @@ function LuCI2() var s = $('