diff --git a/app/models/component.rb b/app/models/component.rb index 19418096..d0ec3343 100644 --- a/app/models/component.rb +++ b/app/models/component.rb @@ -4,5 +4,8 @@ class Component < Item key :engine_name, String key :layout_name, String, :required => true - + key :layout_id, String, :required => true + + belongs_to :layout + end \ No newline at end of file diff --git a/app/models/item.rb b/app/models/item.rb index ab1a8625..472afd7d 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -44,6 +44,11 @@ class Item else self.parent_id = Item.find_by_name( self.parent_name ).id end + + if self.layout_name + self.layout_id = Layout.find_by_name( self.layout_name ).id + end + end end \ No newline at end of file diff --git a/app/models/layout.rb b/app/models/layout.rb index b261e88b..10693f26 100644 --- a/app/models/layout.rb +++ b/app/models/layout.rb @@ -3,6 +3,9 @@ class Layout include MongoMapper::Document key :name, String, :required => true, :index => true + key :description, String key_i18n :content, String + validates_format_of :name, :with => /^[a-zA-Z-_]+$/ + end \ No newline at end of file diff --git a/app/models/page.rb b/app/models/page.rb index fe1cbf51..728cedbe 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -4,5 +4,8 @@ class Page < Item key_i18n :content, String key :layout_name, String, :required => true - + key :layout_id, String, :required => true + + belongs_to :layout + end \ No newline at end of file diff --git a/app/views/admin/components/_form.html.erb b/app/views/admin/components/_form.html.erb index 26e19275..ef8a4d56 100644 --- a/app/views/admin/components/_form.html.erb +++ b/app/views/admin/components/_form.html.erb @@ -13,7 +13,7 @@
<%= 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] } %>
diff --git a/app/views/admin/layouts/_form.html.erb b/app/views/admin/layouts/_form.html.erb index f5a2750e..e64ee6d1 100644 --- a/app/views/admin/layouts/_form.html.erb +++ b/app/views/admin/layouts/_form.html.erb @@ -3,6 +3,11 @@ <%= f.text_field :name, :class => 'text' %>
++<%= f.label :description, "Description" %> +<%= f.text_field :description, :class => 'text' %> +
+<%= f.label "content_zh_tw", "Content (zh_tw)" %> <%= f.text_area "content_zh_tw", :size => '100x30' %> diff --git a/app/views/admin/layouts/index.html.erb b/app/views/admin/layouts/index.html.erb index 64939353..771eed68 100644 --- a/app/views/admin/layouts/index.html.erb +++ b/app/views/admin/layouts/index.html.erb @@ -7,6 +7,7 @@ <% @layouts.each do |layout| %>
<%= 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] } %>