From bec5d164717c6987f81d47d75942e94538649dad Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Tue, 21 Apr 2015 11:59:37 +0100 Subject: bitbake: toaster: Refactor and expand layer add remove mechanism We have multiple pages which have buttons to add and remove layers this patch adds functionality to libtoaster to abstract this and implements it in the pages affected. We handle loading and showing the dependencies dialog here too and generating the notification messages. Also implemented is using the selectmachine api from the projectapp to avoid having to handle this in each page that allows selecting machines. A small number of jshint issues, help text and the machine page name have also been fixed. (Bitbake rev: ae7a656ba7fc6f4356b57aa309a9b6d035e51d2e) Signed-off-by: Michael Wood Signed-off-by: Richard Purdie --- .../lib/toaster/toastergui/static/js/libtoaster.js | 79 +++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'bitbake/lib/toaster/toastergui/static/js/libtoaster.js') diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 9257f735db..1cf1693dde 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -114,7 +114,7 @@ var libtoaster = (function (){ error: function (_data) { console.warn("Call failed"); console.warn(_data); - if (onfail) onfail(data); + if (onfail) onfail(_data); } }); } @@ -219,6 +219,76 @@ var libtoaster = (function (){ return str; } + function _addRmLayer(layerObj, add, doneCb){ + if (add === true) { + /* If adding get the deps for this layer */ + libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, + layerObj.id, + function (layers) { + + /* got result for dependencies */ + if (layers.list.length === 0){ + var editData = { layerAdd : layerObj.id }; + libtoaster.editCurrentProject(editData, function() { + doneCb([]); + }); + return; + } else { + try { + showLayerDepsModal(layerObj, layers.list, null, null, true, doneCb); + } catch (e) { + $.getScript(libtoaster.ctx.jsUrl + "layerDepsModal.js", function(){ + showLayerDepsModal(layerObj, layers.list, null, null, true, doneCb); + }, function(){ + console.warn("Failed to load layerDepsModal"); + }); + } + } + }, null); + } else if (add === false) { + var editData = { layerDel : layerObj.id }; + + libtoaster.editCurrentProject(editData, function () { + doneCb([]); + }, function () { + console.warn ("Removing layer from project failed"); + doneCb(null); + }); + } + } + + function _makeLayerAddRmAlertMsg(layer, layerDepsList, add) { + var alertMsg; + + if (layerDepsList.length > 0 && add === true) { + alertMsg = $("You have added "+(layerDepsList.length+1)+" layers to : and its dependencies "); + + /* Build the layer deps list */ + layerDepsList.map(function(layer, i){ + var link = $(""); + + link.attr("href", layer.layerdetailurl); + link.text(layer.name); + link.tooltip({title: layer.tooltip}); + + if (i !== 0) + alertMsg.append(", "); + + alertMsg.append(link); + }); + } else if (layerDepsList.length === 0 && add === true) { + alertMsg = $("You have added 1 layer to : "); + } else if (add === false) { + alertMsg = $("You have deleted 1 layer from : "); + } + + alertMsg.children("#layer-affected-name").text(layer.name); + alertMsg.children("#project-affected-name").text(libtoaster.ctx.projectName); + alertMsg.children("#project-affected-name").attr("href", libtoaster.ctx.projectPageUrl); + + return alertMsg.html(); + } + return { reload_params : reload_params, @@ -231,6 +301,8 @@ var libtoaster = (function (){ debug: false, parseUrlParams : _parseUrlParams, dumpsUrlParams : _dumpsUrlParams, + addRmLayer : _addRmLayer, + makeLayerAddRmAlertMsg : _makeLayerAddRmAlertMsg, }; })(); @@ -394,6 +466,11 @@ $(document).ready(function() { $('#collapse-exceptions').toggleClass('in'); }); + + $("#hide-alert").click(function(){ + $(this).parent().fadeOut(); + }); + //show warnings section when requested from the previous page if (location.href.search('#warnings') > -1) { $('#collapse-warnings').addClass('in'); -- cgit v1.2.3-54-g00ecf