[ARVADOS] created: 0f30cd32ae07e1d514fa5b9fff7fd796a95a6d84

git at public.curoverse.com git at public.curoverse.com
Fri Aug 29 20:11:03 EDT 2014


        at  0f30cd32ae07e1d514fa5b9fff7fd796a95a6d84 (commit)


commit 0f30cd32ae07e1d514fa5b9fff7fd796a95a6d84
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri Aug 29 20:06:01 2014 -0400

    3637: Propagate checkbox selection through chooser modal, remove session hack.

diff --git a/apps/workbench/app/assets/javascripts/select_modal.js b/apps/workbench/app/assets/javascripts/select_modal.js
index dda230f..ba106d1 100644
--- a/apps/workbench/app/assets/javascripts/select_modal.js
+++ b/apps/workbench/app/assets/javascripts/select_modal.js
@@ -37,20 +37,28 @@ $(document).on('click', '.selectable', function() {
     var data = [];
     var $modal = $(this).closest('.modal');
     var action_data = $(this).data('action-data');
+    var action_data_from_params = $(this).data('action-data-from-params');
     var selection_param = action_data.selection_param;
     $modal.find('.modal-error').removeClass('hide').hide();
     $modal.find('.selectable.active[data-object-uuid]').each(function() {
         var val = $(this).attr('data-object-uuid');
         data.push({name: selection_param, value: val});
     });
-    $.each(action_data, function(key, value) {
-        data.push({name: key, value: value});
-    });
+    $.each($.extend({}, action_data, action_data_from_params),
+           function(key, value) {
+               if (value instanceof Array && key[-1] != ']') {
+                   for (var i in value) {
+                       data.push({name: key + '[]', value: value[i]});
+                   }
+               } else {
+                   data.push({name: key, value: value});
+               }
+           });
     $.ajax($(this).attr('data-action-href'),
            {dataType: 'json',
             type: $(this).attr('data-method'),
             data: data,
-            traditional: true,
+            traditional: false,
             context: {modal: $modal, action_data: action_data}}).
         fail(function(jqxhr, status, error) {
             if (jqxhr.readyState == 0 || jqxhr.status == 0) {
diff --git a/apps/workbench/app/controllers/projects_controller.rb b/apps/workbench/app/controllers/projects_controller.rb
index 0b14679..fce7758 100644
--- a/apps/workbench/app/controllers/projects_controller.rb
+++ b/apps/workbench/app/controllers/projects_controller.rb
@@ -77,32 +77,6 @@ class ProjectsController < ApplicationController
     end
   end
 
-  def move_items
-    target_uuid = params['target']
-    uuids_to_add = session[:selected_move_items]
-
-    uuids_to_add.
-      collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
-      uniq.
-      each do |resource_class|
-      resource_class.filter([['uuid','in',uuids_to_add]]).each do |dst|
-        if resource_class == Collection and not Collection.attribute_info.include?(:name)
-          dst = Link.new(owner_uuid: target_uuid,
-                         tail_uuid: target_uuid,
-                         head_uuid: dst.uuid,
-                         link_class: 'name',
-                         name: target_uuid)
-        else
-          dst.owner_uuid = target_uuid
-          dst.tail_uuid = target_uuid if dst.class == Link
-        end
-        dst.save!
-      end
-    end
-    session[:selected_move_items] = nil
-    redirect_to @object
-  end
-
   def destroy
     while (objects = Link.filter([['owner_uuid','=', at object.uuid],
                                   ['tail_uuid','=', at object.uuid]])).any?
diff --git a/apps/workbench/app/views/application/_choose.js.erb b/apps/workbench/app/views/application/_choose.js.erb
index c482b45..d85e566 100644
--- a/apps/workbench/app/views/application/_choose.js.erb
+++ b/apps/workbench/app/views/application/_choose.js.erb
@@ -1,8 +1,25 @@
-<% session[:selected_move_items] = params['move_items'] if params['move_items'] %>
+<%
+=begin
+
+Parameters received from the caller/requestor of the modal are
+attached to the action button (.btn-primary) as follows:
+
+action_class -- string -- added as a pseudoclass to the action button.
+
+action_href -- string -- will be available at $(btn).attr('data-action-href')
+
+action_data -- json-encoded object -- will be at $(btn).data('action-data')
+
+action_data_form_params -- array -- for each X in this array, the
+value of params[X] during this "show chooser" request will be in
+$(btn).data('action-data-from-params')[X].
+
+=end %>
 $('body > .modal-container').html("<%= escape_javascript(render partial: 'choose.html', locals: {multiple: multiple}) %>");
 $('body > .modal-container .modal').modal('show');
 $('body > .modal-container .modal .modal-footer .btn-primary').
     addClass('<%= j params[:action_class] %>').
     attr('data-action-href', '<%= j params[:action_href] %>').
     attr('data-method', '<%= j params[:action_method] %>').
-    data('action-data', <%= raw params[:action_data] %>);
+    data('action-data', <%= raw params[:action_data] %>).
+    data('action-data-from-params', <%= raw params.select { |k,v| k.in?(params[:action_data_from_params] || []) }.to_json %>);
diff --git a/apps/workbench/app/views/projects/_show_tab_contents.html.erb b/apps/workbench/app/views/projects/_show_tab_contents.html.erb
index 8fb588f..40433ba 100644
--- a/apps/workbench/app/views/projects/_show_tab_contents.html.erb
+++ b/apps/workbench/app/views/projects/_show_tab_contents.html.erb
@@ -17,18 +17,21 @@
                   'method' => 'delete',
                   'data-toggle' => 'dropdown'
             %></li>
-	          <li><%= link_to "Move selected", '#',
-            		  'data-href' => choose_projects_path(
-                                   title: 'Move to...',
-                                   editable: true,
-                                   action_name: 'Move',
-                                   action_href: move_items_project_path,
-                                   action_method: 'get',
-                                   action_data: {selection_param: 'target',
-                                                 success: 'page-refresh'}.to_json),
+	  <li><%= link_to "Move selected", '#',
+                  'data-href' => choose_projects_path(
+                    title: 'Move selected items to...',
+                    editable: true,
+                    action_name: 'Move',
+                    action_href: actions_path,
+                    action_method: 'post',
+                    action_data_from_params: ['selection'],
+                    action_data: {
+                      move_selections_into_project: true,
+                      selection_param: 'uuid',
+                      success: 'page-refresh'}.to_json),
                   'data-remote' => true,
-                  'data-selection-param-name' => 'move_items[]',
-		              'data-selection-action' => 'move'
+                  'data-selection-param-name' => 'selection[]',
+                  'data-selection-action' => 'move'
             %></li>
         </ul>
       </div>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index e58796e..8f01a76 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -70,7 +70,6 @@ ArvadosWorkbench::Application.routes.draw do
   resources :projects do
     match 'remove/:item_uuid', on: :member, via: :delete, action: :remove_item
     match 'remove_items', on: :member, via: :delete, action: :remove_items
-    get 'move_items', on: :member, action: :move_items
     get 'choose', on: :collection
     post 'share_with', on: :member
   end

commit a16c764ae43c82913b69be61b526c6eb04ab20e6
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri Aug 29 20:02:38 2014 -0400

    3637: Operate only on selections within this container, even if clippy has more.

diff --git a/apps/workbench/app/assets/javascripts/selection.js b/apps/workbench/app/assets/javascripts/selection.js
index a313c8b..36c7f4d 100644
--- a/apps/workbench/app/assets/javascripts/selection.js
+++ b/apps/workbench/app/assets/javascripts/selection.js
@@ -189,9 +189,12 @@ function dispatch_selection_action() {
     if ($(this).closest('.disabled').length > 0) {
 	return false;
     }
-    $('.persistent-selection:checkbox:checked').each(function() {
-        data.push({name: param_name, value: $(this).val()});
-    });
+    $(this).
+        closest('.selection-action-container').
+        find(':checkbox:checked').
+        each(function() {
+            data.push({name: param_name, value: $(this).val()});
+        });
     if (href.indexOf('?') >= 0)
         href += '&';
     else
@@ -202,7 +205,8 @@ function dispatch_selection_action() {
 }
 
 function enable_disable_selection_actions() {
-    var $checked = $('.persistent-selection:checkbox:checked');
+    var $container = $(this).closest('.selection-action-container');
+    var $checked = $('.persistent-selection:checkbox:checked', $container);
     $('[data-selection-action]').
         closest('div.btn-group-sm').
         find('ul li').
@@ -216,6 +220,7 @@ function enable_disable_selection_actions() {
 
 $(document).
     on('selections-updated ready ajax:complete', function() {
-        $('[data-selection-action]').click(dispatch_selection_action);
-        enable_disable_selection_actions();
+        var $btn = $('[data-selection-action]');
+        $btn.click(dispatch_selection_action);
+        enable_disable_selection_actions.call($btn);
     });

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list