Commit 4467d7c062571d624e4429ce111800847be5e126

Authored by LeandroNunes
1 parent 44d63989

ActionItem0: Adding list an link blocks




git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@35 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
... ... @@ -4,6 +4,29 @@ class ApplicationController < ActionController::Base
4 4  
5 5 before_filter :detect_stuff_by_domain
6 6  
  7 + before_filter :detect_edit_layout
  8 +
  9 + def detect_edit_layout
  10 + @edit_layout = true unless params[:edit_layout].nil?
  11 + end
  12 +
  13 +# after_filter :render_actions
  14 +
  15 + def render_actions
  16 +@bla = 'funfou'
  17 +#return @bla
  18 + render_action('index', nil, true)
  19 +# render :update do |page|
  20 +# page.replace_html 'box_1', :partial => 'pending_todos'
  21 +# page.replace_html 'completed_todos', :partial => 'completed_todos'
  22 +# page.replace_html 'working_todos', :partial => 'working_todos'
  23 +# end
  24 + end
  25 +
  26 +# def render(type = nil)
  27 +# render_actions
  28 +# end
  29 +
7 30 protected
8 31  
9 32 def detect_stuff_by_domain
... ...
app/controllers/home_controller.rb
1 1 class HomeController < ApplicationController
  2 +
  3 + def index
  4 + #TODO this is a test case of owner
  5 + @owner = User.find(1)
  6 + end
  7 +
  8 +def teste
  9 + render :update do |page|
  10 + page.replace_html 'box_1', :partial => 'leo'
  11 +#'nem acredito'
  12 +# page.replace_html 'completed_todos', :partial => 'completed_todos'
  13 +# page.replace_html 'working_todos', :partial => 'working_todos'
  14 + end
  15 +
  16 +end
2 17 end
... ...
app/helpers/application_helper.rb
1 1 # Methods added to this helper will be available to all templates in the application.
2 2 module ApplicationHelper
  3 +
  4 +
  5 + def show_block(owner,box_number)
  6 + blocks = owner.boxes.find(:first, :conditions => ['number = ?', box_number]).blocks
  7 + @out = blocks.map {|b| b.to_html}.join('')
  8 + end
  9 +
3 10 end
... ...
app/models/block.rb
... ... @@ -7,4 +7,8 @@ class Block &lt; ActiveRecord::Base
7 7 # A block must be associated to a box
8 8 validates_presence_of :box_id
9 9  
  10 + def to_html
  11 + return '<p>bli</p>'
  12 + end
  13 +
10 14 end
... ...
app/models/box.rb
1 1 class Box < ActiveRecord::Base
  2 + has_many :blocks
2 3 belongs_to :owner, :polymorphic => true
3 4  
4 5 #we cannot have two boxs with the same number to the same owner
... ...
app/models/link_block.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class LinkBlock < ActiveRecord::Base
  2 +end
... ...
app/models/list_block.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class ListBlock < ActiveRecord::Base
  2 +end
... ...
app/views/layouts/application.rhtml
... ... @@ -6,13 +6,20 @@
6 6 </head>
7 7 <body>
8 8 <%= image_tag 'loading.gif', :id=>'spinner', :style=>"display:none; float:right;" %>
  9 +
  10 + <%= link_to _('edit layout'), params.merge({:edit_layout => true}) %>
  11 + <%= link_to _('show layout'), params.merge({:edit_layout => false}) %>
  12 + <%= link_to _('acao diferente'), :action => 'teste' %>
  13 +
  14 +teste
  15 +<%= @bla %>
  16 +oxe
  17 +
9 18 <div id="box_1" >
10   - <ul>
11   - <li> lado esquerdo
12   - </li>
13   - </ul>
  19 + <%= show_block(@owner, 1)%>
14 20 </div>
15 21 <div id="box_2" >
  22 + <%= show_block(@owner, 1)%>
16 23 <ul>
17 24 <li>
18 25 <%= yield %>
... ... @@ -20,6 +27,7 @@
20 27 </ul>
21 28 </div>
22 29 <div id="box_3" >
  30 + <%= show_block(@owner, 1)%>
23 31 <ul>
24 32 <li> lado direito
25 33 </li>
... ...
test/fixtures/link_blocks.yml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
  2 +one:
  3 + id: 1
  4 +two:
  5 + id: 2
... ...
test/fixtures/list_blocks.yml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
  2 +one:
  3 + id: 1
  4 +two:
  5 + id: 2
... ...
test/unit/link_block_test.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class LinkBlockTest < Test::Unit::TestCase
  4 + fixtures :link_blocks
  5 +
  6 + # Replace this with your real tests.
  7 + def test_truth
  8 + assert true
  9 + end
  10 +end
... ...
test/unit/list_block_test.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ListBlockTest < Test::Unit::TestCase
  4 + fixtures :list_blocks
  5 +
  6 + # Replace this with your real tests.
  7 + def test_truth
  8 + assert true
  9 + end
  10 +end
... ...