diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/templates/layers.html')
-rw-r--r-- | bitbake/lib/toaster/toastergui/templates/layers.html | 223 |
1 files changed, 27 insertions, 196 deletions
diff --git a/bitbake/lib/toaster/toastergui/templates/layers.html b/bitbake/lib/toaster/toastergui/templates/layers.html index 24d31c770e..2367e7c33a 100644 --- a/bitbake/lib/toaster/toastergui/templates/layers.html +++ b/bitbake/lib/toaster/toastergui/templates/layers.html | |||
@@ -1,12 +1,32 @@ | |||
1 | {% extends "baseprojectpage.html" %} | 1 | {% extends "baseprojectpage.html" %} |
2 | {% load projecttags %} | 2 | {% load projecttags %} |
3 | {% load humanize %} | 3 | {% load humanize %} |
4 | {% load static %} | ||
4 | 5 | ||
5 | {% block localbreadcrumb %} | 6 | {% block localbreadcrumb %} |
6 | <li>All compatible layers</li> | 7 | <li>All compatible layers</li> |
7 | {% endblock %} | 8 | {% endblock %} |
8 | 9 | ||
10 | |||
9 | {% block projectinfomain %} | 11 | {% block projectinfomain %} |
12 | |||
13 | <script src="{% static 'js/layerBtn.js' %}"></script> | ||
14 | <script> | ||
15 | |||
16 | $(document).ready(function (){ | ||
17 | var ctx = { | ||
18 | projectLayers : {{projectlayerset}}, | ||
19 | }; | ||
20 | |||
21 | try { | ||
22 | layerBtnsInit(ctx); | ||
23 | } catch (e) { | ||
24 | document.write("Sorry, An error has occurred loading this page"); | ||
25 | console.warn(e); | ||
26 | } | ||
27 | }); | ||
28 | </script> | ||
29 | |||
10 | <div class="page-header"> | 30 | <div class="page-header"> |
11 | <h1> | 31 | <h1> |
12 | {% if request.GET.filter and objects.paginator.count > 0 or request.GET.search and objects.paginator.count > 0 %} | 32 | {% if request.GET.filter and objects.paginator.count > 0 or request.GET.search and objects.paginator.count > 0 %} |
@@ -20,7 +40,11 @@ | |||
20 | </h1> | 40 | </h1> |
21 | </div> | 41 | </div> |
22 | 42 | ||
23 | <div id="zone1alerts"> | 43 | <div id="zone1alerts" style="display:none"> |
44 | <div class="alert alert-info lead"> | ||
45 | <button type="button" class="close" id="hide-alert">×</button> | ||
46 | <span id="alert-msg"></span> | ||
47 | </div> | ||
24 | </div> | 48 | </div> |
25 | 49 | ||
26 | {% if objects.paginator.count == 0 %} | 50 | {% if objects.paginator.count == 0 %} |
@@ -89,12 +113,11 @@ | |||
89 | </td> | 113 | </td> |
90 | {% if project %} | 114 | {% if project %} |
91 | <td class="add-del-layers" value="{{o.pk}}"> | 115 | <td class="add-del-layers" value="{{o.pk}}"> |
92 | <div id="layer-tooltip-{{o.pk}}" style="display: none; font-size: 11px; line-height: 1.3;" class="tooltip-inner">layer was modified</div> | 116 | <button class="btn btn-danger btn-block layer-exists-{{o.pk}} layerbtn" style="display:none;" data-layer='{ "id": {{o.pk}}, "name": "{{o.layer.name}}", "url": "{%url 'layerdetails' o.pk%}"}' data-directive="remove" > |
93 | <button id="layer-del-{{o.pk}}" class="btn btn-danger btn-block remove-layer layerbtn" style="display:none;" onclick="layerDel({{o.pk}}, '{{o.layer.name}}', '{%url 'layerdetails' o.pk%}')" > | ||
94 | <i class="icon-trash"></i> | 117 | <i class="icon-trash"></i> |
95 | Delete layer | 118 | Delete layer |
96 | </button> | 119 | </button> |
97 | <button id="layer-add-{{o.pk}}" class="btn btn-block layerbtn" style="display:none;" onclick="layerAdd({{o.pk}}, '{{o.layer.name}}', '{%url 'layerdetails' o.pk%}')" title="layer added"> | 120 | <button class="btn btn-block layer-add-{{o.pk}} layerbtn" data-layer='{ "id": {{o.pk}}, "name": "{{o.layer.name}}", "url": "{%url 'layerdetails' o.pk%}"}' data-directive="add"> |
98 | <i class="icon-plus"></i> | 121 | <i class="icon-plus"></i> |
99 | Add layer | 122 | Add layer |
100 | </button> | 123 | </button> |
@@ -104,198 +127,6 @@ | |||
104 | {% endfor %} | 127 | {% endfor %} |
105 | {% include "basetable_bottom.html" %} | 128 | {% include "basetable_bottom.html" %} |
106 | 129 | ||
107 | <!-- Modals --> | ||
108 | |||
109 | <!-- 'Layer dependencies modal' --> | ||
110 | <div id="dependencies_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true"> | ||
111 | <form id="dependencies_modal_form"> | ||
112 | <div class="modal-header"> | ||
113 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button> | ||
114 | <h3><span class="layer-name"></span> dependencies</h3> | ||
115 | </div> | ||
116 | <div class="modal-body"> | ||
117 | <p><strong class="layer-name"></strong> depends on some layers that are not added to your project. Select the ones you want to add:</p> | ||
118 | <ul class="unstyled" id="dependencies_list"> | ||
119 | </ul> | ||
120 | </div> | ||
121 | <div class="modal-footer"> | ||
122 | <button class="btn btn-primary" type="submit">Add layers</button> | ||
123 | <button class="btn" type="reset" data-dismiss="modal">Cancel</button> | ||
124 | </div> | ||
125 | </form> | ||
126 | </div> | ||
127 | |||
128 | {% if project %} | ||
129 | <script> | ||
130 | |||
131 | var tooltipUpdateText; | ||
132 | |||
133 | /* ensure csrf cookie exists {% csrf_token %} */ | ||
134 | function _makeXHREditCall(data, onsuccess, onfail) { | ||
135 | $.ajax( { | ||
136 | type: "POST", | ||
137 | url: "{% url 'xhr_projectedit' project.id %}", | ||
138 | data: data, | ||
139 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | ||
140 | success: function (_data) { | ||
141 | if (_data.error != "ok") { | ||
142 | console.warn(_data.error); | ||
143 | } else { | ||
144 | updateButtons(_data.layers.map(function (e) {return e.id})); | ||
145 | if (onsuccess != undefined) onsuccess(_data); | ||
146 | } | ||
147 | }, | ||
148 | error: function (_data) { | ||
149 | console.warn("Call failed"); | ||
150 | console.warn(_data); | ||
151 | } | ||
152 | }); | ||
153 | } | ||
154 | |||
155 | function updateLayerCountLabels (amount) { | ||
156 | /* Update the filter labels */ | ||
157 | var countLabel = $("#projectlayer__project\\:{{project.id}}_count"); | ||
158 | countLabel.text(Number(countLabel.text())+amount); | ||
159 | |||
160 | var countLabelRemaining = $("#projectlayer__project\\:NOT{{project.id}}_count"); | ||
161 | countLabelRemaining.text(Number(countLabelRemaining.text())-amount); | ||
162 | } | ||
163 | |||
164 | |||
165 | function layerDel(layerId, layerName, layerURL) { | ||
166 | tooltipUpdateText = "1 layer deleted"; | ||
167 | _makeXHREditCall({ 'layerDel': layerId }, function () { | ||
168 | updateLayerCountLabels(-1); | ||
169 | |||
170 | show_alert("You have deleted <strong>1</strong> layer from <a href=\"{% url 'project' project.id%}\">{{project.name}}</a>: <a href=\""+layerURL+"\">" + layerName +"</a>"); | ||
171 | }); | ||
172 | } | ||
173 | |||
174 | function show_alert(text, cls) { | ||
175 | $("#zone1alerts").html("<div class=\"alert alert-info lead\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>" + text + "</div>"); | ||
176 | } | ||
177 | |||
178 | function show_dependencies_modal(layerId, layerName, layerURL, dependencies) { | ||
179 | // update layer name | ||
180 | $('.layer-name').text(layerName); | ||
181 | var deplistHtml = ""; | ||
182 | for (var i = 0; i < dependencies.length; i++) { | ||
183 | deplistHtml += "<li><label class=\"checkbox\"><input name=\"dependencies\" value=\"" | ||
184 | deplistHtml += dependencies[i].id; | ||
185 | deplistHtml +="\" type=\"checkbox\" checked=\"checked\"/>"; | ||
186 | deplistHtml += dependencies[i].name; | ||
187 | deplistHtml += "</label></li>"; | ||
188 | } | ||
189 | $('#dependencies_list').html(deplistHtml); | ||
190 | |||
191 | var selected = [layerId]; | ||
192 | var layer_link_list = "<a href='"+layerURL+"'>"+layerName+"</a>"; | ||
193 | |||
194 | $("#dependencies_modal_form").submit(function (e) { | ||
195 | e.preventDefault(); | ||
196 | $("input[name='dependencies']:checked").map(function () { selected.push(parseInt($(this).val()))}); | ||
197 | if (selected.length > 1) { | ||
198 | tooltipUpdateText = "" + selected.length + " layers added"; | ||
199 | } else { | ||
200 | tooltipUpdateText = "1 layer added"; | ||
201 | } | ||
202 | |||
203 | for (var i = 0; i < selected.length; i++) { | ||
204 | for (var j = 0; j < dependencies.length; j++) { | ||
205 | if (dependencies[j].id == selected[i]) { | ||
206 | layer_link_list+= ", <a href='"+dependencies[j].layerdetailurl+"'>"+dependencies[j].name+"</a>" | ||
207 | break; | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | $('#dependencies_modal').modal('hide'); | ||
213 | |||
214 | {% if project %} | ||
215 | _makeXHREditCall({ 'layerAdd': selected.join(",") }, function () { | ||
216 | show_alert("You have added <strong>"+selected.length+"</strong> layers to <a href=\"{% url 'project' project.id%}\">{{project.name}}</a>: " + layer_link_list); | ||
217 | }); | ||
218 | {% endif %} | ||
219 | |||
220 | }); | ||
221 | $('#dependencies_modal').modal('show'); | ||
222 | } | ||
223 | |||
224 | |||
225 | function layerAdd(layerId, layerName, layerURL) { | ||
226 | $.ajax({ | ||
227 | url: '{% url "xhr_datatypeahead" %}', | ||
228 | data: {'type': 'layerdeps','value':layerId}, | ||
229 | success: function(_data) { | ||
230 | if (_data.error != "ok") { | ||
231 | console.warn(_data.error); | ||
232 | } else { | ||
233 | updateLayerCountLabels(_data.list.length+1); | ||
234 | |||
235 | if (_data.list.length > 0) { | ||
236 | show_dependencies_modal(layerId, layerName, layerURL, _data.list); | ||
237 | } | ||
238 | else { | ||
239 | tooltipUpdateText = "1 layer added"; | ||
240 | _makeXHREditCall({ 'layerAdd': layerId }, function () { | ||
241 | show_alert("You have added <strong>1</strong> layer to <a href=\"{% url 'project' project.id%}\">{{project.name}}</a>: <a href=\""+layerURL+"\">" + layerName +"</a>"); | ||
242 | }); | ||
243 | } | ||
244 | } | ||
245 | } | ||
246 | }) | ||
247 | } | ||
248 | |||
249 | function button_set(id, state) { | ||
250 | var tohide, toshow; | ||
251 | if (state == "add") | ||
252 | { | ||
253 | tohide = "#layer-del-"; | ||
254 | toshow = "#layer-add-"; | ||
255 | } | ||
256 | else if (state == "del") | ||
257 | { | ||
258 | tohide = "#layer-add-"; | ||
259 | toshow = "#layer-del-"; | ||
260 | } | ||
261 | |||
262 | |||
263 | var previouslyvisible = $(tohide + id).is(":visible"); | ||
264 | if (previouslyvisible) { | ||
265 | $(tohide + id).fadeOut( function() { | ||
266 | $("#layer-tooltip-" + id).text(tooltipUpdateText); | ||
267 | $("#layer-tooltip-" + id).fadeIn().delay(2000).fadeOut(function(){ | ||
268 | $(toshow + id).delay(300).fadeIn(); | ||
269 | }); | ||
270 | }); | ||
271 | } else { | ||
272 | $(tohide + id).hide(); | ||
273 | $("#layer-tooltip-" + id).hide(); | ||
274 | $(toshow + id).show(); | ||
275 | } | ||
276 | }; | ||
277 | |||
278 | function updateButtons(projectLayers) { | ||
279 | var displayedLayers = []; | ||
280 | $(".add-del-layers").map(function () { displayedLayers.push(parseInt($(this).attr('value')))}); | ||
281 | for (var i=0; i < displayedLayers.length; i++) { | ||
282 | if (projectLayers.indexOf(displayedLayers[i]) > -1) { | ||
283 | button_set(displayedLayers[i], "del"); | ||
284 | } | ||
285 | else { | ||
286 | button_set(displayedLayers[i], "add"); | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
291 | $(document).ready(function (){ | ||
292 | $('.layerbtn').tooltip({ trigger: 'manual' }); | ||
293 | updateButtons({{projectlayerset}}); | ||
294 | }); | ||
295 | |||
296 | </script> | ||
297 | {%endif%} | ||
298 | |||
299 | {%endif%} | 130 | {%endif%} |
300 | 131 | ||
301 | {% endblock %} | 132 | {% endblock %} |