diff --git a/app/controllers/admin/translations_controller.rb b/app/controllers/admin/translations_controller.rb
index f4e5cead..21ec2265 100644
--- a/app/controllers/admin/translations_controller.rb
+++ b/app/controllers/admin/translations_controller.rb
@@ -73,6 +73,10 @@ class Admin::TranslationsController < ApplicationController
result << var if var.document_class.eql?('UserRoleModel')
result
end
+ @user_info_model_i18n_variables = @i18n_variables.inject([]) do |result, var|
+ result << var if var.document_class.eql?('UserInfoModel')
+ result
+ end
end
end
diff --git a/app/controllers/admin/user_attribute_models_controller.rb b/app/controllers/admin/user_attribute_models_controller.rb
deleted file mode 100644
index 7455d0e3..00000000
--- a/app/controllers/admin/user_attribute_models_controller.rb
+++ /dev/null
@@ -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
diff --git a/app/controllers/admin/user_info_models_controller.rb b/app/controllers/admin/user_info_models_controller.rb
new file mode 100644
index 00000000..6deafdd5
--- /dev/null
+++ b/app/controllers/admin/user_info_models_controller.rb
@@ -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
diff --git a/app/controllers/admin/user_role_models_controller.rb b/app/controllers/admin/user_role_models_controller.rb
new file mode 100644
index 00000000..f4f71cab
--- /dev/null
+++ b/app/controllers/admin/user_role_models_controller.rb
@@ -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
diff --git a/app/controllers/panel/users_controller.rb b/app/controllers/panel/users_controller.rb
index 27c196dc..1e67c11b 100644
--- a/app/controllers/panel/users_controller.rb
+++ b/app/controllers/panel/users_controller.rb
@@ -9,10 +9,12 @@ class Panel::UsersController < ApplicationController
def show
@user = User.find(params[:id])
+ @user_info_models = UserInfoModel.all.entries
end
def new
@user = User.new
+ @user_info_models = UserInfoModel.all.entries
@user_role_models = UserRoleModel.all.entries
session[:last_page] = get_go_back || panel_users_url
end
@@ -28,6 +30,7 @@ class Panel::UsersController < ApplicationController
def edit
@user = User.find(params[:id])
+ @user_info_models = UserInfoModel.all.entries
@user_role_models = UserRoleModel.all.entries
session[:last_page] = get_go_back || panel_users_url
end
@@ -42,6 +45,7 @@ class Panel::UsersController < ApplicationController
if @user.update_attributes(params[:user])
redirect_to :action => :index
else
+ @user_info_models = UserInfoModel.all.entries
@user_role_models = UserRoleModel.all.entries
render :action => :edit
end
diff --git a/app/models/attribute_model.rb b/app/models/attribute_model.rb
index 35a38be6..4c89e2b4 100644
--- a/app/models/attribute_model.rb
+++ b/app/models/attribute_model.rb
@@ -8,7 +8,7 @@ class AttributeModel
field :locale, :type => Boolean
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
# Destroy the i18n_variable
@@ -26,7 +26,7 @@ class AttributeModel
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_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
self.i18n_variable_id = var.id
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 35280cb8..1c5ab9a7 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -7,11 +7,11 @@ class User
mount_uploader :avatar, AvatarUploader
field :admin, :type => Boolean, :default => true
- field :active_attributes, :type => Array
+ field :active_roles, :type => Array
- embeds_one :user_info
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
def user_roles=(*attrs)
@@ -20,11 +20,16 @@ class User
user_roles.build(roles)
else
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
+ # 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
def get_role_from_model_key(key)
self.user_roles.detect {|a| a.key.to_s == key.to_s }
diff --git a/app/models/user_attribute_model.rb b/app/models/user_attribute_model.rb
index 2ba0cacd..3d95bbc9 100644
--- a/app/models/user_attribute_model.rb
+++ b/app/models/user_attribute_model.rb
@@ -21,6 +21,30 @@ class UserAttributeModel
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
# Destroy the i18n_variable for each attribute_models if marked to destroy
diff --git a/app/models/user_info.rb b/app/models/user_info.rb
index d267f455..8af5b950 100644
--- a/app/models/user_info.rb
+++ b/app/models/user_info.rb
@@ -4,6 +4,6 @@ class UserInfo
field :key
- embedded_in :user, :inverse_of => :user_info
+ embedded_in :user, :inverse_of => :user_infos
end
diff --git a/app/models/user_info_model.rb b/app/models/user_info_model.rb
index 66ecfdd7..cacf2a55 100644
--- a/app/models/user_info_model.rb
+++ b/app/models/user_info_model.rb
@@ -1,3 +1,3 @@
class UserInfoModel < UserAttributeModel
-
+
end
diff --git a/app/models/user_role_model.rb b/app/models/user_role_model.rb
index 22f11b99..b35fce32 100644
--- a/app/models/user_role_model.rb
+++ b/app/models/user_role_model.rb
@@ -1,27 +1,3 @@
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
diff --git a/app/views/admin/translations/_edit_user_attribute_model.html.erb b/app/views/admin/translations/_edit_user_attribute_model.html.erb
index 899ff745..829d1c11 100644
--- a/app/views/admin/translations/_edit_user_attribute_model.html.erb
+++ b/app/views/admin/translations/_edit_user_attribute_model.html.erb
@@ -1,11 +1,11 @@
<% @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
end %>