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') %> +
-<%= render :partial => 'design_file' ,:locals => { :fieldname=>"javascript",:object=>@design ,:f=>f,:rtype=>'javascripts' ,:item_destroy=>true } %> + <%= f.label "javascript", t('admin.javascript') %> +
-<%= render :partial => 'design_file' ,:locals => { :fieldname=>"image",:object=>@design ,:f=>f,:rtype=>'',:item_snapshot=>true ,:item_destroy=>true } %> + <%= f.label "image", t('admin.image') %> +