From 123c4f76160b674358e3427a0b4663de835b229b Mon Sep 17 00:00:00 2001 From: LeandroNunes Date: Mon, 16 Jul 2007 00:22:56 +0000 Subject: [PATCH] ActionItem0: adding sort possibility on edit template --- app/controllers/edit_template_controller.rb | 24 +++++++++++++++++++++++- app/helpers/application_helper.rb | 2 +- app/helpers/edit_template_helper.rb | 7 ++++--- app/views/layouts/application.rhtml | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/controllers/edit_template_controller.rb b/app/controllers/edit_template_controller.rb index 012301d..f1eb0ec 100644 --- a/app/controllers/edit_template_controller.rb +++ b/app/controllers/edit_template_controller.rb @@ -1,5 +1,13 @@ class EditTemplateController < ApplicationController + before_filter :manage_template + + attr_accessor :controller_manage_template + + def manage_template? + self.controller_manage_template == true ? true : false + end + # This method changes a block content to a different box place and # updates all boxes at the ends def change_box @@ -10,7 +18,6 @@ class EditTemplateController < ApplicationController @boxes.each do |box| @box = box page.replace_html "box_#{box.number}", {:partial => 'layouts/box_template'} - page.sortable "sort_#{box.number}", :url => {:action => 'sort_box', :box_number => box.number} end end end @@ -30,4 +37,19 @@ class EditTemplateController < ApplicationController render :partial => 'layouts/box_template' end + def set_sort_mode + box = Box.find(params[:box_id]) + render :update do |page| + @box = box + page.replace_html "box_#{box.number}", {:partial => 'layouts/box_template'} + page.sortable "sort_#{box.number}", :url => {:action => 'sort_box', :box_number => box.number} + end + end + + private + + def manage_template + self.controller_manage_template = true + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3e2d480..80e887e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -77,7 +77,7 @@ module ApplicationHelper # Check if the current controller is the controller that allows layout editing def edit_mode? - controller.controller_name == 'edit_template' ? true : false + controller.manage_template? end # Shows the block as the struture bellow diff --git a/app/helpers/edit_template_helper.rb b/app/helpers/edit_template_helper.rb index b0cdc3c..3f1edf1 100644 --- a/app/helpers/edit_template_helper.rb +++ b/app/helpers/edit_template_helper.rb @@ -7,11 +7,12 @@ module EditTemplateHelper # In this case the layout can be manipulated def edit_blocks(box, main_content = "") blocks = box.blocks_sort_by_position - content_tag(:ul, box.name + + content_tag(:ul, box.name + + link_to_remote(_('sort'), {:update => "sort_#{box.number}", :url => {:action => 'set_sort_mode', :box_id => box.id }}, :class => 'sort_button') + blocks.map {|b| content_tag(:li, b.name, :class =>"block_item_box_#{box.number}" , :id => "block_#{b.id}" ) + draggable("block_#{b.id}") }.to_s, :id => "sort_#{box.number}" - ) + drag_drop_items(box) + sortable_block(box.number) + ) + drag_drop_items(box) end # Allows the biven box to have sortable elements @@ -23,7 +24,7 @@ module EditTemplateHelper # Allows an element item to be draggable def draggable(item) - draggable_element(item, :ghosting=>true, :revert=>true) + draggable_element(item, :ghosting => true, :revert => true) end # Allows an draggable element change between diferrents boxes diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 0a331a1..88962ad 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -6,7 +6,7 @@ - <%= image_tag 'loading.gif', :id=>'spinner', :style=>"display:none; float:right;" %> + <%= image_tag 'loading.gif', :id => 'spinner', :style => "display:none; float:right;" %> <%= link_to _('Show Layout'), :controller => 'home' %> <%= link_to _('Edit Layout'), :controller => 'edit_template' %> -- libgit2 0.21.2