summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2015-04-21 11:59:37 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-08 17:42:06 +0100
commitbec5d164717c6987f81d47d75942e94538649dad (patch)
tree189574b0de84b2f7ebc83fd3c0230be35d28f997 /bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js
parenta4cfca604b2c5ab35baf69c2070afa0087842b68 (diff)
downloadpoky-bec5d164717c6987f81d47d75942e94538649dad.tar.gz
bitbake: toaster: Refactor and expand layer add remove mechanism
We have multiple pages which have buttons to add and remove layers this patch adds functionality to libtoaster to abstract this and implements it in the pages affected. We handle loading and showing the dependencies dialog here too and generating the notification messages. Also implemented is using the selectmachine api from the projectapp to avoid having to handle this in each page that allows selecting machines. A small number of jshint issues, help text and the machine page name have also been fixed. (Bitbake rev: ae7a656ba7fc6f4356b57aa309a9b6d035e51d2e) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js b/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js
new file mode 100644
index 0000000000..825f9dccd5
--- /dev/null
+++ b/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js
@@ -0,0 +1,90 @@
1/*
2 * layer: Object representing the parent layer { id: .. name: ... url }
3 * dependencies: array of dependency layer objects { id: .. name: ..}
4 * title: optional override for title
5 * body: optional override for body
6 * addToProject: Whether to add layers to project on accept
7 * successAdd: function to run on success
8 */
9function showLayerDepsModal(layer, dependencies, title, body, addToProject, successAdd) {
10
11 if ($("#dependencies-modal").length === 0) {
12 $.get(libtoaster.ctx.htmlUrl + "/layer_deps_modal.html", function(html){
13 $("body").append(html);
14 setupModal();
15 });
16 } else {
17 setupModal();
18 }
19
20 function setupModal(){
21
22 if (title) {
23 $('#dependencies-modal #title').text(title);
24 } else {
25 $('#dependencies-modal #title').text(layer.name);
26 }
27
28 if (body) {
29 $("#dependencies-modal #body-text").html(body);
30 } else {
31 $("#dependencies-modal #layer-name").text(layer.name);
32 }
33
34 var deplistHtml = "";
35 for (var i = 0; i < dependencies.length; i++) {
36 deplistHtml += "<li><label class=\"checkbox\"><input name=\"dependencies\" value=\"";
37 deplistHtml += dependencies[i].id;
38 deplistHtml +="\" type=\"checkbox\" checked=\"checked\"/>";
39 deplistHtml += dependencies[i].name;
40 deplistHtml += "</label></li>";
41 }
42 $('#dependencies-list').html(deplistHtml);
43
44 $("#dependencies-modal").data("deps", dependencies);
45
46 $('#dependencies-modal').modal('show');
47
48 /* Discard the old submission function */
49 $("#dependencies-modal-form").unbind('submit');
50
51 $("#dependencies-modal-form").submit(function (e) {
52 e.preventDefault();
53 var selectedLayerIds = [];
54 var selectedLayers = [];
55
56 $("input[name='dependencies']:checked").each(function () {
57 selectedLayerIds.push(parseInt($(this).val()));
58 });
59
60 /* -1 is a special dummy Id which we use when the layer isn't yet in the
61 * system, normally we would add the current layer to the selection.
62 */
63 if (layer.id != -1)
64 selectedLayerIds.push(layer.id);
65
66 /* Find the selected layer objects from our original list */
67 for (var i = 0; i < selectedLayerIds.length; i++) {
68 for (var j = 0; j < dependencies.length; j++) {
69 if (dependencies[j].id == selectedLayerIds[i]) {
70 selectedLayers.push(dependencies[j]);
71 }
72 }
73 }
74
75 if (addToProject) {
76 libtoaster.editCurrentProject({ 'layerAdd': selectedLayerIds.join(",") }, function () {
77 if (successAdd) {
78 successAdd(selectedLayers);
79 }
80 }, function () {
81 console.warn("Adding layers to project failed");
82 });
83 } else {
84 successAdd(selectedLayers);
85 }
86
87 $('#dependencies-modal').modal('hide');
88 });
89 }
90}