blob: a0509f9aa3661798e292d3f66c873deb6a04c12b [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001"use strict";
2
3function layerBtnsInit(ctx) {
4
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
71 /* Setup the initial state of the buttons */
72
73 for (var i in ctx.projectLayers){
74 $(".layer-exists-" + ctx.projectLayers[i]).show();
75 $(".layer-add-" + ctx.projectLayers[i]).hide();
76 }
77}