blob: a0b1b94de149f7baadccee6c187c3b0433dd692c [file] [log] [blame]
Steven Burrowsc8468932017-03-17 16:13:41 +00001(function () {
2 'use-strict';
3
4 var instance;
5
6 // TODO: Commented k2b map and addToggles are not implement in Topo2 yet.
7
8 // key to button mapping data
9 var k2b = {
10 O: { id: 'topo2-summary-tog', gid: 'm_summary', isel: true},
11 I: { id: 'topo2-instance-tog', gid: 'm_uiAttached', isel: true },
12 // D: { id: 'details-tog', gid: 'm_details', isel: true },
13 // H: { id: 'hosts-tog', gid: 'm_endstation', isel: false },
14 // M: { id: 'offline-tog', gid: 'm_switch', isel: true },
15 P: { id: 'topo2-ports-tog', gid: 'm_ports', isel: true },
Steven Burrows9f7a2d72017-03-29 13:59:07 +010016 B: { id: 'topo2-bkgrnd-tog', gid: 'm_map', isel: true },
Steven Burrowsc8468932017-03-17 16:13:41 +000017
18 // Z: { id: 'oblique-tog', gid: 'm_oblique', isel: false },
19 // N: { id: 'filters-btn', gid: 'm_filters' },
20 L: { id: 'topo2-cycleLabels-btn', gid: 'm_cycleLabels' },
21 R: { id: 'topo2-resetZoom-btn', gid: 'm_resetZoom' },
22
23 E: { id: 'topo2-eqMaster-btn', gid: 'm_eqMaster' }
24 };
25
26 angular.module('ovTopo2')
27 .factory('Topo2ToolbarService', [
28 'FnService', 'ToolbarService', 'Topo2KeyCommandService',
29 function (fs, tbs, t2kcs) {
30
31 var Toolbar = function () {
32 instance = this;
33 this.el = tbs.createToolbar(this.className);
34 };
35
36 Toolbar.prototype = {
37
38 className: 'topo2-toolbar',
39
40 init: function () {
41 this.initKeyData();
42 this.addFirstRow();
43 this.el.addRow();
44 this.addSecondRow();
45
46 this.el.show();
47 },
48 initKeyData: function () {
49 _.each(k2b, function(value, key) {
50 var data = t2kcs.getActionEntry(key);
51 if (data) {
52 value.cb = data[0]; // on-click callback
53 value.tt = data[1] + ' (' + key + ')'; // tooltip
54 }
55 });
56 },
57 getKey: function (key) {
58 return k2b[key];
59 },
60 keyListener: function (key) {
61 var v = this.getKey(key);
62
63 if (v && v.tog) {
64 v.tog.toggleNoCb();
65 }
66 },
67 addButton: function (key) {
68 var v = this.getKey(key);
69 v.btn = this.el.addButton(v.id, v.gid, v.cb, v.tt);
70 },
71 addToggle: function (key, suppressIfMobile) {
72 var v = this.getKey(key);
73 if (suppressIfMobile && fs.isMobile()) { return; }
74 v.tog = this.el.addToggle(v.id, v.gid, v.isel, v.cb, v.tt);
75 },
76
77 addFirstRow: function () {
78 this.addToggle('I');
79 this.addToggle('O');
80 // this.addToggle('D');
81 this.el.addSeparator();
82
83 // this.addToggle('H');
84 // this.addToggle('M');
85 this.addToggle('P', true);
86 this.addToggle('B');
87 },
88 addSecondRow: function () {
89 //addToggle('X');
90 // this.addToggle('Z');
91 // this.addButton('N');
92 this.addButton('L');
93 this.addButton('R');
94 this.el.addSeparator();
95 this.addButton('E');
96 },
97
98 destroy: function () {
99 // TODO: Should the tbs remove button id's in the destroyToolbar method?
100 // If you go topo2 -> topo -> topo2 there's a button id conflict
101 tbs.destroyToolbar(this.className);
102 }
103 };
104
105 return instance || new Toolbar();
106 }
107 ]);
108})();