From 801d2ae380816cfa5512f4bd1b66988c3578b530 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 22 Jul 2017 09:17:50 +0200 Subject: [PATCH] Migrate to toastr. --- src/scheduler/schedule.controller.ts | 34 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/scheduler/schedule.controller.ts b/src/scheduler/schedule.controller.ts index 5f53ba5..97f67a6 100644 --- a/src/scheduler/schedule.controller.ts +++ b/src/scheduler/schedule.controller.ts @@ -1,3 +1,7 @@ +import { Logger } from '@nsalaun/ng-logger'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { ToastrService } from 'ngx-toastr'; + var scheduleFormTmpl = require('./schedule.form.tmpl.html'), scheduleDeleteTmpl = require('./schedule.delete.tmpl.html'); @@ -8,7 +12,7 @@ export class ScheduleController{ constructor( private $stateParams, - private Notification, + private toastrService: ToastrService, private ScheduledOperation, private $modal ) { @@ -42,14 +46,14 @@ export class ScheduleController{ * Save operation. */ save = function(operation) { - return operation.$save().then(function(operation) { - this.Notification.success('Scheduled operation #' + operation.id + ' saved.'); + return operation.$save().then((operation) => { + this.toastrService.success('Scheduled operation #' + operation.id + ' saved.'); this.operations = this.load(); return operation; - }, function(result){ - this.Notification.error( + }, (result) => { + this.toastrService.error( 'Error while saving scheduled operation: ' + result.message ); }); @@ -66,7 +70,7 @@ export class ScheduleController{ controller: function($scope, title, operation, $delete) { $scope.title = title; $scope.operation = operation; - $scope.$delete = function() { + $scope.$delete = () => { $scope.$hide(); $delete($scope.operation); }; @@ -74,7 +78,9 @@ export class ScheduleController{ locals: { title: title, operation: operation, - $delete: this.delete + $delete: (operation) => { + this.delete(operation); + } } }); }; @@ -85,14 +91,14 @@ export class ScheduleController{ delete = function(operation) { var id = operation.id; - return operation.$delete().then(function() { - this.Notification.success('Scheduled operation #' + id + ' deleted.'); + return operation.$delete().then(() => { + this.toastrService.success('Scheduled operation #' + id + ' deleted.'); this.operations = this.load(); return operation; - }, function(result) { - this.Notification.error( + }, (result) => { + this.toastrService.error( 'An error occurred while trying to delete scheduled operation #' + id + ':
' + result ); @@ -116,7 +122,7 @@ export class ScheduleController{ controller: function($scope, title, operation, $save) { $scope.title = title; $scope.operation = operation; - $scope.$save = function() { + $scope.$save = () => { $scope.$hide(); $save($scope.operation); }; @@ -124,7 +130,9 @@ export class ScheduleController{ locals: { title: title, operation: operation, - $save: this.save + $save: (operation) => { + this.save(operation); + } } }); };