Bri Prebilic Cole

GUI -- Refactored ToolbarService to have only new toolbar functions.

Change-Id: I0319335915f37d3a63b3ac734d8f8e00ebed20ae
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
33 } 33 }
34 34
35 function button(div, id, gid, cb, tooltip) { 35 function button(div, id, gid, cb, tooltip) {
36 - if (!div || div.empty()) { 36 + if (!div) {
37 $log.warn('Button cannot append to div'); 37 $log.warn('Button cannot append to div');
38 return null; 38 return null;
39 } 39 }
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
53 } 53 }
54 54
55 function toggle(div, id, gid, initState, cb, tooltip) { 55 function toggle(div, id, gid, initState, cb, tooltip) {
56 - if (!div || div.empty()) { 56 + if (!div) {
57 $log.warn('Toggle cannot append to div'); 57 $log.warn('Toggle cannot append to div');
58 return null; 58 return null;
59 } 59 }
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
84 } 84 }
85 85
86 function radioSet(div, id, rset) { 86 function radioSet(div, id, rset) {
87 - if (!div || div.empty()) { 87 + if (!div) {
88 $log.warn('Radio buttons cannot append to div'); 88 $log.warn('Radio buttons cannot append to div');
89 return null; 89 return null;
90 } 90 }
......
...@@ -22,80 +22,16 @@ ...@@ -22,80 +22,16 @@
22 22
23 var $log, fs, ps, bns; 23 var $log, fs, ps, bns;
24 24
25 - var toolBtnIds = {},
26 - toolbarPanel,
27 - toolbarDiv;
28 -
29 var ids = [], 25 var ids = [],
30 tbarId, 26 tbarId,
31 tbarPanel, 27 tbarPanel,
32 - tbarDiv; 28 + tbarDiv,
29 + tbarArrowDiv;
33 30
34 function init() { 31 function init() {
35 - toolBtnIds = {};
36 ids = []; 32 ids = [];
37 } 33 }
38 34
39 - function addButton(btn) {
40 - // pass in button object and pass separate the pieces in this function,
41 - // to be passed to ButtonService
42 - var btndiv = toolbarDiv.append('div').attr('class', 'btn');
43 - // use ButtonService to create btn with other arguments and btndiv
44 - }
45 -
46 - function addToggle(tog) {
47 - var togdiv = toolbarDiv.append('div').attr('class', 'tog');
48 - // use ButtonService to create btn with other arguments and togdiv
49 - }
50 -
51 - function addRadio(rad) {
52 - var raddiv = toolbarDiv.append('div').attr('class', 'rad');
53 - // use ButtonService to create btn with other arguments and raddiv
54 - }
55 -
56 - function addSeparator() {
57 - toolbarDiv.append('div')
58 - .attr('class', 'sep')
59 - .style({'width': '2px',
60 - 'border-width': '1px',
61 - 'border-style': 'solid'});
62 - }
63 -
64 - function makeButton(id, gid, cb) {
65 - return {
66 - t: 'btn',
67 - id: id,
68 - gid: gid,
69 - cb: cb
70 - };
71 - }
72 -
73 - function makeToggle(id, gid, cb) {
74 - return {
75 - t: 'tog',
76 - id: id,
77 - gid: gid,
78 - cb: cb
79 - };
80 - }
81 -
82 - function makeRadio(id, gid, cb) {
83 - (id in toolBtnIds) ? toolBtnIds[id] += 1 : toolBtnIds[id] = 0;
84 - return {
85 - t: 'rad',
86 - id: id + '-' + toolBtnIds[id],
87 - rid: toolBtnIds[id] + '',
88 - gid: gid,
89 - cb: cb
90 - };
91 - }
92 -
93 - function separator() {
94 - return {
95 - t: 'sep'
96 - };
97 - }
98 -
99 function validId(id, caller) { 35 function validId(id, caller) {
100 if (fs.inArray(id, ids) !== -1) { 36 if (fs.inArray(id, ids) !== -1) {
101 $log.warn(caller + ': ID already exists'); 37 $log.warn(caller + ': ID already exists');
...@@ -104,39 +40,38 @@ ...@@ -104,39 +40,38 @@
104 return true; 40 return true;
105 } 41 }
106 42
107 - function addButton1(id, gid, cb, tooltip) { 43 + function addButton(id, gid, cb, tooltip) {
108 var btnId = tbarId + '-' + id; 44 var btnId = tbarId + '-' + id;
109 - if (!validId(btnId, 'addButton')) { 45 + if (!validId(btnId, 'addButton')) { return null; }
110 - return null;
111 - }
112 ids.push(btnId); 46 ids.push(btnId);
113 return bns.button(tbarDiv, btnId, gid, cb, tooltip); 47 return bns.button(tbarDiv, btnId, gid, cb, tooltip);
114 } 48 }
115 49
116 - function addToggle1(id, gid, initState, cb, tooltip) { 50 + function addToggle(id, gid, initState, cb, tooltip) {
117 var togId = tbarId + '-' + id; 51 var togId = tbarId + '-' + id;
118 - if (!validId(togId, 'addToggle')) { 52 + if (!validId(togId, 'addToggle')) { return null; }
119 - return null;
120 - }
121 ids.push(togId); 53 ids.push(togId);
122 return bns.toggle(tbarDiv, togId, gid, initState, cb, tooltip); 54 return bns.toggle(tbarDiv, togId, gid, initState, cb, tooltip);
123 } 55 }
124 56
125 function addRadioSet(id, rset) { 57 function addRadioSet(id, rset) {
126 var radId = tbarId + '-' + id; 58 var radId = tbarId + '-' + id;
127 - if (!validId(radId, 'addRadioSet')) { 59 + if (!validId(radId, 'addRadioSet')) { return null; }
128 - return null;
129 - }
130 ids.push(radId); 60 ids.push(radId);
131 return bns.radioSet(tbarDiv, radId, rset); 61 return bns.radioSet(tbarDiv, radId, rset);
132 } 62 }
133 63
134 - // TODO: finish this and remove unneeded code 64 + function addSeparator() {
135 - function addSeparator1() { 65 + if (!tbarDiv) {
136 - 66 + $log.warn('Separator cannot append to div');
67 + return null;
68 + }
69 + tbarArrowDiv = tbarDiv.append('div')
70 + .classed('sep', true)
71 + .style('width', '2px');
137 } 72 }
138 73
139 - function createToolbar1(id, settings) { 74 + function createToolbar(id, settings) {
140 if (!id) { 75 if (!id) {
141 $log.warn('createToolbar: no ID given'); 76 $log.warn('createToolbar: no ID given');
142 return null; 77 return null;
...@@ -144,78 +79,23 @@ ...@@ -144,78 +79,23 @@
144 tbarId = 'tbar-' + id; 79 tbarId = 'tbar-' + id;
145 var opts = fs.isO(settings) || {}; // default settings should be put here 80 var opts = fs.isO(settings) || {}; // default settings should be put here
146 81
147 - if (!validId(tbarId, 'createToolbar')) { 82 + if (!validId(tbarId, 'createToolbar')) { return null; }
148 - return null;
149 - }
150 ids.push(tbarId); 83 ids.push(tbarId);
151 84
152 tbarPanel = ps.createPanel(tbarId, opts); 85 tbarPanel = ps.createPanel(tbarId, opts);
153 tbarDiv = tbarPanel.classed('toolbar', true); 86 tbarDiv = tbarPanel.classed('toolbar', true);
154 87
155 - // TODO: change names of functions
156 return { 88 return {
157 - addButton1: addButton1, 89 + addButton: addButton,
158 - addToggle1: addToggle1, 90 + addToggle: addToggle,
159 addRadioSet: addRadioSet, 91 addRadioSet: addRadioSet,
160 - addSeparator1: addSeparator1 92 + addSeparator: addSeparator
161 } 93 }
162 } 94 }
163 95
164 - // function currently not working 96 + //function currently not working
165 function destroyToolbar(id) { 97 function destroyToolbar(id) {
166 - ps.destroyPanel(id); 98 + //ps.destroyPanel(id);
167 - }
168 -
169 - function createToolbar(tbarId, tools) {
170 - var api;
171 -
172 - if (!tbarId) {
173 - $log.warn('createToolbar: no ID given');
174 - return null;
175 - }
176 - if (!tools || tools.constructor !== Array || !tools.length) {
177 - $log.warn('createToolbar: no tools given');
178 - return null;
179 - }
180 -
181 - for (var i = 0; i < tools.length; i += 1) {
182 - if (tools[i].t === 'rad' || tools[i].t === 'sep') {
183 - continue;
184 - } else {
185 - if (tools[i].id in toolBtnIds) {
186 - $log.warn('createToolbar: item with id '
187 - + tools[i].id + ' already exists');
188 - return null;
189 - }
190 - toolBtnIds[tools[i].id] = 1;
191 - }
192 - }
193 -
194 - // need to pass in an object with settings for where the toolbar will go
195 - toolbarPanel = ps.createPanel(tbarId, {});
196 - toolbarPanel.classed('toolbar', true);
197 - toolbarDiv = toolbarPanel.el();
198 -
199 - tools.forEach(function (tool) {
200 - switch (tool['t']) {
201 - case 'btn': addButton(tool); break;
202 - case 'tog': addToggle(tool); break;
203 - case 'rad': addRadio(tool); break;
204 - default: addSeparator(); break;
205 - }
206 - });
207 -
208 - // api functions to be returned defined here
209 -
210 - function size(arr) {
211 - return arr.length;
212 - }
213 -
214 - api = {
215 - size: size
216 - };
217 -
218 - return api;
219 } 99 }
220 100
221 angular.module('onosWidget') 101 angular.module('onosWidget')
...@@ -229,14 +109,8 @@ ...@@ -229,14 +109,8 @@
229 109
230 return { 110 return {
231 init: init, 111 init: init,
232 - makeButton: makeButton,
233 - makeToggle: makeToggle,
234 - makeRadio: makeRadio,
235 - separator: separator,
236 createToolbar: createToolbar, 112 createToolbar: createToolbar,
237 - createToolbar1: createToolbar1,
238 destroyToolbar: destroyToolbar 113 destroyToolbar: destroyToolbar
239 }; 114 };
240 }]); 115 }]);
241 -
242 }()); 116 }());
......