Modify edit page. Still need to handle "form" with drop down lists

This commit is contained in:
chris2tof 2011-08-24 02:34:24 +08:00
parent 1d214bedec
commit 27d47215e9
10 changed files with 42 additions and 8 deletions

View File

@ -26,6 +26,11 @@ class Admin::PagesController < ApplicationController
end end
def edit def edit
@item = Page.find(params[:id])
@i18n_variable = @item.i18n_variable
@designs = Design.all.entries
@design = @item.design
@default_design = @design.themes.detect {|t| t.id == @item.theme_id }
end end
def create def create
@ -48,6 +53,18 @@ class Admin::PagesController < ApplicationController
end end
def update def update
@item = Page.find(params[:id])
if @item.update_attributes(params[:item])
flash[:notice] = t('admin.update_success_page')
respond_to do |format|
format.html {
redirect_to admin_page_url(@item)
}
format.js {}
end
else
render :action => "edit"
end
end end
def destroy def destroy

View File

@ -12,6 +12,7 @@ module Admin::ItemHelper
ret << "<ul>" ret << "<ul>"
ret << "<li>" ret << "<li>"
ret << (link_to node.name, dest) ret << (link_to node.name, dest)
ret << ' | ' << (link_to t('admin.edit'), eval("edit_admin_#{node._type.downcase}_path(node)")) if node._type.eql?('Page')
ret << ' | ' << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page') if node._type.eql?('Page') ret << ' | ' << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page') if node._type.eql?('Page')
ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id), :class => 'new_link') if node._type.eql?('Page') ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id), :class => 'new_link') if node._type.eql?('Page')
ret << ' | ' << (link_to t(:delete), eval("delete_admin_#{node._type.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete') ret << ' | ' << (link_to t(:delete), eval("delete_admin_#{node._type.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete')

View File

@ -2,8 +2,6 @@ class Theme < Stylesheet
embedded_in :design embedded_in :design
field :name field :name
has_many :pages
before_save :set_name before_save :set_name
protected protected

View File

@ -1,11 +1,11 @@
class Page < Item class Page < Item
field :content field :content
field :theme_id
validates_presence_of :design_id validates_presence_of :design_id
belongs_to :design belongs_to :design
belongs_to :theme
has_many :page_parts has_many :page_parts
def create_parts def create_parts

View File

@ -0,0 +1,10 @@
<%= flash_messages %>
<h1><%= t('admin.editing_page') %></h1>
<%= form_for @item, :url => admin_page_path(@item) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>

View File

@ -16,13 +16,13 @@
<p> <p>
<%= t('admin.design_name') %> <%= t('admin.design_name') %>
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, :selected => @default_design.id %> <%#= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, :selected => @default_design.id %>
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] } %>
</p> </p>
<p> <p>
<%= @item.design.inspect %>
<%= t('admin.theme') %> <%= t('admin.theme') %>
<%= f.select :theme_id, @default_design.themes.collect { |t| [t.name, t.id] }, :selected => @default_design.themes.detect {|t| t.file_filename.to_s == 'default.css' }.id %> <%#= f.select :theme_id, @default_design.themes.collect { |t| [t.name, t.id] }, :selected => @default_design.themes.detect {|t| t.file_filename.to_s == 'default.css' }.id %>
<%#= f.collection_select :design, @designs, :id, :title %> <%= f.select :theme_id, @design.themes.collect { |t| [t.name, t.id] }%>
</p> </p>
<p> <p>

View File

@ -0,0 +1,5 @@
<% content_for :sidebar do %>
<%= render 'admin/items/site_map_left_bar' %>
<% end -%>
<%= render 'edit' %>

View File

@ -0,0 +1 @@
$('#panel_main').html("<%= escape_javascript(render 'edit') %>");

View File

@ -0,0 +1,2 @@
$('#panel_main').html("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
history.pushState(null, document.title, "<%= escape_javascript(admin_page_url(@item)) %>");

View File

@ -114,7 +114,7 @@ namespace :dev do
design_1.save design_1.save
home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design.id, :name => 'home', :is_published => true ) home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design_1.id, :name => 'home', :is_published => true, :theme_id => theme.id )
home.page_parts.create!( :name => 'header_1', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id ) home.page_parts.create!( :name => 'header_1', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id )
end end