fixing duplicate when updating design
This commit is contained in:
parent
e3a50ccf69
commit
f8d1a1315b
|
@ -17,7 +17,7 @@ $('input.multi_files').change(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
$('a.remove_mark').live("click",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).parent().css("text-decoration","line-through")
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
return false;
|
return false;
|
||||||
|
|
Binary file not shown.
|
@ -17,6 +17,7 @@ class Design
|
||||||
embeds_many :javascripts
|
embeds_many :javascripts
|
||||||
embeds_many :images
|
embeds_many :images
|
||||||
|
|
||||||
|
before_save :cleanup_empty_fields
|
||||||
after_save :procs_embedded_objects
|
after_save :procs_embedded_objects
|
||||||
|
|
||||||
def javascripts=(*attrs)
|
def javascripts=(*attrs)
|
||||||
|
@ -40,10 +41,14 @@ class Design
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
def cleanup_empty_fields
|
||||||
|
end
|
||||||
def procs_embedded_objects
|
def procs_embedded_objects
|
||||||
[self.stylesheets, self.javascripts, self.images].each do |objects|
|
[self.stylesheets, self.javascripts, self.images].each do |objects|
|
||||||
objects.each do |object|
|
objects.each do |object|
|
||||||
|
if object.file.blank?
|
||||||
|
object.to_save = false
|
||||||
|
end
|
||||||
if object.to_save
|
if object.to_save
|
||||||
object.to_save = false
|
object.to_save = false
|
||||||
object.save
|
object.save
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
|
<% item_destroy ||= false %>
|
||||||
|
<% item_snapshot ||= false %>
|
||||||
|
<% li_class = ''%>
|
||||||
|
|
||||||
<% fieldname_p = fieldname.pluralize %>
|
<% fieldname_p = fieldname.pluralize %>
|
||||||
<%= f.label "fieldname", t('admin.'+fieldname) %>
|
<%= f.label "fieldname", t('admin.'+fieldname) %>
|
||||||
<ul>
|
<ul>
|
||||||
<% object.send(fieldname_p).each do |t| %>
|
<% object.send(fieldname_p).each do |t| %>
|
||||||
<li class="r_destroy r_snapshot"> <%= t.file_filename %>
|
<% li_class += 'r_destroy ' if item_destroy %>
|
||||||
<%=fields_for "design["+(fieldname_p)+"][]",t,:index=>nil do |f| %>
|
<% 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 :id %>
|
||||||
<%= f.hidden_field :to_destroy %>
|
<%= f.hidden_field :to_destroy %>
|
||||||
<%end%>
|
<%end%>
|
||||||
<a class="remove_mark" href="#">Del</a>
|
<a class="remove_mark" href="#"><%= t('Delete') %></a>
|
||||||
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</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}%>
|
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<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>
|
||||||
|
|
||||||
<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>
|
||||||
|
|
||||||
<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>
|
</p>
|
||||||
|
|
Loading…
Reference in New Issue