Fixing upload bug

This commit is contained in:
Kaito 2011-07-26 18:22:17 +08:00
parent 1ac10e70a2
commit dabd6dd5b5
5 changed files with 44 additions and 56 deletions

View File

@ -1,3 +1,7 @@
$(".r_edit").live("click",function(){
$(this).after($("<span style='border:solid; width:400px;height:300px; float:right;'></span>").load($(this).attr("path")));
});
$(".r_snapshot").live({ $(".r_snapshot").live({
mouseenter: mouseenter:
function(){ function(){
@ -11,11 +15,11 @@ $(".r_snapshot").live({
); );
$('input.multi_files').live("change", function(){ $('input.multi_files').live("change", function(){
$(this).prev("ul").append("<li>"+$(this).val()+"</li>"); $(this).parent().prev("ul").append("<li>"+$(this).val()+"</li>");
new_node =$(this).clone(); new_node =$(this).parent().clone();
$(this).css("display","none"); $(this).css("display","none");
new_node.val(""); new_node.children('input.multi_files').val("");
$(this).before(new_node) $(this).parent().before(new_node);
}); });
$('a.remove_mark').live("click",function(){ $('a.remove_mark').live("click",function(){

View File

@ -23,6 +23,11 @@ class Admin::DesignsController < ApplicationController
end end
end end
def file_edit
@design = Design.find(params[:id])
debugger
end
def edit def edit
@design = Design.find(params[:id]) @design = Design.find(params[:id])
end end

View File

@ -18,6 +18,7 @@ class Design
embeds_many :images embeds_many :images
after_save :procs_embedded_objects after_save :procs_embedded_objects
after_destroy :del_embedded_objects
def javascripts=(*attrs) def javascripts=(*attrs)
self.files = (attrs << 'javascripts') self.files = (attrs << 'javascripts')
@ -35,7 +36,7 @@ class Design
def files=(attrs) def files=(attrs)
files = eval(attrs.last) files = eval(attrs.last)
attrs[0].each do |a| attrs[0].each do |a|
if(a[:id].nil?) if(a[:id]=='' && !a[:file].nil?)
files.build(:file => a[:file], :to_save => true) files.build(:file => a[:file], :to_save => true)
else else
files.each do |file| files.each do |file|
@ -48,6 +49,13 @@ class Design
end end
protected protected
def del_embedded_objects
[self.stylesheets, self.javascripts, self.images].each do |objects|
objects.each do |object|
object.destroy
end
end
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|

View File

@ -1,5 +1,6 @@
<% item_destroy ||= false %> <% item_destroy ||= false %>
<% item_snapshot ||= false %> <% item_snapshot ||= false %>
<% item_editable ||= false %>
<% li_class = ''%> <% li_class = ''%>
<% fieldname_p = fieldname.pluralize %> <% fieldname_p = fieldname.pluralize %>
@ -8,7 +9,9 @@
<% object.send(fieldname_p).each do |t| %> <% object.send(fieldname_p).each do |t| %>
<% li_class += 'r_destroy ' if item_destroy %> <% li_class += 'r_destroy ' if item_destroy %>
<% li_class += 'r_snapshot ' if item_snapshot %> <% li_class += 'r_snapshot ' if item_snapshot %>
<li class="<%= li_class %>" <%= "path='#{t.file.url}'" if item_snapshot %> > <%= t.file_filename %> <% li_class += 'r_edit ' if item_editable %>
<li class="<%= li_class %>" <%= "path='#{t.file.url}'" if (item_snapshot || item_editable) %> >
<%= t.file_filename %>
<% if item_destroy %> <% if item_destroy %>
<%=fields_for "design["+fieldname_p+"][]",t,:index=>nil do |f| %> <%=fields_for "design["+fieldname_p+"][]",t,:index=>nil do |f| %>
<%= f.hidden_field :id %> <%= f.hidden_field :id %>
@ -16,9 +19,16 @@
<%end%> <%end%>
<a class="remove_mark" href="#"><%= t('Delete') %></a> <a class="remove_mark" href="#"><%= t('Delete') %></a>
<%end%> <%end%>
<% if item_editable %>
<a class="edit_mark" href="#"><%= t('Edit') %></a>
<% end %>
</li> </li>
<% end %> <% end %>
</ul> </ul>
<p class="new_file">
<%= fields_for "design["+fieldname_p+"][]", object, :index => nil do |f| %> <%= fields_for "design["+fieldname_p+"][]", object, :index => nil do |f| %>
<%= f.hidden_field :id,{:value=>''} %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%> <%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%>
</p>
<% end %> <% end %>

View File

@ -26,52 +26,13 @@
<p> <p>
<%= f.label "stylesheet", t('admin.stylesheet') %> <%= render :partial => 'design_file' ,:locals => { :fieldname=>"stylesheet",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %>
<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' ,:item_destroy=>true,:item_editable=>true} %>
<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=>'images' ,:item_destroy=>true,:item_snapshot=>true} %>
<ul>
<% @design.images.each do |t| %>
<li class="r_destroy r_snapshot" path="<%= t.file %>" item_id="<%=t.id %>"><%= t.file_filename %>
<%=fields_for "design[images][]",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[images][]", @design, :index => nil do |f| %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>"images"}%>
<% end %>
</p> </p>