9426: collection Tags tab (in progress)
[arvados.git] / apps / workbench / app / assets / javascripts / edit_collection_tags.js
1 // On loading of a collection, enable the "lock" button and
2 // disable all file modification controls (upload, rename, delete)
3 $(document).
4     on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
5         $('.edit-collection-tags').removeClass('disabled');
6         $('.collection-tag-add').addClass('hide');
7         $('.collection-tag-remove').addClass('hide');
8         $('.collection-tag-save').addClass('hide');
9         $('.collection-tag-cancel').addClass('hide');
10         $('.collection-tag-field').prop("contenteditable", false);
11     }).
12     on('click', '.edit-collection-tags', function(event) {
13         $('.edit-collection-tags').addClass('disabled');
14         $('.collection-tag-add').removeClass('hide');
15         $('.collection-tag-remove').removeClass('hide');
16         $('.collection-tag-save').removeClass('hide');
17         $('.collection-tag-cancel').removeClass('hide');
18         $('.collection-tag-field').prop("contenteditable", true);
19         $('div').remove('.collection-tags-status-label');
20     }).
21     on('click', '.collection-tag-save', function(e){
22       var tag_data = {};
23       var $tags = $(".collection-tags-table");
24       $tags.find('tr').each(function (i, el) {
25         var $tds = $(this).find('td');
26         var $key = $tds.eq(1).text();
27         if ($key && $key.trim().length > 0) {
28           tag_data[$key.trim()] = $tds.eq(2).text().trim();
29         }
30       });
31
32       $.ajax($(location).attr('pathname')+'/save_tags', {
33           type: 'POST',
34           data: {tag_data}
35       }).success(function(data, status, jqxhr) {
36         $('.collection-tags-status').append('<div class="collection-tags-status-label alert alert-success"><p class="contain-align-left">Saved successfully.</p></div>');
37       }).fail(function(jqxhr, status, error) {
38         $('.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>');
39       });
40     });
41
42 jQuery(function($){
43   $(document).on('click', '.collection-tag-remove', function(e) {
44     $(this).parents('tr').detach();
45   });
46
47   $(document).on('click', '.collection-tag-add', function(e) {
48     var $collection_tags = $(this).closest('.collection-tags-container');
49     var $clone = $collection_tags.find('tr.hide').clone(true).removeClass('hide');
50     $collection_tags.find('table').append($clone);
51   });
52 });