From a272b871e225c10454ebe7a8e9fee2c4ee6d2c81 Mon Sep 17 00:00:00 2001 From: Kaito Date: Fri, 22 Jul 2011 15:54:38 +0800 Subject: [PATCH] complete del and destroy funciton for desgin --- .gitignore | 3 ++ app/controllers/admin/designs_controller.rb | 5 +++ app/models/design.rb | 10 +++-- app/views/admin/designs/_form.html.erb | 46 +++++++++++++++++++-- config/application.rb | 2 +- 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 43bf0b8b..dde823ca 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ public/uploads/**/* uploads/**/* .DS_Store + +*.swp + public/javascripts public/stylesheets config/application.rb diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index 08824525..7fba1b1f 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.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 diff --git a/app/models/design.rb b/app/models/design.rb index 69817c0f..95b54931 100644 --- a/app/models/design.rb +++ b/app/models/design.rb @@ -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 diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index 2cf07038..3815feb7 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -1,4 +1,5 @@ <%= stylesheet_link_tag "design_temp" %> +<%= javascript_include_tag "design_temp" %>

<%= f.label :title, t('admin.title') %> <%= f.text_field :title, :class => 'text' %> @@ -25,13 +26,52 @@

-<%= render :partial => 'design_file' ,:locals => { :fieldname=>"stylesheet",:object=>@design ,:f=>f,:rtype=>'stylesheets',:item_destroy=>true } %> + <%= f.label "stylesheet", t('admin.stylesheet') %> +

+ <%= 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=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' ,:item_destroy=>true } %> + <%= f.label "javascript", t('admin.javascript') %> +

+ <%= 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=>"image",:object=>@design ,:f=>f,:rtype=>'',:item_snapshot=>true ,:item_destroy=>true } %> + <%= f.label "image", t('admin.image') %> +

+ <%= fields_for "design[images][]", @design, :index => nil do |f| %> + <%= f.file_field :file ,{:class=>"multi_files",:rtype=>"images"}%> + <% end %>

diff --git a/config/application.rb b/config/application.rb index c6289ee3..1f7649ca 100644 --- a/config/application.rb +++ b/config/application.rb @@ -53,7 +53,7 @@ module PrototypeR4 config.filter_parameters += [:password] # Enable the asset pipeline - config.assets.enabled = true + config.assets.enabled = false end end