Permalink
Browse files

modified page parts so that they use the actual title that the user s…

…upplied as their title and then we transform it into something dom usable afterward. This makes the tests pass. Supplied migration to change existing page parts to the new format. So either page[:side_body] will work as well as page['SiDE BoDy'] or page['Side Body'] - case is not important neither are spaces vs underscores.
  • Loading branch information...
1 parent 6771dcd commit de6d523bc212e08b645f37259ccc2a945963c9ed @parndt parndt committed Feb 4, 2010
@@ -0,0 +1,13 @@
+class ChangePartTitlesToTitleizedVersionForNewFormat < ActiveRecord::Migration
+ def self.up
+ PagePart.all.each do |page_part|
+ page_part.update_attribute(:title, page_part.title.titleize)
+ end
+ end
+
+ def self.down
+ PagePart.all.each do |page_part|
+ page_part.update_attribute(:title, page_part.title.downcase.gsub(" ", "_"))
+ end
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100202034802) do
+ActiveRecord::Schema.define(:version => 20100204011654) do
create_table "images", :force => true do |t|
t.integer "parent_id"
@@ -287,7 +287,7 @@ var page_options = {
// Hook into the loaded function. This will be called when WYMeditor has done its thing.
WYMeditor.loaded = function(){
- page_options.tabs = $('#page-tabs').tabs();
+ page_options.tabs = $('#page-tabs').tabs({tabTemplate: '<li><a href="#{href}">#{label}</a></li>'});
}
if(this.enable_parts){
@@ -314,7 +314,8 @@ var page_options = {
title: 'Create Content Section',
modal: true,
resizable: false,
- autoOpen: false
+ autoOpen: false,
+ width: 600
});
$('#add_page_part').click(function(e){
@@ -328,21 +329,29 @@ var page_options = {
var part_title = $('#new_page_part_title').val();
if(part_title.length > 0){
- var tab_title = part_title.toLowerCase().gsub(" ", "_");
+ var tab_title = part_title.toLowerCase().replace(" ", "_");
- if ($('#part_' + tab_title).size() == 0){
+ if ($('#part_' + tab_title).size() == 0) {
$.get(page_options.new_part_url,
- {title: tab_title, part_index: $('#new_page_part_index').val(), body: ''},
- function(data, status){
+ {
+ title: part_title
+ , part_index: $('#new_page_part_index').val()
+ , body: ''
+ }
+ , function(data, status){
// Add a new tab for the new content section.
$('#page_part_editors').append(data);
- page_options.tabs.tabs('add', '#part_' + tab_title, part_title);
- page_options.tabs.tabs('select', '#part_' + tab_title);
+ page_options.tabs.tabs('add', '#page_part_new_' + $('#new_page_part_index').val(), part_title);
+ page_options.tabs.tabs('select', '#page_part_new_' + $('#new_page_part_index').val());
+
// turn the new textarea into a wymeditor.
$('#page_parts_attributes_' + $('#new_page_part_index').val() + "_body").wymeditor(wymeditor_boot_options);
+
// Wipe the title and increment the index counter by one.
$('#new_page_part_index').val(parseInt($('#new_page_part_index').val()) + 1);
$('#new_page_part_title').val('');
+
+ $('#page-tabs').tabs();
}
);
}else{
@@ -1135,19 +1135,70 @@ ul#plugins li {
width:auto;
}
+.ui-widget-overlay {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ opacity: .75;
+ filter:Alpha(Opacity=75);
+}
+.ui-widget-overlay {
+ background: #000;
+}
+
+.ui-dialog {
+ position: relative;
+ background-color: #fff;
+ color: #000;
+ border: 4px solid #525252;
+ width: auto;
+}
+.ui-dialog .ui-dialog-titlebar {
+ float: left;
+ position: relative;
+ width: 100%;
+ background-color: #e8e8e8;
+}
+.ui-dialog .ui-dialog-title {
+ float: left;
+ height: 33px;
+ line-height: 33px;
+ font-size: 16px;
+ padding-left: 10px;
+}
+.ui-dialog .ui-dialog-titlebar-close {
+ position: absolute;
+ right: 10px;
+ top: 5px;
+ width: 19px;
+ border: none;
+}
+.ui-dialog .ui-dialog-titlebar-close span {
+ display: block;
+ margin: 1px;
+ background: transparent url('/images/thickbox/cross.png') top left no-repeat;
+ text-indent:-10000px;
+}
+.ui-dialog .ui-dialog-titlebar-close:hover, .ui-dialog .ui-dialog-titlebar-close:focus {
+ padding: 0;
+}
+#new_page_part_dialog .field {
+ padding: 30px 10px;
+}
-.ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: .75;filter:Alpha(Opacity=75); }
-.ui-widget-overlay {background: #000; }
-
-.ui-dialog { position: relative; background-color: #fff; color: #000; border: 4px solid #525252; width: auto; }
-.ui-dialog .ui-dialog-titlebar { float: left; position: relative; width: 100%; background-color: #e8e8e8;}
-.ui-dialog .ui-dialog-title { float: left; height: 33px; line-height: 33px; font-size: 16px; padding-left: 10px; }
-.ui-dialog .ui-dialog-titlebar-close { position: absolute; right: 10px; top: 5px; width: 19px; border: none; }
-.ui-dialog .ui-dialog-titlebar-close span { display: block; margin: 1px; background: transparent url('/images/thickbox/cross.png') top left no-repeat; text-indent:-10000px; }
-.ui-dialog .ui-dialog-titlebar-close:hover, .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; }
-#new_page_part_dialog{ float: left; margin: 0px; width: 100%; }
-#new_page_part_dialog .field { margin: 10px; }
-
-.ui-tabs-hide { display:none; }
-.ui-tabs .ui-state-default, .ui-tabs .ui-state-default a { background-color: #c2c3b3; line-height: 27px; margin-top: 3px; }
-.ui-tabs .ui-state-active, .ui-tabs .ui-state-active a { background-color: #808080; color: #fff; line-height: 33px; margin-top: 0px; }
+.ui-tabs-hide {
+ display:none;
+}
+.ui-tabs .ui-state-default, .ui-tabs .ui-state-default a {
+ background-color: #c2c3b3;
+ line-height: 27px;
+ margin-top: 3px;
+}
+.ui-tabs .ui-state-active, .ui-tabs .ui-state-active a {
+ background-color: #808080;
+ color: #fff;
+ line-height: 33px;
+ margin-top: 0px;
+}
@@ -1,9 +1,9 @@
home_page_body:
- title: Body
+ title: body
page: home_page
body: This is the body
-
+
home_page_side_body:
- title: Side Body
+ title: side_body
page: home_page
body: This is the side body
@@ -1,7 +1,11 @@
class Admin::PagePartsController < Admin::BaseController
def new
- render :partial => "/admin/pages/page_part_field", :locals => {:title => params[:title], :body => params[:body], :new_part => true, :part_index => params[:part_index]}
+ render :partial => "/admin/pages/page_part_field", :locals => {
+ :part => PagePart.new(:title => params[:title], :body => params[:body]),
+ :new_part => true,
+ :part_index => params[:part_index]
+ }
end
def destroy
@@ -5,7 +5,7 @@ class Admin::PagesController < Admin::BaseController
def new
@page = Page.new
- RefinerySetting.find_or_set(:default_page_parts, ["body", "side_body"]).each do |page_part|
+ RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"]).each do |page_part|
@page.parts << PagePart.new(:title => page_part)
end
end
@@ -15,4 +15,4 @@ def expire_menu_fragment_caching
expire_fragment(%r{site_menu})
end
-end
+end
@@ -128,7 +128,7 @@ def [](part_title)
# the way that we call page parts seems flawed, will probably revert to page.parts[:title] in a future release.
if (super_value = super).blank?
# self.parts is already eager loaded so we can now just grab the first element matching the title we specified.
- part = self.parts.reject {|part| part.title.downcase != part_title.to_s.downcase}.first
+ part = self.parts.detect {|part| (part.title == part_title.to_s) || (part.title.downcase.gsub(" ", "_") == part_title.to_s.downcase.gsub(" ", "_")) }
return part.body unless part.nil?
end
@@ -1,5 +1,5 @@
-<% linked = (page_link.url == params[:current_link]) unless params[:current_link].blank? %>
+<% linked = (page_link.url == params[:current_link]) if params[:current_link].present? %>
<li class='clearfix<%= " child#{child}" if child %><%= " linked" if linked%>' id="<%= dom_id(page_link) -%>">
<%= link_to page_link.title_with_meta, page_link.url, :title => 'Link to this Page', :rel => page_link.title, :class => 'page_link' %>
</li>
-<%= render :partial => 'page_link', :collection => page_link.children, :locals => {:child => child ? (child+1) : 1} unless page_link.children.empty? %>
+<%= render :partial => 'page_link', :collection => page_link.children, :locals => {:child => child ? (child+1) : 1} unless page_link.children.empty? %>
@@ -7,9 +7,9 @@
</div>
<div id="page-tabs" class="clearfix">
<ul id="page_parts">
- <% @page.parts.each do |p| %>
+ <% @page.parts.each_with_index do |part, part_index| %>
<li>
- <%= link_to p.title.titleize, "#part_#{p.title}" %>
+ <%= link_to part.title, "##{@page.new_record? ? "page_part_new_#{part_index}" : dom_id(part)}" %>
</li>
<% end %>
</ul>
@@ -27,7 +27,11 @@
<div id='page_part_editors' style="clear:left">
<% part_index = -1 %>
<% f.fields_for :parts do |p| %>
- <%= render :partial => "page_part_field", :locals => {:title => p.object.title, :body => p.object.body, :part_index => (part_index += 1), :new_part => @page.new_record?} %>
+ <%= render :partial => "page_part_field", :locals => {
+ :part => p.object,
+ :part_index => (part_index += 1),
+ :new_part => @page.new_record?
+ } %>
<% end %>
</div>
</div>
@@ -103,18 +107,21 @@
<%= f.label :draft, "Save as Draft", :class => "stripped" %>
</div>
<%= render :partial => "/shared/admin/form_actions", :locals => {:f => f, :continue_editing => true} %>
- <div id='new_page_part_dialog' style='display: none'>
- <div class='field'>
- <label for='new_page_part_title'>Title</label>
- <input id='new_page_part_title' value='' class='larger' size='40' />
- <input id='new_page_part_index' type='hidden' value='<%= @page.parts.size %>' />
- </div>
- <div id='dialog-form-actions' class='form-actions'>
- <%= f.submit 'Save', :id => "new_page_part_save" %>
- or
- <%= link_to "Cancel", "", :id => "new_page_part_cancel", :class => "close_dialog" %>
+ <% if RefinerySetting.find_or_set(:new_page_parts, false) %>
+ <div id='new_page_part_dialog' style='display: none'>
+ <div class='field'>
+ <label for='new_page_part_title'>Title</label>
+ <input id='new_page_part_title' value='' class='larger' size='40' />
+ <input id='new_page_part_index' type='hidden' value='<%= @page.parts.size %>' />
+ </div>
+ <%= render :partial => "/shared/admin/form_actions", :locals => {
+ :f => f,
+ :continue_editing => false,
+ :submit_button_id => "new_page_part_save",
+ :cancel_button_id => "new_page_part_cancel"
+ } %>
</div>
- </div>
+ <% end %>
<% end %>
<% content_for :head do %>
@@ -1,4 +1,4 @@
-<div class='page_part field' id='part_<%= title.downcase.gsub(" ", "_") %>'>
- <%= hidden_field_tag "page[parts_attributes][#{part_index}][title]", title if new_part %>
- <%= text_area_tag "page[parts_attributes][#{part_index}][body]", body, :rows => 20, :cols => 140, :class => 'wymeditor' %>
-</div>
+<div class='page_part field' id='<%= new_part ? "page_part_new_#{part_index}" : dom_id(part) %>'>
+ <%= hidden_field_tag "page[parts_attributes][#{part_index}][title]", part.title if new_part %>
+ <%= text_area_tag "page[parts_attributes][#{part_index}][body]", part.body, :rows => 20, :cols => 140, :class => 'wymeditor' %>
+</div>
@@ -1,5 +1,5 @@
<div class='form-actions'>
- <%= f.submit 'Save', :id => "submit_button", :class => "wymupdate" -%>
+ <%= f.submit 'Save', :id => "#{submit_button_id ||= "submit_button"}", :class => "wymupdate" -%>
<% if (continue_editing ||= false and !f.object.new_record?) -%>
or
<%= render :partial => "/shared/admin/continue_editing", :locals => {:f => f} -%>
@@ -8,6 +8,6 @@
or
<%= link_to "Cancel", (cancel_url ||= send("admin_#{f.object.class.name.pluralize.underscore}_url")),
:title => (title ||= "Cancelling will lose all changes you've made to this #{f.object.class.name.underscore.gsub("_", " ")}"),
- :id => "cancel_button", :class => "close_dialog" %>
+ :id => "#{cancel_button_id ||= "cancel_button"}", :class => "close_dialog" %>
<% end -%>
</div>

0 comments on commit de6d523

Please sign in to comment.