From 69e6305e9af186a8465c902dbf18cc12dd425d8a Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Sun, 14 Aug 2011 15:02:32 -0700 Subject: [PATCH] add preview and title to teaser elements, as per niels request --- .../my_projects_overviews_controller.rb | 5 ++- app/models/my_projects_overview.rb | 8 ++-- .../_block_textilizable.rhtml | 38 ++++++++++++------- .../blocks/_textilizable.rhtml | 2 +- app/views/my_projects_overviews/index.rhtml | 1 + .../my_projects_overviews/page_layout.rhtml | 8 +++- 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index 0ea9c2509d..ae83f5fa48 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -47,7 +47,9 @@ class MyProjectsOverviewsController < ApplicationController def update_custom_element block_name = params["block_name"] - @overview.save_custom_element(block_name, params["textile_#{block_name}"]) + block_title = params["block_title_#{block_name}"] + textile = params["textile_#{block_name}"] + @overview.save_custom_element(block_name, block_title, textile) redirect_to :back end @@ -72,6 +74,7 @@ class MyProjectsOverviewsController < ApplicationController render(:partial => "block_textilizable", :locals => { :user => @user, :project => @project, + :block_title => l(:label_custom_element), :block_name => @overview.hidden.first.first, :textile => @overview.hidden.first.last}) else diff --git a/app/models/my_projects_overview.rb b/app/models/my_projects_overview.rb index 8f81c06ed0..a7db9ae5d5 100644 --- a/app/models/my_projects_overview.rb +++ b/app/models/my_projects_overview.rb @@ -4,17 +4,17 @@ class MyProjectsOverview < ActiveRecord::Base serialize :right, Array serialize :hidden, Array - def save_custom_element(name, new_content) + def save_custom_element(name, title, new_content) el = custom_elements.detect {|x| x.first == name} return unless el - el.pop - el << new_content + el[1] = title + el[2] = new_content save end def new_custom_element idx = custom_elements.any? ? custom_elements.sort.last.first.next : "a" - [idx, "h2. #{l(:info_custom_text)}"] + [idx, l(:label_custom_text), "h2. #{l(:info_custom_text)}"] end def elements diff --git a/app/views/my_projects_overviews/_block_textilizable.rhtml b/app/views/my_projects_overviews/_block_textilizable.rhtml index bebf1168c7..b7c8a59d77 100644 --- a/app/views/my_projects_overviews/_block_textilizable.rhtml +++ b/app/views/my_projects_overviews/_block_textilizable.rhtml @@ -9,18 +9,30 @@
- <% form_for :overview, @overview, - :url => {:action => 'update_custom_element'}, - :html => {:id => "block_form_#{block_name.dasherize}", - :class => nil, - :method => :put, - :multipart => true} do |f| %> -
- <%= hidden_field_tag 'block_name', block_name %> - <%= text_area_tag "textile_#{block_name}", textile, :cols => 40, :rows => 5, :class => 'wiki-edit' %> - <%= wikitoolbar_for "textile_#{block_name}" %> -
- <%= submit_tag l(:button_submit) %> - <% end %> +
+ Preview +
+ +
+ <%= render :partial => "my_projects_overviews/blocks/textilizable", + :locals => { :block_title => block_title, + :textile => textile } + %> +
diff --git a/app/views/my_projects_overviews/blocks/_textilizable.rhtml b/app/views/my_projects_overviews/blocks/_textilizable.rhtml index 4e2effcb5e..211bea25da 100644 --- a/app/views/my_projects_overviews/blocks/_textilizable.rhtml +++ b/app/views/my_projects_overviews/blocks/_textilizable.rhtml @@ -1,4 +1,4 @@ -

<%=l(:label_custom_text)%>

+

<%= block_title || l(:label_custom_text) %>

diff --git a/app/views/my_projects_overviews/index.rhtml b/app/views/my_projects_overviews/index.rhtml index 365bffc2b6..95f0e9e767 100644 --- a/app/views/my_projects_overviews/index.rhtml +++ b/app/views/my_projects_overviews/index.rhtml @@ -30,6 +30,7 @@ <%= render :partial => "my_projects_overviews/blocks/textilizable", :locals => { :project => @project, :user => @user, + :block_title => b[1], :textile => b.last } %> <% end %> diff --git a/app/views/my_projects_overviews/page_layout.rhtml b/app/views/my_projects_overviews/page_layout.rhtml index a227036b4e..4b9b5bb507 100644 --- a/app/views/my_projects_overviews/page_layout.rhtml +++ b/app/views/my_projects_overviews/page_layout.rhtml @@ -76,7 +76,9 @@ function removeBlock(block) { <%= render(:partial => 'block', :locals => {:block_name => b}) %> <% elsif b.respond_to? :to_ary %> <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, :textile => b.last}) %> + :locals => {:block_name => b.first, + :block_title => b[1], + :textile => b.last}) %> <% end %> <% end %> @@ -89,7 +91,9 @@ function removeBlock(block) { <%= render(:partial => 'block', :locals => {:block_name => b}) %> <% elsif b.respond_to? :to_ary %> <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, :textile => b.last}) %> + :locals => {:block_name => b.first, + :block_title => b[1], + :textile => b.last}) %> <% end %> <% end %>