orbit-basic/app/controllers/admin/designs_controller.rb

80 lines
2.0 KiB
Ruby
Raw Normal View History

class Admin::DesignsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :is_admin?
2011-07-19 10:31:53 +00:00
def index
@designs = Design.all.entries
end
def new
@design = Design.new
end
def update
params[:design][:existing_task_attributes] ||= {}
@design = Design.find(params[:id])
if @design.update_attributes(params[:design])
flash[:notice] = "Successfully updated design and tasks."
redirect_to admin_designs_path(@design)
else
render :action => 'edit'
end
end
def apply
@design = Design.find(params[:id])
Layout.create(:name => @design.title,:description=>@design.intro,:content=>@design.layout.file.read)
#TODO do somehting to validate
# doc = Nokogiri::HTML(@design.layout.file.read)
flash[:notice] = "Successfully applied design and created a layout."
redirect_to admin_designs_url
end
def edit_file
2011-07-26 10:22:17 +00:00
@design = Design.find(params[:id])
filename = params[:filename]
files = @design.stylesheets + @design.javascripts + @design.images
file_to_removed = files.find{ |obj|
obj.file_filename == filename
}
type = file_to_removed._type
new_file = ""
Dir.mktmpdir('design_temp'){ |dir|
temp_file = File.new(dir+'/'+filename,'w+')
temp_file.write params[:context]
replace_target = eval("@design.#{type.downcase.pluralize}")
new_file = replace_target.build(:file => temp_file,:to_save=>true)
file_to_removed.destroy
@design.save
temp_file.close
}
render :json => new_file.file.url
2011-07-26 10:22:17 +00:00
end
def edit
@design = Design.find(params[:id])
end
def destroy
@design = Design.find(params[:id])
@design.destroy
redirect_to admin_designs_url
end
def create
@design = Design.new(params[:design])
if @design.save
flash[:notice] = "Successfully created design and tasks."
redirect_to admin_designs_path
else
render :action => 'new'
end
end
end