blob: 620d2c60089c01d563501d4f8082dcce98db2e2b [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;
Steven Burrowsc8468932017-03-17 16:13:41 +000033 };
34
35 Toolbar.prototype = {
36
37 className: 'topo2-toolbar',
38
39 init: function () {
Steven Burrows9053fdb2017-04-12 12:08:16 -070040 this.el = tbs.createToolbar(this.className);
Steven Burrowsc8468932017-03-17 16:13:41 +000041 this.initKeyData();
42 this.addFirstRow();
43 this.el.addRow();
44 this.addSecondRow();
45
Simon Hunt47f8fb72017-04-11 13:49:31 -070046 this.el.hide();
Steven Burrowsc8468932017-03-17 16:13:41 +000047 },
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
Simon Hunt47f8fb72017-04-11 13:49:31 -070077 toggle: function () {
78 this.el.toggle();
79 },
80
Steven Burrowsc8468932017-03-17 16:13:41 +000081 addFirstRow: function () {
82 this.addToggle('I');
83 this.addToggle('O');
84 // this.addToggle('D');
85 this.el.addSeparator();
86
87 // this.addToggle('H');
88 // this.addToggle('M');
89 this.addToggle('P', true);
90 this.addToggle('B');
91 },
92 addSecondRow: function () {
93 //addToggle('X');
94 // this.addToggle('Z');
95 // this.addButton('N');
96 this.addButton('L');
97 this.addButton('R');
98 this.el.addSeparator();
99 this.addButton('E');
100 },
101
102 destroy: function () {
103 // TODO: Should the tbs remove button id's in the destroyToolbar method?
104 // If you go topo2 -> topo -> topo2 there's a button id conflict
105 tbs.destroyToolbar(this.className);
106 }
107 };
108
109 return instance || new Toolbar();
110 }
111 ]);
112})();