blob: a5a6563d1ad203c26c501f7427a5eef95ad289ae [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001"use strict";
2
Patrick Williamsf1e5d692016-03-30 15:21:19 -05003function layerBtnsInit() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004
5 /* Remove any current bindings to avoid duplicated binds */
6 $(".layerbtn").unbind('click');
7
8 $(".layerbtn").click(function (){
9 var layerObj = $(this).data("layer");
10 var add = ($(this).data('directive') === "add");
11 var thisBtn = $(this);
12
13 libtoaster.addRmLayer(layerObj, add, function (layerDepsList){
14 libtoaster.showChangeNotification(libtoaster.makeLayerAddRmAlertMsg(layerObj, layerDepsList, add));
15
16 /* In-cell notification */
17 var notification = $('<div id="temp-inline-notify" style="display: none; font-size: 11px; line-height: 1.3;" class="tooltip-inner"></div>');
18 thisBtn.parent().append(notification);
19
20 if (add){
21 if (layerDepsList.length > 0)
22 notification.text(String(layerDepsList.length + 1) + " layers added");
23 else
24 notification.text("1 layer added");
25
26 var layerBtnsFadeOut = $();
27 var layerExistsBtnFadeIn = $();
28
29 layerBtnsFadeOut = layerBtnsFadeOut.add(".layer-add-" + layerObj.id);
30 layerExistsBtnFadeIn = layerExistsBtnFadeIn.add(".layer-exists-" + layerObj.id);
31
32 for (var i in layerDepsList){
33 layerBtnsFadeOut = layerBtnsFadeOut.add(".layer-add-" + layerDepsList[i].id);
34 layerExistsBtnFadeIn = layerExistsBtnFadeIn.add(".layer-exists-" + layerDepsList[i].id);
35 }
36
37 layerBtnsFadeOut.fadeOut().promise().done(function(){
38 notification.fadeIn().delay(500).fadeOut(function(){
39 /* Fade in the buttons */
40 layerExistsBtnFadeIn.fadeIn();
41 notification.remove();
42 });
43 });
44 } else {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045 notification.text("1 layer removed");
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 /* Deleting a layer we only hanlde the one button */
47 thisBtn.fadeOut(function(){
48 notification.fadeIn().delay(500).fadeOut(function(){
49 $(".layer-add-" + layerObj.id).fadeIn();
50 notification.remove();
51 });
52 });
53 }
54
55 });
56 });
57
Patrick Williamsc0f7c042017-02-23 20:41:17 -060058 $("td .build-recipe-btn").unbind('click');
59 $("td .build-recipe-btn").click(function(e){
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 e.preventDefault();
61 var recipe = $(this).data('recipe-name');
62
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063 libtoaster.startABuild(null, recipe,
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 function(){
65 /* Success */
66 window.location.replace(libtoaster.ctx.projectBuildsUrl);
67 });
68 });
69
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070 $("td .set-default-recipe-btn").unbind('click');
71 $("td .set-default-recipe-btn").click(function(e){
72 e.preventDefault();
73 var recipe = $(this).data('recipe-name');
74
75 libtoaster.setDefaultImage(null, recipe,
76 function(){
77 /* Success */
78 window.location.replace(libtoaster.ctx.projectSpecificPageUrl);
79 });
80 });
81
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082
Patrick Williamsf1e5d692016-03-30 15:21:19 -050083 $(".customise-btn").unbind('click');
84 $(".customise-btn").click(function(e){
85 e.preventDefault();
86 var imgCustomModal = $("#new-custom-image-modal");
87
88 if (imgCustomModal.length == 0)
89 throw("Modal new-custom-image not found");
90
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050091 var recipe = {id: $(this).data('recipe'), name: null}
92 newCustomImageModalSetRecipes([recipe]);
Patrick Williamsf1e5d692016-03-30 15:21:19 -050093 imgCustomModal.modal('show');
94 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095}