blob: 74bb8a7a1f55da0efb0f612311373d1facb4b61b [file] [log] [blame]
Matteo Scandolocc8fa152016-02-22 09:57:55 -08001(function () {
2 'use strict';
Matteo Scandolo4b3d8722016-02-24 11:22:48 -08003 angular.module('xos.diagnostic')
Matteo Scandolo5bb16682016-03-01 17:08:45 -08004 .directive('selectSubscriberModal', function(){
Matteo Scandolocc8fa152016-02-22 09:57:55 -08005 return {
6 scope: {
7 subscribers: '=',
8 open: '='
9 },
10 bindToController: true,
11 restrict: 'E',
Matteo Scandolo5bb16682016-03-01 17:08:45 -080012 templateUrl: 'templates/select-subscriber-modal.tpl.html',
Matteo Scandolocc8fa152016-02-22 09:57:55 -080013 controllerAs: 'vm',
14 controller: function($rootScope){
15
16 this.close = () => {
17 this.open = false;
18 };
19
20 this.select = (subscriber) => {
21 $rootScope.$emit('subscriber.selected', subscriber);
22 this.close();
23 };
24 }
25 };
Matteo Scandolo5bb16682016-03-01 17:08:45 -080026 })
27 .directive('subscriberStatusModal', function(){
28 return {
29 scope: {
30 open: '=',
31 subscriber: '='
32 },
33 bindToController: true,
34 restrict: 'E',
35 templateUrl: 'templates/subscriber-status-modal.tpl.html',
36 controllerAs: 'vm',
Matteo Scandolo5fc82c32016-03-02 10:59:46 -080037 controller: function($log, $timeout, $scope, Subscribers){
Matteo Scandolo5bb16682016-03-01 17:08:45 -080038
Matteo Scandolo5fc82c32016-03-02 10:59:46 -080039 $scope.$watch(() => this.open, () => {
40 this.success = null;
41 this.formError = null;
Matteo Scandolo5bb16682016-03-01 17:08:45 -080042 });
43
44 this.close = () => {
45 this.open = false;
46 };
47
Matteo Scandolo5fc82c32016-03-02 10:59:46 -080048 this.updateSubscriber = (subscriber) => {
49
50 Subscribers.update(subscriber).$promise
51 .then(() => {
52 this.success = 'Subscriber successfully updated!';
53 })
54 .catch((e) => {
55 this.formError = e;
56 })
57 .finally(() => {
58 $timeout(() => {
59 this.close();
60 }, 1500);
61 });
Matteo Scandolo5bb16682016-03-01 17:08:45 -080062 };
63 }
64 };
Matteo Scandolocc8fa152016-02-22 09:57:55 -080065 });
66})();