Change the design for the whole site form designs index

This commit is contained in:
chris 2012-12-07 12:14:31 +08:00
parent c74ead8318
commit ff435a4af4
9 changed files with 38 additions and 1 deletions

View File

@ -57,6 +57,24 @@ class Admin::SitesController < ApplicationController
end end
def change_design
design = Design.find(params[:site_id]) rescue nil
update_design(design) if design
render :nothing => true
end
protected
def update_design(design)
@site.design = design
if @site.save
theme_id = design.themes.first.id
Page.all.each do |page|
page.update_attributes({design_id: design.id, theme_id: (theme_id unless page.root?)})
end
end
end
private private
def get_site def get_site

View File

@ -10,6 +10,7 @@ class Design
mount_uploader :zip_file, AssetUploader mount_uploader :zip_file, AssetUploader
has_one :site
has_one :css_default, as: :css, :autosave => true, :dependent => :destroy has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
has_one :layout, :autosave => true, :dependent => :destroy has_one :layout, :autosave => true, :dependent => :destroy
has_one :css_reset, :autosave => true, :dependent => :destroy has_one :css_reset, :autosave => true, :dependent => :destroy

View File

@ -26,6 +26,7 @@ class Site
field :footer, localize: true field :footer, localize: true
field :sub_menu, localize: true field :sub_menu, localize: true
belongs_to :design
has_many :site_metas, :autosave => true, :dependent => :destroy has_many :site_metas, :autosave => true, :dependent => :destroy
def generate_keys def generate_keys

View File

@ -9,6 +9,7 @@
</ul> </ul>
</div> </div>
</td> </td>
<td class="span1"><%= radio_button_tag 'design_default', design.id, (@site.design.id.to_s.eql?(design.id.to_s) ? true : false), :class => 'design_default', :rel => admin_sites_path %> <%=@site.design.id.to_s.eql?(design.id.to_s)%></td>
<td class="span7"><%= design.intro %></td> <td class="span7"><%= design.intro %></td>
<td class="span2"><%= design.author %></td> <td class="span2"><%= design.author %></td>
</tr> </tr>

View File

@ -2,6 +2,7 @@
<tr> <tr>
<th class="span1 strong"></th> <th class="span1 strong"></th>
<th class="span2"></th> <th class="span2"></th>
<th class="span1"></th>
<th class="span7"></th> <th class="span7"></th>
<th class="span2"></th> <th class="span2"></th>
</tr> </tr>
@ -9,4 +10,15 @@
<tbody> <tbody>
<tbody id="tbody_designs" class="sort-holder"> <tbody id="tbody_designs" class="sort-holder">
<%= render :partial => 'design', :collection => @designs %> <%= render :partial => 'design', :collection => @designs %>
</tbody> </tbody>
<% content_for :page_specific_javascript do %>
<script>
$(document).ready(function(){
$(document).on('change', '.design_default', function(){
$(this).attr('value');
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/change_design');
});
});
</script>
<% end %>

View File

@ -1,4 +1,5 @@
<%= render_sort_bar(true, delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), <%= render_sort_bar(true, delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]),
['title', 'title','span2', :title], ['title', 'title','span2', :title],
['', '', 'span1', :default],
['intro', 'intro', 'span7', :intro], ['intro', 'intro', 'span7', :intro],
['author', 'author', 'span2', :author]).html_safe %> ['author', 'author', 'span2', :author]).html_safe %>

View File

@ -148,6 +148,7 @@ en:
web_link: Link web_link: Link
dashboard_: Dashboard dashboard_: Dashboard
deadline: Deadline deadline: Deadline
default: Default
default_css: Default CSS default_css: Default CSS
delete: delete:
file: Delete file file: Delete file

View File

@ -148,6 +148,7 @@ zh_tw:
web_link: 鏈接 web_link: 鏈接
dashboard_: 儀表版 dashboard_: 儀表版
deadline: 最後期限 deadline: 最後期限
default: Default
default_css: 預設樣式表 default_css: 預設樣式表
delete: delete:
file: 刪除檔案 file: 刪除檔案

View File

@ -128,6 +128,7 @@ Orbit::Application.routes.draw do
get 'sitemap_toggle', :on => :member get 'sitemap_toggle', :on => :member
get 'system_info' get 'system_info'
get 'ui_theme' get 'ui_theme'
get 'change_design'
end end
resources :tags resources :tags
resources :users resources :users