blob: a4d03c2a93a497287313e4612b412f84838879e2 [file] [log] [blame]
Simon Huntb9c495e2015-11-05 15:08:06 -08001// 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 Huntdf8a6402016-02-04 10:58:54 -080036 ['$log', '$scope', 'WebSocketService', 'KeyService', 'NavService',
Simon Huntb9c495e2015-11-05 15:08:06 -080037
Simon Huntdf8a6402016-02-04 10:58:54 -080038 function (_$log_, _$scope_, _wss_, _ks_, ns) {
Simon Huntb9c495e2015-11-05 15:08:06 -080039 $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 Huntdf8a6402016-02-04 10:58:54 -080053 // custom click handler for button
Simon Huntb9c495e2015-11-05 15:08:06 -080054 $scope.getData = getData;
55
Simon Huntdf8a6402016-02-04 10:58:54 -080056 // custom click handler for icon
57 // pass straight through to nav service navTo()
58 $scope.nav = ns.navTo;
59
Simon Huntb9c495e2015-11-05 15:08:06 -080060 // 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}());