$(".tab-pane-Upload").removeClass("disabled");
$(".tab-pane-Upload").attr("data-original-title", "");
$("#Upload-tab").attr("data-toggle", "tab");
-
- $('.edit-collection-tags').removeClass('disabled');
- $('#edit-collection-tags').attr('title', '');
} else {
// User clicked "no" and so do not unlock
}
$(".tab-pane-Upload").addClass("disabled");
$(".tab-pane-Upload").attr("data-original-title", "Unlock collection to upload files");
$("#Upload-tab").attr("data-toggle", "disabled");
-
- $('.edit-collection-tags').removeClass('hide');
- $('.edit-collection-tags').addClass('disabled');
- $('#edit-collection-tags').attr('title', 'Unlock collection to edit tags');
- $('.collection-tag-add').addClass('hide');
- $('.collection-tag-remove').addClass('hide');
- $('.collection-tag-save').addClass('hide');
- $('.collection-tag-cancel').addClass('hide');
- $('.collection-tag-field').prop("contenteditable", false);
}
- }).
- on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
- $('.edit-collection-tags').removeClass('hide');
- $('.collection-tag-add').addClass('hide');
- $('.collection-tag-remove').addClass('hide');
- $('.collection-tag-save').addClass('hide');
- $('.collection-tag-cancel').addClass('hide');
- $('.collection-tag-field').prop("contenteditable", false);
- }).
- on('click', '.edit-collection-tags', function(event) {
- $('.edit-collection-tags').addClass('hide');
- $('.collection-tag-add').removeClass('hide');
- $('.collection-tag-remove').removeClass('hide');
- $('.collection-tag-save').removeClass('hide');
- $('.collection-tag-cancel').removeClass('hide');
- $('.collection-tag-field').prop("contenteditable", true);
});
-
-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);
- });
-});
--- /dev/null
+// On loading of a collection, enable the "lock" button and
+// disable all file modification controls (upload, rename, delete)
+$(document).
+ on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
+ $('.edit-collection-tags').removeClass('disabled');
+ $('.collection-tag-add').addClass('hide');
+ $('.collection-tag-remove').addClass('hide');
+ $('.collection-tag-save').addClass('hide');
+ $('.collection-tag-cancel').addClass('hide');
+ $('.collection-tag-field').prop("contenteditable", false);
+ }).
+ on('click', '.edit-collection-tags', function(event) {
+ $('.edit-collection-tags').addClass('disabled');
+ $('.collection-tag-add').removeClass('hide');
+ $('.collection-tag-remove').removeClass('hide');
+ $('.collection-tag-save').removeClass('hide');
+ $('.collection-tag-cancel').removeClass('hide');
+ $('.collection-tag-field').prop("contenteditable", true);
+ $('div').remove('.collection-tags-status-label');
+ }).
+ on('click', '.collection-tag-save', function(e){
+ var tag_data = {};
+ 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) {
+ tag_data[$key.trim()] = $tds.eq(2).text().trim();
+ }
+ });
+
+ $.ajax($(location).attr('pathname')+'/save_tags', {
+ type: 'POST',
+ data: {tag_data}
+ }).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>');
+ });
+ });
+
+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);
+ });
+});
end
end
+ def save_tags
+ props = @object.properties
+ props[:tags] = params['tag_data']
+ if @object.update_attributes properties: props
+ else
+ self.render_error status: 422
+ end
+ end
+
protected
def find_usable_token(token_list)
--- /dev/null
+<%
+ tags = object.properties[:tags]
+%>
+
+ <% tags.andand.each do |k, v| %>
+ <tr class="collection-tag-<%=k%>">
+ <td>
+ <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer;"></i>
+ </td>
+ <td class="collection-tag-field">
+ <%= k %>
+ </td>
+ <td class="collection-tag-field">
+ <%= v %>
+ </td>
+ </tr>
+ <% end %>
+
+ <!-- A hidden row to add new tag -->
+ <tr class="collection-tag-hidden hide">
+ <td>
+ <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer"></i>
+ </td>
+ <td class="collection-tag-field"></td>
+ <td class="collection-tag-field"></td>
+ </tr>
<%
object = @object unless object
- tags = object.properties[:tags]
%>
<div class="collection-tags-container" style="padding-left:2em;padding-right:2em;">
<% if object.editable? %>
- <p title="Unlock collection to edit tags" id="edit-collection-tags">
- <button type="button" class="btn btn-primary edit-collection-tags disabled">Edit</button>
+ <p title="Edit tags" id="edit-collection-tags">
+ <button type="button" class="btn btn-primary edit-collection-tags">Edit</button>
</p>
<% end %>
</tr>
</thead>
- <tbody>
- <% tags.andand.each do |k, v| %>
- <tr class="collection-tag-<%=k%>">
- <td>
- <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer;"></i>
- </td>
- <td class="collection-tag-field">
- <%= k %>
- </td>
- <td class="collection-tag-field">
- <%= v %>
- </td>
- </tr>
- <% end %>
-
- <!-- A hidden row to add new tag -->
- <tr class="collection-tag-hidden hide">
- <td>
- <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer"></i>
- </td>
- <td class="collection-tag-field"></td>
- <td class="collection-tag-field"></td>
- </tr>
+ <tbody class="collection-tag-rows">
+ <%= render partial: 'show_tag_rows', locals: {object: object} %>
</tbody>
</table>
<div>
<button class="btn btn-primary btn-sm collection-tag-add hide"><i class="glyphicon glyphicon-plus"></i> Add new tag </button>
</div>
<div class="pull-right">
- <button type="button" class="btn btn-primary collection-tag-save hide">Save</button>
- <button type="button" class="btn btn-primary collection-tag-cancel hide">Cancel</button>
+ <%= link_to(save_tags_collection_path, {class: 'btn btn-primary collection-tag-save hide', :remote => true, method: 'post', return_to: request.url}) do %>
+ Save
+ <% end %>
+ <button type="button" class="btn btn-sm btn-primary collection-tag-cancel hide">Cancel</button>
</div>
+
+ <div><div class="collection-tags-status"/></div></div>
<% end %>
</div>
</div>
post 'unshare', :on => :member
get 'choose', on: :collection
post 'remove_selected_files', on: :member
+ post 'save_tags', on: :member
end
get('/collections/download/:uuid/:reader_token/*file' => 'collections#show_file',
format: false)