aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/machines.js
blob: fbcafc26b50872f5e70955325fd731a74c00bcd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict"

function machinesPageInit (ctx) {


  function setLayerInCurrentPrj(addLayerBtn, depsList){
    var alertMsg = $("#alert-msg");

    $(".select-or-add").each(function(){
      /* If we have added a layer it may also enable other machines so search
       * for other machines that have that layer and enable them */
      var selectMachineBtn = $(this).children(".select-machine-btn");
      var otherAddLayerBtns = $(this).children(".add-layer");

      if (addLayerBtn.data('layer-version-id') ==  selectMachineBtn.data('layer-version-id')) {
        otherAddLayerBtns.fadeOut(function(){
          selectMachineBtn.fadeIn();
        });
      }
    });

    /* Reset alert message */
    alertMsg.text("");

    /* If we have added layer dependencies */
    if (depsList) {
      alertMsg.append("You have added <strong>"+(depsList.length+1)+"</strong> layers to <a id=\"project-affected-name\"></a>: <span id=\"layer-affected-name\"></span> and its dependencies ");

        /* Build the layer deps list */
        depsList.map(function(layer, i){
          var link = $("<a></a>");

          link.attr("href", layer.layerdetailurl);
          link.text(layer.name);
          link.tooltip({title: layer.tooltip});

          if (i != 0)
            alertMsg.append(", ");

          alertMsg.append(link);
        });
    } else {
      alertMsg.append("You have added <strong>1</strong> layer to <a id=\"project-affected-name\"></a>: <strong id=\"layer-affected-name\"></strong>");
    }

    var layerName = addLayerBtn.data('layer-name');
    alertMsg.children("#layer-affected-name").text(layerName);
    alertMsg.children("#project-affected-name").text(libtoaster.ctx.projectName).attr('href', libtoaster.ctx.projectPageUrl);

    $("#alert-area").show();
  }

  $("#dismiss-alert").click(function(){ $(this).parent().hide() });

  /* Add or remove this layer from the project */
  $(".add-layer").click(function() {
      var btn = $(this);
      /* If adding get the deps for this layer */
      var layer = {
        id : $(this).data('layer-version-id'),
        name : $(this).data('layer-name'),
      };

      libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, layer.id, function (data) {
        /* got result for dependencies */
        if (data.list.length == 0){
          var editData = { layerAdd : layer.id };
          libtoaster.editCurrentProject(editData, function() {
              setLayerInCurrentPrj(btn);
          });
          return;
        } else {
          /* The add deps will include this layer so no need to add it
           * separately.
           */
          show_layer_deps_modal(ctx.projectId, layer, data.list, null, null, true, function () {
            /* Success add deps and layer */
            setLayerInCurrentPrj(btn, data.list);
          });
        }
      }, null);
  });

  $(".select-machine-btn").click(function(){
    var data =  { machineName : $(this).data('machine-name') };
    libtoaster.editCurrentProject(data, function (){
        window.location.replace(libtoaster.ctx.projectPageUrl+"#/machineselected");
    }, null);
  });

  $("#show-all-btn").click(function(){
    $("#search").val("")
    $("#searchform").submit();
  });
}