From f8d1a1315b04051030fa9f349097388fb8e1eccf Mon Sep 17 00:00:00 2001 From: Matthew Fu Date: Wed, 20 Jul 2011 17:05:28 +0800 Subject: [PATCH] fixing duplicate when updating design --- app/assets/javascripts/design_temp.js | 2 +- .../admin/.designs_controller.rb.swp | Bin 0 -> 12288 bytes app/models/design.rb | 7 ++++++- app/views/admin/designs/_design_file.html.erb | 16 ++++++++++++---- app/views/admin/designs/_form.html.erb | 6 +++--- 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 app/controllers/admin/.designs_controller.rb.swp diff --git a/app/assets/javascripts/design_temp.js b/app/assets/javascripts/design_temp.js index 812c2a18..8cbc9470 100644 --- a/app/assets/javascripts/design_temp.js +++ b/app/assets/javascripts/design_temp.js @@ -17,7 +17,7 @@ $('input.multi_files').change(function(){ }); $('a.remove_mark').live("click",function(){ - $(this).prev("input").value("true"); + $(this).prev("input").val("true"); $(this).parent().css("text-decoration","line-through") $(this).remove(); return false; diff --git a/app/controllers/admin/.designs_controller.rb.swp b/app/controllers/admin/.designs_controller.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..2336817e6cdf9baf51898671ae09f7b8e75e4a5e GIT binary patch literal 12288 zcmeI2PiqrF7>B3cq*kRCy(qj!N?VYm+CyQrVzCDmst3^urH0Awq#d%|U3O+|OItxt zUi}(=02TTL?8$>7dQdN3Jop*(H`z@#NNRd6@4&-uX5abu%;b>l+n9cIXOU*BGXmwb z5V!A--@80KDn6eOq9wJBUHyQPHL}QN1A_4QS-Zp9Qk=F-B7Ieh(}uP+nIttoj%*r- zp-N3n2J1Si1B7z4jg3b6;a!6H}yqo$a4X^<=zy{a=8(;%$ zfDNz#HlQN>s3CF}YM1hkD8&brk|%wu{&wL02)u$wa1d-7I@~@X8cg2dY_gU#{2HAq3gfTV*A6#wfdN>L}>; zse^8RShMYISi0+D&IRY{R4MNN+9r#|x%s;?z+RRFhqRYR)}^(nZe&)O?&^As9a03* zKem@WwW*EO(Q4goUe72iw6ilu+q)v)j(irq0{d-d5sYo^6KTp#l3`d?$c)#@6iu*e vY7<{^qEK$dnWakmWLAWaQ)p=3<<5Iver(LGZdN^Ar}-oawJ+VNFYCo$lB`1g literal 0 HcmV?d00001 diff --git a/app/models/design.rb b/app/models/design.rb index b9e664bd..bd391b15 100644 --- a/app/models/design.rb +++ b/app/models/design.rb @@ -17,6 +17,7 @@ class Design embeds_many :javascripts embeds_many :images + before_save :cleanup_empty_fields after_save :procs_embedded_objects def javascripts=(*attrs) @@ -40,10 +41,14 @@ class Design end protected - + def cleanup_empty_fields + end def procs_embedded_objects [self.stylesheets, self.javascripts, self.images].each do |objects| objects.each do |object| + if object.file.blank? + object.to_save = false + end if object.to_save object.to_save = false object.save diff --git a/app/views/admin/designs/_design_file.html.erb b/app/views/admin/designs/_design_file.html.erb index 610ba099..fb8a08ec 100644 --- a/app/views/admin/designs/_design_file.html.erb +++ b/app/views/admin/designs/_design_file.html.erb @@ -1,16 +1,24 @@ +<% item_destroy ||= false %> +<% item_snapshot ||= false %> +<% li_class = ''%> + <% fieldname_p = fieldname.pluralize %> <%= f.label "fieldname", t('admin.'+fieldname) %>
    <% object.send(fieldname_p).each do |t| %> -
  • <%= t.file_filename %> - <%=fields_for "design["+(fieldname_p)+"][]",t,:index=>nil do |f| %> + <% li_class += 'r_destroy ' if item_destroy %> + <% li_class += 'r_snapshot ' if item_snapshot %> +
  • <%= t.file_filename %> + <% if item_destroy %> + <%=fields_for "design["+fieldname_p+"][]",t,:index=>nil do |f| %> <%= f.hidden_field :id %> <%= f.hidden_field :to_destroy %> <%end%> - Del + <%= t('Delete') %> + <% end %>
  • <% end %>
-<%= fields_for "design["+(fieldname_p)+"][]", object, :index => nil do |f| %> +<%= fields_for "design["+fieldname_p+"][]", object, :index => nil do |f| %> <%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%> <% end %> diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index 9d65cf2e..2cf07038 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -25,13 +25,13 @@

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

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

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