add user_info

This commit is contained in:
chris 2011-02-01 15:12:23 +08:00 committed by ihower
parent a06aa15721
commit 318c264cae
30 changed files with 347 additions and 218 deletions

View File

@ -73,6 +73,10 @@ class Admin::TranslationsController < ApplicationController
result << var if var.document_class.eql?('UserRoleModel') result << var if var.document_class.eql?('UserRoleModel')
result result
end end
@user_info_model_i18n_variables = @i18n_variables.inject([]) do |result, var|
result << var if var.document_class.eql?('UserInfoModel')
result
end
end end
end end

View File

@ -1,48 +0,0 @@
class Admin::UserRoleModelsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :is_admin?
def index
@user_role_models = UserRoleModel.all.entries
end
def show
@user_role_model = UserRoleModel.find(params[:id])
end
def new
@user_role_model = UserRoleModel.new
session[:last_page] = get_go_back || admin_user_role_models_url
end
def edit
@user_role_model = UserRoleModel.find(params[:id])
@i18n_variable = @user_role_model.i18n_variable
session[:last_page] = get_go_back || admin_user_role_models_url
end
def create
@user_role_model = UserRoleModel.new(params[:user_role_model])
@user_role_model.save
redirect_to :action => :index
end
def update
@user_role_model = UserRoleModel.find(params[:id])
@user_role_model.update_attributes(params[:user_role_model])
redirect_to :action => :index
end
def destroy
@user_role_model = UserRoleModel.find(params[:id])
@user_role_model.destroy
@user_role_model.destroy_i18n_variables
redirect_to :action => :index
end
end

View File

@ -0,0 +1,58 @@
class Admin::UserInfoModelsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
def index
@user_attribute_models = UserInfoModel.all.entries
render :template => 'admin/user_attribute_models/index'
end
def show
#@user_attribute_model = UserInfoModel.find(params[:id])
end
def new
@user_attribute_model = UserInfoModel.new
session[:last_page] = get_go_back || admin_user_info_models_url
render :template => 'admin/user_attribute_models/new'
end
def edit
@user_attribute_model = UserInfoModel.find(params[:id])
@i18n_variable = @user_attribute_model.i18n_variable
session[:last_page] = get_go_back || admin_user_info_models_url
render :template => 'admin/user_attribute_models/edit'
end
def create
@user_attribute_model = UserInfoModel.new(params[:user_info_model])
@user_attribute_model.save
redirect_to :action => :index
end
def update
@user_attribute_model = UserInfoModel.find(params[:id])
@user_attribute_model.update_attributes(params[:user_info_model])
redirect_to :action => :index
end
def destroy
@user_attribute_model = UserInfoModel.find(params[:id])
@user_attribute_model.destroy
@user_attribute_model.destroy_i18n_variables
redirect_to :action => :index
end
protected
def set_attribute
@attribute = 'info'
end
end

View File

@ -0,0 +1,58 @@
class Admin::UserRoleModelsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
def index
@user_attribute_models = UserRoleModel.all.entries
render :template => 'admin/user_attribute_models/index'
end
def show
#@user_attribute_model = UserRoleModel.find(params[:id])
end
def new
@user_attribute_model = UserRoleModel.new
session[:last_page] = get_go_back || admin_user_role_models_url
render :template => 'admin/user_attribute_models/new'
end
def edit
@user_attribute_model = UserRoleModel.find(params[:id])
@i18n_variable = @user_attribute_model.i18n_variable
session[:last_page] = get_go_back || admin_user_role_models_url
render :template => 'admin/user_attribute_models/edit'
end
def create
@user_attribute_model = UserRoleModel.new(params[:user_role_model])
@user_attribute_model.save
redirect_to :action => :index
end
def update
@user_attribute_model = UserRoleModel.find(params[:id])
@user_attribute_model.update_attributes(params[:user_role_model])
redirect_to :action => :index
end
def destroy
@user_attribute_model = UserRoleModel.find(params[:id])
@user_attribute_model.destroy
@user_attribute_model.destroy_i18n_variables
redirect_to :action => :index
end
protected
def set_attribute
@attribute = 'role'
end
end

View File

@ -9,10 +9,12 @@ class Panel::UsersController < ApplicationController
def show def show
@user = User.find(params[:id]) @user = User.find(params[:id])
@user_info_models = UserInfoModel.all.entries
end end
def new def new
@user = User.new @user = User.new
@user_info_models = UserInfoModel.all.entries
@user_role_models = UserRoleModel.all.entries @user_role_models = UserRoleModel.all.entries
session[:last_page] = get_go_back || panel_users_url session[:last_page] = get_go_back || panel_users_url
end end
@ -28,6 +30,7 @@ class Panel::UsersController < ApplicationController
def edit def edit
@user = User.find(params[:id]) @user = User.find(params[:id])
@user_info_models = UserInfoModel.all.entries
@user_role_models = UserRoleModel.all.entries @user_role_models = UserRoleModel.all.entries
session[:last_page] = get_go_back || panel_users_url session[:last_page] = get_go_back || panel_users_url
end end
@ -42,6 +45,7 @@ class Panel::UsersController < ApplicationController
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
redirect_to :action => :index redirect_to :action => :index
else else
@user_info_models = UserInfoModel.all.entries
@user_role_models = UserRoleModel.all.entries @user_role_models = UserRoleModel.all.entries
render :action => :edit render :action => :edit
end end

View File

@ -8,7 +8,7 @@ class AttributeModel
field :locale, :type => Boolean field :locale, :type => Boolean
field :list_options, :type => Array field :list_options, :type => Array
embedded_in :user_role_model, :inverse_of => :attribute_models embedded_in :user_attribute_model, :inverse_of => :attribute_models
validates_uniqueness_of :key validates_uniqueness_of :key
# Destroy the i18n_variable # Destroy the i18n_variable
@ -26,7 +26,7 @@ class AttributeModel
if self.i18n_variable_id if self.i18n_variable_id
self.i18n_variable.update_attributes(attr) self.i18n_variable.update_attributes(attr)
else else
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.user_role_model.i18n_variable_id})) var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.user_attribute_model.i18n_variable_id}))
var.save var.save
self.i18n_variable_id = var.id self.i18n_variable_id = var.id
end end

View File

@ -7,11 +7,11 @@ class User
mount_uploader :avatar, AvatarUploader mount_uploader :avatar, AvatarUploader
field :admin, :type => Boolean, :default => true field :admin, :type => Boolean, :default => true
field :active_attributes, :type => Array field :active_roles, :type => Array
embeds_one :user_info
embeds_many :user_roles embeds_many :user_roles
before_update :clean_active_attributes embeds_many :user_infos
before_update :clean_active_roles
# Update or create the user_role records # Update or create the user_role records
def user_roles=(*attrs) def user_roles=(*attrs)
@ -20,11 +20,16 @@ class User
user_roles.build(roles) user_roles.build(roles)
else else
user_role = user_roles.detect {|a| a.id.to_s == roles[:id].to_s } user_role = user_roles.detect {|a| a.id.to_s == roles[:id].to_s }
user_role.update_roles(roles) user_role.update_attributes(roles)
end end
end end
end end
# Get an user_info from model key
def get_info_from_model_key(key)
self.user_infos.detect {|a| a.key.to_s == key.to_s }
end
# Get an user_role from model key # Get an user_role from model key
def get_role_from_model_key(key) def get_role_from_model_key(key)
self.user_roles.detect {|a| a.key.to_s == key.to_s } self.user_roles.detect {|a| a.key.to_s == key.to_s }

View File

@ -21,6 +21,30 @@ class UserAttributeModel
end end
end end
# Destroy the i18n_variables
def destroy_i18n_variables
self.i18n_variable.destroy rescue nil
self.attribute_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 protected
# Destroy the i18n_variable for each attribute_models if marked to destroy # Destroy the i18n_variable for each attribute_models if marked to destroy

View File

@ -4,6 +4,6 @@ class UserInfo
field :key field :key
embedded_in :user, :inverse_of => :user_info embedded_in :user, :inverse_of => :user_infos
end end

View File

@ -1,27 +1,3 @@
class UserRoleModel < UserAttributeModel class UserRoleModel < UserAttributeModel
# Destroy the i18n_variables
def destroy_i18n_variables
self.i18n_variable.destroy rescue nil
self.attribute_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
end end

View File

@ -1,11 +1,11 @@
<% @vars = @i18n_variables.inject([]) do |result, var| <% @vars = @i18n_variables.inject([]) do |result, var|
result << var if var.parent_id.to_s.eql?(edit_user_role_model.id.to_s) result << var if var.parent_id.to_s.eql?(edit_user_attribute_model.id.to_s)
result result
end %> end %>
<fieldset> <fieldset>
<legend> <legend>
<%= edit_user_role_model.key %> <%= edit_user_attribute_model.key %>
<%#= render :partial => 'action_bar' %> <%#= render :partial => 'action_bar' %>
</legend> </legend>
<table> <table>
@ -16,9 +16,9 @@ end %>
<% end %> <% end %>
</tr> </tr>
<tr> <tr>
<td><%= edit_user_role_model.key %></td> <td><%= edit_user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "i18n_variables[#{edit_user_role_model.id}][#{locale}]", edit_user_role_model[locale] %></td> <td><%= text_field_tag "i18n_variables[#{edit_user_attribute_model.id}][#{locale}]", edit_user_attribute_model[locale] %></td>
<% end %> <% end %>
</tr> </tr>

View File

@ -1,11 +1,11 @@
<% @vars = @i18n_variables.inject([]) do |result, var| <% @vars = @i18n_variables.inject([]) do |result, var|
result << var if var.parent_id.to_s.eql?(user_role_model.id.to_s) result << var if var.parent_id.to_s.eql?(user_attribute_model.id.to_s)
result result
end %> end %>
<fieldset> <fieldset>
<legend> <legend>
<%= user_role_model.key %> <%= user_attribute_model.key %>
<%#= render :partial => 'action_bar' %> <%#= render :partial => 'action_bar' %>
</legend> </legend>
<table> <table>
@ -16,9 +16,9 @@ end %>
<% end %> <% end %>
</tr> </tr>
<tr> <tr>
<td><%= user_role_model.key %></td> <td><%= user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<td><%= user_role_model[locale] %></td> <td><%= user_attribute_model[locale] %></td>
<% end %> <% end %>
</tr> </tr>

View File

@ -10,13 +10,23 @@
</fieldset> </fieldset>
<% end %> <% end %>
<% if @user_role_role_i18n_variables.size > 0 %> <% if @user_info_model_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.user_info') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'edit_user_attribute_model', :collection => @user_info_model_i18n_variables %></div>
</fieldset>
<% end %>
<% if @user_role_model_i18n_variables.size > 0 %>
<fieldset> <fieldset>
<legend> <legend>
<%= t('admin.user_role') %> <%= t('admin.user_role') %>
<%#= render :partial => 'action_bar' %> <%#= render :partial => 'action_bar' %>
</legend> </legend>
<div><%= render :partial => 'edit_user_role_model', :collection => @user_role_model_i18n_variables %></div> <div><%= render :partial => 'edit_user_attribute_model', :collection => @user_role_model_i18n_variables %></div>
</fieldset> </fieldset>
<% end %> <% end %>

View File

@ -42,13 +42,23 @@
</fieldset> </fieldset>
<% end %> <% end %>
<% if @user_info_model_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.user_info') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'user_attribute_model', :collection => @user_info_model_i18n_variables %></div>
</fieldset>
<% end %>
<% if @user_role_model_i18n_variables.size > 0 %> <% if @user_role_model_i18n_variables.size > 0 %>
<fieldset> <fieldset>
<legend> <legend>
<%= t('admin.user_role') %> <%= t('admin.user_role') %>
<%#= render :partial => 'action_bar' %> <%#= render :partial => 'action_bar' %>
</legend> </legend>
<div><%= render :partial => 'user_role_model', :collection => @user_role_model_i18n_variables %></div> <div><%= render :partial => 'user_attribute_model', :collection => @user_role_model_i18n_variables %></div>
</fieldset> </fieldset>
<% end %> <% end %>

View File

@ -1,19 +1,19 @@
<%= fields_for 'user_role_model[attribute_models][]', attribute_model, :index => nil do |f| %> <%= fields_for "user_#{@attribute}_model[attribute_models][]", attribute_model, :index => nil do |f| %>
<tr> <tr>
<td><%= attribute_model.new_record? ? (f.text_field :key, {:style => "width:130px"}) : attribute_model.key %></td> <td><%= attribute_model.new_record? ? (f.text_field :key, {:style => "width:130px"}) : attribute_model.key %></td>
<td class='select_mulitlingual' style='text-align:center'> <td class='select_mulitlingual' style='text-align:center'>
<%= check_box_tag "locale[]", value = '', attribute_model.locale.nil? ? true : attribute_model.locale %> <%= check_box_tag "locale[]", value = '', attribute_model.locale.nil? ? true : attribute_model.locale %>
<%= hidden_field_tag "user_model[attribute_models][][locale]", attribute_model.locale.nil? ? true : attribute_model.locale %> <%= hidden_field_tag "user_#{@attribute}_model[attribute_models][][locale]", attribute_model.locale.nil? ? true : attribute_model.locale %>
</td> </td>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "user_role_model[attribute_models][][i18n_variable][#{locale}]", (attribute_model.i18n_variable[locale] rescue nil), :style => "width:130px" %></td> <td><%= text_field_tag "user_#{@attribute}_model[attribute_models][][i18n_variable][#{locale}]", (attribute_model.i18n_variable[locale] rescue nil), :style => "width:130px" %></td>
<% end %> <% end %>
<td class='select_type'> <td class='select_type'>
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %> <%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
<div <%= attribute_model[:markup].eql?('select') ? nil : "style='display:none'"%>> <div <%= attribute_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
<%= t('admin.options') %>: <%= t('admin.options') %>:
<%= text_field_tag "user_role_model[attribute_models][][select_list_options]", attribute_model.select_list_options, :style => "width:130px" %> <%= text_field_tag "user_#{@attribute}_model[attribute_models][][select_list_options]", attribute_model.select_list_options, :style => "width:130px" %>
</div> </div>
</td> </td>
<td> <td>
@ -21,7 +21,7 @@
<a href="#" class="remove">(<%= t(:delete) %>)</a> <a href="#" class="remove">(<%= t(:delete) %>)</a>
<% else %> <% else %>
<a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a> <a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a>
<%= hidden_field_tag "user_role_model[attribute_models][][should_destroy]", nil , :class => 'should_destroy' %> <%= hidden_field_tag "user_#{@attribute}_model[attribute_models][][should_destroy]", nil , :class => 'should_destroy' %>
<%= f.hidden_field :id %> <%= f.hidden_field :id %>
<%= f.hidden_field :key %> <%= f.hidden_field :key %>
<% end %> <% end %>

View File

@ -6,10 +6,10 @@
<% end %> <% end %>
</tr> </tr>
<tr> <tr>
<td><%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_role_model.key %></td> <td><%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<td> <td>
<%= text_field_tag "user_role_model[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:130px" %> <%= text_field_tag "user_#{@attribute}_model[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:130px" %>
</td> </td>
<% end %> <% end %>
</tr> </tr>
@ -30,7 +30,7 @@
<th><%= t('admin.type')%></th> <th><%= t('admin.type')%></th>
<th></th> <th></th>
</tr> </tr>
<%= render :partial => 'attribute_model', :collection => @user_role_model.attribute_models %> <%= render :partial => 'admin/user_attribute_models/attribute_model', :collection => @user_attribute_model.attribute_models %>
</table> </table>
<a href="#" class="add">(<%= t(:add) %>)</a> <a href="#" class="add">(<%= t(:add) %>)</a>
@ -45,7 +45,7 @@
}); });
$('#field_set_attributes a.add').click(function(){ $('#field_set_attributes a.add').click(function(){
$('#attribute').append("<%= escape_javascript(render(:partial => 'attribute_model', :object => @user_role_model.attribute_models.build)) %>"); $('#attributes').append("<%= escape_javascript(render(:partial => 'admin/user_attribute_models/attribute_model', :object => @user_attribute_model.attribute_models.build)) %>");
}); });
$('#field_set_attributes a.remove_existing_record').click(function(){ $('#field_set_attributes a.remove_existing_record').click(function(){

View File

@ -1,14 +1,14 @@
<h1><%= t('admin.editing_user_role') %>: <%= @user_role_model.key %></h1> <h1><%= t("admin.editing_user_#{@attribute}") %>: <%= @user_attribute_model.key %></h1>
<fieldset> <fieldset>
<legend> <legend>
<%= t('admin.user_role')%> <%= t("admin.user_#{@attribute}")%>
</legend> </legend>
<%= form_for @user_role_model, :url => admin_user_role_model_path(@user_role_model) do |f| %> <%= form_for @user_attribute_model, :url => eval("admin_user_#{@attribute}_model_path(@user_role_model)") do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f, :is_new => false } %> <%= render :partial => "admin/user_attribute_models/form", :locals => { :f => f, :is_new => false } %>
<p> <p>
<%= f.submit t('update') %> <%= link_back %> <%= f.submit t('update') %> <%= link_back %>

View File

@ -1,25 +1,25 @@
<% content_for :secondary do %> <% content_for :secondary do %>
<ul class="list"> <ul class="list">
<li><%= link_to t('admin.new_user_role'), new_admin_user_role_model_path, :class => 'button positive' %></li> <li><%= link_to t("admin.new_user_#{@attribute}"), eval("new_admin_user_#{@attribute}_model_path"), :class => 'button positive' %></li>
</ul> </ul>
<% end -%> <% end -%>
<h1><%= t('admin.list_user_roles') %></h1> <h1><%= t("admin.list_user_#{@attribute}s") %></h1>
<table> <table>
<tr> <tr>
<th><%= t('admin.role') %></th> <th><%= t("admin.#{@attribute}") %></th>
<th><%= t('admin.key') %></th> <th><%= t('admin.key') %></th>
<th><%= t('admin.action') %></th> <th><%= t('admin.action') %></th>
</tr> </tr>
<% @user_role_models.each do |user_role_model| %> <% @user_attribute_models.each do |user_attribute_model| %>
<tr> <tr>
<td><%= user_role_model.i18n_variable[I18n.locale] %></td> <td><%= user_attribute_model.i18n_variable[I18n.locale] %></td>
<td><%= user_role_model.key %></td> <td><%= user_attribute_model.key %></td>
<td> <td>
<%= link_to t(:edit), edit_admin_user_role_model_path(user_role_model) %> | <%= link_to t(:edit), eval("edit_admin_user_#{@attribute}_model_path(user_attribute_model)") %> |
<%= link_to t(:delete), admin_user_role_model_path(user_role_model), :confirm => t('sure?'), :method => :delete %> <%= link_to t(:delete), eval("admin_user_#{@attribute}_model_path(user_attribute_model)"), :confirm => t('sure?'), :method => :delete %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@ -1,14 +1,14 @@
<h1><%= t('admin.new_user_role') %></h1> <h1><%= t("admin.new_user_#{@attribute}") %></h1>
<fieldset id='field_set_attributes'> <fieldset id='field_set_attributes'>
<legend> <legend>
<%= t('admin.user_role')%> <%= t("admin.user_#{@attribute}")%>
</legend> </legend>
<%= form_for @user_role_model, :url => admin_user_role_models_path do |f| %> <%= form_for @user_attribute_model, :url => eval("admin_user_#{@attribute}_models_path") do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f, :is_new => true } %> <%= render :partial => "admin/user_attribute_models/form", :locals => { :f => f, :is_new => true } %>
<p> <p>
<%= f.submit t('create') %> <%= link_back %> <%= f.submit t('create') %> <%= link_back %>

View File

@ -34,6 +34,7 @@
<li><%= link_to t('admin.item'), admin_items_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.layout'), admin_layouts_path %></li>
<li><%= link_to t('admin.asset'), admin_assets_path %></li> <li><%= link_to t('admin.asset'), admin_assets_path %></li>
<li><%= link_to t('admin.user_info'), admin_user_info_models_path %></li>
<li><%= link_to t('admin.user_role'), admin_user_role_models_path %></li> <li><%= link_to t('admin.user_role'), admin_user_role_models_path %></li>
<li><%= link_to t('admin.translation'), admin_translations_path %></li> <li><%= link_to t('admin.translation'), admin_translations_path %></li>
</ul> </ul>

View File

@ -1,25 +0,0 @@
<%= fields_for 'user[user_roles][attributes]', attribute, :index => nil do |f| %>
<%#= f.hidden_field :id unless attribute.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_roles][attributes][i18n_user][#{locale}]", (attribute.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 %>

View File

@ -19,17 +19,42 @@
</p> </p>
</div> </div>
<% @user_role_models.each do |ua| %> <% if @user_info_models %>
<%= render :partial => 'user_role', <fieldset>
<legend><%= t('panel.infos') %></legend>
<% @user_info_models.each do |ua| %>
<fieldset>
<%= render :partial => 'user_attribute',
:object => (@user.user_infos.detect {|u| u.key == ua.key } || @user.user_infos.build),
:locals => {:ua => ua, :type => 'info'} %>
</fieldset>
<% end -%>
</fieldset>
<% end %>
<%= hidden_field_tag :active_roles, @user.active_roles.size > 0 %>
<% if @user_role_models %>
<fieldset id="roles" <%= raw(' style="display: none;"') unless (@user.active_roles.size > 0 rescue nil) %>>
<legend><%= t('panel.roles') %></legend>
<% @user_role_models.each do |ua| %>
<fieldset id="role_<%= ua.key %>" <%= raw(' style="display: none;"') unless (@user.active_roles.include?(ua.key) rescue nil) %>>
<%= render :partial => 'user_attribute',
:object => (@user.user_roles.detect {|u| u.key == ua.key } || @user.user_roles.build), :object => (@user.user_roles.detect {|u| u.key == ua.key } || @user.user_roles.build),
:locals => {:ua => ua} %> :locals => {:ua => ua, :type => 'role'} %>
<% end -%> </fieldset>
<% end -%>
</fieldset>
<% end %>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){ $(document).ready(function(){
$('#select_user_roles input').click(function(){ $('#select_user_roles input').click(function(){
$("#role_"+this.value).toggle(); $('#role_'+this.value).toggle();
if($("#select_user_roles input:checked").length > 0)
{ $('#roles').show(); }
else
{ $('#roles').hide(); }
}); });
}); });
</script> </script>

View File

@ -0,0 +1,17 @@
<fieldset>
<legend><%= am.i18n_variable[I18n.locale] %></legend>
<table>
<% am.attribute_models.each do |attr| %>
<tr>
<td><%= attr.i18n_variable[I18n.locale] %></td>
<td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<%= show_user_attribute["#{attr.key}_#{I18n.locale}"] rescue nil %>
<% else %>
<%= show_user_attribute["#{attr.key}"] rescue nil %>
<% end %>
</td>
</tr>
<% end %>
</table>
</fieldset>

View File

@ -1,14 +1,12 @@
<fieldset id="attribute_<%= ua.key %>"<%= raw(' style="display: none;"') unless (@user.active_attributes.include?(ua.key) rescue nil) %>> <%= fields_for "user[user_#{type}s]", user_attribute, :index => nil do |f| %>
<%= fields_for 'user[user_roles]', user_role, :index => nil do |f| %>
<legend><%= ua.i18n_variable[I18n.locale] %></legend> <legend><%= ua.i18n_variable[I18n.locale] %></legend>
<%= f.hidden_field :key, :value => ua.key %> <%= f.hidden_field :key, :value => ua.key %>
<%= f.hidden_field :id unless user_role.new_record? %> <%= f.hidden_field :id unless user_attribute.new_record? %>
<table> <table>
<tr> <tr>
<th><%= t('admin.role') %></th> <th><%= t("admin.key") %></th>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th> <th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %> <% end %>
@ -20,15 +18,15 @@
<% if attr["locale"] && attr["markup"] == 'text_field' %> <% if attr["locale"] && attr["markup"] == 'text_field' %>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<td> <td>
<%= text_field_tag "user[user_roles][][#{attr.key}_#{locale}]", (user_role["#{attr.key}_#{locale}"] rescue nil) %> <%= text_field_tag "user[user_#{type}s][][#{attr.key}_#{locale}]", (user_attribute["#{attr.key}_#{locale}"] rescue nil) %>
</td> </td>
<% end -%> <% end -%>
<% else %> <% else %>
<td colspan=<%= @site_valid_locales.size %>> <td colspan=<%= @site_valid_locales.size %>>
<% if attr["markup"] == "text_field" %> <% if attr["markup"] == "text_field" %>
<%= text_field_tag "user[user_roles][][#{attr.key}]", (user_role[attr.key] rescue nil) %> <%= text_field_tag "user[user_#{type}s][][#{attr.key}]", (user_attribute[attr.key] rescue nil) %>
<% elsif attr["markup"] == "select" %> <% elsif attr["markup"] == "select" %>
<%= select_tag "user[user_roles][][#{attr.key}]", options_for_select(attr["options"], user_role[attr.key]) %> <%= select_tag "user[user_#{type}s][][#{attr.key}]", options_for_select(attr["options"], user_attribute[attr.key]) %>
<% end -%> <% end -%>
</td> </td>
<% end -%> <% end -%>
@ -37,6 +35,4 @@
</table> </table>
<% end %> <% end %>
</fieldset>

View File

@ -8,7 +8,7 @@
<table> <table>
<tr> <tr>
<th><%= t('panel.attributes') %></th> <th><%= t('panel.roles') %></th>
<th><%= t('panel.name') %></th> <th><%= t('panel.name') %></th>
<th><%= t('panel.email') %></th> <th><%= t('panel.email') %></th>
<th><%= t('panel.action') %></th> <th><%= t('panel.action') %></th>
@ -16,7 +16,7 @@
<% @users.each do |user| %> <% @users.each do |user| %>
<tr> <tr>
<td><%= user.get_attributes %></td> <td><%= user.get_roles %></td>
<td><%= user[:name] %></td> <td><%= user[:name] %></td>
<td><%= user.email %></td> <td><%= user.email %></td>
<td> <td>

View File

@ -10,23 +10,24 @@
<%= @user.email %> <%= @user.email %>
<% @user.get_active_attribute_models.each do |am| %> <% if @user_info_models %>
<% user_role = @user.get_role_from_model_key(am.key) %>
<fieldset> <fieldset>
<legend><%= am.i18n_variable[I18n.locale] %></legend> <legend><%= t('panel.infos') %></legend>
<table> <% @user_info_models.each do |am| %>
<% am.attribute_models.each do |attr| %> <%= render :partial => 'show_user_attribute',
<tr> :object => @user.get_info_from_model_key(am.key),
<td><%= attr.i18n_variable[I18n.locale] %></td> :locals => {:am => am} %>
<td> <% end -%>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<%= user_role["#{attr.key}_#{I18n.locale}"] %>
<% else %>
<%= user_role["#{attr.key}"] %>
<% end %>
</td>
</tr>
<% end %>
</table>
</fieldset> </fieldset>
<% end -%> <% end %>
<% if @user.active_roles.size > 0 %>
<fieldset>
<legend><%= t('panel.roles') %></legend>
<% @user.get_active_role_models.each do |am| %>
<%= render :partial => 'show_user_attribute',
:object => @user.get_role_from_model_key(am.key),
:locals => {:am => am} %>
<% end -%>
</fieldset>
<% end %>

View File

@ -27,7 +27,6 @@ en:
action: Action action: Action
announcement: Announcement announcement: Announcement
asset: Asset asset: Asset
attribute: Attribute
attributes: Attributes attributes: Attributes
class: Class class: Class
create_success_home: Homepage was successfully created. create_success_home: Homepage was successfully created.
@ -45,7 +44,8 @@ en:
editing_link: Editing link editing_link: Editing link
editing_page: Editing page editing_page: Editing page
editing_snippet: Editing snippet editing_snippet: Editing snippet
editing_user_attribute: Editing user attribute editing_user_info: Editing user information
editing_user_role: Editing user role
enable_language: Enable language enable_language: Enable language
file_name: Filename file_name: Filename
file_size: File size file_size: File size
@ -60,7 +60,8 @@ en:
list_items: Items list list_items: Items list
list_layouts: Layouts list list_layouts: Layouts list
list_snippets: Snippets list list_snippets: Snippets list
list_user_attributes: User attributes list list_user_infos: User information list
list_user_roles: User roles list
move_down: Move down move_down: Move down
move_up: Move up move_up: Move up
multilingual: Multilingual multilingual: Multilingual
@ -74,30 +75,35 @@ en:
new_link: New link new_link: New link
new_page: New page new_page: New page
new_snippet: New snippet new_snippet: New snippet
new_user_attribute: New user attribute new_user_info: New user information
new_user_role: New user role
non_multilingual: Non multilingual non_multilingual: Non multilingual
options: Options options: Options
orig_upload_file: Original filename orig_upload_file: Original filename
position: Position position: Position
published?: Published? published?: Published?
info: Information
role: Role
title: Title title: Title
translation: Translation translation: Translation
type: Type type: Type
user_attribute: User attribute
update_success_home: Homepage was successfully updated. update_success_home: Homepage was successfully updated.
update_success_layout: Layout was successfully updated. update_success_layout: Layout was successfully updated.
update_success_link: Link was successfully updated. update_success_link: Link was successfully updated.
update_success_page: Page was successfully updated. update_success_page: Page was successfully updated.
update_success_snippet: Snippet was successfully updated. update_success_snippet: Snippet was successfully updated.
user_info: User information
user_role: User role
panel: panel:
action: Action action: Action
attributes: Attributes
email: Email email: Email
home: Home home: Home
list_users: Users list list_users: Users list
my_avatar: My Avatar my_avatar: My Avatar
name: Name name: Name
new_user: New user new_user: New user
infos: Information
roles: Roles
user: User user: User
user_panel: User panel user_panel: User panel

View File

@ -24,7 +24,6 @@ zh_tw:
action: 行動 action: 行動
announcement: 公告 announcement: 公告
asset: 資產 asset: 資產
attribute: 屬性
attributes: 屬性 attributes: 屬性
class: 階級 class: 階級
content: 內容 content: 內容
@ -42,7 +41,8 @@ zh_tw:
editing_link: 編輯連結 editing_link: 編輯連結
editing_page: 編輯頁面 editing_page: 編輯頁面
editing_snippet: 編輯片段 editing_snippet: 編輯片段
editing_user_attribute: 編輯人物屬性 editing_user_info: 編輯用戶資料
editing_user_role: 編輯用戶角色
enable_language: 啟用語言 enable_language: 啟用語言
file_name: 檔名 file_name: 檔名
file_size: 檔案大小 file_size: 檔案大小
@ -57,7 +57,8 @@ zh_tw:
list_items: 項目清單 list_items: 項目清單
list_layouts: 佈局清單 list_layouts: 佈局清單
list_snippets: 斷片清單 list_snippets: 斷片清單
list_user_attributes: 人物屬性清單 list_user_infos: 用戶資料清單
list_user_roles: 用戶角色清單
move_down: 往下移 move_down: 往下移
move_up: 往上移 move_up: 往上移
multilingual: 多種語言 multilingual: 多種語言
@ -71,31 +72,36 @@ zh_tw:
new_link: 新增連結 new_link: 新增連結
new_page: 新增頁面 new_page: 新增頁面
new_snippet: 新增片段 new_snippet: 新增片段
new_user_attribute: 新增人物屬性 new_user_info: 新增用戶資料
new_user_role: 新增用戶角色
non_multilingual: 非多種語言 non_multilingual: 非多種語言
options: 選項 options: 選項
orig_upload_file: 原上傳檔名 orig_upload_file: 原上傳檔名
position: 位置 position: 位置
published?: 發布? published?: 發布?
info: 資料
role: 角色
title: 標題 title: 標題
translation: 翻譯 translation: 翻譯
type: 類型 type: 類型
user_attribute: 人物屬性
update_success_home: 首頁已成功更新。 update_success_home: 首頁已成功更新。
update_success_layout: 樣板已成功更新。 update_success_layout: 樣板已成功更新。
update_success_link: 連結已成功更新。 update_success_link: 連結已成功更新。
update_success_page: 頁面已成功更新。 update_success_page: 頁面已成功更新。
update_success_snippet: 片段已成功更新。 update_success_snippet: 片段已成功更新。
user_info: 用戶資料
user_role: 用戶角色
panel: panel:
action: 行動 action: 行動
attributes: 屬性
email: Email email: Email
home: 首頁 home: 首頁
list_users: 使用清單 list_users: 使用清單
my_avatar: 我的頭像 my_avatar: 我的頭像
name: 名稱 name: 名稱
new_user: 新增使用 new_user: 新增使用
infos: 資料
roles: 角色
user: 用戶 user: 用戶
user_panel: 用戶面板 user_panel: 用戶面板

View File

@ -48,7 +48,8 @@ PrototypeR4::Application.routes.draw do
resources :homes resources :homes
resources :snippets resources :snippets
resources :translations resources :translations
resources :user_attribute_models resources :user_info_models
resources :user_role_models
end end
namespace :panel do namespace :panel do