$.fn.editable.defaults.params = function (params) {
var a = {};
var key = params.pk.key;
- a.id = params.pk.id;
+ a.id = $(this).attr('data-object-uuid') || params.pk.id;
a[key] = params.pk.defaults || {};
+ // Remove null values. Otherwise they get transmitted as empty
+ // strings in request params.
+ for (i in a[key]) {
+ if (a[key][i] == null)
+ delete a[key][i];
+ }
a[key][params.name] = params.value;
- if (params.pk._method) {
- a['_method'] = params.pk._method;
+ if (!a.id) {
+ a['_method'] = 'post';
} else {
a['_method'] = 'put';
}
console.log($(this));
});
$('.editable').
- editable().
- on('hidden', function(e, reason) {
- if (reason == 'save') {
- var html = $(this).html();
- var uuid = $(this).attr('data-object-uuid');
- var attr = $(this).attr('data-name');
- var edited = this;
- if (uuid && attr) {
- $("[data-object-uuid='" + uuid + "']" +
- "[data-name='" + attr + "']").each(function() {
- if (this != edited)
- $(this).html(html);
- });
+ editable({
+ success: function(response, newValue) {
+ // If we just created a new object, stash its UUID
+ // so we edit it next time instead of creating
+ // another new object.
+ if (!$(this).attr('data-object-uuid') && response.uuid) {
+ $(this).attr('data-object-uuid', response.uuid);
+ }
+ if (response.href) {
+ $(this).editable('option', 'url', response.href);
}
+ return;
+ }
+ }).
+ on('hidden', function(e, reason) {
+ // After saving a new attribute, update the same
+ // information if it appears elsewhere on the page.
+ if (reason != 'save') return;
+ var html = $(this).html();
+ var uuid = $(this).attr('data-object-uuid');
+ var attr = $(this).attr('data-name');
+ var edited = this;
+ if (uuid && attr) {
+ $("[data-object-uuid='" + uuid + "']" +
+ "[data-name='" + attr + "']").each(function() {
+ if (this != edited)
+ $(this).html(html);
+ });
}
});
});
return render_not_found("object not found")
end
respond_to do |f|
- f.json { render json: @object }
+ f.json { render json: @object.attributes.merge(href: url_for(@object)) }
f.html {
if request.method == 'GET'
render
@new_resource_attrs.reject! { |k,v| k.to_s == 'uuid' }
@object ||= model_class.new @new_resource_attrs
@object.save!
-
- respond_to do |f|
- f.json { render json: @object }
- f.html {
- redirect_to(params[:return_to] || @object)
- }
- f.js { render }
- end
+ show
end
def destroy
def remove_item
@removed_uuids = []
+ links = []
item = ArvadosBase.find params[:item_uuid]
if (item.class == Link and
item.link_class == 'name' and
# Given uuid is a name link, linking an object to this
# folder. First follow the link to find the item we're removing,
# then delete the link.
- link = item
- item = ArvadosBase.find link.head_uuid
+ links << item
+ item = ArvadosBase.find item.head_uuid
+ else
+ # Given uuid is an object. Delete all names.
+ links += Link.where(tail_uuid: @object.uuid,
+ head_uuid: item.uuid,
+ link_class: 'name')
+ end
+ links.each do |link|
@removed_uuids << link.uuid
link.destroy
end
else
ajax_options['data-url'] = url_for(action: "create", controller: object.class.to_s.pluralize.underscore)
ajax_options['data-pk'][:defaults] = object.attributes
- ajax_options['data-pk'][:_method] = 'post'
end
ajax_options['data-pk'] = ajax_options['data-pk'].to_json
<col width="8%" />
</colgroup>
<% @objects_and_names.each do |object, name_link| %>
- <tr data-object-uuid="<%= (name_link || object).uuid %>">
- <td>
- <%= render :partial => "selection_checkbox", :locals => {object: object} %>
- </td>
- <td>
- <%= render :partial => "show_object_button", :locals => {object: object, size: 'xs'} %>
- </td>
- <td>
- <%= render_editable_attribute name_link, 'name', nil, {data: {emptytext: "Unnamed #{object.class_for_display}"}} %>
- </td>
- <td>
- <%= object.content_summary %>
- </td>
- <td title="<%= object.modified_at %>">
- <span>
- <%= raw distance_of_time_in_words(object.modified_at, Time.now).sub('about ','~').sub(' ',' ') + ' ago' rescue object.modified_at %>
- </span>
- </td>
- <td class="arvados-uuid">
- <%= object.uuid %>
- </td>
- <td>
- <% if @object.editable? %>
- <%= link_to({action: 'remove_item', id: @object.uuid, item_uuid: (name_link || object).uuid}, method: :delete, remote: true, data: {confirm: "You are about to remove #{object.class_for_display} #{object.uuid} from this folder.\n\nAre you sure?"}, class: 'btn btn-xs btn-default') do %>
- Remove <i class="fa fa-fw fa-ban"></i>
+ <tr data-object-uuid="<%= (name_link && name_link.uuid) || object.uuid %>">
+ <td>
+ <%= render :partial => "selection_checkbox", :locals => {object: object} %>
+ </td>
+ <td>
+ <%= render :partial => "show_object_button", :locals => {object: object, size: 'xs'} %>
+ </td>
+ <td>
+ <%= render_editable_attribute name_link, 'name', nil, {data: {emptytext: "Unnamed #{object.class_for_display}"}} %>
+ </td>
+ <td>
+ <%= object.content_summary %>
+ </td>
+ <td title="<%= object.modified_at %>">
+ <span>
+ <%= raw distance_of_time_in_words(object.modified_at, Time.now).sub('about ','~').sub(' ',' ') + ' ago' rescue object.modified_at %>
+ </span>
+ </td>
+ <td class="arvados-uuid">
+ <%= object.uuid %>
+ </td>
+ <td>
+ <% if @object.editable? %>
+ <%= link_to({action: 'remove_item', id: @object.uuid, item_uuid: ((name_link && name_link.uuid) || object.uuid)}, method: :delete, remote: true, data: {confirm: "You are about to remove #{object.class_for_display} #{object.uuid} from this folder.\n\nAre you sure?"}, class: 'btn btn-xs btn-default') do %>
+ Remove <i class="fa fa-fw fa-ban"></i>
+ <% end %>
<% end %>
- <% end %>
- </td>
- </tr>
+ </td>
+ </tr>
<% end %>
</tbody>
<thead>
Capybara.current_driver = Capybara.javascript_driver
visit page_with_token 'active', '/'
find('nav a', text: 'Folders').click
- find('tr', text: 'A Folder').
+ find('.side-nav', text: 'A Folder').
find('a,button', text: 'Show').
click
within('.panel', text: api_fixture('groups')['afolder']['name']) do
#find('.panel', text: 'I just edited this.')
end
+ test 'Add a new name, then edit it, without creating a duplicate' do
+ Capybara.current_driver = Capybara.javascript_driver
+ folder_uuid = api_fixture('groups')['afolder']['uuid']
+ specimen_uuid = api_fixture('specimens')['owned_by_afolder_with_no_name_link']['uuid']
+ visit page_with_token 'active', '/folders/' + folder_uuid
+ within('.panel', text: 'Contents') do
+ find('.tr[data-object-uuid="'+specimen_uuid+'"] .editable[data-name="name"]').click
+ find('.editable-input input').set('Now I have a name.')
+ find('.glyphicon-ok').click
+ find('.editable', text: 'Now I have a name.').click
+ find('.editable-input input').set('Now I have a new name.')
+ find('.glyphicon-ok').click
+ find('.editable', text: 'Now I have a new name.')
+ end
+ visit current_path
+ within '.panel', text: 'Contents' do
+ find '.editable', text: 'Now I have a new name.'
+ page.assert_no_selector '.editable', text: 'Now I have a name.'
+ end
+ end
+
end
owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
created_at: 2014-04-21 15:37:48 -0400
modified_at: 2014-04-21 15:37:48 -0400
+
+owned_by_afolder_with_no_name_link:
+ uuid: zzzzz-j58dm-ypsjlol9dofwijz
+ owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
+ created_at: 2014-05-05 04:11:52 -0400
+ modified_at: 2014-05-05 04:11:52 -0400