move design file field to partial

This commit is contained in:
Matthew Fu 2011-07-20 14:04:16 +08:00
parent 612ed629bc
commit e3a50ccf69
3 changed files with 22 additions and 42 deletions

View File

@ -11,9 +11,9 @@ $(".r_snapshot").hover(
$('input.multi_files').change(function(){ $('input.multi_files').change(function(){
$(this).prev("ul").append("<li>"+$(this).val()+"</li>"); $(this).prev("ul").append("<li>"+$(this).val()+"</li>");
new_node =$(this).clone(); new_node =$(this).clone();
new_node.css("display","none"); $(this).css("display","none");
$(this).parent().append(new_node); new_node.val("");
$(this).val(""); $(this).after(new_node)
}); });
$('a.remove_mark').live("click",function(){ $('a.remove_mark').live("click",function(){

View File

@ -0,0 +1,16 @@
<% 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| %>
<%= f.hidden_field :id %>
<%= f.hidden_field :to_destroy %>
<%end%>
<a class="remove_mark" href="#">Del</a>
</li>
<% end %>
</ul>
<%= fields_for "design["+(fieldname_p)+"][]", object, :index => nil do |f| %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%>
<% end %>

View File

@ -25,49 +25,13 @@
<p> <p>
<%= f.label "stylesheet", t('admin.stylesheet') %> <%= render :partial => 'design_file' ,:locals => { :fieldname=>"stylesheet",:object=>@design ,:f=>f,:rtype=>'stylesheets' } %>
<ul>
<% @design.stylesheets.each do |t| %>
<li class="r_destroy r_edit" ><%= t.file_filename %>
<%= fields_for "design[stylesheets][]", t, :index => nil do |f| %>
<%= f.hidden_field :id %>
<%= f.hidden_field :to_destroy %>
<%end%>
<a class="remove_mark" href="#">Del</a></li>
<% end %>
</ul>
<%= fields_for "design[stylesheets][]", @design, :index => nil do |f| %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>"stylesheets"}%>
<% end %>
</p> </p>
<p> <p>
<%= f.label "javascript", t('admin.javascript') %> <%= render :partial => 'design_file' ,:locals => { :fieldname=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' } %>
<ul>
<% @design.javascripts.each do |t| %>
<li class="r_destroy r_edit" ><%= t.file_filename %>
<%=fields_for "design[javascripts][]",t,:index=>nil do |f| %>
<%= f.hidden_field :id %>
<%= f.hidden_field :to_destroy %>
<%end%>
<a class="remove_mark" href="#">Del</a></li>
<% end %>
</ul>
<%= fields_for "design[javascripts][]", @design, :index => nil do |f| %>
<%= f.file_field :file,{:class=>"multi_files",:rtype=>"javascripts"} %>
<% end %>
</p> </p>
<p> <p>
<%= f.label "image", t('admin.image') %> <%= render :partial => 'design_file' ,:locals => { :fieldname=>"image",:object=>@design ,:f=>f,:rtype=>'' } %>
<ul>
<% @design.images.each do |t| %>
<li class="r_destroy r_snapshot" path="<%= t.file %>" item_id="<%=t.id %>"><%= t.file_filename %>
<a class="remove_mark" href="#">Del</a>
</li>
<% end %>
</ul>
<%= fields_for "design[images][]", @design, :index => nil do |f| %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>"images"}%>
<% end %>
</p> </p>