diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb
index 666399a..133a2ca 100644
--- a/app/controllers/my_profile/profile_design_controller.rb
+++ b/app/controllers/my_profile/profile_design_controller.rb
@@ -2,8 +2,28 @@ class ProfileDesignController < BoxOrganizerController
needs_profile
+ BLOCKS = [
+ Block
+ ]
+
def index
- render :action => 'index', :layout => true
+ render :action => 'index'
+ end
+
+ def add_block
+ type = params[:type]
+ if ! type.blank?
+ if BLOCKS.map(&:name).include?(type)
+ boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new
+ redirect_to :action => 'index'
+ else
+ raise ArgumentError.new("Type %s is not allowed. Go away." % type)
+ end
+ else
+ @block_types = BLOCKS
+ @boxes = boxes_holder.boxes
+ render :action => 'add_block', :layout => false
+ end
end
def boxes_editor?
diff --git a/app/views/box_organizer/add_block.rhtml b/app/views/box_organizer/add_block.rhtml
index a0e48d7..6e4f656 100644
--- a/app/views/box_organizer/add_block.rhtml
+++ b/app/views/box_organizer/add_block.rhtml
@@ -1,4 +1,21 @@
-<% button_bar do %>
- <%= submit_button(:add, _("Add")) %>
- <%= lightbox_close_button(_('Close')) %>
+<% form_tag do %>
+
+
<%= _('In what area do you want to put your new block?') %>
+
+ <%= select_tag('box_id', options_for_select(@boxes.map {|item| [ _("Area %d") % item.position, item.id]})) %>
+
+ <%= _('Select the type of block you want to add to your page.') %>
+
+ <% @block_types.each do |item| %>
+
+ <%= radio_button_tag('type', item.name) %>
+ <%= item.description %>
+
+ <% end %>
+
+ <% button_bar do %>
+ <%= submit_button(:add, _("Add")) %>
+ <%= lightbox_close_button(_('Close')) %>
+ <% end %>
+
<% end %>
diff --git a/app/views/box_organizer/index.rhtml b/app/views/box_organizer/index.rhtml
index 5c6bdf9..0c97c4b 100644
--- a/app/views/box_organizer/index.rhtml
+++ b/app/views/box_organizer/index.rhtml
@@ -1,5 +1,5 @@
<%= _('Organizing visual design')%>
-This is a test ... and this is a sample text.
-
-<%= @controller.boxes_holder.class %>
+<% button_bar do %>
+ <%= lightbox_button('add', _('Add a block'), { :action => 'add_block' }) %>
+<% end %>
diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb
index 4c6c581..67de176 100644
--- a/test/functional/profile_design_controller_test.rb
+++ b/test/functional/profile_design_controller_test.rb
@@ -58,9 +58,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase
@request.env['HTTP_REFERER'] = '/editor'
- @controller.expects(:boxes_holder).returns(holder).at_least_once
+ @controller.stubs(:boxes_holder).returns(holder)
end
+ ######################################################
+ # BEGIN - tests for BoxOrganizerController features
+ ######################################################
def test_should_move_block_to_the_end_of_another_block
get :move_block, :profile => 'ze', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}"
@@ -131,5 +134,35 @@ class ProfileDesignControllerTest < Test::Unit::TestCase
assert_equal [1,2], [@b2,@b1].map {|item| item.position}
end
+ ######################################################
+ # END - tests for BoxOrganizerController features
+ ######################################################
+
+ ######################################################
+ # BEGIN - tests for ProfileDesignController features
+ ######################################################
+
+ should 'display popup for adding a new block' do
+ get :add_block, :profile => 'ze'
+ assert_response :success
+ assert_no_tag :tag => 'body' # e.g. no layout
+ end
+
+ should 'actually add a new block' do
+ assert_difference Block, :count do
+ post :add_block, :profile => 'ze', :box_id => 1, :type => Block.name
+ assert_redirected_to :action => 'index'
+ end
+ end
+
+ should 'not allow tp create unknown types' do
+ assert_no_difference Block, :count do
+ assert_raise ArgumentError do
+ post :add_block, :profile => 'ze', :box_id => 1, :type => "PleaseLetMeCrackYourSite"
+ end
+ end
+ end
+
+
end
--
libgit2 0.21.2