diff --git a/www/plugins/es/js/controllers/profile-controllers.js b/www/plugins/es/js/controllers/profile-controllers.js index 0a98e7d5e9a591432195466041116c0f1db0beaf..c2d4f92013db2a71951199e6793edec4ed0f18ed 100644 --- a/www/plugins/es/js/controllers/profile-controllers.js +++ b/www/plugins/es/js/controllers/profile-controllers.js @@ -90,48 +90,47 @@ function ESViewEditProfileController($scope, $q, $timeout, $state, $focus, $tran $scope.$on('$ionicView.enter', $scope.enter); $scope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { - if ($scope.dirty && !$scope.saving) { + if (!$scope.dirty || $scope.saving || event.defaultPrevented) return; - // stop the change state action - event.preventDefault(); + // stop the change state action + event.preventDefault(); - if (!$scope.loading) { - $scope.loading = true; - return UIUtils.alert.confirm('CONFIRM.SAVE_BEFORE_LEAVE', - 'CONFIRM.SAVE_BEFORE_LEAVE_TITLE', { - cancelText: 'COMMON.BTN_NO', - okText: 'COMMON.BTN_YES_SAVE' - }) - .then(function(confirmSave) { - $scope.loading = false; - if (confirmSave) { - $scope.form.$submitted=true; - return $scope.save(false/*silent*/, true/*haswait debounce*/) - .then(function(saved){ - if (saved) { - $scope.dirty = false; - } - return saved; // change state only if not error - }); - } - else { - $scope.dirty = false; - return true; // ok, change state - } - }) - .then(function(confirmGo) { - if (confirmGo) { - // continue to the order state - $ionicHistory.nextViewOptions({ - historyRoot: true + if (!$scope.loading) { + $scope.loading = true; + return UIUtils.alert.confirm('CONFIRM.SAVE_BEFORE_LEAVE', + 'CONFIRM.SAVE_BEFORE_LEAVE_TITLE', { + cancelText: 'COMMON.BTN_NO', + okText: 'COMMON.BTN_YES_SAVE' + }) + .then(function(confirmSave) { + $scope.loading = false; + if (confirmSave) { + $scope.form.$submitted=true; + return $scope.save(false/*silent*/, true/*haswait debounce*/) + .then(function(saved){ + if (saved) { + $scope.dirty = false; + } + return saved; // change state only if not error }); - $state.go(next.name, nextParams); - } - }) - .catch(function(err) { - // Silent - }); - } + } + else { + $scope.dirty = false; + return true; // ok, change state + } + }) + .then(function(confirmGo) { + if (confirmGo) { + // continue to the order state + $ionicHistory.nextViewOptions({ + historyRoot: true + }); + $state.go(next.name, nextParams); + } + }) + .catch(function(err) { + // Silent + }); } }); diff --git a/www/plugins/es/js/controllers/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js index 621387f58a54b74b52dacdf0c914bd7b9bff9a2a..44ab53d1ab260c66ce4785d86a110797476de432 100644 --- a/www/plugins/es/js/controllers/registry-controllers.js +++ b/www/plugins/es/js/controllers/registry-controllers.js @@ -1053,48 +1053,47 @@ function ESRegistryRecordEditController($scope, $timeout, $state, $q, $ionicHis }); $scope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { - if ($scope.dirty && !$scope.saving) { - - // stop the change state action - event.preventDefault(); - - if (!$scope.loading) { - $scope.loading = true; - return UIUtils.alert.confirm('CONFIRM.SAVE_BEFORE_LEAVE', - 'CONFIRM.SAVE_BEFORE_LEAVE_TITLE', { - cancelText: 'COMMON.BTN_NO', - okText: 'COMMON.BTN_YES_SAVE' - }) - .then(function(confirmSave) { - $scope.loading = false; - if (confirmSave) { - $scope.form.$submitted=true; - return $scope.save(false/*silent*/, true/*haswait debounce*/) - .then(function(saved){ - if (saved) { - $scope.dirty = false; - } - return saved; // change state only if not error - }); - } - else { - $scope.dirty = false; - return true; // ok, change state - } - }) - .then(function(confirmGo) { - if (confirmGo) { - // continue to the order state - $ionicHistory.nextViewOptions({ - historyRoot: true + if (!$scope.dirty || $scope.saving || event.defaultPrevented) return; + + // stop the change state action + event.preventDefault(); + + if (!$scope.loading) { + $scope.loading = true; + return UIUtils.alert.confirm('CONFIRM.SAVE_BEFORE_LEAVE', + 'CONFIRM.SAVE_BEFORE_LEAVE_TITLE', { + cancelText: 'COMMON.BTN_NO', + okText: 'COMMON.BTN_YES_SAVE' + }) + .then(function(confirmSave) { + $scope.loading = false; + if (confirmSave) { + $scope.form.$submitted=true; + return $scope.save(false/*silent*/, true/*haswait debounce*/) + .then(function(saved){ + if (saved) { + $scope.dirty = false; + } + return saved; // change state only if not error }); - $state.go(next.name, nextParams); - } - }) - .catch(function(err) { - // Silent - }); - } + } + else { + $scope.dirty = false; + return true; // ok, change state + } + }) + .then(function(confirmGo) { + if (confirmGo) { + // continue to the order state + $ionicHistory.nextViewOptions({ + historyRoot: true + }); + $state.go(next.name, nextParams); + } + }) + .catch(function(err) { + // Silent + }); } });