bringing back page tree toggling

Oleg committed Jan 28, 2011
commit f74e01cd1fb0532e143104a6c9136f1f75c01e13
Showing 14 changed files with 136 additions and 45 deletions
app/controllers/cms_admin/pages_controller.rb +9 -0
@@ @@ -48,6 +48,15 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
@cms_page.cms_layout = @cms_site.cms_layouts.find_by_id(params[:layout_id])
end
+ def toggle_branch
+ @cms_page = @cms_site.cms_pages.find(params[:id])
+ s = (session[:cms_page_tree] ||= [])
+ id = @cms_page.id.to_s
+ s.member?(id) ? s.delete(id) : s << id
+ rescue ActiveRecord::RecordNotFound
+ # do nothing
+ end
+
protected
def check_for_layouts
app/models/cms_page.rb +5 -0
@@ @@ -115,6 +115,11 @@ class CmsPage < ActiveRecord::Base
@cms_tags ||= []
end
+ # Full url for a page
+ def url
+ "http://#{self.cms_site.hostname}#{self.full_path}"
+ end
+
protected
def assign_parent
app/views/cms_admin/pages/_index_branch.html.erb +16 -4
@@ @@ -1,9 +1,21 @@
- <% cms_page ||= index_branch %>
+ <%
+ cms_page ||= index_branch
+ has_children = cms_page.children.present?
+ has_siblings = cms_page.siblings.present?
+ branch_open = (session[:cms_page_tree] || []).member?(cms_page.id.to_s) || cms_page.root?
+ %>
<li id='cms_page_<%= cms_page.id %>'>
<div class='item'>
+ <div class='toggle <%= 'open' if branch_open %>'>
+ <%=
+ if has_children && !cms_page.root?
+ link_to span_tag('toggle'), toggle_branch_cms_admin_page_path(cms_page), :remote => true
+ end
+ %>
+ </div>
<div class='icon'>
- <% if cms_page.siblings.size > 0 %>
+ <% if has_siblings %>
<div class='dragger'></div>
<% end %>
</div>
@@ @@ -15,11 +27,11 @@
<div class='label'>
<%= link_to cms_page.label, edit_cms_admin_page_path(cms_page) %>
<div class='sublabel'>
- <%= link_to cms_page.full_path, cms_page.full_path %>
+ <%= link_to cms_page.url, cms_page.full_path, :target => '_blank' %>
</div>
</div>
</div>
- <% if cms_page.children.present? %>
+ <% if has_children && branch_open %>
<ul>
<%= render :partial => 'index_branch', :collection => cms_page.children %>
</ul>
app/views/cms_admin/pages/form_blocks.js.erb +1 -1
@@ @@ -1 +1 @@
- $('#form_blocks').replaceWith('<%= escape_javascript(render(:partial => "form_blocks")) %>')
\ No newline at end of file
+ $('#form_blocks').replaceWith('<%= escape_javascript(render(:partial => "form_blocks")) %>');
\ No newline at end of file
app/views/cms_admin/pages/toggle_branch.js.erb +10 -0
@@ @@ -0,0 +1,10 @@
+ var li = $('li#cms_page_<%=@cms_page.id%>');
+ li.find('.item .toggle').first().toggleClass('open');
+
+ <% if session[:cms_page_tree].member?(@cms_page.id.to_s) %>
+ if(!li.find('ul')[0]) {
+ li.append('<ul><%= escape_javascript(render :partial => "index_branch", :collection => @cms_page.children) %></ul>');
+ }
+ <% else %>
+ li.find('ul').remove();
+ <% end %>
\ No newline at end of file
config/routes.rb +1 -0
@@ @@ -5,6 +5,7 @@ Rails.application.routes.draw do
resources :pages do
member do
match :form_blocks
+ match :toggle_branch
end
end
resources :sites
comfortable_mexican_sofa/acts_as_tree.rb b/lib/comfortable_mexican_sofa/acts_as_tree.rb +5 -0
@@ @@ -78,6 +78,11 @@ module ComfortableMexicanSofa::ActsAsTree
node
end
+ # Checks if this node is a root
+ def root?
+ !self.parent
+ end
+
# Returns all siblings of the current node.
#
# subchild1.siblings # => [subchild2]
public/images/comfortable_mexican_sofa/arrow_bottom.gif +0 -0
public/images/comfortable_mexican_sofa/arrow_right.gif +0 -0
public/images/comfortable_mexican_sofa/body_bg.jpg +0 -0
public/stylesheets/comfortable_mexican_sofa/structure.css +66 -38
@@ @@ -1,7 +1,7 @@
/* -- Containers --------------------------------------------------------- */
html, body {
height: 100%;
- background: url(/images/comfortable_mexican_sofa/body_bg.jpg);
+ background-color: #515151;
}
.body_wrapper {
height: 100%;
@@ @@ -13,11 +13,10 @@ html, body {
.center_column {
margin: 0px 250px 0px 175px;
min-height: 100%;
- background-color: #ececec;
overflow: hidden;
- box-shadow: inset 0px 0px 3px #000;
- -moz-box-shadow: inset 0px 0px 3px #000;
- -webkit-box-shadow: inset 0px 0px 3px #000;
+ background-color: #D8D8D8;
+ border-left: 1px solid #484844;
+ border-right: 1px solid #484848;
}
.center_column_content {
padding: 25px;
@@ @@ -126,16 +125,18 @@ html, body {
}
.big_button {
float: right;
- padding: 6px 10px;
+ padding: 4px 10px;
font-size: 10px;
+ font-weight: bold;
text-transform: uppercase;
- background: url(/images/comfortable_mexican_sofa/body_bg.jpg);
border-radius: 3px;
-moz-border-radius: 3px;
+ border: 1px solid #9f9f9f;
+ background: -moz-linear-gradient(top, #F9F9F9 0%, #D5D5D5 34%, #B4B4B4 100%);
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F9F9F9), color-stop(34%,#D5D5D5), color-stop(100%,#B4B4B4));
+ text-shadow: #f5f5f5 1px 1px;
letter-spacing: 0.5px;
- }
- .big_button span {
- color: #fff;
+ color: #1b1b1b;
}
/* -- Forms -------------------------------------------------------------- */
@@ @@ -247,61 +248,88 @@ html, body {
vertical-align: top;
padding: 5px;
}
+
/* -- Listings ----------------------------------------------------------- */
ul.list li .item {
overflow: hidden;
padding: 5px;
- border-bottom: 1px solid #fff;
+ background-color: #ececec;
+ border-radius: 3px;
+ -moz-border-radius: 3px;
+ margin-bottom: 5px;
}
- ul.list li .icon {
+ ul.list li .item .toggle {
+ float: left;
+ height: 28px;
+ width: 28px;
+ }
+ ul.list li .item .toggle a {
+ display: block;
+ height: 28px;
+ width: 28px;
+ background: url(/images/comfortable_mexican_sofa/arrow_right.gif) center center no-repeat;
+ }
+ ul.list li .item .toggle a span {
+ display: none;
+ }
+ ul.list li .item .toggle.open a {
+ background-image: url(/images/comfortable_mexican_sofa/arrow_bottom.gif);
+ }
+ ul.list li .item .icon {
+ float: left;
width: 28px;
height: 28px;
background: url(/images/comfortable_mexican_sofa/icon_regular.gif);
- float: left;
}
- ul.list li .action_links {
- float: right;
- opacity: 0.1;
+ ul.list li .item .label {
+ margin-left: 60px;
+ font-size: 14px;
+ font-weight: bold;
}
- table.formatted td.action_links a {
- opacity: 0.1;
+ ul.list li .item .label .sublabel {
+ font-size: 10px;
+ font-weight: normal;
+ }
+ ul.list li ul {
+ margin-left: 28px;
}
ul.list .action_links a,
table.formatted td.action_links a {
margin-left: 3px;
- background-color: #272A2D;
- color: #fff;
+ background-color: #b4b4b4;
+ color: #1b1b1b;
padding: 3px 5px;
font-size: 9px;
text-transform: uppercase;
border-radius: 3px;
-moz-border-radius: 3px;
+ border: 1px solid #9f9f9f;
+ background: -moz-linear-gradient(top, #F9F9F9 0%, #D5D5D5 34%, #B4B4B4 100%);
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F9F9F9), color-stop(34%,#D5D5D5), color-stop(100%,#B4B4B4));
+ text-shadow: #f5f5f5 1px 1px;
+ }
+ ul.list .action_links a:hover,
+ table.formatted td.action_links a:hover {
+ box-shadow: inset 0px 0px 5px #aaa;
+ -moz-box-shadow: inset 0px 0px 5px #aaa;
+ -webkit-box-shadow: inset 0px 0px 5px #aaa;
+ border-color: #484848;
}
- ul.list li .label,
- table.formatted td .label {
- margin-left: 35px;
- font: 16px/18px Georgia, serif;
- color: #1C1F22;
- }
- table.formatted td .label {
- margin-left: 0px;
+ ul.list li .action_links {
+ float: right;
+ opacity: 0.2;
}
- ul.list li .label .sublabel {
- margin-left: 15px;
- font: 11px/14px Arial, sans-serif;
- color: #1C1F22;
+ table.formatted td.action_links a {
+ opacity: 0.2;
}
- ul.list li ul {
- margin-left: 30px;
+ ul.list li .item:hover .action_links,
+ table.formatted tr:hover td.action_links a {
+ opacity: 1;
}
ul.list li .item:hover,
table.formatted tr:hover td {
background-color: #fff;
}
- ul.list li .item:hover .action_links,
- table.formatted tr:hover td.action_links a {
- opacity: 1;
- }
table.formatted {
clear: both;
}
public/stylesheets/comfortable_mexican_sofa/typography.css +2 -2
@@ @@ -1,9 +1,9 @@
body {
- font: 13px Arial, sans-serif;
+ font: 13px 'Lucida Grande', 'Tahoma', sans-serif;
}
h1 {
- font: bold 25px/25px Georgia, serif;
+ font: bold 25px/25px 'Lucida Grande', 'Tahoma', serif;
margin-bottom: 25px;
padding-bottom: 5px;
color: #1C1F22;
test/functional/cms_admin/pages_controller_test.rb +11 -0
@@ @@ -299,4 +299,15 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
assert_redirected_to new_cms_admin_layout_path
assert_equal 'No Layouts found. Please create one.', flash[:error]
end
+
+ def test_get_toggle_branch
+ page = cms_pages(:default)
+ get :toggle_branch, :id => page, :format => :js
+ assert_response :success
+ assert_equal [page.id.to_s], session[:cms_page_tree]
+
+ get :toggle_branch, :id => page, :format => :js
+ assert_response :success
+ assert_equal [], session[:cms_page_tree]
+ end
end
\ No newline at end of file
test/unit/cms_page_test.rb +10 -0
@@ @@ -231,6 +231,16 @@ class CmsPageTest < ActiveSupport::TestCase
assert_equal 1, CmsPage.published.count
end
+ def test_root?
+ assert cms_pages(:default).root?
+ assert !cms_pages(:child).root?
+ end
+
+ def test_url
+ assert_equal 'http://test.host/', cms_pages(:default).url
+ assert_equal 'http://test.host/child-page', cms_pages(:child).url
+ end
+
protected
def new_params(options = {})