juci-openvpn: show current config on pop-up opened by upload/edit button
authorReidar Cederqvist <reidar.cederqvist@gmail.com>
Mon, 26 Feb 2018 14:38:57 +0000 (15:38 +0100)
committerReidar Cederqvist <reidar.cederqvist@gmail.com>
Mon, 26 Feb 2018 14:39:17 +0000 (15:39 +0100)
plugins/juci-openvpn/src/pages/internet-services-openvpn.html
plugins/juci-openvpn/src/pages/internet-services-openvpn.js
plugins/juci-openvpn/src/widgets/openvpn-add-file.html
plugins/juci-openvpn/src/widgets/openvpn-add-file.js

index c9964f1..01bfd9a 100644 (file)
@@ -22,7 +22,7 @@
                        </juci-config-line>
 
                        <juci-config-line title="{{ 'Upload Configuration' | translate}}">
-                               <button ng-click="onAddFile()">Upload a file</button>
+                               <button ng-click="onAddFile()">Upload/Edit</button>
                        </juci-config-line>
 
 
index 189cc0d..8a4b6b6 100644 (file)
@@ -113,18 +113,21 @@ JUCI.app
        };
 
        $scope.onAddFile = function(){
-               var model = {};
+               var model = {
+                       config: $scope.data.ovpn,
+                       old_config: $scope.data.ovpn
+               };
 
                $juciDialog.show("openvpn-add-file", {
                        title: $tr(gettext("Upload OpenVPN configuration")),
                        on_apply: function(btn, inst){
                                model.error = null;
-                               if(!model.key && !model.file){
+                               if(!model.config && !model.file){
                                        model.error = $tr(gettext("You must choose a configuration file or paste it"));
                                        return;
                                }
-                               if(model.key){
-                                       $file.uploadString(filename, model.key).done(function(ret){
+                               if(model.config !== model.old_config){
+                                       $file.uploadString(filename, model.config).done(function(ret){
                                                $scope.save_config();
                                                inst.close();
                                        }).fail(function(e){model.error = e;});
index 32d4f47..0291c36 100644 (file)
@@ -10,7 +10,7 @@
        <juci-config-section>
                <label>{{'Alternatively, paste the configuration:'|translate}}</label>
                <br/>
-               <textarea rows="12" style="width: 100%;" ng-model="model.key">
+               <textarea rows="12" style="width: 100%;" ng-model="model.config">
                </textarea>
        </juci-config-section>
 
index 12463ec..87a7d5e 100644 (file)
@@ -33,11 +33,11 @@ JUCI.app
 .controller("openvpnAddFileModel", function($scope){
        $scope.fileChanged = function(){
                $scope.model.file = document.getElementById("configFileSelector");
-               $scope.model.key = "";
+               $scope.model.config = "";
                $scope.model.error = "";
                $scope.$apply();
        };
-       $scope.$watch("model.key", function(m){
+       $scope.$watch("model.config", function(m){
                if(!m) return;
                if($scope.model.error) $scope.model.error = "";
        }, false);