Use the simpler libtoaster method of showing a notification about
successful import of a layer.
Also a number of whitespace clean ups.

Signed-off-by: Michael Wood <michael.g.w...@intel.com>
---
 .../toaster/toastergui/static/js/importlayer.js    | 59 ++++++++++++++-----
 .../toaster/toastergui/static/js/projectpage.js    | 66 +---------------------
 2 files changed, 47 insertions(+), 78 deletions(-)

diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js 
b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
index 191b30f..570ca33 100644
--- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js
+++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
@@ -17,7 +17,9 @@ function importLayerPageInit (ctx) {
   var currentLayerDepSelection;
   var validLayerName = /^(\w|-)+$/;
 
-  libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.layersTypeAheadUrl, { 
include_added: "true" }, function(item){
+  libtoaster.makeTypeahead(layerDepInput,
+                           libtoaster.ctx.layersTypeAheadUrl,
+                           { include_added: "true" }, function(item){
     currentLayerDepSelection = item;
   });
 
@@ -95,7 +97,8 @@ function importLayerPageInit (ctx) {
 
     $("#layer-deps-list").append(newLayerDep);
 
-    libtoaster.getLayerDepsForProject(currentLayerDepSelection.layerdetailurl, 
function (data){
+    libtoaster.getLayerDepsForProject(currentLayerDepSelection.layerdetailurl,
+                                      function (data){
         /* These are the dependencies of the layer added as a dependency */
         if (data.list.length > 0) {
           currentLayerDepSelection.url = 
currentLayerDepSelection.layerdetailurl;
@@ -150,7 +153,9 @@ function importLayerPageInit (ctx) {
       var body = "<strong>"+layer.name+"</strong>'s dependencies ("+
         depNames.join(", ")+"</span>) require some layers that are not added 
to your project. Select the ones you want to add:</p>";
 
-      showLayerDepsModal(layer, depDepsArray, title, body, false, 
function(layerObsList){
+      showLayerDepsModal(layer,
+                         depDepsArray,
+                         title, body, false, function(layerObsList){
         /* Add the accepted layer dependencies' ids to the allDeps array */
         for (var key in layerObsList){
           allDeps.push(layerObsList[key].id);
@@ -191,9 +196,8 @@ function importLayerPageInit (ctx) {
             if (data.error != "ok") {
               console.log(data.error);
             } else {
-              /* Success layer import now go to the project page */
-              $.cookie('layer-imported-alert', JSON.stringify(data), { path: 
'/'});
-              
window.location.replace(libtoaster.ctx.projectPageUrl+'?notify=layer-imported');
+              createImportedNotification(data);
+              window.location.replace(libtoaster.ctx.projectPageUrl);
             }
           },
           error: function (data) {
@@ -204,6 +208,30 @@ function importLayerPageInit (ctx) {
     }
   });
 
+  /* Layer imported notification */
+  function createImportedNotification(imported){
+    var message = "Layer imported";
+
+    if (imported.deps_added.length === 0) {
+      message = "You have imported <strong><a class=\"alert-link\" 
href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a></strong>
 and added it to your project.";
+    } else {
+
+      var links = "<a 
href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a>,
 ";
+
+      imported.deps_added.map (function(item, index){
+        links +='<a href="'+item.layerdetailurl+'">'+item.name+'</a>';
+        /*If we're at the last element we don't want the trailing comma */
+        if (imported.deps_added[index+1] !== undefined)
+          links += ', ';
+      });
+
+      /* Length + 1 here to do deps + the imported layer */
+      message = 'You have imported <strong><a 
href="'+imported.imported_layer.layerdetailurl+'">'+imported.imported_layer.name+'</a></strong>
 and added <strong>'+(imported.deps_added.length+1)+'</strong> layers to your 
project: <strong>'+links+'</strong>';
+    }
+
+    libtoaster.setNotification("layer-imported", message);
+  }
+
   function enable_import_btn(enabled) {
     var importAndAddHint = $("#import-and-add-hint");
 
@@ -230,10 +258,13 @@ function importLayerPageInit (ctx) {
     }
 
     if (valid) {
-      if ($("#local-dir-radio").prop("checked") && localDirPath.val().length > 
0) {
+      if ($("#local-dir-radio").prop("checked") &&
+          localDirPath.val().length > 0) {
         enable_import_btn(true);
       }
-      if ($("#git-repo-radio").prop("checked") && vcsURLInput.val().length > 0 
&& gitRefInput.val().length > 0) {
+
+      if ($("#git-repo-radio").prop("checked") &&
+          vcsURLInput.val().length > 0 && gitRefInput.val().length > 0) {
         enable_import_btn(true);
       }
     }
@@ -266,13 +297,13 @@ function importLayerPageInit (ctx) {
   }
 
   layerNameInput.on('blur', function() {
-      if (!$(this).val()){
-        return;
-      }
-      var name = $(this).val();
+    if (!$(this).val()){
+      return;
+    }
+    var name = $(this).val();
 
-      /* Check if the layer name exists */
-      $.getJSON(libtoaster.ctx.layersTypeAheadUrl,
+    /* Check if the layer name exists */
+    $.getJSON(libtoaster.ctx.layersTypeAheadUrl,
         { include_added: "true" , search: name, format: "json" },
         function(layer) {
           if (layer.results.length > 0) {
diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js 
b/bitbake/lib/toaster/toastergui/static/js/projectpage.js
index 7f19c0d..4536703 100644
--- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js
+++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js
@@ -50,70 +50,8 @@ function projectPageInit(ctx) {
     $("#delete-project-modal .project-name").text(prjInfo.name);
   });
 
-  (function notificationRequest(){
-
-    if (urlParams.hasOwnProperty('notify')){
-      switch (urlParams.notify){
-        case 'new-project':
-          $("#project-created-notification").show();
-          break;
-        case 'layer-imported':
-          layerImportedNotification();
-          break;
-        case 'layer-deleted':
-          layerDeletedNotification();
-        default:
-          break;
-      }
-    }
-  })();
-
-  /* Layer deleted notification */
-  function layerDeletedNotification(){
-    var layer = $.cookie("layer-deleted");
-
-    if (!layer)
-      return;
-
-    var message = "You have deleted <strong>1</strong> layer from your ";
-    message += "project: <strong>" + layer + "</strong>";
-
-    libtoaster.showChangeNotification(message);
-
-    $.removeCookie("layer-deleted", { path: "/"});
-  }
-
-
-  /* Layer imported notification */
-  function layerImportedNotification(){
-    var imported = $.cookie("layer-imported-alert");
-    var message = "Layer imported";
-
-    if (!imported)
-      return;
-    else
-      imported = JSON.parse(imported);
-
-    if (imported.deps_added.length === 0) {
-      message = "You have imported <strong><a class=\"alert-link\" 
href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a></strong>
 and added it to your project.";
-    } else {
-
-      var links = "<a 
href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a>,
 ";
-
-      imported.deps_added.map (function(item, index){
-        links +='<a href="'+item.layerdetailurl+'">'+item.name+'</a>';
-        /*If we're at the last element we don't want the trailing comma */
-        if (imported.deps_added[index+1] !== undefined)
-          links += ', ';
-      });
-
-      /* Length + 1 here to do deps + the imported layer */
-      message = 'You have imported <strong><a 
href="'+imported.imported_layer.layerdetailurl+'">'+imported.imported_layer.name+'</a></strong>
 and added <strong>'+(imported.deps_added.length+1)+'</strong> layers to your 
project: <strong>'+links+'</strong>';
-    }
-
-    libtoaster.showChangeNotification(message);
-
-    $.removeCookie("layer-imported-alert", { path: "/"});
+  if (urlParams.hasOwnProperty('notify') && urlParams.notify === 
'new-project'){
+    $("#project-created-notification").show();
   }
 
   /* Add/Rm layer functionality */
-- 
2.7.4

-- 
_______________________________________________
toaster mailing list
toaster@yoctoproject.org
https://lists.yoctoproject.org/listinfo/toaster

Reply via email to