3 on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
4 $('.edit-collection-tags').removeClass('disabled');
5 $('#edit-collection-tags').attr("title", "Edit tags");
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);
12 on('click', '.edit-collection-tags', function(event) {
13 $('.edit-collection-tags').addClass('disabled');
14 $('#edit-collection-tags').attr("title", "");
15 $('.collection-tag-add').removeClass('hide');
16 $('.collection-tag-remove').removeClass('hide');
17 $('.collection-tag-save').removeClass('hide');
18 $('.collection-tag-cancel').removeClass('hide');
19 $('.collection-tag-field').prop("contenteditable", true);
20 $('div').remove('.collection-tags-status-label');
22 on('click', '.collection-tag-save', function(event) {
26 var $tags = $(".collection-tags-table");
27 $tags.find('tr').each(function (i, el) {
28 var $tds = $(this).find('td');
29 var $key = $tds.eq(1).text();
30 if ($key && $key.trim().length > 0) {
32 tag_data[$key.trim()] = $tds.eq(2).text().trim();
37 if (has_tags == false) {
38 to_send = {tag_data: "empty"}
40 to_send = {tag_data: tag_data}
43 $.ajax($(location).attr('pathname')+'/save_tags', {
46 }).success(function(data, status, jqxhr) {
47 $('.collection-tags-status').append('<div class="collection-tags-status-label alert alert-success"><p class="contain-align-left">Saved successfully.</p></div>');
48 }).fail(function(jqxhr, status, error) {
49 $('.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>');
52 on('click', '.collection-tag-cancel', function(event) {
53 $.ajax($(location).attr('pathname')+'/tags', {
57 on('click', '.collection-tag-remove', function(event) {
58 $(this).parents('tr').detach();
60 on('click', '.collection-tag-add', function(event) {
61 var $collection_tags = $(this).closest('.collection-tags-container');
62 var $clone = $collection_tags.find('tr.hide').clone(true).removeClass('hide');
63 $collection_tags.find('table').append($clone);
65 on('keypress', '.collection-tag-field', function(event){
66 return event.which != 13;