Index: test/fixtures/packages.yml =================================================================== --- test/fixtures/packages.yml (revision 9) +++ test/fixtures/packages.yml (working copy) @@ -3,7 +3,9 @@ id: 1 user_id: 1000001 name: package1 + images: /images another: id: 2 user_id: 1000001 name: package2 + images: /images Index: app/controllers/home_controller.rb =================================================================== --- app/controllers/home_controller.rb (revision 9) +++ app/controllers/home_controller.rb (working copy) @@ -52,4 +52,38 @@ @result = @player.result @session[:back_to] = {:controller => controller_name, :action => action_name} end + + def swap + drag_dom_id = params[:id] + drop_dom_id = params[:recv_id] + + /drag_(\d+)/ =~ drag_dom_id + drag_position = $1.to_i+1 + /drop_(\d+)/ =~ drop_dom_id + drop_position = $1.to_i+1 + + drag_card = nil + drop_card = nil + Card.with_scope(mine) { + drag_card = Card.find_by_position(drag_position) + drop_card = Card.find_by_position(drop_position) + } + + if drag_card && drop_card + # swap position + orig_drag_card_position = drag_card.position + drag_card.position = drop_card.position + drop_card.position = orig_drag_card_position + + drag_card.save! + drop_card.save! + elsif drag_card + drag_card.move_to_bottom + end + + @cards = cards + render :update do |page| + page.replace_html 'pockets', :partial => 'pockets' + end + end end Index: app/views/home/_pockets.rhtml =================================================================== --- app/views/home/_pockets.rhtml (revision 9) +++ app/views/home/_pockets.rhtml (working copy) @@ -32,13 +32,33 @@ <% end %> -<% for card in @cards %> - <% show = link_to card.image_tag, :controller => 'card', :action => 'show', :id => card %> -
<%= pocket_link_to card %>
+<% NUM_CARDS_MAX.times do |i| %> + <% next unless card = @cards[i] %> +
<%= card.image_tag %>
<% end %> -<% (NUM_CARDS_MAX - @cards.size).times do %> -
<%= free_pocket_link_to card %>
+<% (@cards.size...NUM_CARDS_MAX).each do |i| %> +
<%= free_pocket_link_to card=nil %>
<% end %> + + + + <% %w(off def agi life).each do |name| %> Index: app/views/home/index.rhtml =================================================================== --- app/views/home/index.rhtml (revision 9) +++ app/views/home/index.rhtml (working copy) @@ -28,7 +28,7 @@ DefCard.new.image_tag end %> -<%= render :partial=>'pockets' %> +
<%= render :partial=>'pockets' %>
<%= link_to 'lock »(未実装)' %>
<% if @player.num_commands > 0 %> Index: app/views/layouts/_html_header.rhtml =================================================================== --- app/views/layouts/_html_header.rhtml (revision 9) +++ app/views/layouts/_html_header.rhtml (working copy) @@ -6,5 +6,5 @@ <%= stylesheet_link_tag 'default' %> <%= stylesheet_link_tag 'scaffold' %> <%= stylesheet_link_tag 'base' %> - <%= javascript_include_tag "prototype" %> + <%= javascript_include_tag :defaults %>