Let page edit from can select layout

This commit is contained in:
Wen-Tien Chang 2010-01-28 17:42:55 +08:00
parent 12de9d2514
commit 8da5323fd0
8 changed files with 24 additions and 4 deletions

View File

@ -4,5 +4,8 @@ class Component < Item
key :engine_name, String key :engine_name, String
key :layout_name, String, :required => true key :layout_name, String, :required => true
key :layout_id, String, :required => true
belongs_to :layout
end end

View File

@ -44,6 +44,11 @@ class Item
else else
self.parent_id = Item.find_by_name( self.parent_name ).id self.parent_id = Item.find_by_name( self.parent_name ).id
end end
if self.layout_name
self.layout_id = Layout.find_by_name( self.layout_name ).id
end
end end
end end

View File

@ -3,6 +3,9 @@ class Layout
include MongoMapper::Document include MongoMapper::Document
key :name, String, :required => true, :index => true key :name, String, :required => true, :index => true
key :description, String
key_i18n :content, String key_i18n :content, String
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
end end

View File

@ -4,5 +4,8 @@ class Page < Item
key_i18n :content, String key_i18n :content, String
key :layout_name, String, :required => true key :layout_name, String, :required => true
key :layout_id, String, :required => true
belongs_to :layout
end end

View File

@ -13,7 +13,7 @@
<p> <p>
<%= f.label :layout_name, "Layout Name" %> <%= f.label :layout_name, "Layout Name" %>
<%= f.text_field :layout_name, :class => 'text' %> <%= f.select :layout_name, Layout.all.map{ |l| [l.description, l.name] } %>
</p> </p>
<p> <p>

View File

@ -3,6 +3,11 @@
<%= f.text_field :name, :class => 'text' %> <%= f.text_field :name, :class => 'text' %>
</p> </p>
<p>
<%= f.label :description, "Description" %>
<%= f.text_field :description, :class => 'text' %>
</p>
<p id="content_zh_tw_block"> <p id="content_zh_tw_block">
<%= f.label "content_zh_tw", "Content (zh_tw)" %> <%= f.label "content_zh_tw", "Content (zh_tw)" %>
<%= f.text_area "content_zh_tw", :size => '100x30' %> <%= f.text_area "content_zh_tw", :size => '100x30' %>

View File

@ -7,6 +7,7 @@
<% @layouts.each do |layout| %> <% @layouts.each do |layout| %>
<tr> <tr>
<td><%= layout.name %></td> <td><%= layout.name %></td>
<td><%= layout.description %></td>
<td><%= link_to t(:edit), edit_admin_layout_path(layout) %></td> <td><%= link_to t(:edit), edit_admin_layout_path(layout) %></td>
<td><%= link_to t(:delete), admin_layout_path(layout), :confirm => 'Are you sure?', :method => :delete %></td> <td><%= link_to t(:delete), admin_layout_path(layout), :confirm => 'Are you sure?', :method => :delete %></td>
</tr> </tr>

View File

@ -19,7 +19,7 @@
<p> <p>
<%= f.label :layout_name, "Layout Name" %> <%= f.label :layout_name, "Layout Name" %>
<%= f.text_field :layout_name, :class => 'text' %> <%= f.select :layout_name, Layout.all.map{ |l| [l.description, l.name] } %>
</p> </p>
<p id="content_zh_tw_block"> <p id="content_zh_tw_block">