complete del and destroy funciton for desgin

This commit is contained in:
Kaito 2011-07-22 15:54:38 +08:00
parent 29ce3199ec
commit a272b871e2
5 changed files with 59 additions and 7 deletions

3
.gitignore vendored
View File

@ -7,6 +7,9 @@ public/uploads/**/*
uploads/**/* uploads/**/*
.DS_Store .DS_Store
*.swp
public/javascripts public/javascripts
public/stylesheets public/stylesheets
config/application.rb config/application.rb

View File

@ -1,5 +1,7 @@
class Admin::DesignsController < ApplicationController class Admin::DesignsController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_user!
before_filter :is_admin?
def index def index
@ -26,6 +28,9 @@ class Admin::DesignsController < ApplicationController
end end
def destroy def destroy
@design = Design.find(params[:id])
@design.destroy
redirect_to admin_designs_url
end end
def create def create

View File

@ -17,7 +17,6 @@ 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)
@ -38,13 +37,17 @@ class Design
attrs[0].each do |a| attrs[0].each do |a|
if(a[:id].nil?) if(a[:id].nil?)
files.build(:file => a[:file], :to_save => true) 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]
end
end
end end
end end
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|
@ -55,6 +58,7 @@ class Design
object.to_save = false object.to_save = false
object.save object.save
end end
debugger
if object.to_destroy if object.to_destroy
object.destroy object.destroy
end end

View File

@ -1,4 +1,5 @@
<%= stylesheet_link_tag "design_temp" %> <%= stylesheet_link_tag "design_temp" %>
<%= javascript_include_tag "design_temp" %>
<p> <p>
<%= f.label :title, t('admin.title') %> <%= f.label :title, t('admin.title') %>
<%= f.text_field :title, :class => 'text' %> <%= f.text_field :title, :class => 'text' %>
@ -25,13 +26,52 @@
<p> <p>
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"stylesheet",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true } %> <%= 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 %>
</p> </p>
<p> <p>
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' ,:item_destroy=>true } %> <%= 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 %>
</p> </p>
<p> <p>
<%= render :partial => 'design_file' ,:locals => { :fieldname=>"image",:object=>@design ,:f=>f,:rtype=>'',:item_snapshot=>true ,:item_destroy=>true } %> <%= 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 %>
</p> </p>

View File

@ -53,7 +53,7 @@ module PrototypeR4
config.filter_parameters += [:password] config.filter_parameters += [:password]
# Enable the asset pipeline # Enable the asset pipeline
config.assets.enabled = true config.assets.enabled = false
end end
end end