Page form with drop down. Modifications for Designs

This commit is contained in:
chris2tof committed 2011-08-25 08:13:38 +08:00
1 parent 27d47215e9
commit c427e2af14
12 files changed
+118 -49

No files matched your search

+6 -10
View File
@@ -10,10 +10,9 @@ class Admin::DesignsController < ApplicationController
def upload_package
if !params[:design].nil?
temp_file = Tempfile.new("temp_file")
temp_file.binmode
original_file = params[:design][:package_file]
#if original_file.content_type == 'application/zip'
temp_file.write(original_file.read)
temp_file.write(original_file.read.force_encoding('UTF-8'))
temp_file.rewind
filename = File.basename(original_file.original_filename,".zip")
unzip_design(temp_file, filename)
@@ -36,16 +35,14 @@ class Admin::DesignsController < ApplicationController
zip_file.entries.each do |entry|
case (path = entry.to_s)
when /\A(#{zip_name})\/[^\/]*(\.css)\z/ #for structure css
filename = File.basename(entry.to_s,".css")
filename = File.basename(entry.to_s)
temp_file4structure = File.new(dir + '/' + filename, 'w+')
temp_file4structure.binmode
temp_file4structure.write (zip_file.read entry )
temp_file4structure.write (zip_file.read entry ).force_encoding('UTF-8')
design.structure_css = temp_file4structure
when /\A(#{zip_name})\/[^\/]*(\.html)\z/ #for layout html
filename = File.basename(entry.to_s,".css")
filename = File.basename(entry.to_s)
temp_file4layout = File.new(dir + '/' + filename, 'w+')
temp_file4layout.binmode
temp_file4layout.write (zip_file.read entry )
temp_file4layout.write (zip_file.read entry ).force_encoding('UTF-8')
design.layout.file = temp_file4layout
design.layout.to_save=true
when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/
@@ -63,8 +60,7 @@ class Admin::DesignsController < ApplicationController
eval("#{type}_entries").each do |entry|
filename = File.basename entry.to_s
temp_file = File.new(dir + '/' + filename, 'w+')
temp_file.binmode
temp_file.write zip_file.read entry
temp_file.write (zip_file.read entry).force_encoding('UTF-8')
build_and_store = eval("design.#{type}").build
build_and_store.file = temp_file
build_and_store.file_filename = filename
+11 -2
View File
@@ -23,6 +23,7 @@ class Admin::PagesController < ApplicationController
@item.parent_id = @parent_item.id rescue nil
@designs = Design.all.entries
@default_design = @designs.detect {|d| d.title.to_s == 'Bob' }
@default_theme = @default_design.themes.detect {|t| t.name.to_s == 'default' }
end
def edit
@@ -30,7 +31,6 @@ class Admin::PagesController < ApplicationController
@i18n_variable = @item.i18n_variable
@designs = Design.all.entries
@design = @item.design
@default_design = @design.themes.detect {|t| t.id == @item.theme_id }
end
def create
@@ -54,7 +54,7 @@ class Admin::PagesController < ApplicationController
def update
@item = Page.find(params[:id])
if @item.update_attributes(params[:item])
if @item.update_attributes(params[:page])
flash[:notice] = t('admin.update_success_page')
respond_to do |format|
format.html {
@@ -87,4 +87,13 @@ class Admin::PagesController < ApplicationController
end
end
def reload_themes
@design = Design.find(params[:id])
@themes = @design.themes
@default_theme = @themes.detect {|t| t.name.to_s == 'default' }
respond_to do |format|
format.js {}
end
end
end
+40
View File
@@ -1,8 +1,37 @@
require 'mongo'
class GridfsController < ActionController::Metal
def serve
gridfs_path = env["PATH_INFO"].gsub("/gridfs/", "")
gridfs_file = Mongo::GridFileSystem.new(Mongoid.database).open(gridfs_path, 'r') rescue nil
if gridfs_file
self.response_body = gridfs_file.read
self.content_type = gridfs_file.content_type
else
serve_rescue(gridfs_path.split('/').pop)
end
end
def serve_images
gridfs_path = env["PATH_INFO"]
serve_rescue(gridfs_path.split('/').pop)
end
def serve_rescue(file_name)
referer = request.env['HTTP_REFERER']
if referer.include?('admin')
page = Page.find(referer.split('/').pop)
else
vars = request.env['HTTP_REFERER'].split('/')
names = get_names(vars, [])
page = Page.find_by_name(names.pop)
names.reverse_each do |name|
page = page.children.find_by_name(name)
end
end
image = page.design.images.detect{|i| i.file_filename == file_name}
gridfs_path = image.file.url.gsub("/gridfs/", "")
begin
gridfs_file = Mongo::GridFileSystem.new(Mongoid.database).open(gridfs_path, 'r')
self.response_body = gridfs_file.read
@@ -13,4 +42,15 @@ class GridfsController < ActionController::Metal
self.response_body = ''
end
end
def get_names(vars, names)
page = Page.all(:conditions => {:name => vars.last})
names << vars.pop
if page.count > 1
get_names(vars, names)
else
names
end
end
end