Commit 123c4f76160b674358e3427a0b4663de835b229b

Authored by LeandroNunes
1 parent 4a2b904d

ActionItem0: adding sort possibility on edit template

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@77 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/edit_template_controller.rb
1 1 class EditTemplateController < ApplicationController
2 2  
  3 + before_filter :manage_template
  4 +
  5 + attr_accessor :controller_manage_template
  6 +
  7 + def manage_template?
  8 + self.controller_manage_template == true ? true : false
  9 + end
  10 +
3 11 # This method changes a block content to a different box place and
4 12 # updates all boxes at the ends
5 13 def change_box
... ... @@ -10,7 +18,6 @@ class EditTemplateController &lt; ApplicationController
10 18 @boxes.each do |box|
11 19 @box = box
12 20 page.replace_html "box_#{box.number}", {:partial => 'layouts/box_template'}
13   - page.sortable "sort_#{box.number}", :url => {:action => 'sort_box', :box_number => box.number}
14 21 end
15 22 end
16 23 end
... ... @@ -30,4 +37,19 @@ class EditTemplateController &lt; ApplicationController
30 37 render :partial => 'layouts/box_template'
31 38 end
32 39  
  40 + def set_sort_mode
  41 + box = Box.find(params[:box_id])
  42 + render :update do |page|
  43 + @box = box
  44 + page.replace_html "box_#{box.number}", {:partial => 'layouts/box_template'}
  45 + page.sortable "sort_#{box.number}", :url => {:action => 'sort_box', :box_number => box.number}
  46 + end
  47 + end
  48 +
  49 + private
  50 +
  51 + def manage_template
  52 + self.controller_manage_template = true
  53 + end
  54 +
33 55 end
... ...
app/helpers/application_helper.rb
... ... @@ -77,7 +77,7 @@ module ApplicationHelper
77 77  
78 78 # Check if the current controller is the controller that allows layout editing
79 79 def edit_mode?
80   - controller.controller_name == 'edit_template' ? true : false
  80 + controller.manage_template?
81 81 end
82 82  
83 83 # Shows the block as the struture bellow
... ...
app/helpers/edit_template_helper.rb
... ... @@ -7,11 +7,12 @@ module EditTemplateHelper
7 7 # In this case the layout can be manipulated
8 8 def edit_blocks(box, main_content = "")
9 9 blocks = box.blocks_sort_by_position
10   - content_tag(:ul, box.name +
  10 + content_tag(:ul, box.name +
  11 + link_to_remote(_('sort'), {:update => "sort_#{box.number}", :url => {:action => 'set_sort_mode', :box_id => box.id }}, :class => 'sort_button') +
11 12 blocks.map {|b|
12 13 content_tag(:li, b.name, :class =>"block_item_box_#{box.number}" , :id => "block_#{b.id}" ) + draggable("block_#{b.id}")
13 14 }.to_s, :id => "sort_#{box.number}"
14   - ) + drag_drop_items(box) + sortable_block(box.number)
  15 + ) + drag_drop_items(box)
15 16 end
16 17  
17 18 # Allows the biven box to have sortable elements
... ... @@ -23,7 +24,7 @@ module EditTemplateHelper
23 24  
24 25 # Allows an element item to be draggable
25 26 def draggable(item)
26   - draggable_element(item, :ghosting=>true, :revert=>true)
  27 + draggable_element(item, :ghosting => true, :revert => true)
27 28 end
28 29  
29 30 # Allows an draggable element change between diferrents boxes
... ...
app/views/layouts/application.rhtml
... ... @@ -6,7 +6,7 @@
6 6  
7 7 </head>
8 8 <body>
9   - <%= image_tag 'loading.gif', :id=>'spinner', :style=>"display:none; float:right;" %>
  9 + <%= image_tag 'loading.gif', :id => 'spinner', :style => "display:none; float:right;" %>
10 10  
11 11 <%= link_to _('Show Layout'), :controller => 'home' %>
12 12 <%= link_to _('Edit Layout'), :controller => 'edit_template' %>
... ...