diff --git a/src/operations/index.js b/src/operations/index.js index b483524..bc9adc8 100644 --- a/src/operations/index.js +++ b/src/operations/index.js @@ -58,7 +58,7 @@ var operationModule = angular.module('accountant.operations', [ * Controller for the operations. */ .controller('OperationController', function($rootScope, $scope, $routeParams, - $ngBootbox, Notification, Operation) { + $ngBootbox, $uibModal, Notification, Operation, $log) { var vm = this; @@ -167,6 +167,23 @@ var operationModule = angular.module('accountant.operations', [ ); }; + vm.modify = function(operation, $index) { + $uibModal.open({ + component: 'operationModalComponent', + resolve: { + operation: function() { + return operation; + } + } + }).result.then(function(operation) { + // FIXME Alexis Lahouze 2017-06-15 Save Operation and reload data to + // update balances. + $log.info('modal validated', operation); + }, function() { + $log.info('modal-component dismissed at: ' + new Date()); + }); + }; + /* * Reload operations on rangeSelectedEvent. */ @@ -181,56 +198,41 @@ var operationModule = angular.module('accountant.operations', [ vm.load(moment().date(1).year(2000), moment()); }) -.directive('operationFormDialog', function($log, $ngBootbox) { - return { - restrict: 'A', - scope: { - operation: '=ngModel' - }, - link: function(scope, element) { - var title = 'Operation'; +.component('operationModalComponent', { + templateUrl: operationFormTmpl, + bindings: { + resolve: '<', + close: '&', + dismiss: '&' + }, + controller: function() { + var vm = this; - if (scope.operation && scope.operation.id) { - title = title + ' #' + scope.operation.id; - } + vm.$onInit = function() { + vm.operation = vm.resolve.operation; + }; - scope.form = {}; - - element.on('click', function() { - scope.data = {}; - angular.copy(scope.operation, scope.data); - - // Open dialog with form. - $ngBootbox.customDialog({ - scope: scope, - title: title, - templateUrl: operationFormTmpl, - onEscape: true, - buttons: { - save: { - label: 'Save', - className: 'btn-success', - callback: function() { - // Validate form - $log.log(scope.form); - - // Save operation - $log.log(scope.operation); - - // TODO Alexis Lahouze 2016-05-24 Save operation, handle return. - return false; - } - }, - cancel: { - label: 'Cancel', - className: 'btn-default', - callback: true - } - } - }); + 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 "Operation #" + vm.operation.id; + } else { + return "Operation"; + } + }; + } }); module.exports = operationModule; diff --git a/src/operations/operation.form.tmpl.html b/src/operations/operation.form.tmpl.html index a898317..f145f2f 100644 --- a/src/operations/operation.form.tmpl.html +++ b/src/operations/operation.form.tmpl.html @@ -16,43 +16,56 @@ --> -