Chris's first commit at Fri Jan 28 2011 10:14:32 GMT+0800 (CST)
This commit is contained in:
1 parent
554aa0a95d
commit
19a7d51e60
145 files changed
+12742
-893
No files matched your search
@@ -2,24 +2,24 @@ class Admin::AssetsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def show
|
||||
@asset = Asset.find(params[:id])
|
||||
send_data @asset.data.file.read, :filename => @asset.filename,
|
||||
:type => @asset.data.content_type,
|
||||
:disposition => 'inline' # or 'attachment'
|
||||
end
|
||||
before_filter :is_admin?
|
||||
|
||||
def index
|
||||
@assets = Asset.all
|
||||
@assets = Asset.all.entries
|
||||
end
|
||||
|
||||
def show
|
||||
#TODO
|
||||
end
|
||||
|
||||
def edit
|
||||
@asset = Asset.find(params[:id])
|
||||
session[:last_page] = get_go_back || admin_assets_url
|
||||
end
|
||||
|
||||
def new
|
||||
@asset = Asset.new
|
||||
session[:last_page] = get_go_back || admin_assets_url
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
class Admin::HomesController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
def show
|
||||
#TODO
|
||||
end
|
||||
|
||||
def new
|
||||
@home = Home.new
|
||||
@home.is_published = true
|
||||
@home.parent_id = nil
|
||||
session[:last_page] = get_go_back || admin_items_url
|
||||
end
|
||||
|
||||
def edit
|
||||
@home = Home.find(params[:id])
|
||||
@i18n_variable = @home.i18n_variable
|
||||
session[:last_page] = get_go_back || admin_items_url
|
||||
end
|
||||
|
||||
def create
|
||||
@home = Home.new(params[:home])
|
||||
|
||||
if @home.save
|
||||
flash[:notice] = t('admin.create_success_home')
|
||||
redirect_to admin_items_url
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@home = Home.find(params[:id])
|
||||
if @home.update_attributes(params[:home])
|
||||
flash[:notice] = t('admin.update_success_home')
|
||||
redirect_to admin_items_url
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@home = Home.find(params[:id])
|
||||
@home.destroy
|
||||
|
||||
redirect_to admin_items_url
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,31 +3,34 @@ class Admin::ItemsController < ApplicationController
|
||||
layout "admin"
|
||||
|
||||
before_filter :authenticate_user!
|
||||
|
||||
before_filter :find_parent_item
|
||||
before_filter :find_snippets, :only => :index
|
||||
before_filter :is_admin?
|
||||
|
||||
def index
|
||||
@items = Item.all( :conditions => { :parent_id => @parent_item.id } )
|
||||
@items.unshift Item.find_by_name("root") if @parent_item.name == 'root'
|
||||
end
|
||||
|
||||
def up
|
||||
@item = Item.find(params[:id])
|
||||
@item.move_higher
|
||||
redirect_to admin_items_url( :parent_name => @item.parent_name )
|
||||
end
|
||||
|
||||
def down
|
||||
@item = Item.find(params[:id])
|
||||
@item.move_lower
|
||||
redirect_to admin_items_url( :parent_name => @item.parent_name )
|
||||
@items = Item.where(:parent_id => @parent_item.id).entries rescue []
|
||||
@items = Item.where(:_type => 'Home').entries unless (!@items.empty? || @parent_item)
|
||||
end
|
||||
|
||||
|
||||
#TODO
|
||||
# Allow to move items down and up different parents
|
||||
# def up
|
||||
# @item = Item.find(params[:id])
|
||||
# @item.move_higher
|
||||
# redirect_to admin_items_url( :parent_name => @item.parent_name )
|
||||
# end
|
||||
#
|
||||
# def down
|
||||
# @item = Item.find(params[:id])
|
||||
# @item.move_lower
|
||||
# redirect_to admin_items_url( :parent_name => @item.parent_name )
|
||||
# end
|
||||
|
||||
protected
|
||||
|
||||
def find_snippets
|
||||
@snippets = Snippet.all( :conditions => { :parent_id => @parent_item.id } )
|
||||
@snippets = Snippet.where( { :parent_id => @parent_item.id } ) rescue nil
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,33 +2,36 @@ class Admin::LayoutsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
def index
|
||||
@layouts = Layout.all
|
||||
@layouts = Layout.all.entries
|
||||
end
|
||||
|
||||
def show
|
||||
@layout = Layout.find(params[:id])
|
||||
|
||||
redirect_to "/#{@layout.name}"
|
||||
#TODO
|
||||
# @layout = Layout.find(params[:id])
|
||||
# redirect_to "/#{@layout.name}"
|
||||
end
|
||||
|
||||
def new
|
||||
@layout = Layout.new
|
||||
session[:last_page] = get_go_back || admin_layouts_url
|
||||
end
|
||||
|
||||
def edit
|
||||
@layout = Layout.find(params[:id])
|
||||
session[:last_page] = get_go_back || admin_layouts_url
|
||||
end
|
||||
|
||||
def create
|
||||
@layout = Layout.new(params[:layout])
|
||||
|
||||
if @layout.save
|
||||
flash[:notice] = 'Layout was successfully created.'
|
||||
flash[:notice] = t('admin.create_success_layout')
|
||||
redirect_to admin_layouts_url
|
||||
else
|
||||
render :action => "new"
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +39,7 @@ class Admin::LayoutsController < ApplicationController
|
||||
@layout = Layout.find(params[:id])
|
||||
|
||||
if @layout.update_attributes(params[:layout])
|
||||
flash[:notice] = 'Layout was successfully updated.'
|
||||
flash[:notice] = t('admin.update_success_layout')
|
||||
redirect_to admin_layouts_url
|
||||
else
|
||||
render :action => "edit"
|
||||
|
||||
@@ -3,6 +3,7 @@ class Admin::LinksController < ApplicationController
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :find_parent_item
|
||||
before_filter :is_admin?
|
||||
|
||||
def show
|
||||
#TODO
|
||||
@@ -11,19 +12,22 @@ class Admin::LinksController < ApplicationController
|
||||
def new
|
||||
@link = Link.new
|
||||
@link.is_published = true
|
||||
@link.parent_name = @parent_item.name
|
||||
@link.parent_id = @parent_item.id rescue nil
|
||||
session[:last_page] = get_go_back || admin_links_url
|
||||
end
|
||||
|
||||
def edit
|
||||
@link = Link.find(params[:id])
|
||||
@i18n_variable = @link.i18n_variable
|
||||
session[:last_page] = get_go_back || admin_links_url
|
||||
end
|
||||
|
||||
def create
|
||||
@link = Link.new(params[:link])
|
||||
|
||||
if @link.save
|
||||
flash[:notice] = 'Link was successfully created.'
|
||||
redirect_to admin_items_url( :parent_name => @link.parent_name )
|
||||
flash[:notice] = t('admin.create_success_link')
|
||||
redirect_to admin_items_url( :parent_id => @link.parent_id )
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
@@ -33,8 +37,8 @@ class Admin::LinksController < ApplicationController
|
||||
@link = Link.find(params[:id])
|
||||
|
||||
if @link.update_attributes(params[:link])
|
||||
flash[:notice] = 'Link was successfully updated.'
|
||||
redirect_to admin_items_url( :parent_name => @link.parent_name )
|
||||
flash[:notice] = t('admin.update_success_link')
|
||||
redirect_to admin_items_url( :parent_id => @link.parent_id )
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
@@ -44,7 +48,7 @@ class Admin::LinksController < ApplicationController
|
||||
@link = Link.find(params[:id])
|
||||
@link.destroy
|
||||
|
||||
redirect_to admin_items_url( :parent_name => @link.parent_name )
|
||||
redirect_to admin_items_url( :parent_id => @link.parent_id )
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,6 +3,7 @@ class Admin::PagesController < ApplicationController
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :find_parent_item
|
||||
before_filter :is_admin?
|
||||
|
||||
def show
|
||||
#TODO
|
||||
@@ -11,19 +12,22 @@ class Admin::PagesController < ApplicationController
|
||||
def new
|
||||
@page = Page.new
|
||||
@page.is_published = true
|
||||
@page.parent_name = @parent_item.name
|
||||
@page.parent_id = @parent_item.id rescue nil
|
||||
session[:last_page] = get_go_back || admin_items_url
|
||||
end
|
||||
|
||||
def edit
|
||||
@page = Page.find(params[:id])
|
||||
@i18n_variable = @page.i18n_variable
|
||||
session[:last_page] = get_go_back || admin_items_url
|
||||
end
|
||||
|
||||
def create
|
||||
@page = Page.new(params[:page])
|
||||
|
||||
if @page.save
|
||||
flash[:notice] = 'Page was successfully created.'
|
||||
redirect_to admin_items_url( :parent_name => @page.parent_name )
|
||||
flash[:notice] = t('admin.create_success_page')
|
||||
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
@@ -31,10 +35,9 @@ class Admin::PagesController < ApplicationController
|
||||
|
||||
def update
|
||||
@page = Page.find(params[:id])
|
||||
|
||||
if @page.update_attributes(params[:page])
|
||||
flash[:notice] = 'Page was successfully updated.'
|
||||
redirect_to admin_items_url( :parent_name => @page.parent_name )
|
||||
flash[:notice] = t('admin.update_success_page')
|
||||
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
@@ -44,7 +47,7 @@ class Admin::PagesController < ApplicationController
|
||||
@page = Page.find(params[:id])
|
||||
@page.destroy
|
||||
|
||||
redirect_to admin_items_url( :parent_name => @page.parent_name )
|
||||
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,6 +3,7 @@ class Admin::SnippetsController < ApplicationController
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :find_parent_item
|
||||
before_filter :is_admin?
|
||||
|
||||
def show
|
||||
#TODO
|
||||
@@ -10,19 +11,21 @@ class Admin::SnippetsController < ApplicationController
|
||||
|
||||
def new
|
||||
@snippet = Snippet.new
|
||||
@snippet.parent_name = @parent_item.name
|
||||
@snippet.parent_id = @parent_item.id
|
||||
session[:last_page] = get_go_back || admin_items_url
|
||||
end
|
||||
|
||||
def edit
|
||||
@snippet = Snippet.find(params[:id])
|
||||
session[:last_page] = get_go_back || admin_items_url
|
||||
end
|
||||
|
||||
def create
|
||||
@snippet = Snippet.new(params[:snippet])
|
||||
|
||||
if @snippet.save
|
||||
flash[:notice] = 'Snippet was successfully created.'
|
||||
redirect_to admin_items_url( :parent_name => @snippet.parent_name )
|
||||
flash[:notice] = t('admin.create_success_snippet')
|
||||
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
@@ -32,8 +35,8 @@ class Admin::SnippetsController < ApplicationController
|
||||
@snippet = Snippet.find(params[:id])
|
||||
|
||||
if @snippet.update_attributes(params[:snippet])
|
||||
flash[:notice] = 'Snippet was successfully updated.'
|
||||
redirect_to admin_items_url( :parent_name => @snippet.parent_name )
|
||||
flash[:notice] = t('admin.update_success_snippet')
|
||||
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
@@ -43,7 +46,7 @@ class Admin::SnippetsController < ApplicationController
|
||||
@snippet = Snippet.find(params[:id])
|
||||
@snippet.destroy
|
||||
|
||||
redirect_to admin_items_url( :parent_name => @snippet.parent_name )
|
||||
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,78 @@
|
||||
class Admin::TranslationsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
def index
|
||||
set_variables
|
||||
end
|
||||
|
||||
def edit
|
||||
set_variables
|
||||
session[:last_page] = get_go_back || admin_translations_url
|
||||
end
|
||||
|
||||
# Update either the i18n_variables or the languages
|
||||
def update
|
||||
begin
|
||||
case params[:id]
|
||||
# Update the i18n_variables
|
||||
when 'all'
|
||||
params[:i18n_variables].each do |id, var|
|
||||
i18n_variable = I18nVariable.find(id)
|
||||
i18n_variable.update_attributes(var)
|
||||
end
|
||||
# Add a language
|
||||
when 'add'
|
||||
site = Site.find(session[:site])
|
||||
if !site.valid_locales.include?(params[:language])
|
||||
site.valid_locales << params[:language]
|
||||
site.save
|
||||
I18nVariable.create({:key => params[:language], :document_class => 'language'})
|
||||
end
|
||||
# Enable a language
|
||||
when 'enable'
|
||||
site = Site.find(session[:site])
|
||||
if !site.in_use_locales.include?(params[:enable_language])
|
||||
site.in_use_locales << params[:enable_language]
|
||||
site.save
|
||||
end
|
||||
# Disable a language
|
||||
when 'disable'
|
||||
site = Site.find(session[:site])
|
||||
if site.in_use_locales.include?(params[:disable_language])
|
||||
site.in_use_locales.delete(params[:disable_language])
|
||||
site.save
|
||||
end
|
||||
# Delete a language and the corresponding i18n_variables
|
||||
when 'delete'
|
||||
site = Site.find(session[:site])
|
||||
site.in_use_locales.delete(params[:delete_language])
|
||||
site.valid_locales.delete(params[:delete_language])
|
||||
site.save
|
||||
I18nVariable.destroy_all(:conditions => {:document_class => 'language', :key => params[:delete_language]})
|
||||
end
|
||||
redirect_to admin_translations_url
|
||||
rescue
|
||||
set_variables
|
||||
render :action => :edit
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Get the i18n_variables and languages
|
||||
def set_variables
|
||||
@i18n_variables = I18nVariable.all.entries
|
||||
@language_i18n_variables = @i18n_variables.inject([]) do |result, var|
|
||||
result << var if var.document_class.eql?('language')
|
||||
result
|
||||
end
|
||||
@user_attribute_model_i18n_variables = @i18n_variables.inject([]) do |result, var|
|
||||
result << var if var.document_class.eql?('UserAttributeModel')
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,48 @@
|
||||
class Admin::UserAttributeModelsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
def index
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
end
|
||||
|
||||
def show
|
||||
@user_attribute_model = UserAttributeModel.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@user_attribute_model = UserAttributeModel.new
|
||||
session[:last_page] = get_go_back || admin_user_attribute_models_url
|
||||
end
|
||||
|
||||
def edit
|
||||
@user_attribute_model = UserAttributeModel.find(params[:id])
|
||||
@i18n_variable = @user_attribute_model.i18n_variable
|
||||
session[:last_page] = get_go_back || admin_user_attribute_models_url
|
||||
end
|
||||
|
||||
def create
|
||||
@user_attribute_model = UserAttributeModel.new(params[:user_attribute_model])
|
||||
@user_attribute_model.save
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
||||
def update
|
||||
@user_attribute_model = UserAttributeModel.find(params[:id])
|
||||
@user_attribute_model.update_attributes(params[:user_attribute_model])
|
||||
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
||||
def destroy
|
||||
@user_attribute_model = UserAttributeModel.find(params[:id])
|
||||
@user_attribute_model.destroy
|
||||
|
||||
@user_attribute_model.destroy_i18n_variables
|
||||
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,10 +2,41 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
|
||||
helper :all
|
||||
before_filter :set_locale
|
||||
before_filter :set_locale, :set_site
|
||||
|
||||
Liquid::Template.register_filter(SnippetFilter)
|
||||
# Find the parent for the given item
|
||||
def find_parent_item
|
||||
@parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil
|
||||
end
|
||||
|
||||
|
||||
# Clean the link back
|
||||
# Remove the locale but keep all the other params
|
||||
def get_go_back
|
||||
begin
|
||||
if env['REQUEST_URI'].include?('locale=')
|
||||
session[:last_page]
|
||||
else
|
||||
target = env['HTTP_REFERER'].split('?')
|
||||
vars = target[1].split('&')
|
||||
vars.delete_if {|var| var.include? 'locale=' }
|
||||
if vars.size > 0
|
||||
target[0].to_s + '?' + vars.join('&')
|
||||
else
|
||||
target[0].to_s
|
||||
end
|
||||
end
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
# Check if the current_user is admin
|
||||
def is_admin?
|
||||
redirect_to root_url unless current_user.admin?
|
||||
end
|
||||
|
||||
# Parse and render the pages with liquid
|
||||
def render_liquid_page
|
||||
if @page
|
||||
@layout = @page.layout
|
||||
@@ -18,26 +49,31 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Set I18n.locale
|
||||
def set_locale
|
||||
# update session if passed
|
||||
if params[:locale] && VALID_LOCALES.include?( params[:locale] )
|
||||
session[:locale] = params[:locale]
|
||||
end
|
||||
|
||||
session[:locale] = params[:locale] if params[:locale]
|
||||
|
||||
# set locale based on session or default
|
||||
I18n.locale = session[:locale] || I18n.default_locale
|
||||
end
|
||||
|
||||
def find_parent_item
|
||||
@parent_item = Item.find_by_name(params[:parent_name] || 'root')
|
||||
unless @parent_item
|
||||
@parent_item = Page.create( :name => "root", :title => "root", :layout_name => "root" )
|
||||
end
|
||||
end
|
||||
|
||||
def require_entry_name
|
||||
render :text => 'missing entry_name' if params[:entry_name].blank?
|
||||
return
|
||||
begin
|
||||
# check if locale is valid for non site pages
|
||||
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) && !VALID_LOCALES.include?(session[:locale])
|
||||
I18n.locale = I18n.default_locale
|
||||
else
|
||||
I18n.locale = session[:locale]
|
||||
end
|
||||
rescue
|
||||
I18n.locale = I18n.default_locale
|
||||
end
|
||||
end
|
||||
|
||||
# Set the site variables
|
||||
def set_site
|
||||
# set site if exist or create site
|
||||
site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []})
|
||||
session[:site] = site.id
|
||||
@site_in_use_locales = site.in_use_locales
|
||||
@site_valid_locales = site.valid_locales
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
class PagesController < ApplicationController
|
||||
|
||||
def index
|
||||
@page = Page.find_by_name('root')
|
||||
@page = Home.find_by_name('home')
|
||||
if @page
|
||||
render_liquid_page
|
||||
else
|
||||
@@ -10,8 +10,15 @@ class PagesController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
@page = Page.find_by_full_name(params[:page_name])
|
||||
render_liquid_page
|
||||
item = Item.first(:conditions => {:full_name => params[:page_name]})
|
||||
case item._type
|
||||
when 'Page'
|
||||
@page = item
|
||||
render_liquid_page
|
||||
when 'Link'
|
||||
redirect_to "http://#{item[:url]}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -4,7 +4,7 @@ class Panel::UsersController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
@users = User.all
|
||||
@users = User.all.entries
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -13,7 +13,8 @@ class Panel::UsersController < ApplicationController
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
@user_attributes = UserAttribute.all
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
session[:last_page] = get_go_back || panel_users_url
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -27,14 +28,21 @@ class Panel::UsersController < ApplicationController
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
@user_attributes = UserAttribute.all
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
session[:last_page] = get_go_back || panel_users_url
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
|
||||
# Update changes to the avatar
|
||||
@user.remove_avatar! if params[:file]
|
||||
@user.avatar = params[:file] if params[:file]
|
||||
|
||||
if @user.update_attributes(params[:user])
|
||||
redirect_to :action => :index
|
||||
else
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
render :action => :edit
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class SitesController < ApplicationController
|
||||
|
||||
#layout 'set_up'
|
||||
|
||||
def index
|
||||
@site = Site.first
|
||||
if @site
|
||||
@title = "site"
|
||||
else
|
||||
redirect_to :action => :new
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@site = Site.new
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user