summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/machines.js
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/machines.js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/machines.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/machines.js b/bitbake/lib/toaster/toastergui/static/js/machines.js
new file mode 100644
index 0000000000..a3ea43baed
--- /dev/null
+++ b/bitbake/lib/toaster/toastergui/static/js/machines.js
@@ -0,0 +1,89 @@
1"use strict"
2
3function machinesPageInit (ctx) {
4
5
6 function setLayerInCurrentPrj(addLayerBtn, depsList){
7 var alertMsg = $("#alert-msg");
8
9 $(".select-or-add").each(function(){
10 /* If we have added a layer it may also enable other machines so search
11 * for other machines that have that layer and enable them */
12 var selectMachineBtn = $(this).children(".select-machine-btn");
13 var otherAddLayerBtns = $(this).children(".add-layer");
14
15 if (addLayerBtn.data('layer-version-id') == selectMachineBtn.data('layer-version-id')) {
16 otherAddLayerBtns.fadeOut(function(){
17 selectMachineBtn.fadeIn();
18 });
19 }
20 });
21
22 /* Reset alert message */
23 alertMsg.text("");
24
25 /* If we have added layer dependencies */
26 if (depsList) {
27 alertMsg.append("You have added <strong>"+(depsList.length+1)+"</strong> layers: <span id=\"layer-affected-name\"></span> and its dependencies ");
28
29 /* Build the layer deps list */
30 depsList.map(function(layer, i){
31 var link = $("<a></a>");
32
33 link.attr("href", layer.layerdetailurl);
34 link.text(layer.name);
35 link.tooltip({title: layer.tooltip});
36
37 if (i != 0)
38 alertMsg.append(", ");
39
40 alertMsg.append(link);
41 });
42 } else {
43 alertMsg.append("You have added <strong>1</strong> layer: <span id=\"layer-affected-name\"></span>");
44 }
45
46 var layerName = addLayerBtn.data('layer-name');
47 alertMsg.children("#layer-affected-name").text(layerName);
48 $("#alert-area").show();
49 }
50
51 /* Add or remove this layer from the project */
52 $(".add-layer").click(function() {
53 var btn = $(this);
54 /* If adding get the deps for this layer */
55 var layer = {
56 id : $(this).data('layer-version-id'),
57 name : $(this).data('layer-name'),
58 };
59
60 libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, layer.id, function (data) {
61 /* got result for dependencies */
62 if (data.list.length == 0){
63 var editData = { layerAdd : layer.id };
64 libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData,
65 function() {
66 setLayerInCurrentPrj(btn);
67 });
68 return;
69 } else {
70 /* The add deps will include this layer so no need to add it
71 * separately.
72 */
73 show_layer_deps_modal(ctx.projectId, layer, data.list, null, null, true, function () {
74 /* Success add deps and layer */
75 setLayerInCurrentPrj(btn, data.list);
76 console.log ("TODO SUCCESS");
77 });
78 }
79 }, null);
80 });
81
82 $(".select-machine-btn").click(function(){
83 var data = { machineName : $(this).data('machine-name') };
84 libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, data,
85 function (){
86 window.location.replace(ctx.projectPageUrl);
87 }, null);
88 });
89}