1.fix parent page 2.add page title

This commit is contained in:
Wen-Tien Chang 2010-01-08 18:36:36 +08:00
parent 38e365e4b5
commit 9f1ba2ae66
9 changed files with 61 additions and 48 deletions

View File

@ -3,7 +3,7 @@ class Admin::PagesController < ApplicationController
layout "admin" layout "admin"
def index def index
@pages = Page.all( :conditions => { :parent_page_id => "root" } ) @pages = Page.all( :conditions => { :parent_page_name => params[:parent] || "root" } )
end end
def show def show
@ -15,7 +15,7 @@ class Admin::PagesController < ApplicationController
def new def new
@page = Page.new @page = Page.new
@page.is_published = true @page.is_published = true
@page.parent_page_id = params[:parent_page_id] @page.parent_page_name = params[:parent_page_name]
end end
def edit def edit
@ -27,7 +27,7 @@ class Admin::PagesController < ApplicationController
if @page.save if @page.save
flash[:notice] = 'Page was successfully created.' flash[:notice] = 'Page was successfully created.'
redirect_to admin_pages_url redirect_to admin_pages_url( :parent_page_name => @page.parent_page_name )
else else
render :action => "new" render :action => "new"
end end

View File

@ -2,19 +2,21 @@ class Page
include MongoMapper::Document include MongoMapper::Document
key :name, String key :name, String
key :parent_page_id, String key :parent_page_name, String
key_i18n :title, String
key_i18n :content, String key_i18n :content, String
key :layout_id, String key :layout_id, String
key :layout_name, String key :layout_name, String
key :use_engine, String
key :external_link, String key :external_link, String
key :position, Integer key :position, Integer
key :is_published, Boolean key :is_published, Boolean
key :is_component, Boolean
key :component_name, String
belongs_to :layout belongs_to :layout
has_many :children, :class_name => 'Page', :foreign_key => 'parent_page_id'
validates_presence_of :name validates_presence_of :name
validates_presence_of :position validates_presence_of :position
@ -42,8 +44,8 @@ class Page
self.position = (max_page)? max_page.position.to_i + 1 : 1 self.position = (max_page)? max_page.position.to_i + 1 : 1
end end
if self.parent_page_id.blank? if self.parent_page_name.blank?
self.parent_page_id = "root" self.parent_page_name = "root"
end end
end end

View File

@ -3,6 +3,22 @@
<%= f.text_field :name, :class => 'text' %> <%= f.text_field :name, :class => 'text' %>
</p> </p>
<p>
<%= f.label :title, "Title en" %>
<%= f.text_field :title_en, :class => 'text' %>
</p>
<p>
<%= f.label :title, "Title zh_tw" %>
<%= f.text_field :title_zh_tw, :class => 'text' %>
</p>
<p>
<%= f.label :parent_page_name, "Parent Page Name" %>
<%= f.text_field :parent_page_name, :class => 'text' %>
</p>
<p> <p>
<%= f.label :layout_name, "Layout Name" %> <%= f.label :layout_name, "Layout Name" %>
<%= f.text_field :layout_name, :class => 'text' %> <%= f.text_field :layout_name, :class => 'text' %>
@ -22,7 +38,12 @@
<p> <p>
<%= f.label :is_published, "Is Published" %> <%= f.label :is_published, "Is Published" %>
<%= f.radio_button :is_published, 1 %>Yes <%= f.radio_button :is_published, 0 %> No <%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
</p>
<p>
<%= f.label :is_component, "Is component" %>
<%= f.radio_button :is_component, true %>Yes <%= f.radio_button :is_component, false %> No
</p> </p>
<p> <p>
@ -30,11 +51,6 @@
<%= f.text_field :external_link %> <%= f.text_field :external_link %>
</p> </p>
<p>
<%= f.label :use_engine, "Use Engine" %>
<%= f.text_field :use_engine %>
<p>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$('#content_en_block').hide(); $('#content_en_block').hide();

View File

@ -1,18 +1,18 @@
<% content_for :secondary do %> <% content_for :secondary do %>
<ul> <ul class="list">
<li><%= link_to 'New pages', new_admin_page_path, :class => 'button positive' %></li> <li><%= link_to 'New pages', new_admin_page_path, :class => 'button positive' %></li>
<li><%= link_to 'New component entry', '#' %>
<li><%= link_to 'New root menu snippets', new_admin_snippet_path( :menu => 'root' ), :class => 'button positive' %></li> <li><%= link_to 'New root menu snippets', new_admin_snippet_path( :menu => 'root' ), :class => 'button positive' %></li>
</ul> </ul>
<% end -%> <% end -%>
<h1>Listing pages</h1> <h1>Listing pages: <%= params[:parent] || "root" %></h1>
<table> <table>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Children</th> <th>Title</th>
<th>Layout</th> <th>Layout</th>
<th>Parent</th>
<th>Position</th> <th>Position</th>
<th>Published?</th> <th>Published?</th>
<th>Action</th> <th>Action</th>
@ -20,22 +20,16 @@
<% @pages.each do |page| %> <% @pages.each do |page| %>
<tr> <tr>
<td><%= link_to page.name, admin_page_path(page) %></td> <td><%= link_to page.name, admin_pages_path(:parent => page.name) %></td>
<td> <td><%=h page.title %>
<ul>
<% page.children.each do |child| %>
<li><%= child.name %></li>
<% end -%>
</ul>
</td>
<td><%= page.layout_name %></th> <td><%= page.layout_name %></th>
<td><%= page.parent_page_id %></td>
<td><%= page.position %></td> <td><%= page.position %></td>
<td><%= page.is_published.to_s %></td> <td><%= page.is_published.to_s %></td>
<td> <td>
<%= link_to 'Edit', edit_admin_page_path(page) %> | <%= link_to t(:show), page_path(page.name) %> |
<%= link_to 'Add Child', new_admin_page_path( :parent_page_id => page.id ) %> | <%= link_to t(:edit), edit_admin_page_path(page) %> |
<%= link_to 'Destroy', admin_page_path(page), :confirm => 'Are you sure?', :method => :delete %> <%= link_to t(:add_chile_page, :scope => :admin), new_admin_page_path( :parent_page_name => page.name ) %> |
<%= link_to t(:delete), admin_page_path(page), :confirm => 'Are you sure?', :method => :delete %>
</td> </td>
</tr> </tr>

View File

@ -2,7 +2,7 @@
<% form_for :page, :url => admin_pages_path do |f| %> <% form_for :page, :url => admin_pages_path do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= f.hidden_field :parent_page_id %> <%= f.hidden_field :parent_page_name %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>

View File

@ -1,7 +1,12 @@
zh_tw: zh_tw:
show: 顯示
edit: 編輯
delete: 刪除
admin: admin:
home: 首頁 home: 首頁
page: 頁面管理 page: 頁面管理
snippet: 片段管理 snippet: 片段管理
layout: 樣版管理 layout: 樣版管理
add_chile_page: 新增子頁
announcement: 公告管理 announcement: 公告管理

View File

@ -50,7 +50,7 @@ ActionController::Routing::Routes.draw do |map|
# Note: These default routes make all actions in every controller accessible via GET requests. You should # Note: These default routes make all actions in every controller accessible via GET requests. You should
# consider removing the them or commenting them out if you're using named routes and resources. # consider removing the them or commenting them out if you're using named routes and resources.
map.connect ':page_name', :controller => 'pages', :action => 'show' map.page ':page_name', :controller => 'pages', :action => 'show'
#map.connect ':controller/:action/:id' #map.connect ':controller/:action/:id'
#map.connect ':controller/:action/:id.:format' #map.connect ':controller/:action/:id.:format'

View File

@ -285,22 +285,6 @@ please read http://easyframework.com/documentation.php
/* // header */ /* // header */
/* content */
.content a, .content a:visited{
text-decoration:underline;
}
/* // content */
/* footer */
#footer a, #footer a:visited{
text-decoration:underline;
}
/* // footer */
/* clearfix */ /* clearfix */
.inner:after, .content:after, .cols:after, .fixed:after{ .inner:after, .content:after, .cols:after, .fixed:after{

View File

@ -0,0 +1,12 @@
ul.list{
margin:1em 0;
padding:0;
border-top:1px solid #ccc;
width:200px;
}
ul.list li{
margin:0;
padding:.5em 0;
list-style:none;
border-bottom:1px solid #ccc;
}