9426: js updates
authorradhika <radhika@curoverse.com>
Wed, 21 Jun 2017 01:09:02 +0000 (21:09 -0400)
committerradhika <radhika@curoverse.com>
Wed, 21 Jun 2017 01:09:02 +0000 (21:09 -0400)
Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika@curoverse.com>

apps/workbench/app/assets/javascripts/edit_collection_tags.js
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/views/collections/_show_tag_rows.html.erb

index 06cd64b00a0fdf3183fdcf5f309fc87d0304ac63..f13c54c353da761d5b7fe86dd433914ba1fe0513 100644 (file)
@@ -1,6 +1,5 @@
-// On loading of a collection, enable the "lock" button and
-// disable all file modification controls (upload, rename, delete)
-$(document).
+jQuery(function($){
+  $(document).
     on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
         $('.edit-collection-tags').removeClass('disabled');
         $('#edit-collection-tags').attr("title", "Edit tags");
@@ -20,46 +19,47 @@ $(document).
         $('.collection-tag-field').prop("contenteditable", true);
         $('div').remove('.collection-tags-status-label');
     }).
-    on('click', '.collection-tag-save', function(e){
+    on('click', '.collection-tag-save', function(event) {
       var tag_data = {};
+      var has_tags = false;
+
       var $tags = $(".collection-tags-table");
       $tags.find('tr').each(function (i, el) {
         var $tds = $(this).find('td');
         var $key = $tds.eq(1).text();
         if ($key && $key.trim().length > 0) {
+          has_tags = true;
           tag_data[$key.trim()] = $tds.eq(2).text().trim();
         }
       });
 
-      if(jQuery.isEmptyObject(tag_data)){
-        tag_data["empty"]=true
+      var to_send;
+      if (has_tags == false) {
+        to_send = {tag_data: "empty"}
       } else {
-        tag_data = {tag_data}
+        to_send = {tag_data: tag_data}
       }
 
       $.ajax($(location).attr('pathname')+'/save_tags', {
           type: 'POST',
-          data: tag_data
+          data: to_send
       }).success(function(data, status, jqxhr) {
         $('.collection-tags-status').append('<div class="collection-tags-status-label alert alert-success"><p class="contain-align-left">Saved successfully.</p></div>');
       }).fail(function(jqxhr, status, error) {
         $('.collection-tags-status').append('<div class="collection-tags-status-label alert alert-danger"><p class="contain-align-left">We are sorry. There was an error saving tags. Please try again.</p></div>');
       });
     }).
-    on('click', '.collection-tag-cancel', function(e){
+    on('click', '.collection-tag-cancel', function(event) {
       $.ajax($(location).attr('pathname')+'/tags', {
           type: 'GET'
       });
+    }).
+    on('click', '.collection-tag-remove', function(event) {
+      $(this).parents('tr').detach();
+    }).
+    on('click', '.collection-tag-add', function(event) {
+      var $collection_tags = $(this).closest('.collection-tags-container');
+      var $clone = $collection_tags.find('tr.hide').clone(true).removeClass('hide');
+      $collection_tags.find('table').append($clone);
     });
-
-jQuery(function($){
-  $(document).on('click', '.collection-tag-remove', function(e) {
-    $(this).parents('tr').detach();
-  });
-
-  $(document).on('click', '.collection-tag-add', function(e) {
-    var $collection_tags = $(this).closest('.collection-tags-container');
-    var $clone = $collection_tags.find('tr.hide').clone(true).removeClass('hide');
-    $collection_tags.find('table').append($clone);
-  });
 });
index bfba2f57f8616facadc818e3d4c016d8206d92c0..6b5e6133db3d4025b85e2c7f61c134b6a5f0b2c9 100644 (file)
@@ -350,11 +350,13 @@ class CollectionsController < ApplicationController
   end
 
   def save_tags
-    tags = nil
-    if params['tag_data']
-      tags = params['tag_data']
-    elsif params['empty']
-      tags = {}
+    tags_param = params['tag_data']
+    if tags_param
+      if tags_param.is_a?(String) && tags_param == "empty"
+        tags = {}
+      else
+        tags = tags_param
+      end
     end
 
     if tags
index 653fb377050683e3ebc7091db1ae628af2f1c362..8d2ae7b360400f8706c573baa04efb34228dbb54 100644 (file)
@@ -1,8 +1,8 @@
 <%
   tags = object.properties[:tags]
 %>
-
-        <% tags.andand.each do |k, v| %>
+        <% if tags.andand.is_a?(Hash) %>
+        <% tags.each do |k, v| %>
           <tr class="collection-tag-<%=k%>">
             <td>
               <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer;"></i>
@@ -15,6 +15,7 @@
             </td>
           </tr>
         <% end %>
+        <% end %>
 
         <!-- A hidden row to add new tag -->
         <tr class="collection-tag-hidden hide">