From d9e8f378cd84e06ff02d8086b1ba75fc57f21bc4 Mon Sep 17 00:00:00 2001 From: Benoit Lavenier <benoit.lavenier@e-is.pro> Date: Tue, 18 Aug 2020 18:55:38 +0200 Subject: [PATCH] [fix] Avoid many popup "Do you want to quit without saving" --- .../es/js/controllers/profile-controllers.js | 77 +++++++++--------- .../es/js/controllers/registry-controllers.js | 81 +++++++++---------- 2 files changed, 78 insertions(+), 80 deletions(-) diff --git a/www/plugins/es/js/controllers/profile-controllers.js b/www/plugins/es/js/controllers/profile-controllers.js index 0a98e7d5e..c2d4f9201 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 621387f58..44ab53d1a 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 + }); } }); -- GitLab