diff --git a/luciexpress/htdocs/js/app.js b/luciexpress/htdocs/js/app.js index 67599bf0d..6f60036d8 100644 --- a/luciexpress/htdocs/js/app.js +++ b/luciexpress/htdocs/js/app.js @@ -122,7 +122,7 @@ JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $ $rootScope.errors = []; $rootScope.$on("error", function(ev, data){ $rootScope.errors.push({message: data}); - console.log("ERROR: "+ev.name+": "+JSON.stringify(Object.keys(ev.currentScope))); + //console.log("ERROR: "+ev.name+": "+JSON.stringify(Object.keys(ev.currentScope))); }); // set current language gettextCatalog.currentLanguage = "en"; diff --git a/luciexpress/htdocs/js/uci.js b/luciexpress/htdocs/js/uci.js index a3382b5dc..e597a56fb 100644 --- a/luciexpress/htdocs/js/uci.js +++ b/luciexpress/htdocs/js/uci.js @@ -283,10 +283,14 @@ return deferred.promise(); } + /* UCISection.prototype.$save = function(){ var deferred = $.Deferred(); var self = this; + // try to validate the section using section wide validator + if(self[".validator"] instanceof Function) self[".validator"](self); + $rpc.uci.set({ config: self[".config"][".name"], section: self[".name"], @@ -297,7 +301,7 @@ deferred.reject(); }); return deferred.promise(); - } + }*/ UCISection.prototype.$delete = function(){ var self = this; @@ -326,6 +330,9 @@ if(!type) return {}; var self = this; var changed = {}; + + if(type[".validator"] instanceof Function) type[".validator"](self); + Object.keys(type).map(function(k){ if(self[k] && self[k].dirty){ //console.log("Adding dirty field: "+k); @@ -443,12 +450,13 @@ }); } - UCIConfig.prototype.$registerSectionType = function(name, descriptor){ + UCIConfig.prototype.$registerSectionType = function(name, descriptor, validator){ var config = this[".name"]; var conf_type = section_types[config]; if(typeof conf_type === "undefined") conf_type = section_types[config] = {}; conf_type[name] = descriptor; this["@"+name] = []; + if(validator !== undefined && validator instanceof Function) conf_type[name][".validator"] = validator; console.log("Registered new section type "+config+"."+name); } diff --git a/luciexpress/htdocs/plugins/core/widgets/luci.config.js b/luciexpress/htdocs/plugins/core/widgets/luci.config.js index 26cbb4d7f..1baadff3d 100644 --- a/luciexpress/htdocs/plugins/core/widgets/luci.config.js +++ b/luciexpress/htdocs/plugins/core/widgets/luci.config.js @@ -75,19 +75,30 @@ $juci.module("core") ''+ '
', replace: true, + scope: { + onPreApply: "&" + }, controller: "luciConfigApplyController" }; }).controller("luciConfigApplyController", function($scope, $uci){ $scope.onApply = function(){ + if($scope.onPreApply) $scope.onPreApply(); $scope.busy = 1; - $uci.save().done(function(){ - console.log("Saved uci configuration!"); - }).fail(function(){ - console.error("Could not save uci configuration!"); - }).always(function(){ + try { + $uci.save().done(function(){ + console.log("Saved uci configuration!"); + }).fail(function(){ + console.error("Could not save uci configuration!"); + }).always(function(){ + $scope.busy = 0; + setTimeout(function(){$scope.$apply();}, 0); + }); + } catch(e){ $scope.busy = 0; setTimeout(function(){$scope.$apply();}, 0); - }); + $scope.$emit("error", e.message); + console.error("Error while applying config: "+e.message); + } } $scope.onCancel = function(){ // simple way to reset diff --git a/luciexpress/htdocs/plugins/core/widgets/luci.errors.html b/luciexpress/htdocs/plugins/core/widgets/luci.errors.html index eb5f054ba..6969b8c20 100644 --- a/luciexpress/htdocs/plugins/core/widgets/luci.errors.html +++ b/luciexpress/htdocs/plugins/core/widgets/luci.errors.html @@ -1,5 +1,5 @@