aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
blob: 71a28f7b2a4de9810e440c1e895a811e1408b352 (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
"use strict";

/* Used for the newcustomimage_modal actions */
function newCustomImageModalInit(ctx){

  var newCustomImgBtn = $("#create-new-custom-image-btn");
  var imgCustomModal = $("#new-custom-image-modal");

  newCustomImgBtn.click(function(e){
    e.preventDefault();

    var name = imgCustomModal.find('input').val();
    var baseRecipeId = imgCustomModal.data('recipe');

    if (name.length > 0) {
      createCustomRecipe(name, baseRecipeId);
      imgCustomModal.modal('hide');
    } else {
      console.warn("TODO No name supplied");
    }
  });

  function createCustomRecipe(name, baseRecipeId){
    var data = {
      'name' : name,
      'project' : libtoaster.ctx.projectId,
      'base' : baseRecipeId,
    };

    $.ajax({
        type: "POST",
        url: ctx.xhrCustomRecipeUrl,
        data: data,
        headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
        success: function (ret) {
          if (ret.error !== "ok") {
            console.warn(ret.error);
          } else {
            window.location.replace(ret.url + '?notify=new');
          }
        },
        error: function (ret) {
          console.warn("Call failed");
          console.warn(ret);
        }
    });
  }
}