blob: 291173384108d48579704504ee64a2ab279f5984 [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
Matteo Scandolobd663742016-03-07 16:07:13 -080044 $scope.$watch(() => this.subscriber, () => {
45 this.subscriber.uplink_speed = parseInt(this.subscriber.uplink_speed, 10);
46 this.subscriber.downlink_speed = parseInt(this.subscriber.downlink_speed, 10);
47 });
48
Matteo Scandolo5bb16682016-03-01 17:08:45 -080049 this.close = () => {
50 this.open = false;
51 };
52
Matteo Scandolo5fc82c32016-03-02 10:59:46 -080053 this.updateSubscriber = (subscriber) => {
54
55 Subscribers.update(subscriber).$promise
56 .then(() => {
57 this.success = 'Subscriber successfully updated!';
58 })
59 .catch((e) => {
60 this.formError = e;
61 })
62 .finally(() => {
63 $timeout(() => {
64 this.close();
65 }, 1500);
66 });
Matteo Scandolo5bb16682016-03-01 17:08:45 -080067 };
68 }
69 };
Matteo Scandolocc8fa152016-02-22 09:57:55 -080070 });
71})();