dealing with layout file bug
This commit is contained in:
parent
37633ac23d
commit
9cea77430f
|
@ -0,0 +1,45 @@
|
|||
<%= stylesheet_link_tag "design_temp" %>
|
||||
<%= javascript_include_tag "design_temp" %>
|
||||
<p>
|
||||
<%= f.label :title, t('admin.title') %>
|
||||
<%= f.text_field :title, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :author, t('admin.author') %>
|
||||
<%= f.text_field :author, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :intro, t('admin.intro') %>
|
||||
<%= f.text_field :intro, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label "layout", t('admin.layout') %>
|
||||
<% if @design.layout.blank? %>
|
||||
<%= f.file_field :layout_file %>
|
||||
<% else%>
|
||||
<% debugger %>
|
||||
<%= File.basename (@design.layout.url) %>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label "structure_css", t('admin.structure_css') %>
|
||||
<% if @design.structure_css.blank? %>
|
||||
<%= f.file_field :structure_css %>
|
||||
<% else%>
|
||||
<%= File.basename (Design.all.last.structure_css.url) %>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"themes",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' ,:item_destroy=>true,:item_editable=>true} %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"image",:object=>@design ,:f=>f,:rtype=>'images' ,:item_destroy=>true,:item_snapshot=>true} %>
|
||||
</p>
|
|
@ -11,7 +11,7 @@ class Design
|
|||
validates_presence_of :title
|
||||
validates_presence_of :author
|
||||
|
||||
embeds_one :layout
|
||||
embeds_one :layout,:class_name=>Layout
|
||||
mount_uploader :structure_css, DesignFileUploader
|
||||
|
||||
embeds_many :themes
|
||||
|
@ -21,6 +21,10 @@ class Design
|
|||
after_save :procs_embedded_objects
|
||||
after_destroy :del_embedded_objects
|
||||
|
||||
def layout=(*attrs)
|
||||
self.files = (attrs << 'layout')
|
||||
end
|
||||
|
||||
def javascripts=(*attrs)
|
||||
self.files = (attrs << 'javascripts')
|
||||
end
|
||||
|
@ -35,7 +39,12 @@ class Design
|
|||
|
||||
# Update or create the attribute_model records
|
||||
def files=(attrs)
|
||||
files = eval(attrs.last)
|
||||
case attrs.last
|
||||
when 'layout'
|
||||
files = self.layout.build
|
||||
else
|
||||
files = eval(attrs.last)
|
||||
end
|
||||
attrs[0].each do |a|
|
||||
if(a[:id]=='' && !a[:file].nil? )
|
||||
if(a[:file]!='')
|
||||
|
@ -53,14 +62,14 @@ class Design
|
|||
|
||||
protected
|
||||
def del_embedded_objects
|
||||
[self.themes, self.javascripts, self.images].each do |objects|
|
||||
[self.layout,self.themes, self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
object.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
def procs_embedded_objects
|
||||
[self.themes, self.javascripts, self.images].each do |objects|
|
||||
[self.layout,self.themes, self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
if object.file.blank?
|
||||
object.to_save = false
|
||||
|
|
|
@ -4,7 +4,7 @@ class Layout < DesignFile
|
|||
|
||||
attr_reader :content
|
||||
field :name, :index => true
|
||||
references_many :children, :class_name => "Item"
|
||||
# references_many :children, :class_name => "Item"
|
||||
has_many :layout_parts
|
||||
|
||||
validates_presence_of :name
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
<p>
|
||||
<%= f.label "layout", t('admin.layout') %>
|
||||
<% if @design.layout.blank? %>
|
||||
<%= f.file_field :layout_file %>
|
||||
<%= f.file_field :layout %>
|
||||
<% else%>
|
||||
<%= File.basename (Design.all.last.layout.url) %>
|
||||
<%= File.basename (@design.layout.file.url) %>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
<ul id="nav">
|
||||
<li><%= link_to t('homepage'), root_path %></li>
|
||||
<li><%= link_to t('admin.item'), admin_items_path %></li>
|
||||
<li><%= link_to t('admin.layout'), admin_layouts_path %></li>
|
||||
<li><%= link_to t('admin.design'), admin_designs_path %></li>
|
||||
<li><%= link_to t('admin.asset'), admin_assets_path %></li>
|
||||
|
|
Loading…
Reference in New Issue