1 // js for sample app view
6 var $log, $scope, fs, wss, ps;
9 var detailsReq = 'sampleDetailsRequest',
10 detailsResp = 'sampleDetailsResponse',
11 pName = 'item-details-panel',
13 propOrder = ['id', 'label', 'code'],
14 friendlyProps = ['Item ID', 'Item Label', 'Special Code'];
17 function addProp(tbody, index, value) {
18 var tr = tbody.append('tr');
20 function addCell(cls, txt) {
21 tr.append('td').attr('class', cls).html(txt);
23 addCell('label', friendlyProps[index] + ' :');
24 addCell('value', value);
27 function populatePanel(panel) {
28 var title = panel.append('h3'),
29 tbody = panel.append('table').append('tbody');
31 title.text('Item Details');
33 propOrder.forEach(function (prop, i) {
34 addProp(tbody, i, $scope.panelDetails[prop]);
38 panel.append('h4').text('Comments');
39 panel.append('p').text($scope.panelDetails.comment);
42 function respDetailsCb(data) {
43 $scope.panelDetails = data.details;
47 angular.module('ovSample', [])
48 .controller('OvSampleCtrl',
49 ['$log', '$scope', 'TableBuilderService',
50 'FnService', 'WebSocketService',
52 function (_$log_, _$scope_, tbs, _fs_, _wss_) {
59 $scope.panelDetails = {};
61 // details response handler
62 handlers[detailsResp] = respDetailsCb;
63 wss.bindHandlers(handlers);
65 // custom selection callback
66 function selCb($event, row) {
68 wss.sendEvent(detailsReq, { id: row.id });
72 $log.debug('Got a click on:', row);
75 // TableBuilderService creating a table for us
83 $scope.$on('$destroy', function () {
84 wss.unbindHandlers(handlers);
87 $log.log('OvSampleCtrl has been created');
90 .directive('itemDetailsPanel', ['PanelService', 'KeyService',
94 link: function (scope, element, attrs) {
96 // insert details panel with PanelService
98 var panel = ps.createPanel(pName, {
104 scope.hidePanel = function () { panel.hide(); };
106 function closePanel() {
107 if (panel.isVisible()) {
113 // create key bindings to handle panel
115 esc: [closePanel, 'Close the details panel'],
119 ['click', 'Select a row to show item details']
122 // update the panel's contents when the data is changed
123 scope.$watch('panelDetails', function () {
124 if (!fs.isEmptyObject(scope.panelDetails)) {
126 populatePanel(panel);
131 // cleanup on destroyed scope
132 scope.$on('$destroy', function () {
134 ps.destroyPanel(pName);