Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | "use strict"; |
| 2 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 3 | function layerBtnsInit() { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 45 | notification.text("1 layer removed"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 58 | $("td .build-recipe-btn").unbind('click'); |
| 59 | $("td .build-recipe-btn").click(function(e){ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | e.preventDefault(); |
| 61 | var recipe = $(this).data('recipe-name'); |
| 62 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 63 | libtoaster.startABuild(null, recipe, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | function(){ |
| 65 | /* Success */ |
| 66 | window.location.replace(libtoaster.ctx.projectBuildsUrl); |
| 67 | }); |
| 68 | }); |
| 69 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 70 | $("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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 83 | $(".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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 91 | var recipe = {id: $(this).data('recipe'), name: null} |
| 92 | newCustomImageModalSetRecipes([recipe]); |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 93 | imgCustomModal.modal('show'); |
| 94 | }); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | } |