Fixing upload bug
This commit is contained in:
parent
1ac10e70a2
commit
dabd6dd5b5
|
@ -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({
|
||||
mouseenter:
|
||||
function(){
|
||||
|
@ -11,11 +15,11 @@ $(".r_snapshot").live({
|
|||
);
|
||||
|
||||
$('input.multi_files').live("change", function(){
|
||||
$(this).prev("ul").append("<li>"+$(this).val()+"</li>");
|
||||
new_node =$(this).clone();
|
||||
$(this).parent().prev("ul").append("<li>"+$(this).val()+"</li>");
|
||||
new_node =$(this).parent().clone();
|
||||
$(this).css("display","none");
|
||||
new_node.val("");
|
||||
$(this).before(new_node)
|
||||
new_node.children('input.multi_files').val("");
|
||||
$(this).parent().before(new_node);
|
||||
});
|
||||
|
||||
$('a.remove_mark').live("click",function(){
|
||||
|
|
|
@ -23,6 +23,11 @@ class Admin::DesignsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def file_edit
|
||||
@design = Design.find(params[:id])
|
||||
debugger
|
||||
end
|
||||
|
||||
def edit
|
||||
@design = Design.find(params[:id])
|
||||
end
|
||||
|
|
|
@ -18,6 +18,7 @@ class Design
|
|||
embeds_many :images
|
||||
|
||||
after_save :procs_embedded_objects
|
||||
after_destroy :del_embedded_objects
|
||||
|
||||
def javascripts=(*attrs)
|
||||
self.files = (attrs << 'javascripts')
|
||||
|
@ -35,12 +36,12 @@ class Design
|
|||
def files=(attrs)
|
||||
files = eval(attrs.last)
|
||||
attrs[0].each do |a|
|
||||
if(a[:id].nil?)
|
||||
if(a[:id]=='' && !a[:file].nil?)
|
||||
files.build(:file => a[:file], :to_save => true)
|
||||
else
|
||||
files.each do |file|
|
||||
if file.id.to_s == a[:id]
|
||||
file.to_destroy = a[:to_destroy]
|
||||
file.to_destroy = a[:to_destroy]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -48,6 +49,13 @@ class Design
|
|||
end
|
||||
|
||||
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
|
||||
[self.stylesheets, self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<% item_destroy ||= false %>
|
||||
<% item_snapshot ||= false %>
|
||||
<% item_editable ||= false %>
|
||||
<% li_class = ''%>
|
||||
|
||||
<% fieldname_p = fieldname.pluralize %>
|
||||
|
@ -8,17 +9,26 @@
|
|||
<% object.send(fieldname_p).each do |t| %>
|
||||
<% li_class += 'r_destroy ' if item_destroy %>
|
||||
<% li_class += 'r_snapshot ' if item_snapshot %>
|
||||
<li class="<%= li_class %>" <%= "path='#{t.file.url}'" 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%>
|
||||
<a class="remove_mark" href="#"><%= t('Delete') %></a>
|
||||
<% end %>
|
||||
<% 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 %>
|
||||
<%=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="#"><%= t('Delete') %></a>
|
||||
<%end%>
|
||||
|
||||
<% if item_editable %>
|
||||
<a class="edit_mark" href="#"><%= t('Edit') %></a>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<p class="new_file">
|
||||
<%= fields_for "design["+fieldname_p+"][]", object, :index => nil do |f| %>
|
||||
<%= f.hidden_field :id,{:value=>''} %>
|
||||
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%>
|
||||
</p>
|
||||
<% end %>
|
||||
|
|
|
@ -26,52 +26,13 @@
|
|||
|
||||
|
||||
<p>
|
||||
<%= f.label "stylesheet", t('admin.stylesheet') %>
|
||||
<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 %>
|
||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"stylesheet",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true,:item_editable=>true } %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label "javascript", t('admin.javascript') %>
|
||||
<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 %>
|
||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' ,:item_destroy=>true,:item_editable=>true} %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label "image", t('admin.image') %>
|
||||
<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 %>
|
||||
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"image",:object=>@design ,:f=>f,:rtype=>'images' ,:item_destroy=>true,:item_snapshot=>true} %>
|
||||
</p>
|
||||
|
|
Loading…
Reference in New Issue