Page form with drop down. Modifications for Designs
This commit is contained in:
parent
27d47215e9
commit
c427e2af14
|
@ -0,0 +1,3 @@
|
|||
$("#page_design_id").live('change', function() {
|
||||
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_themes');
|
||||
});
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -3,12 +3,16 @@ class LayoutPart
|
|||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :name_tag
|
||||
field :name
|
||||
field :id_tag
|
||||
field :editable_tag
|
||||
field :editable
|
||||
field :class_tag
|
||||
field :content
|
||||
|
||||
embedded_in :layout
|
||||
|
||||
def editable?
|
||||
self.editable.eql?('true')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ class Theme < Stylesheet
|
|||
protected
|
||||
|
||||
def set_name
|
||||
self.name = self.file_filename.split('.')[0]
|
||||
self.name = File.basename(self.file_filename,".css")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,15 +3,13 @@ class Page < Item
|
|||
field :content
|
||||
field :theme_id
|
||||
|
||||
validates_presence_of :design_id
|
||||
|
||||
belongs_to :design
|
||||
has_many :page_parts
|
||||
|
||||
def create_parts
|
||||
page_design = self.get_design
|
||||
page_design = self.design
|
||||
page_design.layout.layout_parts.each do |p|
|
||||
self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) if p['editable']
|
||||
self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) if p.editable?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,8 +21,4 @@ class Page < Item
|
|||
end
|
||||
end
|
||||
|
||||
def get_design
|
||||
Design.find(design_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
# encoding: utf-8
|
||||
|
||||
class AssetUploader < CarrierWave::Uploader::Base
|
||||
require 'mime/types'
|
||||
|
||||
process :set_content_type
|
||||
|
||||
def set_content_type(*args)
|
||||
content_type = file.content_type == 'binary/octet-stream' || 'application/octet-stream' || file.content_type.blank? ? MIME::Types.type_for(original_filename).first.to_s : file.content_type
|
||||
self.file.instance_variable_set(:@content_type, content_type)
|
||||
end
|
||||
|
||||
# Include RMagick or ImageScience support:
|
||||
# include CarrierWave::RMagick
|
||||
|
|
|
@ -16,13 +16,19 @@
|
|||
|
||||
<p>
|
||||
<%= t('admin.design_name') %>
|
||||
<%#= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, :selected => @default_design.id %>
|
||||
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] } %>
|
||||
<% if @design %>
|
||||
<%= f.collection_select :design_id, @designs, :id, :title, {}, :rel => admin_pages_path %>
|
||||
<% else %>
|
||||
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, {:selected => @default_design.id}, {:rel => admin_pages_path} %>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
<%= t('admin.theme') %>
|
||||
<%#= f.select :theme_id, @default_design.themes.collect { |t| [t.name, t.id] }, :selected => @default_design.themes.detect {|t| t.file_filename.to_s == 'default.css' }.id %>
|
||||
<%= f.select :theme_id, @design.themes.collect { |t| [t.name, t.id] }%>
|
||||
<% if @design %>
|
||||
<%= f.select :theme_id, @design.themes.collect { |t| [t.name.capitalize, t.id] }%>
|
||||
<% else %>
|
||||
<%= f.select :theme_id, @default_design.themes.collect { |t| [t.name.capitalize, t.id] }, :selected => @default_theme.id %>
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$('#page_theme_id').html("<%= escape_javascript(options_from_collection_for_select(@themes, :id, :name, @default_theme.id )) %>");
|
|
@ -27,6 +27,7 @@ PrototypeR4::Application.routes.draw do
|
|||
resources :pages do
|
||||
member do
|
||||
get 'delete'
|
||||
get 'reload_themes'
|
||||
end
|
||||
end
|
||||
resources :page_parts
|
||||
|
@ -49,7 +50,9 @@ PrototypeR4::Application.routes.draw do
|
|||
|
||||
# routes for gridfs files
|
||||
match "/gridfs/*path" => "gridfs#serve"
|
||||
|
||||
match "/images/*path" => "gridfs#serve_images"
|
||||
match "/admin/pages/images/*path" => "gridfs#serve_images"
|
||||
|
||||
# routes for pages to generate
|
||||
match '*page_name' => 'pages#show', :as => :page, :constraints => lambda{|request|
|
||||
!request.path.starts_with?("/panel")
|
||||
|
|
|
@ -89,11 +89,12 @@ module Parser
|
|||
end
|
||||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
ret = ''
|
||||
ret << "<div id='#{tag.attr['name']}'>"
|
||||
ret << page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }.content rescue ''
|
||||
ret << tag.expand
|
||||
ret << '</div>'
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil
|
||||
if part
|
||||
part.content
|
||||
else
|
||||
tag.expand
|
||||
end
|
||||
end
|
||||
c.define_tag 'link' do |tag|
|
||||
item = Item.first(:conditions => { :full_name => tag.attr['name'] })
|
||||
|
@ -107,7 +108,7 @@ module Parser
|
|||
|
||||
def parse_page(page)
|
||||
if page._type == 'Page'
|
||||
layout_content = page.design.layout.content
|
||||
layout_content = page.design.layout.content.force_encoding('UTF-8')
|
||||
context = parser_context(page)
|
||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||
parser.parse(parser.parse(layout_content))
|
||||
|
@ -116,7 +117,7 @@ module Parser
|
|||
|
||||
def parse_page_edit(page)
|
||||
if page._type == 'Page'
|
||||
layout_content = page.design.layout.content
|
||||
layout_content = page.design.layout.content.force_encoding('UTF-8')
|
||||
context = parser_context_edit(page)
|
||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||
parser.parse(parser.parse(layout_content))
|
||||
|
@ -184,17 +185,20 @@ module Parser
|
|||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
|
||||
ret = ''
|
||||
ret << "<div id='#{tag.attr['name']}'"
|
||||
ret << " part_id='#{part.id}'" if part
|
||||
ret << " class='editable'" if part
|
||||
ret << " style='border:solid 1px; margin:5px; padding:5px;'>"
|
||||
ret << "<div class='edit_link' style='display:none'>" if part
|
||||
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>" if part
|
||||
ret << '</div>' if part
|
||||
ret << part.i18n_variable[I18n.locale.to_s] rescue ''
|
||||
ret << tag.expand
|
||||
ret << '</div>'
|
||||
if part
|
||||
ret = ''
|
||||
ret << "<div id='#{tag.attr['name']}'"
|
||||
ret << " part_id='#{part.id}'"
|
||||
ret << " class='editable'"
|
||||
ret << " style='border:solid 1px; margin:5px; padding:5px;'>"
|
||||
ret << "<div class='edit_link' style='display:none'>"
|
||||
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>"
|
||||
ret << '</div>'
|
||||
ret << part.i18n_variable[I18n.locale.to_s] rescue ''
|
||||
ret << '</div>'
|
||||
else
|
||||
tag.expand
|
||||
end
|
||||
end
|
||||
c.define_tag 'link' do |tag|
|
||||
item = Item.first(:conditions => { :full_name => tag.attr['name'] })
|
||||
|
@ -210,7 +214,7 @@ module Parser
|
|||
|
||||
#=============
|
||||
def parse_layout_layout_part(layout)
|
||||
content = layout.content
|
||||
content = layout.content.force_encoding('UTF-8')
|
||||
context = parser_layout_layout_part(layout)
|
||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||
parser.parse(content)
|
||||
|
@ -226,8 +230,9 @@ module Parser
|
|||
data={}
|
||||
data[:class_tag]=tag.attr['class'].to_s
|
||||
data[:id_tag]=tag.attr['id'].to_s
|
||||
data[:name_tag]=tag.attr['name'].to_s
|
||||
data[:editable_tag]=tag.attr['editable'].to_s
|
||||
data[:name]=tag.attr['name'].to_s
|
||||
data[:editable]=tag.attr['editable'].to_s
|
||||
data[:content] = tag.expand.force_encoding('UTF-8') if !(tag.attr['editable'].eql?('true'))
|
||||
layout.layout_parts.create(data)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue