Chris's first commit at Fri Jan 28 2011 10:14:32 GMT+0800 (CST)

This commit is contained in:
ihower committed 2011-04-13 18:19:51 +08:00
1 parent 554aa0a95d
commit 19a7d51e60
145 files changed
+12742 -893

No files matched your search

+8 -8
View File
@@ -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
+52
View File
@@ -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
+19 -16
View File
@@ -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
+10 -7
View File
@@ -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"
+10 -6
View File
@@ -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
+10 -7
View File
@@ -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
+9 -6
View File
@@ -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
+55 -19
View File
@@ -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
+10 -3
View File
@@ -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
+11 -3
View File
@@ -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
+18
View File
@@ -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
+3 -3
View File
@@ -1,8 +1,8 @@
module AdminHelper
def show_parent_items_link(parent_item)
@parent_items = @parent_item.ancestors.map{ |i| i.name }
( @parent_items.map{ |i| link_to(i, admin_items_path(:parent_name=>i) ) } << parent_item.name ).join("/").html_safe
def show_parent_items_link
@parent_items = @parent_item.ancestors.map{ |i| i }
link_to('/' , admin_items_path) + ( @parent_items.map{ |i| link_to(i.name, admin_items_path(:parent_id=>i.id) ) } << @parent_item.name ).join("/").html_safe
end
end
+9
View File
@@ -1,2 +1,11 @@
module ApplicationHelper
def colorize_in_use_locale(locale)
@site_in_use_locales.include?(locale)? 'green' : 'red'
end
def link_back
link_to t('back'), session[:last_page]
end
end
+2
View File
@@ -0,0 +1,2 @@
module SitesHelper
end
+6 -35
View File
@@ -1,41 +1,12 @@
class Asset
include MongoMapper::Document
include Grip::HasAttachment
include Mongoid::Document
key :filename, String, :required => true
key :description, String
mount_uploader :data, AssetUploader
has_grid_attachment :data, :required => true
field :filename
field :description
before_validation :setup_filename
after_save :save_static_file
after_destroy :delete_static_file
validates_presence_of :filename, :data
def url
"/assets/#{self.filename}"
end
def location
"#{RAILS_ROOT}/public/assets/#{self.filename}"
end
protected
def setup_filename
if self.filename.blank? && self.data
self.filename = self.data.file_name
end
end
def save_static_file
f = File.new(self.location, "wb")
f.write(self.data.file.read)
f.close
end
def delete_static_file
File.delete(self.location) rescue nil
end
end
end
+50
View File
@@ -0,0 +1,50 @@
class AttributeAttrModel
include Mongoid::Document
field :key
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
field :markup
field :locale, :type => Boolean
field :options, :type => Array
embedded_in :user_attribute_model, :inverse_of => :attribute_attr_models
validates_uniqueness_of :key
# Destroy the i18n_variable
def destroy_i18n_variable
self.i18n_variable.destroy rescue nil
end
# Get the i18n_variable
def i18n_variable
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
end
# Update or create the i18n_variable record
def i18n_variable=(attr)
if self.i18n_variable_id
self.i18n_variable.update_attributes(attr)
else
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.user_attribute_model.i18n_variable_id}))
var.save
self.i18n_variable_id = var.id
end
end
# Convert the string options into an array
def select_options=(var)
self.options = var.gsub(' ', '').split(',')
end
# Convert the array options into a string
def select_options
self.options.to_a.join(', ')
end
# Check if the attribute_attr is set to be destroyed
def should_destroy?
should_destroy.to_i == 1 rescue nil
end
end
+10
View File
@@ -0,0 +1,10 @@
class Home < Page
private
# Remove the validation for parent_id
def validates_presence_of_parent_id?
false
end
end
+13
View File
@@ -0,0 +1,13 @@
class I18nLiquid < Liquid::Tag
def initialize(tag_name, value, tokens)
super
@value = value.to_s
end
def render(context)
I18nVariable.first(:conditions => {:key => @value})[I18n.locale] rescue ''
end
end
Liquid::Template.register_tag('t', I18nLiquid)
+9
View File
@@ -0,0 +1,9 @@
class I18nVariable
include Mongoid::Document
field :key
field :document_class
field :parent_id, :index => true
end
+52 -32
View File
@@ -1,66 +1,86 @@
class Item
include MongoMapper::Document
include Mongoid::Document
key :_type, String
key :name, String, :required => true, :index => true
key :full_name, String, :required => true, :index => true
key :parent_id, ObjectId, :index => true
key_i18n :title, String, :required => true
key :position, Integer, :required => true
key :is_published, Boolean, :required => true, :default => true, :index => true
field :name, :index => true
field :full_name, :index => true
field :i18n_variable_id, :type => BSON::ObjectId
field :parent_id, :index => true
field :parent_name
field :position, :type => Integer
field :is_published, :type => Boolean, :default => true, :index => true
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
validates_uniqueness_of :name, :scope => :parent_id
validates_presence_of :name, :full_name, :position, :is_published
validates_presence_of :parent_id, :if => :validates_presence_of_parent_id?
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy
referenced_in :parent, :class_name => "Item"
references_many :children, :class_name => "Item"
before_validation :setup_default_value
attr_accessor :parent_name
def parent_name
@parent_name || self.parent.name
end
def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true })
end
# Get an array of ancestors
def ancestors
node, nodes = self, []
nodes << node = node.parent while !node.parent.blank?
nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
# Update or create the i18n_variable record
def i18n_variable=(attr)
if self.i18n_variable_id
self.i18n_variable.update_attributes(attr) rescue nil
else
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class}))
var.save
self.i18n_variable_id = var.id
end
end
# Get the i18n_variable
def i18n_variable
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
end
# Check if the page is home
def is_home?
self.name.eql?('home') && self.parent_id.nil?
end
# Build the url from the array of ancestors
def url
urls = ancestors.map{ |a| a.name } << self.name
urls.delete("root")
"/#{urls.join("/")}"
urls.join("/")
end
protected
def setup_default_value
# Set the position value within the parent scope
if self.position.blank?
max_page = Page.last(:order => 'position')
self.position = (max_page)? max_page.position.to_i + 1 : 1
max_page = Item.where(:parent_id => self.parent_id).count
self.position = (max_page)? max_page + 1 : 1
end
if self.parent_name.blank?
self.parent_name = nil
self.parent_id = nil
else
self.parent_id = Item.find_by_name( self.parent_name ).id
end
# Set the parent value
self.parent_name = Item.first(:conditions => {:id => self.parent_id} ).name rescue nil
# Build the full_name from the ancestors array
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
# Remove root node if not root
full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/")
end
# Enable the validation for parent_id
def validates_presence_of_parent_id?
true
end
end
end
+10 -5
View File
@@ -1,14 +1,19 @@
class Layout
include MongoMapper::Document
include Mongoid::Document
key :name, String, :required => true, :index => true
key :description, String
key_i18n :content, String
field :name, :index => true
field :description
field :content
many :children, :class_name => "Item", :foreign_key => "layout_id", :dependent => :nullify
references_many :children, :class_name => "Item"
validates_presence_of :name
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates_uniqueness_of :name
def self.exist_one?
Layout.count > 0
end
end
+5 -3
View File
@@ -1,9 +1,11 @@
class Link < Item
key :url, String, :required => true
field :url
validates_presence_of :url
def link
ApplicationController.helpers.link_to(self.title, self.url)
ApplicationController.helpers.link_to(self.name, self.url)
end
end
end
+8 -6
View File
@@ -1,12 +1,14 @@
class Page < Item
include LayoutSupport
#include LayoutSupport
key_i18n :content, String
key :layout_name, String, :required => true
key :layout_id, ObjectId, :required => true
field :content
field :layout_name
field :layout_id
belongs_to :layout
validates_presence_of :layout_name, :layout_id
referenced_in :layout
protected
@@ -14,7 +16,7 @@ class Page < Item
super
if self.layout_name
self.layout_id = Layout.find_by_name( self.layout_name ).id
self.layout_id = Layout.first(:conditions => {:name => self.layout_name} ).id
end
end
+8
View File
@@ -0,0 +1,8 @@
class Site
include Mongoid::Document
field :in_use_locales, :type => Array
field :valid_locales, :type => Array
end
+33 -34
View File
@@ -1,38 +1,37 @@
class Snippet
include MongoMapper::Document
include Mongoid::Document
key :name, String, :required => true, :index => true
key :full_name, String, :required => true, :index => true
key :parent_id, ObjectId, :required => true, :index => true
key_i18n :content, String
before_validation :setup_default_value
validates_uniqueness_of :name, :scope => :parent_id
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
attr_accessor :parent_name
def parent_name
@parent_name || self.parent.name
end
protected
field :name, :index => true
field :full_name, :index => true
field :parent_id, :index => true
field :parent_name
field :content
before_validation :setup_default_value
validates_presence_of :name, :full_name, :parent_id
validates_uniqueness_of :name, :scope => :parent_id
referenced_in :parent, :class_name => "Item", :foreign_key => :parent_id
def ancestors
node, nodes = self, []
nodes << node = node.parent while !node.parent.blank?
nodes.reverse
end
def setup_default_value
self.parent_id = Item.find_by_name( self.parent_name || 'root' ).id
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/")
end
end
# Get an array of ancestors
def ancestors
node, nodes = self, []
nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
def setup_default_value
# Set the parent value
self.parent_name = Item.find( self.parent_id ).name rescue nil
# Build the full_name from the ancestors array
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
# Remove root node if not root
full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/")
end
end
+18 -4
View File
@@ -1,13 +1,27 @@
module SnippetFilter
def render_snippet(snippet_name)
snippet = Snippet.find_by_name(snippet_name)
snippet = Snippet.first(:conditions => {:name => snippet_name})
if snippet
return Liquid::Template.parse( snippet.content ).render
else
return "nothing"
return t('nothing')
end
end
end
def ruling_snippet(snippet_name)
case snippet_name
when 'language_bar'
site = Site.first
@site_in_use_locales = site.in_use_locales
@site_valid_locales = site.valid_locales
end
return Liquid::Template.parse( eval(File.open("#{RAILS_ROOT}/lib/snippets/#{snippet_name}.snippet").read) ).render
end
end
Liquid::Template.register_filter(SnippetFilter)
+46 -10
View File
@@ -1,18 +1,54 @@
class User
include MongoMapper::Document
include Mongoid::Document
devise :authenticatable, :recoverable, :rememberable, :trackable
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
key :use_attributes, Array
mount_uploader :avatar, AvatarUploader
def method_missing(method)
safe_read(method)
field :admin, :type => Boolean, :default => false
field :active_attributes, :type => Array
embeds_many :user_attributes
before_update :clean_active_attributes
# Update or create the user_attribute records
def user_attributes=(attrs)
attrs.each do |attributes|
if attributes[:id].blank?
user_attributes.build(attributes)
else
user_attribute = user_attributes.detect {|a| a.id.to_s == attributes[:id].to_s }
user_attribute.update_attributes(attributes)
end
end
end
def safe_read(key)
self[key]
rescue MongoMapper::KeyNotFound
return ""
# Get an user_attribute from model key
def get_attribute_from_model_key(key)
self.user_attributes.detect {|a| a.key.to_s == key.to_s }
end
end
# Get the active user_attribute_models
def get_active_attribute_models
self.active_attributes.map{ |attr| get_attribute_model(attr) }
end
# Get an user_attribute_model from key
def get_attribute_model(key)
UserAttributeModel.first(:conditions => {:key => key})
end
# Get the active attributes names or default to '-'
def get_attributes
(self.active_attributes.nil? || self.active_attributes.empty?) ? '-' : self.active_attributes.map{|attr| I18nVariable.first(:conditions => {:key => attr})[I18n.locale] rescue attr}.join(' / ')
end
protected
# Remove empty values
def clean_active_attributes
self.active_attributes.delete('') if self.active_attributes
end
end
+4 -4
View File
@@ -1,9 +1,9 @@
class UserAttribute
include MongoMapper::Document
include Mongoid::Document
key :key, String
key_i18n :name, String
key :attrs, Array
field :key
embedded_in :user, :inverse_of => :user_attributes
end
+59
View File
@@ -0,0 +1,59 @@
class UserAttributeModel
include Mongoid::Document
field :key
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
embeds_many :attribute_attr_models
after_update :destroy_attrs
# Update or create the attribute_attr_model records
def attribute_attr_models=(attrs)
attrs.each do |attributes|
if attributes[:id].blank?
attribute_attr_models.build(attributes)
else
attribute_attr_model = attribute_attr_models.detect {|a| a.id.to_s == attributes[:id].to_s }
attribute_attr_model.update_attributes(attributes)
end
end
end
# Destroy the i18n_variables
def destroy_i18n_variables
self.i18n_variable.destroy rescue nil
self.attribute_attr_models.each do |attr|
attr.destroy_i18n_variable
end
end
# Update or create the i18n_variable record
def i18n_variable=(attr)
if self.i18n_variable_id
self.i18n_variable.update_attributes(attr) rescue nil
else
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class}))
var.save
self.i18n_variable_id = var.id
end
end
# Get the i18n_variable
def i18n_variable
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
end
protected
# Destroy the attribute_attr_models if marked to destroy
def destroy_attrs
attribute_attr_models.each do |a|
if a.should_destroy?
a.destroy
end
end
end
end
+47
View File
@@ -0,0 +1,47 @@
# encoding: utf-8
class AssetUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
# storage :file
# storage :s3
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"assets/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# def filename
# "something.jpg" if original_filename
# end
end
+62
View File
@@ -0,0 +1,62 @@
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::ImageScience
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
# storage :file
# storage :s3
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"avatar/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
version :thumb do
process :resize_to_fit => [80, 80]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# def filename
# "something.jpg" if original_filename
# end
# def manipulate!
# raise current_path.inspect
# image = ::MiniMagick::Image.open(current_path)
# image = yield(image)
# image.write(current_path)
# ::MiniMagick::Image.open(current_path)
# rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
# raise CarrierWave::ProcessingError.new("Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: #{e}")
# end
end
+3 -5
View File
@@ -1,16 +1,14 @@
<%= f.error_messages %>
<p>
<%= f.label :filename, "FileName" %>
<%= f.label :filename, t('admin.file_name') %>
<%= f.text_field :filename, :class => 'text' %>
</p>
<p>
<%= f.label :description, "Description" %>
<%= f.label :description, t('admin.description') %>
<%= f.text_field :description, :class => 'text' %>
</p>
<p>
<%= f.label :data, "Data" %>
<%= f.label :data, t('admin.data') %>
<%= f.file_field :data %>
</p>
+3 -5
View File
@@ -1,12 +1,10 @@
<h1>Editing assets</h1>
<h1><%= t('editing_asset') %></h1>
<% form_for @asset, :url => admin_asset_path(@asset), :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Update' %>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>
<%= link_to 'Back', admin_assets_path %>
+21 -20
View File
@@ -1,31 +1,32 @@
<h1>Listing assets</h1>
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1><%= t('admin.list_assets') %></h1>
<table>
<tr>
<th>檔案</th>
<th>描述</th>
<th>格式</th>
<th>原上傳檔名</th>
<th>檔案大小</th>
<th></th>
<th></th>
<th><%= t('admin.file_name') %></th>
<th><%= t('admin.description') %></th>
<th><%= t('admin.format') %></th>
<th><%= t('admin.orig_upload_file') %></th>
<th><%= t('admin.file_name') %></th>
<th><%= t('admin.action') %></th>
</tr>
<% @assets.each do |asset| %>
<tr>
<td><%#= link_to asset.filename, admin_asset_path(asset) %>
<%= link_to asset.url, asset.url %>
</td>
<td><%= link_to asset.filename, asset.data.url, :target => '_blank' %></td>
<td><%= asset.description %></td>
<td><%= asset.data.content_type %></td>
<td><%= asset.data.file_name %></td>
<td><%= number_to_human_size(asset.data.file_size) %></td>
<td><%= link_to t(:edit), edit_admin_asset_path(asset) %></td>
<td><%= link_to t(:delete), admin_asset_path(asset), :confirm => 'Are you sure?', :method => :delete %></td>
<td><%= asset.data.file.content_type %></td>
<td><%= asset.data_filename %></td>
<td><%= number_to_human_size(asset.data.file.file_length) %></td>
<td>
<%= link_to t(:edit), edit_admin_asset_path(asset) %> |
<%= link_to t(:delete), admin_asset_path(asset), :confirm => t('sure?'), :method => :delete %>
</td>
</tr>
<% end %>
</table>
<br />
<%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :class => 'button positive' %>
+4 -5
View File
@@ -1,11 +1,10 @@
<h1>New Asset</h1>
<h1><%= t('admin.new_asset') %></h1>
<% form_for :asset, :url => admin_assets_path, :html => { :multipart => true } do |f| %>
<%= form_for :asset, :url => admin_assets_path, :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Create' %>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end %>
<% end %>
+30
View File
@@ -0,0 +1,30 @@
<%= f.hidden_field :parent_id %>
<p>
<%= f.label :name, t('admin.name') %>
<%= f.text_field :name, :class => 'text', :value => 'home', :disabled => true %>
<%= f.hidden_field :name, :value => 'home' %>
</p>
<% @site_valid_locales.each do |locale| %>
<p>
<%= label_tag "#{f}[title]", "#{t('admin.title')} #{locale}" %>
<%= text_field_tag "#{f}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
</p>
<% end %>
<p>
<%= f.label :layout_name, t('admin.layout_name') %>
<%= f.select :layout_name, Layout.all.map{ |l| [l.description, l.name] } %>
</p>
<p>
<%= f.label "content", t('admin.content') %>
<%= f.text_area "content", :size => '100x30' %>
</p>
<p>
<%= f.label :is_published, "#{t('admin.is_published')} ?" %>
<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
</p>
+10
View File
@@ -0,0 +1,10 @@
<h1><%= t('admin.editing_home') %></h1>
<%= form_for @home, :url => admin_home_path(@home) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>
+11
View File
@@ -0,0 +1,11 @@
<h1><%= t('admin.new_home') %></h1>
<%= form_for :home, :url => admin_homes_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end %>
+1 -1
View File
@@ -7,5 +7,5 @@
<td>
<%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_component_path(item) %> |
<%= link_to t(:delete), admin_component_path(item), :confirm => 'Are you sure?', :method => :delete %>
<%= link_to t(:delete), admin_component_path(item), :confirm => t('sure?'), :method => :delete %>
</td>
+10
View File
@@ -0,0 +1,10 @@
<td><%= item.class %></td>
<td><%= link_to item.name, admin_items_path(:parent_id => item.id) %></td>
<td><%= item.i18n_variable[I18n.locale] rescue nil %>
<td><%= item.position %></td>
<td><%= item.is_published.to_s %></td>
<td>
<%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_home_path(item) %> |
<%= link_to t(:delete), admin_home_path(item), :confirm => t('sure?'), :method => :delete %>
</td>
+10 -11
View File
@@ -1,11 +1,10 @@
<td><%= item.class %></td>
<td><%= link_to item.name, admin_items_path(:parent_name => item.name) %></td>
<td><%=h item.title %>
<td><%= item.position %></td>
<td><%= item.is_published.to_s %></td>
<td>
<%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_link_path(item) %> |
<%= link_to t(:delete), admin_link_path(item), :confirm => 'Are you sure?', :method => :delete %>
</td>
<td><%= item.class %></td>
<td><%= item.name %></td>
<td><%= item.i18n_variable[I18n.locale] rescue nil %>
<td><%= item.position %></td>
<td><%= item.is_published.to_s %></td>
<td>
<%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_link_path(item) %> |
<%= link_to t(:delete), admin_link_path(item), :confirm => t('sure?'), :method => :delete %>
</td>
+4 -4
View File
@@ -1,11 +1,11 @@
<td><%= item.class %></td>
<td><%= link_to item.name, admin_items_path(:parent_name => item.name) %></td>
<td><%=h item.title %>
<td><%= link_to item.name, admin_items_path(:parent_id => item.id) %></td>
<td><%= item.i18n_variable[I18n.locale] rescue nil %>
<td><%= item.position %></td>
<td><%= item.is_published.to_s %></td>
<td>
<%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_page_path(item) %> |
<%= link_to t(:delete), admin_page_path(item), :confirm => 'Are you sure?', :method => :delete %>
</td>
<%= link_to t(:delete), admin_page_path(item), :confirm => t('sure?'), :method => :delete %>
</td>
+3 -3
View File
@@ -1,4 +1,4 @@
<h1>Listing snippets</h1>
<h1><%= t('admin.list_snippets') %></h1>
<table>
<tr>
@@ -9,7 +9,7 @@
<td><%= snippet.name %></td>
<td><%= link_to t(:show), admin_snippet_path(snippet) %>
<td><%= link_to t(:edit), edit_admin_snippet_path(snippet) %></td>
<td><%= link_to t(:delete), admin_snippet_path(snippet), :confirm => 'Are you sure?', :method => :delete %></td>
<td><%= link_to t(:delete), admin_snippet_path(snippet), :confirm => t('sure?'), :method => :delete %></td>
</tr>
<% end %>
<% end if snippets%>
</table>
+37 -25
View File
@@ -1,32 +1,44 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_page, :scope => :admin), new_admin_page_path( :parent_name => @parent_item.name ), :class => 'button positive' %></li>
<li><%= link_to t(:new_link, :scope => :admin), new_admin_link_path( :parent_name => @parent_item.name ) %>
<li><%= link_to t(:new_snippet, :scope => :admin ), new_admin_snippet_path( :parent_name => @parent_item.name ), :class => 'button positive' %></li>
</ul>
<ul class="list">
<% if (@items.empty? && !@parent_item ) || (!@items.empty? && @items[0].is_home?) %>
<li><%= t('admin.new_page') %></li>
<li><%= t('admin.new_link') %></li>
<li><%= t('admin.new_snippet') %></li>
<% else %>
<li><%= link_to t('admin.new_page'), new_admin_page_path( :parent_id => @parent_item.id ), :class => 'button positive' %></li>
<li><%= link_to t('admin.new_link'), new_admin_link_path( :parent_id => @parent_item.id ) %>
<li><%= link_to t('admin.new_snippet'), new_admin_snippet_path( :parent_id => @parent_item.id ), :class => 'button positive' %></li>
<% end %>
</ul>
<% end -%>
<h1>Listing items: <%= show_parent_items_link(@parent_item) %></h1>
<h1><%= t('admin.list_items') %>: <%= show_parent_items_link unless @parent_item.nil? %></h1>
<table>
<tr>
<th>Class</th>
<th>Name</th>
<th>Title</th>
<th>Position</th>
<th>Published?</th>
<th>Action</th>
<th></th>
</tr>
<% @items.each do |item| %>
<tr>
<%= render :partial => item.class.to_s.downcase, :locals => { :item => item } %>
<!--<td><%= link_to t(:move_up, :scope => :admin), up_admin_item_path(item), :method => :put %> |
<%= link_to t(:move_down, :scope => :admin), down_admin_item_path(item), :method => :put %></td>-->
</tr>
<% if !Layout.exist_one? %>
<div style='color:red'><%= t('admin.no_layout') %>: <%= link_to t('create').downcase, new_admin_layout_path %></div>
<br/>
<% elsif (@items.empty? && !@parent_item ) %>
<div style='color:red'><%= t('admin.no_home_page') %>: <%= link_to t('create').downcase, new_admin_home_path(:parent_id => nil) %></div>
<br/>
<% else %>
<table>
<tr>
<th><%= t('admin.class') %></th>
<th><%= t('admin.name') %></th>
<th><%= t('admin.title') %></th>
<th><%= t('admin.position') %></th>
<th><%= t('admin.published?') %></th>
<th><%= t('admin.action') %></th>
<th></th>
</tr>
<% @items.each do |item| %>
<tr>
<%= render :partial => item.class.to_s.downcase, :locals => { :item => item } %>
<!--<td><%= link_to t(:move_up, :scope => :admin), up_admin_item_path(item), :method => :put %> |
<%= link_to t(:move_down, :scope => :admin), down_admin_item_path(item), :method => :put %></td>-->
</tr>
<% end if @items %>
</table>
<% end %>
</table>
<%= render :partial => "snippets", :locals => { :snippets => @snippets } %>
+5 -21
View File
@@ -1,30 +1,14 @@
<p>
<%= f.label :name, "Name" %>
<%= f.label :name, t('admin.name') %>
<%= f.text_field :name, :class => 'text' %>
</p>
<p>
<%= f.label :description, "Description" %>
<%= f.label :description, t('admin.description') %>
<%= f.text_field :description, :class => 'text' %>
</p>
<p id="content_zh_tw_block">
<%= f.label "content_zh_tw", "Content (zh_tw)" %>
<%= f.text_area "content_zh_tw", :size => '100x30' %>
<p>
<%= f.label "content", t('admin.content') %>
<%= f.text_area :content, :size => '100x30' %>
</p>
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
<p id="content_en_block">
<%= f.label "content_en", "Content (en)" %>
<%= f.text_area "content_en", :size => '100x30' %>
</p>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#content_en_block').hide();
$('#toggle_content_en_block').click(function(){
$('#content_en_block').toggle();
});
</script>
<% end -%>
+3 -6
View File
@@ -1,12 +1,9 @@
<h1>Editing layouts</h1>
<h1><%= t('admin.editing_layout') %></h1>
<% form_for @layout, :url => admin_layout_path(@layout) do |f| %>
<%= form_for @layout, :url => admin_layout_path(@layout) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Update' %>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>
<%= link_to 'Back', admin_layouts_path %>
+14 -7
View File
@@ -1,19 +1,26 @@
<h1>Listing layouts</h1>
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_layout, :scope => :admin), new_admin_layout_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1><%= t('admin.list_layouts') %></h1>
<table>
<tr>
<th><%= t('admin.name') %></th>
<th><%= t('admin.description') %></th>
<th><%= t('admin.action') %></th>
</tr>
<% @layouts.each do |layout| %>
<tr>
<td><%= layout.name %></td>
<td><%= layout.description %></td>
<td><%= link_to t(:edit), edit_admin_layout_path(layout) %></td>
<td><%= link_to t(:delete), admin_layout_path(layout), :confirm => 'Are you sure?', :method => :delete %></td>
<td>
<%= link_to t(:edit), edit_admin_layout_path(layout) %> |
<%= link_to t(:delete), admin_layout_path(layout), :confirm => t('sure?'), :method => :delete %>
</td>
</tr>
<% end %>
</table>
<br />
<%= link_to t(:new_layout, :scope => :admin), new_admin_layout_path, :class => 'button positive' %>
+3 -6
View File
@@ -1,13 +1,10 @@
<h1>New layouts</h1>
<h1><%= t('admin.new_layout') %></h1>
<% form_for :layout, :url => admin_layouts_path do |f| %>
<%= form_for :layout, :url => admin_layouts_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Create' %>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end %>
<%= link_to 'Back', admin_layouts_path %>
+9 -13
View File
@@ -1,28 +1,24 @@
<%= f.error_messages %>
<%= f.hidden_field :parent_name %>
<%= f.hidden_field :parent_id %>
<p>
<%= f.label :name, "Name" %>
<%= f.text_field :name, :class => 'text' %>
</p>
<p>
<%= f.label :title, "Title en" %>
<%= f.text_field :title_en, :class => 'text' %>
</p>
<% @site_valid_locales.each do |locale| %>
<p>
<%= label_tag "link[title]", "#{t('admin.title')} #{locale}" %>
<%= text_field_tag "link[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
</p>
<% end %>
<p>
<%= f.label :title, "Title zh_tw" %>
<%= f.text_field :title_zh_tw, :class => 'text' %>
</p>
<p>
<%= f.label :is_published, "Is Published" %>
<%= f.label :is_published, t('admin.is_published') %>
<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
</p>
<p>
<%= f.label :url, "URL" %>
<%= f.text_field :url %>
</p>
</p>
+4 -4
View File
@@ -1,10 +1,10 @@
<h1>Editing pages</h1>
<h1><%= t('admin.editing_link') %></h1>
<% form_for @link, :url => admin_link_path(@link) do |f| %>
<%= form_for @link, :url => admin_link_path(@link) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Update' %>
<%= f.submit t(:update) %> <%= link_back %>
</p>
<% end %>
<% end %>
+4 -4
View File
@@ -1,11 +1,11 @@
<h1><%= t(:new_link, :scope => :admin) %></h1>
<h1><%= t('admin.new_link') %></h1>
<% form_for @link, :url => admin_links_path do |f| %>
<%= form_for @link, :url => admin_links_path do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Create' %>
<%= f.submit t(:create) %> <%= link_back %>
</p>
<% end %>
<% end %>
+19 -34
View File
@@ -1,49 +1,34 @@
<%= f.error_messages %>
<%= f.hidden_field :parent_name %>
<%= f.hidden_field :parent_id %>
<p>
<%= f.label :name, "Name" %>
<%= f.text_field :name, :class => 'text' %>
</p>
<p>
<%= f.label :title, "Title en" %>
<%= f.text_field :title_en, :class => 'text' %>
<%= f.label :name, t('admin.name') %>
<% if @page.parent_id.nil? %>
<%= f.text_field :name, :class => 'text', :value => 'home', :disabled => true %>
<%= f.hidden_field :name, :value => 'home' %>
<% else %>
<%= f.text_field :name, :class => 'text' %>
<% end %>
</p>
<p>
<%= f.label :title, "Title zh_tw" %>
<%= f.text_field :title_zh_tw, :class => 'text' %>
</p>
<% @site_valid_locales.each do |locale| %>
<p>
<%= label_tag "#{f}[title]", "#{t('admin.title')} #{locale}" %>
<%= text_field_tag "#{f}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
</p>
<% end %>
<p>
<%= f.label :layout_name, "Layout Name" %>
<%= f.label :layout_name, t('admin.layout_name') %>
<%= f.select :layout_name, Layout.all.map{ |l| [l.description, l.name] } %>
</p>
<p id="content_zh_tw_block">
<%= f.label "content_zh_tw", "Content (zh_tw)" %>
<%= f.text_area "content_zh_tw", :size => '100x30' %>
</p>
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
<p id="content_en_block">
<%= f.label "content_en", "Content (en)" %>
<%= f.text_area "content_en", :size => '100x30' %>
<p>
<%= f.label "content", t('admin.content') %>
<%= f.text_area "content", :size => '100x30' %>
</p>
<p>
<%= f.label :is_published, "Is Published" %>
<%= f.label :is_published, "#{t('admin.is_published')} ?" %>
<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
</p>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#content_en_block').hide();
$('#toggle_content_en_block').click(function(){
$('#content_en_block').toggle();
});
</script>
<% end -%>
+6 -5
View File
@@ -1,10 +1,11 @@
<h1>Editing pages</h1>
<% form_for @page, :url => admin_page_path(@page) do |f| %>
<h1><%= t('admin.editing_page') %></h1>
<%= form_for @page, :url => admin_page_path(@page) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Update' %>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>
<% end %>
+4 -4
View File
@@ -1,11 +1,11 @@
<h1>New pages</h1>
<% form_for :page, :url => admin_pages_path do |f| %>
<h1><%= t('admin.new_page') %></h1>
<%= form_for :page, :url => admin_pages_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Create' %>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end %>
+5 -22
View File
@@ -1,28 +1,11 @@
<%= f.error_messages %>
<%= f.hidden_field :parent_name %>
<%= f.hidden_field :parent_id %>
<p>
<%= f.label :name, "Name" %>
<%= f.label :name, t('admin.name') %>
<%= f.text_field :name, :class => 'text' %>
</p>
<p id="content_zh_tw_block">
<%= f.label "content_zh_tw", "Content (zh_tw)" %>
<%= f.text_area "content_zh_tw", :size => '100x30' %>
<p>
<%= f.label "content", t('admin.content') %>
<%= f.text_area "content", :size => '100x30' %>
</p>
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
<p id="content_en_block">
<%= f.label "content_en", "Content (en)" %>
<%= f.text_area "content_en", :size => '100x30' %>
</p>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#content_en_block').hide();
$('#toggle_content_en_block').click(function(){
$('#content_en_block').toggle();
});
</script>
<% end -%>
+4 -4
View File
@@ -1,11 +1,11 @@
<h1>Editing snippets</h1>
<h1><%= t('admin.editing_snippet') %></h1>
<% form_for @snippet, :url => admin_snippet_path(@snippet) do |f| %>
<%= form_for @snippet, :url => admin_snippet_path(@snippet) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Update' %>
<%= f.submit 'Update' %> <%= link_back %>
</p>
<% end %>
<% end %>
+3 -3
View File
@@ -1,4 +1,4 @@
<h1>New snippets</h1>
<h1><%= t('admin.new_snippet') %></h1>
<% form_for :snippet, :url => admin_snippets_path do |f| %>
<%= f.error_messages %>
@@ -6,6 +6,6 @@
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit 'Create' %>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end %>
<% end %>
@@ -0,0 +1 @@
<a href="#" class="edit"><%= t(:edit) %></a> | <a href="#" class="hide"><%= t(:hide) %></a>
@@ -0,0 +1,16 @@
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<% @language_i18n_variables.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "i18n_variables[#{var.id}][#{locale}]", var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>
@@ -0,0 +1,34 @@
<% @vars = @i18n_variables.inject([]) do |result, var|
result << var if var.parent_id.to_s.eql?(edit_user_attribute_model.id.to_s)
result
end %>
<fieldset>
<legend>
<%= edit_user_attribute_model.key %>
<%#= render :partial => 'action_bar' %>
</legend>
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<tr>
<td><%= edit_user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "i18n_variables[#{edit_user_attribute_model.id}][#{locale}]", edit_user_attribute_model[locale] %></td>
<% end %>
</tr>
<% @vars.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "i18n_variables[#{var.id}][#{locale}]", var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>
</fieldset>
@@ -0,0 +1,16 @@
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<% @language_i18n_variables.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>
@@ -0,0 +1,34 @@
<% @vars = @i18n_variables.inject([]) do |result, var|
result << var if var.parent_id.to_s.eql?(user_attribute_model.id.to_s)
result
end %>
<fieldset>
<legend>
<%= user_attribute_model.key %>
<%#= render :partial => 'action_bar' %>
</legend>
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<tr>
<td><%= user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= user_attribute_model[locale] %></td>
<% end %>
</tr>
<% @vars.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>
</fieldset>
@@ -0,0 +1,25 @@
<%= form_tag admin_translation_path('all'), :method => :put do %>
<% if @language_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.language') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'edit_language' %></div>
</fieldset>
<% end %>
<% if @user_attribute_model_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.user_attribute') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'edit_user_attribute_model', :collection => @user_attribute_model_i18n_variables %></div>
</fieldset>
<% end %>
<%= submit_tag t('update') %> <%= link_back %>
<% end %>
@@ -0,0 +1,69 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:edit), edit_admin_translation_path('all'), :class => 'button positive' %></li>
<li>
<%= t('admin.add_language') %>:
<%= form_tag admin_translation_path('add'), :method => :put do %>
<%= text_field_tag 'language', '', :style => "width:100px" %>
<%= submit_tag t(:add) %>
<% end %>
</li>
<li>
<%= t('admin.enable_language') %>:
<%= form_tag admin_translation_path('enable'), :method => :put do %>
<%= select_tag 'enable_language', options_for_select(@site_valid_locales - @site_in_use_locales), :style => "width:100px" %>
<%= submit_tag t(:enable) %>
<% end %>
</li>
<li>
<%= t('admin.disable_language') %>:
<%= form_tag admin_translation_path('disable'), :method => :put do %>
<%= select_tag 'disable_language', options_for_select(@site_in_use_locales), :style => "width:100px" %>
<%= submit_tag t(:disable) %>
<% end %>
</li>
<li>
<%= t('admin.delete_language') %>:
<%= form_tag admin_translation_path('delete'), :method => :put do %>
<%= select_tag 'delete_language', options_for_select(@site_valid_locales), :style => "width:100px" %>
<%= submit_tag t(:delete), :confirm => t('sure?') %>
<% end %>
</li>
</ul>
<% end -%>
<% if @language_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.language') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'language' %></div>
</fieldset>
<% end %>
<% if @user_attribute_model_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.user_attribute') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'user_attribute_model', :collection => @user_attribute_model_i18n_variables %></div>
</fieldset>
<% end %>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('div a.hide').live( "click", function(){
$(this).parent().next().hide();
$(this).replaceWith("<a href='#' class='show'><%= t(:show) %></a>");
});
$('div a.show').live( "click", function(){
$(this).parent().next().show();
$(this).replaceWith("<a href='#' class='hide'><%= t(:hide) %></a>");
});
</script>
<% end -%>
@@ -0,0 +1,30 @@
<%= fields_for 'user_attribute_model[attribute_attr_models][]', attribute_attr_model, :index => nil do |f| %>
<tr>
<td><%= attribute_attr_model.new_record? ? (f.text_field :key, {:style => "width:130px"}) : attribute_attr_model.key %></td>
<td class='select_mulitlingual' style='text-align:center'>
<%= check_box_tag "locale[]", value = '', attribute_attr_model.locale.nil? ? true : attribute_attr_model.locale %>
<%= hidden_field_tag "user_attribute_model[attribute_attr_models][][locale]", attribute_attr_model.locale.nil? ? true : attribute_attr_model.locale %>
</td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "user_attribute_model[attribute_attr_models][][i18n_variable][#{locale}]", (attribute_attr_model.i18n_variable[locale] rescue nil), :style => "width:130px" %></td>
<% end %>
<td class='select_type'>
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
<div <%= attribute_attr_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
<%= t('admin.options') %>:
<%= text_field_tag "user_attribute_model[attribute_attr_models][][select_options]", attribute_attr_model.select_options, :style => "width:130px" %>
</div>
</td>
<td>
<% if attribute_attr_model.new_record? %>
<a href="#" class="remove">(<%= t(:delete) %>)</a>
<% else %>
<a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a>
<%= hidden_field_tag "user_attribute_model[attribute_attr_models][][should_destroy]", nil , :class => 'should_destroy' %>
<%= f.hidden_field :id %>
<% end %>
</td>
</tr>
<% end %>
@@ -0,0 +1,73 @@
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<tr>
<td><%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %>
<td>
<%= text_field_tag "user_attribute_model[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:130px" %>
</td>
<% end %>
</tr>
</table>
<fieldset id='field_set_attribute_attrs'>
<legend>
<%= t('admin.attributes')%>
</legend>
<table id='attribute_attrs'>
<tr>
<th><%= t('admin.key') %></th>
<th><%= t('admin.multilingual') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
<th><%= t('admin.type')%></th>
<th></th>
</tr>
<%= render :partial => 'attribute_attr_model', :collection => @user_attribute_model.attribute_attr_models %>
</table>
<a href="#" class="add">(<%= t(:add) %>)</a>
</fieldset>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#field_set_attribute_attrs a.remove').live('click', function(){
$(this).parent().parent().remove();
});
$('#field_set_attribute_attrs a.add').click(function(){
$('#attribute_attrs').append("<%= escape_javascript(render(:partial => 'attribute_attr_model', :object => @user_attribute_model.attribute_attr_models.build)) %>");
});
$('#field_set_attribute_attrs a.remove_existing_record').click(function(){
$(this).next('.should_destroy').attr('value', 1);
$(this).parent().parent().hide();
});
$('.select_mulitlingual input').live('click', function(){
$(this).next().attr('value', this.checked);
});
$('.select_type select').live('change', function(){
if(this.value == 'select')
{
$(this).next().show();
}
else
{
$(this).next().hide();
}
});
</script>
<% end -%>
@@ -0,0 +1,19 @@
<h1><%= t('admin.editing_user_attribute') %>: <%= @user_attribute_model.key %></h1>
<fieldset>
<legend>
<%= t('admin.user_attribute')%>
</legend>
<%= form_for @user_attribute_model, :url => admin_user_attribute_model_path(@user_attribute_model) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f, :is_new => false } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end -%>
</fieldset>
@@ -0,0 +1,26 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t('admin.new_user_attribute'), new_admin_user_attribute_model_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1><%= t('admin.list_user_attributes') %></h1>
<table>
<tr>
<th><%= t('admin.attribute') %></th>
<th><%= t('admin.key') %></th>
<th><%= t('admin.action') %></th>
</tr>
<% @user_attribute_models.each do |user_attribute_model| %>
<tr>
<td><%= user_attribute_model.i18n_variable[I18n.locale] %></td>
<td><%= user_attribute_model.key %></td>
<td>
<%= link_to t(:edit), edit_admin_user_attribute_model_path(user_attribute_model) %> |
<%= link_to t(:delete), admin_user_attribute_model_path(user_attribute_model), :confirm => t('sure?'), :method => :delete %>
</td>
</tr>
<% end %>
</table>
@@ -0,0 +1,19 @@
<h1><%= t('admin.new_user_attribute') %></h1>
<fieldset id='field_set_attribute_attrs'>
<legend>
<%= t('admin.user_attribute')%>
</legend>
<%= form_for @user_attribute_model, :url => admin_user_attribute_models_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f, :is_new => true } %>
<p>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end -%>
</fieldset>
@@ -0,0 +1,9 @@
<% if user_signed_in? %>
<li>
<%= link_to('Logout', destroy_user_session_path) %>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
</li>
<% end %>
@@ -0,0 +1,9 @@
<% if user_signed_in? %>
<li>
<%= link_to('Edit registration', edit_user_registration_path) %>
</li>
<% else %>
<li>
<%= link_to('Register', new_user_registration_path) %>
</li>
<% end %>
+7
View File
@@ -0,0 +1,7 @@
<%= raw(VALID_LOCALES.map{ |locale|
if I18n.locale.to_s.eql?(locale)
t(:_locale, :locale => locale)
else
link_to t(:_locale, :locale => locale), params.merge({:locale => locale})
end
}.join(' | ')) %>
+19 -8
View File
@@ -5,7 +5,7 @@
<title>R4</title>
<link rel="shortcut icon" href="/favicon.ico">
<%= yield :page_specific_link %>
<%= stylesheet_link_tag "easy", "main", :media => "screen, projection" %>
<%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
<%= stylesheet_link_tag "easyprint", :media => "print" %>
<!--[if IE]>
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
@@ -15,16 +15,27 @@
</head>
<body>
<div id="container">
<div id="banner_link" style='text-align:right'>
<ul class="hmenu">
<li>
<%= render 'layouts/lang_menu' %>
</li>
<%= render 'devise/menu/login_items' %>
</ul>
</div>
<div id="header">
<h1>RulingSite Admin</h1>
<h1>RulingSite <%= t('admin.admin') %></h1>
<ul id="nav">
<li><%= link_to t(:home, :scope => :admin), root_path %></li>
<li><%= link_to t(:item, :scope => :admin), admin_items_path %></li>
<li><%= link_to t(:layout, :scope => :admin), admin_layouts_path %></li>
<li><%= link_to t(:asset, :scope => :admin), admin_assets_path %></li>
<li><%= link_to t(:user_attribute, :scope => :admin), admin_user_attributes_path %></li>
<li><%= link_to t('homepage'), root_path %></li>
<li><%= link_to t('admin.item'), admin_items_path %></li>
<li><%= link_to t('admin.layout'), admin_layouts_path %></li>
<li><%= link_to t('admin.asset'), admin_assets_path %></li>
<li><%= link_to t('admin.user_attribute'), admin_user_attribute_models_path %></li>
<li><%= link_to t('admin.translation'), admin_translations_path %></li>
</ul>
</div>
@@ -46,4 +57,4 @@
"application", :cache => 'all' %>
<%= yield :page_specific_javascript %>
</body>
</html>
</html>
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>R4</title>
<link rel="shortcut icon" href="/favicon.ico">
<%= yield :page_specific_link %>
<%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
<%= stylesheet_link_tag "easyprint", :media => "print" %>
<!--[if IE]>
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
<![endif]-->
<%= yield :page_specific_css %>
<%= csrf_meta_tag %>
</head>
<body>
<div id="container">
<ul class="hmenu">
<%= render 'devise/menu/registration_items' %>
<%= render 'devise/menu/login_items' %>
</ul>
<div id="header">
<h1>RulingSite</h1>
</div>
<div class="content">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<div class="main"><%= yield %></div>
<div class="secondary"><%= yield :secondary %></div>
<div class="tertiary"><%= yield :tertiary %></div>
</div>
<div id="footer">
<p>Rulingcom</p>
</div>
</div>
<%#= javascript_include_tag "jquery",
"jquery-ui",
"rails",
"easy",
"application", :cache => 'all' %>
<%= yield :page_specific_javascript %>
</body>
</html>
+14 -4
View File
@@ -5,7 +5,7 @@
<title>R4</title>
<link rel="shortcut icon" href="/favicon.ico">
<%= yield :page_specific_link %>
<%= stylesheet_link_tag "easy", "main", :media => "screen, projection" %>
<%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
<%= stylesheet_link_tag "easyprint", :media => "print" %>
<!--[if IE]>
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
@@ -15,13 +15,23 @@
</head>
<body>
<div id="container">
<div id="banner_link" style='text-align:right'>
<ul class="hmenu">
<li>
<%= render 'layouts/lang_menu' %>
</li>
<%= render 'devise/menu/login_items' %>
</ul>
</div>
<div id="header">
<h1>RulingSite Panel</h1>
<ul id="nav">
<li><%= link_to t(:home, :scope => :panel), root_path %></li>
<li><%= link_to t(:users, :scope => :panel), panel_users_path %></li>
<li><%= link_to t('panel.home'), root_path %></li>
<li><%= link_to t('panel.user'), panel_users_path %></li>
</ul>
</div>
@@ -43,4 +53,4 @@
"application", :cache => 'all' %>
<%= yield :page_specific_javascript %>
</body>
</html>
</html>
@@ -0,0 +1,25 @@
<%= fields_for 'user[user_attributes][attribute_attrs]', attribute_attr, :index => nil do |f| %>
<%#= f.hidden_field :id unless attribute_attr.new_record? %>
<% if attr["locale"] %>
<p>
<%#= f.hidden_field :key, :value => attr["key"] %>
<% if attr["markup"] == "text_field" %>
<% @site_valid_locales.each do |locale| %>
<%= f.label attr.i18n_variable[locale] %>
<%= text_field_tag "user[user_attributes][attribute_attrs][i18n_user][#{locale}]", (attribute_attr.i18n_user[locale] rescue nil) %>
<% end -%>
<% elsif attr["markup"] == "select" %>
<%= f.select "#{attr["key"]}_#{I18n.locale}", attr["options_#{I18n.locale}"].to_a %>
<% end -%>
</p>
<% else %>
<p>
<%= f.label attr["name"] %>
<% if attr["markup"] == "text_field" %>
<%= f.text_field "#{attr["key"]}" %>
<% elsif attr["markup"] == "select" %>
<%= f.select "#{attr["key"]}", attr["options"].to_a %>
<% end -%>
</p>
<% end -%>
<% end %>
+19 -38
View File
@@ -1,47 +1,28 @@
<div id="select_user_attributes">
<% @user_attributes.each do |ua| %>
<%= check_box_tag "user[use_attributes][]", ua.key, @user.use_attributes.include?(ua.key) %> <%= ua.name %>
<% end -%>
<%= hidden_field_tag 'user[use_attributes][]','' %>
<% @user_attribute_models.each do |ua| %>
<%= check_box_tag "user[active_attributes][]", ua.key, (@user.active_attributes.include?(ua.key) rescue false) %> <%= ua.i18n_variable[locale] %>
<% end -%>
<%= hidden_field_tag 'user[active_attributes][]', '' %>
</div>
<div>
<p>
<%= f.label :email %>
<%= f.text_field :email %>
</p>
<label><%= t('panel.my_avatar') %></label>
<%= image_tag(@user.avatar.thumb.url) if @user.avatar? %>
<%= file_field_tag 'file' %>
<%= hidden_field_tag :avatar_cache %>
</div>
<% @user_attributes.each do |ua| %>
<div id="attribute_<%= ua.key %>"<%= raw(' style="display: none;"') unless @user.use_attributes.include?(ua.key) %>>
<h3><%= ua.name %></h3>
<% ua.attrs.each do |attr| %>
<% if attr["locale"] %>
<p>
<%= f.label attr["name_#{I18n.locale}"] %>
<% if attr["type"] == "text_field" %>
<% VALID_LOCALES.each do |locale| %>
<%= f.text_field "#{ua.key}_#{attr["key"]}_#{locale}" %>(<%= locale %>)
<% end -%>
<% elsif attr["type"] == "select" %>
<%= f.select "#{ua.key}_#{attr["key"]}_#{I18n.locale}", attr["options_#{I18n.locale}"].to_a %>
<% end -%>
</p>
<% else %>
<p>
<%= f.label attr["name"] %>
<% if attr["type"] == "text_field" %>
<%= f.text_field "#{ua.key}_#{attr["key"]}" %>
<% elsif attr["type"] == "select" %>
<%= f.select "#{ua.key}_#{attr["key"]}", attr["options"].to_a %>
<% end -%>
</p>
<% end -%>
<% end -%>
<div>
<p>
<%= f.label :email %>
<%= f.text_field :email %>
</p>
</div>
<% @user_attribute_models.each do |ua| %>
<%= render :partial => 'user_attribute',
:object => (@user.user_attributes.detect {|u| u.key == ua.key } || @user.user_attributes.build),
:locals => {:ua => ua} %>
<% end -%>
<% content_for :page_specific_javascript do %>
@@ -52,4 +33,4 @@
});
});
</script>
<% end -%>
<% end -%>
@@ -0,0 +1,42 @@
<fieldset id="attribute_<%= ua.key %>"<%= raw(' style="display: none;"') unless (@user.active_attributes.include?(ua.key) rescue nil) %>>
<%= fields_for 'user[user_attributes]', user_attribute, :index => nil do |f| %>
<legend><%= ua.i18n_variable[I18n.locale] %></legend>
<%= f.hidden_field :key, :value => ua.key %>
<%= f.hidden_field :id unless user_attribute.new_record? %>
<table>
<tr>
<th><%= t('admin.attribute') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<% ua.attribute_attr_models.each do |attr| %>
<tr>
<td><%= attr.i18n_variable[I18n.locale] %></td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<% @site_valid_locales.each do |locale| %>
<td>
<%= text_field_tag "user[user_attributes][][#{attr.key}_#{locale}]", (user_attribute["#{attr.key}_#{locale}"] rescue nil) %>
</td>
<% end -%>
<% else %>
<td colspan=<%= @site_valid_locales.size %>>
<% if attr["markup"] == "text_field" %>
<%= text_field_tag "user[user_attributes][][#{attr.key}]", (user_attribute[attr.key] rescue nil) %>
<% elsif attr["markup"] == "select" %>
<%= select_tag "user[user_attributes][][#{attr.key}]", options_for_select(attr["options"], user_attribute[attr.key]) %>
<% end -%>
</td>
<% end -%>
</tr>
<% end %>
</table>
<% end %>
</fieldset>
+4 -5
View File
@@ -4,15 +4,14 @@
</ul>
<% end -%>
<h1>Users panel</h1>
<% form_for @user, :url => panel_user_path(@user) do |f| %>
<h1><%= t('panel.user_panel') %></h1>
<%= form_for @user, :url => panel_user_path(@user), :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => 'form', :locals => { :f => f } %>
<p>
<%= f.submit %>
<%= f.submit t(:update) %> <%= link_back %>
</p>
<% end -%>
+11 -12
View File
@@ -1,29 +1,28 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_user, :scope => :panel), new_panel_user_path, :class => 'button positive' %></li>
<li><%= link_to t('panel.new_user'), new_panel_user_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1>Users panel</h1>
<h1><%= t('panel.list_users') %></h1>
<table>
<tr>
<th>Attrs</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
<th><%= t('panel.attributes') %></th>
<th><%= t('panel.name') %></th>
<th><%= t('panel.email') %></th>
<th><%= t('panel.action') %></th>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= user.use_attributes.join(",") %></td>
<td><%= user.name %></td>
<td><%= user.get_attributes %></td>
<td><%= user[:name] %></td>
<td><%= user.email %></td>
<td>
<%= link_to 'Show', panel_user_path(user) %>
<%= link_to 'Edit', edit_panel_user_path(user) %> |
<%= link_to 'Destroy', panel_user_path(user), :method => :delete %></td>
<%= link_to t(:show), panel_user_path(user) %> |
<%= link_to t(:edit), edit_panel_user_path(user) %> |
<%= link_to t(:delete), panel_user_path(user), :method => :delete %></td>
</tr>
<% end %>
</table>
+11 -11
View File
@@ -1,18 +1,18 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_user, :scope => :panel), new_panel_user_path, :class => 'button positive' %></li>
</ul>
<ul class="list">
<li><%= link_to t(:new_user, :scope => :panel), new_panel_user_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1>Users panel</h1>
<h1><%= t('panel.user_panel') %></h1>
<% form_for @user, :url => panel_users_path do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<p>
<%= f.submit %>
</p>
<%= form_for @user, :url => panel_users_path, :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => 'form', :locals => { :f => f } %>
<p>
<%= f.submit t(:create) %> <%= link_back %>
</p>
<% end -%>
+25 -3
View File
@@ -4,7 +4,29 @@
</ul>
<% end -%>
<h1>Users panel</h1>
<h1><%= t('panel.user_panel') %></h1>
<%=h @user.name %>
<%=h @user.email %>
<%= image_tag(@user.avatar.thumb.url) rescue nil %>
<%= @user.email %>
<% @user.get_active_attribute_models.each do |am| %>
<% user_attribute = @user.get_attribute_from_model_key(am.key) %>
<fieldset>
<legend><%= am.i18n_variable[I18n.locale] %></legend>
<table>
<% am.attribute_attr_models.each do |attr| %>
<tr>
<td><%= attr.i18n_variable[I18n.locale] %></td>
<td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<%= user_attribute["#{attr.key}_#{I18n.locale}"] %>
<% else %>
<%= user_attribute["#{attr.key}"] %>
<% end %>
</td>
</tr>
<% end %>
</table>
</fieldset>
<% end -%>
+1
View File
@@ -0,0 +1 @@
<%= @title %>
+1
View File
@@ -0,0 +1 @@
<%= @site.inspect %>