diff --git a/app/assets/javascripts/design_temp.js b/app/assets/javascripts/design_temp.js
index 844ab9c1..7f9570cc 100644
--- a/app/assets/javascripts/design_temp.js
+++ b/app/assets/javascripts/design_temp.js
@@ -1,3 +1,7 @@
+$(".r_edit").live("click",function(){
+ $(this).after($("").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("
"+$(this).val()+"");
- new_node =$(this).clone();
+ $(this).parent().prev("ul").append(""+$(this).val()+"");
+ 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(){
diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb
index 7fba1b1f..9891ff2a 100644
--- a/app/controllers/admin/designs_controller.rb
+++ b/app/controllers/admin/designs_controller.rb
@@ -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
diff --git a/app/models/design.rb b/app/models/design.rb
index 0f11309c..8d0b31fb 100644
--- a/app/models/design.rb
+++ b/app/models/design.rb
@@ -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|
diff --git a/app/views/admin/designs/_design_file.html.erb b/app/views/admin/designs/_design_file.html.erb
index 82fd39ad..498fc4f0 100644
--- a/app/views/admin/designs/_design_file.html.erb
+++ b/app/views/admin/designs/_design_file.html.erb
@@ -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 %>
- > <%= 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%>
- <%= t('Delete') %>
- <% end %>
+ <% li_class += 'r_edit ' if 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%>
+ <%= t('Delete') %>
+ <%end%>
+
+ <% if item_editable %>
+ <%= t('Edit') %>
+ <% end %>
<% end %>
+
<%= fields_for "design["+fieldname_p+"][]", object, :index => nil do |f| %>
+ <%= f.hidden_field :id,{:value=>''} %>
<%= f.file_field :file ,{:class=>"multi_files",:rtype=>rtype}%>
+
<% end %>
diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb
index 3815feb7..c55363be 100644
--- a/app/views/admin/designs/_form.html.erb
+++ b/app/views/admin/designs/_form.html.erb
@@ -26,52 +26,13 @@
- <%= f.label "stylesheet", t('admin.stylesheet') %>
-
- <% @design.stylesheets.each do |t| %>
- - <%= t.file_filename %>
- <%= fields_for "design[stylesheets][]", t, :index => nil do |f| %>
- <%= f.hidden_field :id %>
- <%= f.hidden_field :to_destroy %>
- <%end%>
- Del
- <% end %>
-
- <%= 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 } %>
- <%= f.label "javascript", t('admin.javascript') %>
-
- <% @design.javascripts.each do |t| %>
- - <%= t.file_filename %>
- <%=fields_for "design[javascripts][]",t,:index=>nil do |f| %>
- <%= f.hidden_field :id %>
- <%= f.hidden_field :to_destroy %>
- <%end%>
- Del
- <% end %>
-
- <%= 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} %>
- <%= f.label "image", t('admin.image') %>
-
- <% @design.images.each do |t| %>
- - <%= t.file_filename %>
- <%=fields_for "design[images][]",t,:index=>nil do |f| %>
- <%= f.hidden_field :id %>
- <%= f.hidden_field :to_destroy %>
- <%end%>
- Del
- <% end %>
-
- <%= 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} %>