Class BoxOrganizerController
In: app/controllers/box_organizer_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

[Source]

    # File app/controllers/box_organizer_controller.rb, line 59
59:   def add_block
60:     type = params[:type]
61:     if ! type.blank?
62:       if available_blocks.map(&:name).include?(type)
63:         boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new
64:         redirect_to :action => 'index'
65:       else
66:         raise ArgumentError.new("Type %s is not allowed. Go away." % type)
67:       end
68:     else
69:       @block_types = available_blocks
70:       @boxes = boxes_holder.boxes
71:       render :action => 'add_block', :layout => false
72:     end
73:   end

[Source]

    # File app/controllers/box_organizer_controller.rb, line 75
75:   def edit
76:     @block = boxes_holder.blocks.find(params[:id])
77:     render :action => 'edit', :layout => false
78:   end

[Source]

   # File app/controllers/box_organizer_controller.rb, line 3
3:   def index
4:   end

[Source]

    # File app/controllers/box_organizer_controller.rb, line 6
 6:   def move_block
 7:     @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, ''))
 8: 
 9:     @source_box = @block.box
10: 
11:     target_position = nil
12: 
13:     if (params[:target] =~ /before-block-([0-9]+)/)
14:       block_before = boxes_holder.blocks.find($1)
15:       target_position = block_before.position
16: 
17:       @target_box = block_before.box
18:     else
19:       (params[:target] =~ /end-of-box-([0-9]+)/)
20: 
21:       @target_box = boxes_holder.boxes.find($1)
22:     end
23: 
24:     if (@source_box != @target_box)
25:       @block.remove_from_list
26:       @block.box = @target_box
27:     end
28: 
29:     if target_position.nil?
30:       # insert in the end of the box
31:       @block.insert_at(@target_box.blocks.size + 1)
32:       @block.move_to_bottom
33:     else
34:       # insert the block in the given position
35:       @block.insert_at(@block.position && @block.position < target_position ? target_position - 1 : target_position)
36:     end
37: 
38:     @block.save!
39: 
40:     @target_box.reload
41: 
42:     unless request.xhr?
43:       redirect_to :action => 'index'
44:     end
45:   end

[Source]

    # File app/controllers/box_organizer_controller.rb, line 47
47:   def move_block_down
48:     @block = boxes_holder.blocks.find(params[:id])
49:     @block.move_lower
50:     redirect_to :action => 'index'
51:   end

[Source]

    # File app/controllers/box_organizer_controller.rb, line 53
53:   def move_block_up
54:     @block = boxes_holder.blocks.find(params[:id])
55:     @block.move_higher
56:     redirect_to :action => 'index'
57:   end

[Source]

    # File app/controllers/box_organizer_controller.rb, line 90
90:   def remove
91:     @block = Block.find(params[:id])
92:     if @block.destroy
93:       redirect_to :action => 'index'
94:     else
95:       flash[:notice] = _('Failed to remove block')
96:     end
97:   end

[Source]

    # File app/controllers/box_organizer_controller.rb, line 80
80:   def save
81:     @block = boxes_holder.blocks.find(params[:id])
82:     @block.update_attributes(params[:block])
83:     redirect_to :action => 'index'
84:   end

Protected Instance methods

[Source]

    # File app/controllers/box_organizer_controller.rb, line 86
86:   def boxes_editor?
87:     true
88:   end

[Validate]