juci-mod-system: fix ntp-server page ref #13770
authorReidar Cederqvist <reidar.cederqvist@gmail.com>
Mon, 30 Apr 2018 07:53:01 +0000 (09:53 +0200)
committerReidar Cederqvist <reidar.cederqvist@gmail.com>
Mon, 30 Apr 2018 07:54:23 +0000 (09:54 +0200)
plugins/juci-mod-system/src/pages/settings-system-timeservers.js

index 5a93984..51260d0 100644 (file)
 JUCI.app
 .controller("SettingsSystemTimeservers", function($scope, $rpc, $uci, $tr, gettext){
        $uci.$sync("system").done(function(){
-               if(!$uci.system.ntp) return; 
+               if(!$uci.system.ntp) return;
                $scope.ntp = $uci.system.ntp;
-               $scope.ntp_servers = $uci.system.ntp.server.value.map(function(x){ return { server: x }; }); 
-               $scope.$apply(); 
+               $scope.ntp_servers = $scope.ntp.server.value.map(function(x){ return { server: x }; });
+               $scope.$apply();
+
                $scope.$watch("ntp_servers", function(){
-                       $uci.system.ntp.server.value = []; 
+                       var new_servers = [];
                        $scope.ntp_servers.map(function(ntp){
-                               $uci.system.ntp.server.value.push(ntp.server); 
-                       }); 
-               }, true); 
+                               new_servers.push(ntp.server);
+                       });
+                       $scope.ntp.server.value = new_servers;
+               }, true);
+
                $scope.onDeleteNTPServer = function(ntp){
-                       $scope.ntp_servers = $scope.ntp_servers.filter(function(x){ return x != ntp; }); 
+                       $scope.ntp_servers = $scope.ntp_servers.filter(function(x){ return x !== ntp; });
                }
+
                $scope.onAddNTPServer = function(){
-                       if(!$uci.system.ntp) return; 
-                       $scope.ntp_servers.push({ server: "" }); 
+                       $scope.ntp_servers.push({ server: "" });
                }
-       }); 
+       });
 });