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
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
def get_site

View File

@ -10,6 +10,7 @@ class Design
mount_uploader :zip_file, AssetUploader
has_one :site
has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
has_one :layout, :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 :sub_menu, localize: true
belongs_to :design
has_many :site_metas, :autosave => true, :dependent => :destroy
def generate_keys

View File

@ -9,6 +9,7 @@
</ul>
</div>
</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="span2"><%= design.author %></td>
</tr>

View File

@ -2,6 +2,7 @@
<tr>
<th class="span1 strong"></th>
<th class="span2"></th>
<th class="span1"></th>
<th class="span7"></th>
<th class="span2"></th>
</tr>
@ -9,4 +10,15 @@
<tbody>
<tbody id="tbody_designs" class="sort-holder">
<%= 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]),
['title', 'title','span2', :title],
['', '', 'span1', :default],
['intro', 'intro', 'span7', :intro],
['author', 'author', 'span2', :author]).html_safe %>

View File

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

View File

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

View File

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