summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/customrecipe.js
blob: 4f6b304dd622b3ec24e8065bca196aff9974ee16 (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
"use strict";

function customRecipePageInit(ctx) {

  var urlParams = libtoaster.parseUrlParams();

  (function notificationRequest(){
    if (urlParams.hasOwnProperty('notify') && urlParams.notify === 'new'){
      $("#image-created-notification").show();
    }
  })();

  $("#recipeselection").on('table-done', function(e, total, tableParams){
    /* Table is done so now setup the click handler for the package buttons */
    $(".add-rm-package-btn").click(function(e){
      e.preventDefault();
      addRemovePackage($(this), tableParams);
    });
  });

  function addRemovePackage(pkgBtn, tableParams){
    var pkgBtnData = pkgBtn.data();
    var method;
    var buttonToShow;

    if (pkgBtnData.directive == 'add') {
      method = 'PUT';
      buttonToShow = '#package-rm-btn-' + pkgBtnData.package;
    } else if (pkgBtnData.directive == 'remove') {
      method = 'DELETE';
      buttonToShow = '#package-add-btn-' + pkgBtnData.package;
    } else {
      throw("Unknown package directive: should be add or remove");
    }

    $.ajax({
        type: method,
        url: pkgBtnData.packageUrl,
        headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
        success: function(data){
          /* Invalidate the Add | Rm package table's current cache */
          tableParams.nocache = true;
          $.get(ctx.tableApiUrl, tableParams);
          /* Swap the buttons around */
          pkgBtn.hide();
          $(buttonToShow).show();
        }
    });
  }
}