From eb8dc40360f0cfef56fb6947cc817a547d6d9bc6 Mon Sep 17 00:00:00 2001 From: Dave Cobbley Date: Tue, 14 Aug 2018 10:05:37 -0700 Subject: [Subtree] Removing import-layers directory As part of the move to subtrees, need to bring all the import layers content to the top level. Change-Id: I4a163d10898cbc6e11c27f776f60e1a470049d8f Signed-off-by: Dave Cobbley Signed-off-by: Brad Bishop --- .../toaster/toastergui/static/js/layerDepsModal.js | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 poky/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js (limited to 'poky/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js') diff --git a/poky/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js b/poky/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js new file mode 100644 index 000000000..e9622243a --- /dev/null +++ b/poky/bitbake/lib/toaster/toastergui/static/js/layerDepsModal.js @@ -0,0 +1,98 @@ +/* + * layer: Object representing the parent layer { id: .. name: ... url } + * dependencies: array of dependency layer objects { id: .. name: ..} + * title: optional override for title + * body: optional override for body + * addToProject: Whether to add layers to project on accept + * successAdd: function to run on success + */ +function showLayerDepsModal(layer, + dependencies, + title, + body, + addToProject, + successAdd) { + + if ($("#dependencies-modal").length === 0) { + $.get(libtoaster.ctx.htmlUrl + "/layer_deps_modal.html", function(html){ + $("body").append(html); + setupModal(); + }); + } else { + setupModal(); + } + + function setupModal(){ + + if (title) { + $('#dependencies-modal #title').text(title); + } else { + $('#dependencies-modal #title').text(layer.name); + } + + if (body) { + $("#dependencies-modal #body-text").html(body); + } else { + $("#dependencies-modal #layer-name").text(layer.name); + } + + var deplistHtml = ""; + for (var i = 0; i < dependencies.length; i++) { + deplistHtml += "
  • "; + } + $('#dependencies-list').html(deplistHtml); + + $("#dependencies-modal").data("deps", dependencies); + + /* Clear any alert notifications before showing the modal */ + $(".alert").fadeOut(function(){ + $('#dependencies-modal').modal('show'); + }); + + /* Discard the old submission function */ + $("#dependencies-modal-form").unbind('submit'); + + $("#dependencies-modal-form").submit(function (e) { + e.preventDefault(); + var selectedLayerIds = []; + var selectedLayers = []; + + $("input[name='dependencies']:checked").each(function () { + selectedLayerIds.push(parseInt($(this).val())); + }); + + /* -1 is a special dummy Id which we use when the layer isn't yet in the + * system, normally we would add the current layer to the selection. + */ + if (layer.id != -1) + selectedLayerIds.push(layer.id); + + /* Find the selected layer objects from our original list */ + for (var i = 0; i < selectedLayerIds.length; i++) { + for (var j = 0; j < dependencies.length; j++) { + if (dependencies[j].id == selectedLayerIds[i]) { + selectedLayers.push(dependencies[j]); + } + } + } + + if (addToProject) { + libtoaster.editCurrentProject({ 'layerAdd': selectedLayerIds.join(",") }, function () { + if (successAdd) { + successAdd(selectedLayers); + } + }, function () { + console.warn("Adding layers to project failed"); + }); + } else { + successAdd(selectedLayers); + } + + $('#dependencies-modal').modal('hide'); + }); + } +} -- cgit v1.2.3