blob: 7318b3f50ea82cc204bea175b450fdbb823446b3 [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 {
45 notification.text("1 layer deleted");
46 /* 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
58 $(".build-recipe-btn").unbind('click');
59 $(".build-recipe-btn").click(function(e){
60 e.preventDefault();
61 var recipe = $(this).data('recipe-name');
62
63 libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl,
64 libtoaster.ctx.projectId, recipe,
65 function(){
66 /* Success */
67 window.location.replace(libtoaster.ctx.projectBuildsUrl);
68 });
69 });
70
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071
Patrick Williamsf1e5d692016-03-30 15:21:19 -050072 $(".customise-btn").unbind('click');
73 $(".customise-btn").click(function(e){
74 e.preventDefault();
75 var imgCustomModal = $("#new-custom-image-modal");
76
77 if (imgCustomModal.length == 0)
78 throw("Modal new-custom-image not found");
79
80 imgCustomModal.data('recipe', $(this).data('recipe'));
81 imgCustomModal.modal('show');
82 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083}