Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 1 | // js for sample app view |
| 2 | (function () { |
| 3 | 'use strict'; |
| 4 | |
Simon Hunt | e11ce5a | 2015-07-21 12:11:04 -0700 | [diff] [blame^] | 5 | // injected refs |
| 6 | var $log, $scope, fs, mast, ps, wss; |
| 7 | |
| 8 | // internal state |
| 9 | var selRow, |
| 10 | detailsPanel, |
| 11 | pStartY, pHeight, |
| 12 | wSize; |
| 13 | |
| 14 | // constants |
| 15 | var topPadding = 20, |
| 16 | |
| 17 | detailsReq = 'sampleDetailsRequest', |
| 18 | detailsResp = 'sampleDetailsResponse', |
| 19 | pName = 'item-details-panel', |
| 20 | |
| 21 | propOrder = [ 'id', 'label', 'code'], |
| 22 | friendlyProps = [ 'Item ID', 'Item Label', 'Special Code' ]; |
| 23 | |
| 24 | |
| 25 | function respDetailsCb(data) { |
| 26 | $scope.panelData = data.details; |
| 27 | $scope.$apply(); |
| 28 | } |
| 29 | |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 30 | angular.module('ovSample', []) |
| 31 | .controller('OvSampleCtrl', |
Simon Hunt | e11ce5a | 2015-07-21 12:11:04 -0700 | [diff] [blame^] | 32 | ['$log', '$scope', 'TableBuilderService', |
| 33 | 'FnService', 'WebSocketService', |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 34 | |
Simon Hunt | e11ce5a | 2015-07-21 12:11:04 -0700 | [diff] [blame^] | 35 | function (_$log_, _$scope_, tbs, _fs_, _wss_) { |
| 36 | $log = _$log_; |
| 37 | $scope = _$scope_; |
| 38 | fs = _fs_; |
| 39 | wss = _wss_; |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 40 | |
Simon Hunt | e11ce5a | 2015-07-21 12:11:04 -0700 | [diff] [blame^] | 41 | var handlers = {}; |
| 42 | |
| 43 | $scope.panelData = []; |
| 44 | |
| 45 | function selCb($event, row) { |
| 46 | selRow = angular.element($event.currentTarget); |
| 47 | if ($scope.selId) { |
| 48 | wss.sendEvent(detailsReq, { id: row.id }); |
| 49 | } else { |
| 50 | $log.debug('need to hide details panel'); |
| 51 | //detailsPanel.hide() |
| 52 | } |
| 53 | $log.debug('Got a click on:', row); |
| 54 | } |
| 55 | |
| 56 | tbs.buildTable({ |
| 57 | scope: $scope, |
| 58 | tag: 'sample', |
| 59 | selCb: selCb |
| 60 | }); |
| 61 | |
| 62 | // details response handler |
| 63 | handlers[detailsResp] = respDetailsCb; |
| 64 | wss.bindHandlers(handlers); |
| 65 | |
| 66 | $scope.$on('$destroy', function () { |
| 67 | wss.unbindHandlerse(handlers); |
| 68 | }); |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 69 | |
| 70 | $log.log('OvSampleCtrl has been created'); |
| 71 | }]); |
| 72 | }()); |