blob: 025efc34e9ff63427aa78a364eebdba4c51f6e3d [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',
36 ['$log', '$scope', 'WebSocketService', 'KeyService',
37
38 function (_$log_, _$scope_, _wss_, _ks_) {
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
53 // custom click handler
54 $scope.getData = getData;
55
56 // get data the first time...
57 getData();
58
59 // cleanup
60 $scope.$on('$destroy', function () {
61 wss.unbindHandlers(handlers);
62 ks.unbindKeys();
63 $log.log('OvUiRefCustomCtrl has been destroyed');
64 });
65
66 $log.log('OvUiRefCustomCtrl has been created');
67 }]);
68
69}());