blob: 47b6a8d20a213983f5f77c21e88a1089215d489b [file] [log] [blame]
Matteo Scandolo388795a2016-02-22 09:57:55 -08001(function () {
2 'use strict';
Matteo Scandolo04564952016-02-24 11:22:48 -08003 angular.module('xos.diagnostic')
Matteo Scandolo574c73f2016-03-01 17:08:45 -08004 .directive('selectSubscriberModal', function(){
Matteo Scandolo388795a2016-02-22 09:57:55 -08005 return {
6 scope: {
7 subscribers: '=',
8 open: '='
9 },
10 bindToController: true,
11 restrict: 'E',
Matteo Scandolo574c73f2016-03-01 17:08:45 -080012 templateUrl: 'templates/select-subscriber-modal.tpl.html',
Matteo Scandolo388795a2016-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 Scandolo574c73f2016-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 Scandolo6c6e5942016-03-02 10:59:46 -080037 controller: function($log, $timeout, $scope, Subscribers){
Matteo Scandolo574c73f2016-03-01 17:08:45 -080038
Matteo Scandolo6c6e5942016-03-02 10:59:46 -080039 $scope.$watch(() => this.open, () => {
40 this.success = null;
41 this.formError = null;
Matteo Scandolo574c73f2016-03-01 17:08:45 -080042 });
43
Matteo Scandolo19acf7c2016-03-07 16:07:13 -080044 $scope.$watch(() => this.subscriber, () => {
Matteo Scandolo3a176a22016-03-07 16:42:03 -080045 if(!this.subscriber){
46 return;
47 }
Matteo Scandolo19acf7c2016-03-07 16:07:13 -080048 this.subscriber.uplink_speed = parseInt(this.subscriber.uplink_speed, 10);
49 this.subscriber.downlink_speed = parseInt(this.subscriber.downlink_speed, 10);
50 });
51
Matteo Scandolo574c73f2016-03-01 17:08:45 -080052 this.close = () => {
53 this.open = false;
54 };
55
Matteo Scandolo6c6e5942016-03-02 10:59:46 -080056 this.updateSubscriber = (subscriber) => {
57
58 Subscribers.update(subscriber).$promise
59 .then(() => {
60 this.success = 'Subscriber successfully updated!';
61 })
62 .catch((e) => {
63 this.formError = e;
64 })
65 .finally(() => {
66 $timeout(() => {
67 this.close();
68 }, 1500);
69 });
Matteo Scandolo574c73f2016-03-01 17:08:45 -080070 };
71 }
72 };
Matteo Scandolo388795a2016-02-22 09:57:55 -080073 });
74})();