Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
Matteo Scandolo | 4b3d872 | 2016-02-24 11:22:48 -0800 | [diff] [blame] | 3 | angular.module('xos.diagnostic') |
Matteo Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 4 | .directive('selectSubscriberModal', function(){ |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 5 | return { |
| 6 | scope: { |
| 7 | subscribers: '=', |
| 8 | open: '=' |
| 9 | }, |
| 10 | bindToController: true, |
| 11 | restrict: 'E', |
Matteo Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 12 | templateUrl: 'templates/select-subscriber-modal.tpl.html', |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 13 | 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 Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 26 | }) |
| 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 Scandolo | 5fc82c3 | 2016-03-02 10:59:46 -0800 | [diff] [blame] | 37 | controller: function($log, $timeout, $scope, Subscribers){ |
Matteo Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 38 | |
Matteo Scandolo | 5fc82c3 | 2016-03-02 10:59:46 -0800 | [diff] [blame] | 39 | $scope.$watch(() => this.open, () => { |
| 40 | this.success = null; |
| 41 | this.formError = null; |
Matteo Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 42 | }); |
| 43 | |
Matteo Scandolo | bd66374 | 2016-03-07 16:07:13 -0800 | [diff] [blame] | 44 | $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 Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 49 | this.close = () => { |
| 50 | this.open = false; |
| 51 | }; |
| 52 | |
Matteo Scandolo | 5fc82c3 | 2016-03-02 10:59:46 -0800 | [diff] [blame] | 53 | 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 Scandolo | 5bb1668 | 2016-03-01 17:08:45 -0800 | [diff] [blame] | 67 | }; |
| 68 | } |
| 69 | }; |
Matteo Scandolo | cc8fa15 | 2016-02-22 09:57:55 -0800 | [diff] [blame] | 70 | }); |
| 71 | })(); |