Change the design for the whole site form designs index

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

No files matched your search

+18
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
+1
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
+1
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
+1
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>
+13 -1
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 %>
@@ -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 %>