From 30549dd6d88cc01c114272495bb5421c4dfdf09e Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 8 Jul 2017 09:33:52 +0200 Subject: [PATCH] Use angular strap modal instead of angular-ui-bootstrap one. --- src/scheduler/index.js | 162 +++++++-------------- src/scheduler/schedule.delete.tmpl.html | 37 +++-- src/scheduler/schedule.form.tmpl.html | 184 +++++++++++------------- src/scheduler/scheduler.html | 2 +- 4 files changed, 165 insertions(+), 220 deletions(-) diff --git a/src/scheduler/index.js b/src/scheduler/index.js index 30b209f..e993f5a 100644 --- a/src/scheduler/index.js +++ b/src/scheduler/index.js @@ -48,7 +48,7 @@ module.exports = angular.module('accountant.scheduler', [ ); }) - .controller('SchedulerController', function($rootScope, $routeParams, Notification, ScheduledOperation, $log, $uibModal, $q) { + .controller('SchedulerController', function($rootScope, $routeParams, Notification, ScheduledOperation, $log, $modal) { var vm = this; // Operation store. @@ -92,8 +92,30 @@ module.exports = angular.module('accountant.scheduler', [ Notification.error( 'Error while saving scheduled operation: ' + result.message ); + }); + }; - return $q.reject(result); + /* + * Delete an operation and return a promise. + */ + vm.confirmDelete = function(operation) { + var title = "Delete operation #" + operation.id; + + $modal({ + templateUrl: scheduleDeleteTmpl, + controller: function($scope, title, operation, $delete) { + $scope.title = title; + $scope.operation = operation; + $scope.$delete = function() { + $scope.$hide(); + $delete($scope.operation); + }; + }, + locals: { + title: title, + operation: operation, + $delete: vm.delete + } }); }; @@ -103,30 +125,17 @@ module.exports = angular.module('accountant.scheduler', [ vm.delete = function(operation) { var id = operation.id; - $uibModal.open({ - component: 'scheduleDeleteModalComponent', - resolve: { - operation: function() { - return operation; - } - } - }).result.then(function(operation) { - return operation.$delete().then(function() { - Notification.success('Operation #' + id + ' deleted.'); + return operation.$delete().then(function() { + Notification.success('Scheduled operation #' + id + ' deleted.'); - vm.operations = vm.load(); + vm.operations = vm.load(); - return operation; - }, function(result) { - Notification.error( - 'An error occurred while trying to delete operation #' + - id + ':
' + result - ); - - return $q.reject(result); - }); - }, function() { - return false; + return operation; + }, function(result) { + Notification.error( + 'An error occurred while trying to delete scheduled operation #' + + id + ':
' + result + ); }); }; @@ -135,17 +144,28 @@ module.exports = angular.module('accountant.scheduler', [ * @returns a promise. */ vm.modify = function(operation) { - return $uibModal.open({ - component: 'scheduleModifyModalComponent', - resolve: { - operation: function() { - return operation; - } + // FIXME Alexis Lahouze 2017-06-15 i18n + var title = "Operation"; + + if (operation.id) { + title = title + " #" + operation.id; + } + + $modal({ + templateUrl: scheduleFormTmpl, + controller: function($scope, title, operation, $save) { + $scope.title = title; + $scope.operation = operation; + $scope.$save = function() { + $scope.$hide(); + $save($scope.operation); + }; + }, + locals: { + title: title, + operation: operation, + $save: vm.save } - }).result.then(function(operation) { - return vm.save(operation); - }, function() { - return false; }); }; @@ -153,78 +173,4 @@ module.exports = angular.module('accountant.scheduler', [ vm.operations = vm.load(); }) - .component('scheduleModifyModalComponent', { - templateUrl: scheduleFormTmpl, - bindings: { - resolve: '<', - close: '&', - dismiss: '&' - }, - controller: function() { - var vm = this; - - vm.$onInit = function() { - vm.operation = vm.resolve.operation; - }; - - vm.ok = function() { - vm.close({ - $value: vm.operation - }); - }; - - vm.cancel = function() { - vm.dismiss({ - $value: 'cancel' - }); - }; - - vm.title = function() { - // FIXME Alexis Lahouze 2017-06-15 i18n - if (vm.operation.id) { - return "Scheduled operation #" + vm.operation.id; - } else { - return "Scheduled operation"; - } - }; - } - }) - - .component('scheduleDeleteModalComponent', { - templateUrl: scheduleDeleteTmpl, - bindings: { - resolve: '<', - close: '&', - dismiss: '&' - }, - controller: function() { - var vm = this; - - vm.$onInit = function() { - vm.operation = vm.resolve.operation; - }; - - vm.ok = function() { - vm.close({ - $value: vm.operation - }); - }; - - vm.cancel = function() { - vm.dismiss({ - $value: 'cancel' - }); - }; - - vm.title = function() { - // FIXME Alexis Lahouze 2017-06-15 i18n - if (vm.operation.id) { - return "Scheduled operation #" + vm.operation.id; - } else { - return "Scheduled operation"; - } - }; - } - }) - .name; diff --git a/src/scheduler/schedule.delete.tmpl.html b/src/scheduler/schedule.delete.tmpl.html index 545ce03..904ae6d 100644 --- a/src/scheduler/schedule.delete.tmpl.html +++ b/src/scheduler/schedule.delete.tmpl.html @@ -1,16 +1,25 @@ - + +