fixing duplicate when updating design

This commit is contained in:
Matthew Fu 2011-07-20 17:05:28 +08:00
parent e3a50ccf69
commit f8d1a1315b
5 changed files with 22 additions and 9 deletions

View File

@ -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;

Binary file not shown.

View File

@ -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

View File

@ -1,16 +1,24 @@
<% item_destroy ||= false %>
<% item_snapshot ||= false %>
<% li_class = ''%>
<% fieldname_p = fieldname.pluralize %>
<%= f.label "fieldname", t('admin.'+fieldname) %>
<ul>
<% object.send(fieldname_p).each do |t| %>
<li class="r_destroy r_snapshot"> <%= 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 %>
<li class="<%= li_class %>"> <%= 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%>
<a class="remove_mark" href="#">Del</a>
<a class="remove_mark" href="#"><%= t('Delete') %></a>
<% end %>
</li>
<% end %>
</ul>
<%= 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 %>

View File

@ -25,13 +25,13 @@
<p>
<%= 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 } %>
</p>
<p>
<%= 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 } %>
</p>
<p>
<%= 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 } %>
</p>