diff --git a/:q b/:q new file mode 100644 index 00000000..d0083d8e --- /dev/null +++ b/:q @@ -0,0 +1,45 @@ +<%= stylesheet_link_tag "design_temp" %> +<%= javascript_include_tag "design_temp" %> +

+<%= f.label :title, t('admin.title') %> +<%= f.text_field :title, :class => 'text' %> +

+ +

+<%= f.label :author, t('admin.author') %> +<%= f.text_field :author, :class => 'text' %> +

+ +

+<%= f.label :intro, t('admin.intro') %> +<%= f.text_field :intro, :class => 'text' %> +

+ +

+<%= f.label "layout", t('admin.layout') %> +<% if @design.layout.blank? %> + <%= f.file_field :layout_file %> + <% else%> + <% debugger %> + <%= File.basename (@design.layout.url) %> +<% end %> +

+

+<%= 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 %> +

+

+<%= render :partial => 'design_file' ,:locals => { :fieldname=>"themes",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %> +

+ +

+<%= render :partial => 'design_file' ,:locals => { :fieldname=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' ,:item_destroy=>true,:item_editable=>true} %> +

+ +

+<%= render :partial => 'design_file' ,:locals => { :fieldname=>"image",:object=>@design ,:f=>f,:rtype=>'images' ,:item_destroy=>true,:item_snapshot=>true} %> +

diff --git a/app/models/design.rb b/app/models/design.rb index add424a1..e8bda480 100644 --- a/app/models/design.rb +++ b/app/models/design.rb @@ -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 @@ -20,7 +20,11 @@ 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 diff --git a/app/models/layout.rb b/app/models/layout.rb index 96f2a114..d62eabb7 100644 --- a/app/models/layout.rb +++ b/app/models/layout.rb @@ -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 diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index a07cc071..ccfe3e77 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -18,9 +18,9 @@

<%= 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 %>

diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 3e448cf0..461f3fb2 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -32,7 +32,6 @@