diff options
| author | Arjun Roychowdhury <pliablepixels@gmail.com> | 2015-09-29 13:59:39 -0400 |
|---|---|---|
| committer | Arjun Roychowdhury <pliablepixels@gmail.com> | 2015-09-29 13:59:39 -0400 |
| commit | 054bd7beffd8cc304f48f1b1369c118a28bbbf73 (patch) | |
| tree | 86759428cb164c6fce9a4be9f710981c86381449 | |
| parent | 884bf8c92597c5864b500a478b91675d12c5a477 (diff) | |
I think there is a problem when showing a popup inside ontap of another. Abstracted out. Hopefully fixes https://github.com/pliablepixels/zmNinja/issues/35
| -rw-r--r-- | www/js/StateCtrl.js | 104 |
1 files changed, 67 insertions, 37 deletions
diff --git a/www/js/StateCtrl.js b/www/js/StateCtrl.js index a53b7911..05498352 100644 --- a/www/js/StateCtrl.js +++ b/www/js/StateCtrl.js @@ -104,17 +104,30 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', buttons: [ { text: 'Cancel', + onTap: function(e) + { + return "CANCEL"; + } }, { text: 'OK', onTap: function (e) { - if ($scope.myopt.selectedState != "") - controlZM($scope.myopt.selectedState); + return "OK"; + } } ] }); + + getConfig.then(function(res) { + console.log ("GOT : " + JSON.stringify(res)); + if (res == "OK") + { + if ($scope.myopt.selectedState != "") + controlZM($scope.myopt.selectedState); + } + }); }; @@ -227,37 +240,14 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', // start/stop/restart ZM //---------------------------------------------------------------------- - function controlZM(str) { - if (inProgress) { - ZMDataModel.zmDebug("StateCtrl/controlZM: operation in progress"); - $ionicPopup.alert({ - title: "Operation in Progress", - template: "The previous operation is still in progress. Please wait..." - }); - return; - } - - var statesearch = "startstoprestart"; - var promptstring = 'Are you sure you want to ' + str + ' Zoneminder?'; - - if (statesearch.indexOf(str) == -1) { - promptstring = "Are you sure you want to change state to " + str; - } - - - $ionicPopup.show({ - title: 'Please Confirm', - template: promptstring, - buttons: [ - { - text: 'Cancel', - type: 'button-positive' - }, - { - text: 'Yes', - type: 'button-assertive', - onTap: function (e) { - $scope.zmRun = "please wait..."; + function performZMoperation(str) + { + + + ZMDataModel.zmDebug ("inside performZMoperation with " + str); + + + $scope.zmRun = "please wait..."; $scope.color = 'color:orange;'; $scope.customState = ""; ZMDataModel.zmDebug("StateCtrl/controlZM: POST Control command is " + apiExec + str + ".json"); @@ -266,6 +256,7 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', .then( function (success) { ZMDataModel.zmDebug("StateCtrl/controlZM: returned success"); + inProgress = 0; switch (str) { case "stop": $scope.zmRun = 'stopped'; @@ -275,11 +266,10 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', $scope.zmRun = 'running'; $scope.color = 'color:green;'; getCurrentState(); - break; - + } - inProgress = 0; + }, function (error) { //if (error.status) // it seems to return error with status 0 if ok @@ -292,10 +282,50 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', inProgress = 0; }); //incredible nesting below. I make myself proud. + + + } + + + function controlZM(str) { + if (inProgress) { + ZMDataModel.zmDebug("StateCtrl/controlZM: operation in progress"); + $ionicPopup.alert({ + title: "Operation in Progress", + template: "The previous operation is still in progress. Please wait..." + }); + return; + } + + var statesearch = "startstoprestart"; + + var promptstring = 'Are you sure you want to ' + str + ' Zoneminder?'; + if (statesearch.indexOf(str) == -1) { + promptstring = "Are you sure you want to change state to " + str; + } + + + $ionicPopup.show({ + title: 'Please Confirm', + template: promptstring, + buttons: [ + { + text: 'Cancel', + type: 'button-positive' + }, + { + text: 'Yes', + type: 'button-assertive', + onTap: function (e) { + performZMoperation(str); } } ] - }); + }); + + + + } // Binder so template can call controlZM |
