Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 1 | // js for UI Reference App custom view |
| 2 | (function () { |
| 3 | 'use strict'; |
| 4 | |
| 5 | // injected refs |
| 6 | var $log, $scope, wss, ks; |
| 7 | |
| 8 | // constants |
| 9 | var dataReq = 'uiRefCustomDataRequest', |
| 10 | dataResp = 'uiRefCustomDataResponse'; |
| 11 | |
| 12 | function addKeyBindings() { |
| 13 | var map = { |
| 14 | space: [getData, 'Fetch data from server'], |
| 15 | |
| 16 | _helpFormat: [ |
| 17 | ['space'] |
| 18 | ] |
| 19 | }; |
| 20 | |
| 21 | ks.keyBindings(map); |
| 22 | } |
| 23 | |
| 24 | function getData() { |
| 25 | wss.sendEvent(dataReq); |
| 26 | } |
| 27 | |
| 28 | function respDataCb(data) { |
| 29 | $scope.data = data; |
| 30 | $scope.$apply(); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | angular.module('ovUiRefCustom', []) |
| 35 | .controller('OvUiRefCustomCtrl', |
Simon Hunt | df8a640 | 2016-02-04 10:58:54 -0800 | [diff] [blame^] | 36 | ['$log', '$scope', 'WebSocketService', 'KeyService', 'NavService', |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 37 | |
Simon Hunt | df8a640 | 2016-02-04 10:58:54 -0800 | [diff] [blame^] | 38 | function (_$log_, _$scope_, _wss_, _ks_, ns) { |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 39 | $log = _$log_; |
| 40 | $scope = _$scope_; |
| 41 | wss = _wss_; |
| 42 | ks = _ks_; |
| 43 | |
| 44 | var handlers = {}; |
| 45 | $scope.data = {}; |
| 46 | |
| 47 | // data response handler |
| 48 | handlers[dataResp] = respDataCb; |
| 49 | wss.bindHandlers(handlers); |
| 50 | |
| 51 | addKeyBindings(); |
| 52 | |
Simon Hunt | df8a640 | 2016-02-04 10:58:54 -0800 | [diff] [blame^] | 53 | // custom click handler for button |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 54 | $scope.getData = getData; |
| 55 | |
Simon Hunt | df8a640 | 2016-02-04 10:58:54 -0800 | [diff] [blame^] | 56 | // custom click handler for icon |
| 57 | // pass straight through to nav service navTo() |
| 58 | $scope.nav = ns.navTo; |
| 59 | |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 60 | // get data the first time... |
| 61 | getData(); |
| 62 | |
| 63 | // cleanup |
| 64 | $scope.$on('$destroy', function () { |
| 65 | wss.unbindHandlers(handlers); |
| 66 | ks.unbindKeys(); |
| 67 | $log.log('OvUiRefCustomCtrl has been destroyed'); |
| 68 | }); |
| 69 | |
| 70 | $log.log('OvUiRefCustomCtrl has been created'); |
| 71 | }]); |
| 72 | |
| 73 | }()); |