complete del and destroy funciton for desgin
This commit is contained in:
parent
29ce3199ec
commit
a272b871e2
|
@ -7,6 +7,9 @@ public/uploads/**/*
|
|||
uploads/**/*
|
||||
|
||||
.DS_Store
|
||||
|
||||
*.swp
|
||||
|
||||
public/javascripts
|
||||
public/stylesheets
|
||||
config/application.rb
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class Admin::DesignsController < ApplicationController
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
|
||||
def index
|
||||
|
@ -26,6 +28,9 @@ class Admin::DesignsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@design = Design.find(params[:id])
|
||||
@design.destroy
|
||||
redirect_to admin_designs_url
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -17,7 +17,6 @@ class Design
|
|||
embeds_many :javascripts
|
||||
embeds_many :images
|
||||
|
||||
before_save :cleanup_empty_fields
|
||||
after_save :procs_embedded_objects
|
||||
|
||||
def javascripts=(*attrs)
|
||||
|
@ -38,13 +37,17 @@ class Design
|
|||
attrs[0].each do |a|
|
||||
if(a[:id].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]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def cleanup_empty_fields
|
||||
end
|
||||
def procs_embedded_objects
|
||||
[self.stylesheets, self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
|
@ -55,6 +58,7 @@ class Design
|
|||
object.to_save = false
|
||||
object.save
|
||||
end
|
||||
debugger
|
||||
if object.to_destroy
|
||||
object.destroy
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<%= stylesheet_link_tag "design_temp" %>
|
||||
<%= javascript_include_tag "design_temp" %>
|
||||
<p>
|
||||
<%= f.label :title, t('admin.title') %>
|
||||
<%= f.text_field :title, :class => 'text' %>
|
||||
|
@ -25,13 +26,52 @@
|
|||
|
||||
|
||||
<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>
|
||||
<%= 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>
|
||||
<%= 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>
|
||||
|
|
|
@ -53,7 +53,7 @@ module PrototypeR4
|
|||
config.filter_parameters += [:password]
|
||||
|
||||
# Enable the asset pipeline
|
||||
config.assets.enabled = true
|
||||
config.assets.enabled = false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue