add user_info
This commit is contained in:
parent
73b75ec0b6
commit
2ccc2c9b39
|
@ -69,8 +69,8 @@ class Admin::TranslationsController < ApplicationController
|
|||
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')
|
||||
@user_role_model_i18n_variables = @i18n_variables.inject([]) do |result, var|
|
||||
result << var if var.document_class.eql?('UserRoleModel')
|
||||
result
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,46 +1,46 @@
|
|||
class Admin::UserAttributeModelsController < ApplicationController
|
||||
class Admin::UserRoleModelsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
def index
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
@user_role_models = UserRoleModel.all.entries
|
||||
end
|
||||
|
||||
def show
|
||||
@user_attribute_model = UserAttributeModel.find(params[:id])
|
||||
@user_role_model = UserRoleModel.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@user_attribute_model = UserAttributeModel.new
|
||||
session[:last_page] = get_go_back || admin_user_attribute_models_url
|
||||
@user_role_model = UserRoleModel.new
|
||||
session[:last_page] = get_go_back || admin_user_role_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
|
||||
@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_attribute_model = UserAttributeModel.new(params[:user_attribute_model])
|
||||
@user_attribute_model.save
|
||||
@user_role_model = UserRoleModel.new(params[:user_role_model])
|
||||
@user_role_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])
|
||||
@user_role_model = UserRoleModel.find(params[:id])
|
||||
@user_role_model.update_attributes(params[:user_role_model])
|
||||
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
||||
def destroy
|
||||
@user_attribute_model = UserAttributeModel.find(params[:id])
|
||||
@user_attribute_model.destroy
|
||||
@user_role_model = UserRoleModel.find(params[:id])
|
||||
@user_role_model.destroy
|
||||
|
||||
@user_attribute_model.destroy_i18n_variables
|
||||
@user_role_model.destroy_i18n_variables
|
||||
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ class Panel::UsersController < ApplicationController
|
|||
|
||||
def new
|
||||
@user = User.new
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
@user_role_models = UserRoleModel.all.entries
|
||||
session[:last_page] = get_go_back || panel_users_url
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ class Panel::UsersController < ApplicationController
|
|||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
@user_role_models = UserRoleModel.all.entries
|
||||
session[:last_page] = get_go_back || panel_users_url
|
||||
end
|
||||
|
||||
|
@ -42,7 +42,7 @@ class Panel::UsersController < ApplicationController
|
|||
if @user.update_attributes(params[:user])
|
||||
redirect_to :action => :index
|
||||
else
|
||||
@user_attribute_models = UserAttributeModel.all.entries
|
||||
@user_role_models = UserRoleModel.all.entries
|
||||
render :action => :edit
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
class AttributeAttrModel
|
||||
|
||||
include Mongoid::Document
|
||||
|
||||
field :key
|
||||
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
|
||||
field :markup
|
||||
field :locale, :type => Boolean
|
||||
field :list_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 list_options into an array
|
||||
def select_list_options=(var)
|
||||
self.list_options = var.gsub(' ', '').split(',')
|
||||
end
|
||||
|
||||
# Convert the array list_options into a string
|
||||
def select_list_options
|
||||
self.list_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
|
|
@ -9,46 +9,47 @@ class User
|
|||
field :admin, :type => Boolean, :default => true
|
||||
field :active_attributes, :type => Array
|
||||
|
||||
embeds_many :user_attributes
|
||||
embeds_one :user_info
|
||||
embeds_many :user_roles
|
||||
before_update :clean_active_attributes
|
||||
|
||||
# Update or create the user_attribute records
|
||||
def user_attributes=(*attrs)
|
||||
attrs[0].each do |attributes|
|
||||
if attributes[:id].blank?
|
||||
user_attributes.build(attributes)
|
||||
# Update or create the user_role records
|
||||
def user_roles=(*attrs)
|
||||
attrs[0].each do |roles|
|
||||
if roles[:id].blank?
|
||||
user_roles.build(roles)
|
||||
else
|
||||
user_attribute = user_attributes.detect {|a| a.id.to_s == attributes[:id].to_s }
|
||||
user_attribute.update_attributes(attributes)
|
||||
user_role = user_roles.detect {|a| a.id.to_s == roles[:id].to_s }
|
||||
user_role.update_roles(roles)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 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 }
|
||||
# Get an user_role from model key
|
||||
def get_role_from_model_key(key)
|
||||
self.user_roles.detect {|a| a.key.to_s == key.to_s }
|
||||
end
|
||||
|
||||
# Get the active user_attribute_models
|
||||
def get_active_attribute_models
|
||||
self.active_attributes.map{ |attr| get_attribute_model(attr) } rescue []
|
||||
# Get the active user_role_models
|
||||
def get_active_role_models
|
||||
self.active_roles.map{ |role| get_role_model(role) } rescue []
|
||||
end
|
||||
|
||||
# Get an user_attribute_model from key
|
||||
def get_attribute_model(key)
|
||||
UserAttributeModel.first(:conditions => {:key => key})
|
||||
# Get an user_role_model from key
|
||||
def get_role_model(key)
|
||||
UserRoleModel.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(' / ')
|
||||
# Get the active roles names or default to '-'
|
||||
def get_roles
|
||||
(self.active_roles.nil? || self.active_roles.empty?) ? '-' : self.active_roles.map{|role| I18nVariable.first(:conditions => {:key => role})[I18n.locale] rescue role}.join(' / ')
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Remove empty values
|
||||
def clean_active_attributes
|
||||
self.active_attributes.delete('') if self.active_attributes
|
||||
def clean_active_roles
|
||||
self.active_roles.delete('') if self.active_roles
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
class UserAttribute
|
||||
|
||||
include Mongoid::Document
|
||||
|
||||
field :key
|
||||
|
||||
embedded_in :user, :inverse_of => :user_attributes
|
||||
|
||||
end
|
|
@ -5,53 +5,28 @@ class UserAttributeModel
|
|||
field :key
|
||||
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
|
||||
|
||||
embeds_many :attribute_attr_models
|
||||
embeds_many :attribute_models
|
||||
|
||||
after_update :destroy_attrs
|
||||
|
||||
# Update or create the attribute_attr_model records
|
||||
def attribute_attr_models=(*attrs)
|
||||
# Update or create the attribute_model records
|
||||
def attribute_models=(*attrs)
|
||||
attrs[0].each do |attributes|
|
||||
if attributes[:id].blank?
|
||||
attribute_attr_models.build(attributes)
|
||||
attribute_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)
|
||||
attribute_model = attribute_models.detect {|a| a.id.to_s == attributes[:id].to_s }
|
||||
attribute_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
|
||||
# Destroy the i18n_variable for each attribute_models if marked to destroy
|
||||
def destroy_attrs
|
||||
attribute_attr_models.each do |a|
|
||||
attribute_models.each do |a|
|
||||
if a.should_destroy?
|
||||
a.destroy
|
||||
a.destroy_i18n_variable
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<% @vars = @i18n_variables.inject([]) do |result, var|
|
||||
result << var if var.parent_id.to_s.eql?(edit_user_attribute_model.id.to_s)
|
||||
result << var if var.parent_id.to_s.eql?(edit_user_role_model.id.to_s)
|
||||
result
|
||||
end %>
|
||||
|
||||
<fieldset>
|
||||
<legend>
|
||||
<%= edit_user_attribute_model.key %>
|
||||
<%= edit_user_role_model.key %>
|
||||
<%#= render :partial => 'action_bar' %>
|
||||
</legend>
|
||||
<table>
|
||||
|
@ -16,9 +16,9 @@ end %>
|
|||
<% end %>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><%= edit_user_attribute_model.key %></td>
|
||||
<td><%= edit_user_role_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>
|
||||
<td><%= text_field_tag "i18n_variables[#{edit_user_role_model.id}][#{locale}]", edit_user_role_model[locale] %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<% @vars = @i18n_variables.inject([]) do |result, var|
|
||||
result << var if var.parent_id.to_s.eql?(user_attribute_model.id.to_s)
|
||||
result << var if var.parent_id.to_s.eql?(user_role_model.id.to_s)
|
||||
result
|
||||
end %>
|
||||
|
||||
<fieldset>
|
||||
<legend>
|
||||
<%= user_attribute_model.key %>
|
||||
<%= user_role_model.key %>
|
||||
<%#= render :partial => 'action_bar' %>
|
||||
</legend>
|
||||
<table>
|
||||
|
@ -16,9 +16,9 @@ end %>
|
|||
<% end %>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><%= user_attribute_model.key %></td>
|
||||
<td><%= user_role_model.key %></td>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td><%= user_attribute_model[locale] %></td>
|
||||
<td><%= user_role_model[locale] %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
<% if @user_attribute_model_i18n_variables.size > 0 %>
|
||||
<% if @user_role_role_i18n_variables.size > 0 %>
|
||||
<fieldset>
|
||||
<legend>
|
||||
<%= t('admin.user_attribute') %>
|
||||
<%= t('admin.user_role') %>
|
||||
<%#= render :partial => 'action_bar' %>
|
||||
</legend>
|
||||
<div><%= render :partial => 'edit_user_attribute_model', :collection => @user_attribute_model_i18n_variables %></div>
|
||||
<div><%= render :partial => 'edit_user_role_model', :collection => @user_role_model_i18n_variables %></div>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -42,13 +42,13 @@
|
|||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
<% if @user_attribute_model_i18n_variables.size > 0 %>
|
||||
<% if @user_role_model_i18n_variables.size > 0 %>
|
||||
<fieldset>
|
||||
<legend>
|
||||
<%= t('admin.user_attribute') %>
|
||||
<%= t('admin.user_role') %>
|
||||
<%#= render :partial => 'action_bar' %>
|
||||
</legend>
|
||||
<div><%= render :partial => 'user_attribute_model', :collection => @user_attribute_model_i18n_variables %></div>
|
||||
<div><%= render :partial => 'user_role_model', :collection => @user_role_model_i18n_variables %></div>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
<%= fields_for 'user_attribute_model[attribute_attr_models][]', attribute_attr_model, :index => nil do |f| %>
|
||||
<%= fields_for 'user_role_model[attribute_models][]', attribute_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><%= attribute_model.new_record? ? (f.text_field :key, {:style => "width:130px"}) : attribute_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 %>
|
||||
<%= 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 %>
|
||||
</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>
|
||||
<td><%= text_field_tag "user_role_model[attribute_models][][i18n_variable][#{locale}]", (attribute_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'"%>>
|
||||
<div <%= attribute_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
|
||||
<%= t('admin.options') %>:
|
||||
<%= text_field_tag "user_attribute_model[attribute_attr_models][][select_list_options]", attribute_attr_model.select_list_options, :style => "width:130px" %>
|
||||
<%= text_field_tag "user_role_model[attribute_models][][select_list_options]", attribute_model.select_list_options, :style => "width:130px" %>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<% if attribute_attr_model.new_record? %>
|
||||
<% if attribute_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' %>
|
||||
<%= hidden_field_tag "user_role_model[attribute_models][][should_destroy]", nil , :class => 'should_destroy' %>
|
||||
<%= f.hidden_field :id %>
|
||||
<%= f.hidden_field :key %>
|
||||
<% end %>
|
||||
|
|
|
@ -6,21 +6,21 @@
|
|||
<% end %>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_attribute_model.key %></td>
|
||||
<td><%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_role_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" %>
|
||||
<%= text_field_tag "user_role_model[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:130px" %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<fieldset id='field_set_attribute_attrs'>
|
||||
<fieldset id='field_set_attributes'>
|
||||
<legend>
|
||||
<%= t('admin.attributes')%>
|
||||
</legend>
|
||||
|
||||
<table id='attribute_attrs'>
|
||||
<table id='attributes'>
|
||||
<tr>
|
||||
<th><%= t('admin.key') %></th>
|
||||
<th><%= t('admin.multilingual') %></th>
|
||||
|
@ -30,7 +30,7 @@
|
|||
<th><%= t('admin.type')%></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<%= render :partial => 'attribute_attr_model', :collection => @user_attribute_model.attribute_attr_models %>
|
||||
<%= render :partial => 'attribute_model', :collection => @user_role_model.attribute_models %>
|
||||
</table>
|
||||
|
||||
<a href="#" class="add">(<%= t(:add) %>)</a>
|
||||
|
@ -40,15 +40,15 @@
|
|||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$('#field_set_attribute_attrs a.remove').live('click', function(){
|
||||
$('#field_set_attributes 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_attributes a.add').click(function(){
|
||||
$('#attribute').append("<%= escape_javascript(render(:partial => 'attribute_model', :object => @user_role_model.attribute_models.build)) %>");
|
||||
});
|
||||
|
||||
$('#field_set_attribute_attrs a.remove_existing_record').click(function(){
|
||||
$('#field_set_attributes a.remove_existing_record').click(function(){
|
||||
$(this).next('.should_destroy').attr('value', 1);
|
||||
$(this).parent().parent().hide();
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<h1><%= t('admin.editing_user_attribute') %>: <%= @user_attribute_model.key %></h1>
|
||||
<h1><%= t('admin.editing_user_role') %>: <%= @user_role_model.key %></h1>
|
||||
|
||||
<fieldset>
|
||||
<legend>
|
||||
<%= t('admin.user_attribute')%>
|
||||
<%= t('admin.user_role')%>
|
||||
</legend>
|
||||
|
||||
<%= form_for @user_attribute_model, :url => admin_user_attribute_model_path(@user_attribute_model) do |f| %>
|
||||
<%= form_for @user_role_model, :url => admin_user_role_model_path(@user_role_model) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<%= render :partial => "form", :locals => { :f => f, :is_new => false } %>
|
||||
|
|
|
@ -1,26 +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>
|
||||
<li><%= link_to t('admin.new_user_role'), new_admin_user_role_model_path, :class => 'button positive' %></li>
|
||||
</ul>
|
||||
<% end -%>
|
||||
|
||||
<h1><%= t('admin.list_user_attributes') %></h1>
|
||||
<h1><%= t('admin.list_user_roles') %></h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th><%= t('admin.attribute') %></th>
|
||||
<th><%= t('admin.role') %></th>
|
||||
<th><%= t('admin.key') %></th>
|
||||
<th><%= t('admin.action') %></th>
|
||||
</tr>
|
||||
|
||||
<% @user_attribute_models.each do |user_attribute_model| %>
|
||||
<% @user_role_models.each do |user_role_model| %>
|
||||
<tr>
|
||||
<td><%= user_attribute_model.i18n_variable[I18n.locale] %></td>
|
||||
<td><%= user_attribute_model.key %></td>
|
||||
<td><%= user_role_model.i18n_variable[I18n.locale] %></td>
|
||||
<td><%= user_role_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 %>
|
||||
<%= link_to t(:edit), edit_admin_user_role_model_path(user_role_model) %> |
|
||||
<%= link_to t(:delete), admin_user_role_model_path(user_role_model), :confirm => t('sure?'), :method => :delete %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</table>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<h1><%= t('admin.new_user_attribute') %></h1>
|
||||
<h1><%= t('admin.new_user_role') %></h1>
|
||||
|
||||
<fieldset id='field_set_attribute_attrs'>
|
||||
<fieldset id='field_set_attributes'>
|
||||
<legend>
|
||||
<%= t('admin.user_attribute')%>
|
||||
<%= t('admin.user_role')%>
|
||||
</legend>
|
||||
|
||||
<%= form_for @user_attribute_model, :url => admin_user_attribute_models_path do |f| %>
|
||||
<%= form_for @user_role_model, :url => admin_user_role_models_path do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<%= render :partial => "form", :locals => { :f => f, :is_new => true } %>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<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.user_role'), admin_user_role_models_path %></li>
|
||||
<li><%= link_to t('admin.translation'), admin_translations_path %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<%= fields_for 'user[user_attributes][attribute_attrs]', attribute_attr, :index => nil do |f| %>
|
||||
<%#= f.hidden_field :id unless attribute_attr.new_record? %>
|
||||
<%= 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_attributes][attribute_attrs][i18n_user][#{locale}]", (attribute_attr.i18n_user[locale] rescue nil) %>
|
||||
<%= 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 %>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<div id="select_user_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] %>
|
||||
<div id="select_user_roles">
|
||||
<% @user_role_models.each do |ua| %>
|
||||
<%= check_box_tag "user[active_roles][]", ua.key, (@user.active_roles.include?(ua.key) rescue false) %> <%= ua.i18n_variable[locale] %>
|
||||
<% end -%>
|
||||
<%= hidden_field_tag 'user[active_attributes][]', '' %>
|
||||
<%= hidden_field_tag 'user[active_roles][]', '' %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
@ -19,17 +19,17 @@
|
|||
</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),
|
||||
<% @user_role_models.each do |ua| %>
|
||||
<%= render :partial => 'user_role',
|
||||
:object => (@user.user_roles.detect {|u| u.key == ua.key } || @user.user_roles.build),
|
||||
:locals => {:ua => ua} %>
|
||||
<% end -%>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(document).ready(function(){
|
||||
$('#select_user_attributes input').click(function(){
|
||||
$("#attribute_"+this.value).toggle();
|
||||
$('#select_user_roles input').click(function(){
|
||||
$("#role_"+this.value).toggle();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
<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| %>
|
||||
<%= fields_for 'user[user_roles]', user_role, :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? %>
|
||||
<%= f.hidden_field :id unless user_role.new_record? %>
|
||||
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<th><%= t('admin.attribute') %></th>
|
||||
<th><%= t('admin.role') %></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| %>
|
||||
<% ua.attribute_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) %>
|
||||
<%= text_field_tag "user[user_roles][][#{attr.key}_#{locale}]", (user_role["#{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) %>
|
||||
<%= text_field_tag "user[user_roles][][#{attr.key}]", (user_role[attr.key] rescue nil) %>
|
||||
<% elsif attr["markup"] == "select" %>
|
||||
<%= select_tag "user[user_attributes][][#{attr.key}]", options_for_select(attr["options"], user_attribute[attr.key]) %>
|
||||
<%= select_tag "user[user_roles][][#{attr.key}]", options_for_select(attr["options"], user_role[attr.key]) %>
|
||||
<% end -%>
|
||||
</td>
|
||||
<% end -%>
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
<%= @user.email %>
|
||||
|
||||
<% @user.get_active_attribute_models.each do |am| %>
|
||||
<% user_attribute = @user.get_attribute_from_model_key(am.key) %>
|
||||
<% user_role = @user.get_role_from_model_key(am.key) %>
|
||||
<fieldset>
|
||||
<legend><%= am.i18n_variable[I18n.locale] %></legend>
|
||||
<table>
|
||||
<% am.attribute_attr_models.each do |attr| %>
|
||||
<% am.attribute_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}"] %>
|
||||
<%= user_role["#{attr.key}_#{I18n.locale}"] %>
|
||||
<% else %>
|
||||
<%= user_attribute["#{attr.key}"] %>
|
||||
<%= user_role["#{attr.key}"] %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue