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 %>
- <%= edit_user_role_model.key %> + <%= edit_user_attribute_model.key %> <%#= render :partial => 'action_bar' %> @@ -16,9 +16,9 @@ end %> <% end %> - + <% @site_valid_locales.each do |locale| %> - + <% end %> diff --git a/app/views/admin/translations/_user_attribute_model.html.erb b/app/views/admin/translations/_user_attribute_model.html.erb index b326021a..1d7f0eca 100644 --- a/app/views/admin/translations/_user_attribute_model.html.erb +++ b/app/views/admin/translations/_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?(user_role_model.id.to_s) + result << var if var.parent_id.to_s.eql?(user_attribute_model.id.to_s) result end %>
- <%= user_role_model.key %> + <%= user_attribute_model.key %> <%#= render :partial => 'action_bar' %>
<%= edit_user_role_model.key %><%= edit_user_attribute_model.key %><%= text_field_tag "i18n_variables[#{edit_user_role_model.id}][#{locale}]", edit_user_role_model[locale] %><%= text_field_tag "i18n_variables[#{edit_user_attribute_model.id}][#{locale}]", edit_user_attribute_model[locale] %>
@@ -16,9 +16,9 @@ end %> <% end %> - + <% @site_valid_locales.each do |locale| %> - + <% end %> diff --git a/app/views/admin/translations/edit.html.erb b/app/views/admin/translations/edit.html.erb index d3ca2971..0850d633 100644 --- a/app/views/admin/translations/edit.html.erb +++ b/app/views/admin/translations/edit.html.erb @@ -10,13 +10,23 @@ <% end %> - <% if @user_role_role_i18n_variables.size > 0 %> + <% if @user_info_model_i18n_variables.size > 0 %> +
+ + <%= t('admin.user_info') %> + <%#= render :partial => 'action_bar' %> + +
<%= render :partial => 'edit_user_attribute_model', :collection => @user_info_model_i18n_variables %>
+
+ <% end %> + + <% if @user_role_model_i18n_variables.size > 0 %>
<%= t('admin.user_role') %> <%#= render :partial => 'action_bar' %> -
<%= render :partial => 'edit_user_role_model', :collection => @user_role_model_i18n_variables %>
+
<%= render :partial => 'edit_user_attribute_model', :collection => @user_role_model_i18n_variables %>
<% end %> diff --git a/app/views/admin/translations/index.html.erb b/app/views/admin/translations/index.html.erb index 5b24ec02..e17ffc83 100644 --- a/app/views/admin/translations/index.html.erb +++ b/app/views/admin/translations/index.html.erb @@ -42,13 +42,23 @@ <% end %> +<% if @user_info_model_i18n_variables.size > 0 %> +
+ + <%= t('admin.user_info') %> + <%#= render :partial => 'action_bar' %> + +
<%= render :partial => 'user_attribute_model', :collection => @user_info_model_i18n_variables %>
+
+<% end %> + <% if @user_role_model_i18n_variables.size > 0 %>
<%= t('admin.user_role') %> <%#= render :partial => 'action_bar' %> -
<%= render :partial => 'user_role_model', :collection => @user_role_model_i18n_variables %>
+
<%= render :partial => 'user_attribute_model', :collection => @user_role_model_i18n_variables %>
<% end %> diff --git a/app/views/admin/user_attribute_models/_attribute_attr_model.html.erb b/app/views/admin/user_attribute_models/_attribute_model.html.erb similarity index 56% rename from app/views/admin/user_attribute_models/_attribute_attr_model.html.erb rename to app/views/admin/user_attribute_models/_attribute_model.html.erb index 34f572fd..88098505 100644 --- a/app/views/admin/user_attribute_models/_attribute_attr_model.html.erb +++ b/app/views/admin/user_attribute_models/_attribute_model.html.erb @@ -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| %> <% @site_valid_locales.each do |locale| %> - + <% end %> - + <% @site_valid_locales.each do |locale| %> <% end %> @@ -30,7 +30,7 @@ - <%= render :partial => 'attribute_model', :collection => @user_role_model.attribute_models %> + <%= render :partial => 'admin/user_attribute_models/attribute_model', :collection => @user_attribute_model.attribute_models %>
<%= user_role_model.key %><%= user_attribute_model.key %><%= user_role_model[locale] %><%= user_attribute_model[locale] %>
<%= attribute_model.new_record? ? (f.text_field :key, {:style => "width:130px"}) : attribute_model.key %> <%= 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 %> <%= text_field_tag "user_role_model[attribute_models][][i18n_variable][#{locale}]", (attribute_model.i18n_variable[locale] rescue nil), :style => "width:130px" %><%= text_field_tag "user_#{@attribute}_model[attribute_models][][i18n_variable][#{locale}]", (attribute_model.i18n_variable[locale] rescue nil), :style => "width:130px" %> <%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
> <%= 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" %>
@@ -21,7 +21,7 @@ (<%= t(:delete) %>) <% else %> (<%= t(:delete) %>) - <%= 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 :key %> <% end %> diff --git a/app/views/admin/user_attribute_models/_form.html.erb b/app/views/admin/user_attribute_models/_form.html.erb index e32d6d11..94c92615 100644 --- a/app/views/admin/user_attribute_models/_form.html.erb +++ b/app/views/admin/user_attribute_models/_form.html.erb @@ -6,10 +6,10 @@ <% end %>
<%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_role_model.key %><%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_attribute_model.key %> - <%= 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" %>
<%= t('admin.type')%>
(<%= t(:add) %>) @@ -45,7 +45,7 @@ }); $('#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(){ diff --git a/app/views/admin/user_attribute_models/edit.html.erb b/app/views/admin/user_attribute_models/edit.html.erb index 8d5b3c6f..2caf3de0 100644 --- a/app/views/admin/user_attribute_models/edit.html.erb +++ b/app/views/admin/user_attribute_models/edit.html.erb @@ -1,14 +1,14 @@ -

<%= t('admin.editing_user_role') %>: <%= @user_role_model.key %>

+

<%= t("admin.editing_user_#{@attribute}") %>: <%= @user_attribute_model.key %>

- <%= t('admin.user_role')%> + <%= t("admin.user_#{@attribute}")%> - <%= 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 %> - <%= render :partial => "form", :locals => { :f => f, :is_new => false } %> + <%= render :partial => "admin/user_attribute_models/form", :locals => { :f => f, :is_new => false } %>

<%= f.submit t('update') %> <%= link_back %> diff --git a/app/views/admin/user_attribute_models/index.html.erb b/app/views/admin/user_attribute_models/index.html.erb index eb543feb..4e758f17 100644 --- a/app/views/admin/user_attribute_models/index.html.erb +++ b/app/views/admin/user_attribute_models/index.html.erb @@ -1,25 +1,25 @@ <% content_for :secondary do %>

<% end -%> -

<%= t('admin.list_user_roles') %>

+

<%= t("admin.list_user_#{@attribute}s") %>

- + -<% @user_role_models.each do |user_role_model| %> +<% @user_attribute_models.each do |user_attribute_model| %> - - + + <% end %> diff --git a/app/views/admin/user_attribute_models/new.html.erb b/app/views/admin/user_attribute_models/new.html.erb index 2b14840f..041c1dd1 100644 --- a/app/views/admin/user_attribute_models/new.html.erb +++ b/app/views/admin/user_attribute_models/new.html.erb @@ -1,14 +1,14 @@ -

<%= t('admin.new_user_role') %>

+

<%= t("admin.new_user_#{@attribute}") %>

- <%= t('admin.user_role')%> + <%= t("admin.user_#{@attribute}")%> - <%= 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 %> - <%= render :partial => "form", :locals => { :f => f, :is_new => true } %> + <%= render :partial => "admin/user_attribute_models/form", :locals => { :f => f, :is_new => true } %>

<%= f.submit t('create') %> <%= link_back %> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 64caa9cf..9f7106f6 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -34,6 +34,7 @@

  • <%= link_to t('admin.item'), admin_items_path %>
  • <%= link_to t('admin.layout'), admin_layouts_path %>
  • <%= link_to t('admin.asset'), admin_assets_path %>
  • +
  • <%= link_to t('admin.user_info'), admin_user_info_models_path %>
  • <%= link_to t('admin.user_role'), admin_user_role_models_path %>
  • <%= link_to t('admin.translation'), admin_translations_path %>
  • diff --git a/app/views/panel/users/_attribute_attr.html.erb b/app/views/panel/users/_attribute_attr.html.erb deleted file mode 100644 index 3a958465..00000000 --- a/app/views/panel/users/_attribute_attr.html.erb +++ /dev/null @@ -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"] %> -

    - <%#= 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 -%> -

    - <% else %> -

    - <%= 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 -%> -

    - <% end -%> -<% end %> diff --git a/app/views/panel/users/_form.html.erb b/app/views/panel/users/_form.html.erb index 208066ed..1034c8c2 100644 --- a/app/views/panel/users/_form.html.erb +++ b/app/views/panel/users/_form.html.erb @@ -19,17 +19,42 @@

    -<% @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 -%> +<% if @user_info_models %> +
    + <%= t('panel.infos') %> + <% @user_info_models.each do |ua| %> +
    + <%= render :partial => 'user_attribute', + :object => (@user.user_infos.detect {|u| u.key == ua.key } || @user.user_infos.build), + :locals => {:ua => ua, :type => 'info'} %> +
    + <% end -%> +
    +<% end %> + +<%= hidden_field_tag :active_roles, @user.active_roles.size > 0 %> +<% if @user_role_models %> + +<% end %> <% content_for :page_specific_javascript do %> diff --git a/app/views/panel/users/_show_user_attribute.html.erb b/app/views/panel/users/_show_user_attribute.html.erb new file mode 100644 index 00000000..1ff9fe45 --- /dev/null +++ b/app/views/panel/users/_show_user_attribute.html.erb @@ -0,0 +1,17 @@ +
    + <%= am.i18n_variable[I18n.locale] %> +
    <%= t('admin.role') %><%= t("admin.#{@attribute}") %> <%= t('admin.key') %> <%= t('admin.action') %>
    <%= user_role_model.i18n_variable[I18n.locale] %><%= user_role_model.key %><%= user_attribute_model.i18n_variable[I18n.locale] %><%= user_attribute_model.key %> - <%= 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 %> + <%= link_to t(:edit), eval("edit_admin_user_#{@attribute}_model_path(user_attribute_model)") %> | + <%= link_to t(:delete), eval("admin_user_#{@attribute}_model_path(user_attribute_model)"), :confirm => t('sure?'), :method => :delete %>
    + <% am.attribute_models.each do |attr| %> + + + + + <% end %> +
    <%= attr.i18n_variable[I18n.locale] %> + <% 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 %> +
    +
    diff --git a/app/views/panel/users/_user_attribute.html.erb b/app/views/panel/users/_user_attribute.html.erb index 8c5db101..a31c3100 100644 --- a/app/views/panel/users/_user_attribute.html.erb +++ b/app/views/panel/users/_user_attribute.html.erb @@ -1,42 +1,38 @@ - +<% end %> diff --git a/app/views/panel/users/index.html.erb b/app/views/panel/users/index.html.erb index 4e8fff04..57559047 100644 --- a/app/views/panel/users/index.html.erb +++ b/app/views/panel/users/index.html.erb @@ -8,7 +8,7 @@ - + @@ -16,7 +16,7 @@ <% @users.each do |user| %> - +
    <%= t('panel.attributes') %><%= t('panel.roles') %> <%= t('panel.name') %> <%= t('panel.email') %> <%= t('panel.action') %>
    <%= user.get_attributes %><%= user.get_roles %> <%= user[:name] %> <%= user.email %> diff --git a/app/views/panel/users/show.html.erb b/app/views/panel/users/show.html.erb index fbc679d8..ec6d40a3 100644 --- a/app/views/panel/users/show.html.erb +++ b/app/views/panel/users/show.html.erb @@ -10,23 +10,24 @@ <%= @user.email %> -<% @user.get_active_attribute_models.each do |am| %> - <% user_role = @user.get_role_from_model_key(am.key) %> +<% if @user_info_models %>
    - <%= am.i18n_variable[I18n.locale] %> - - <% am.attribute_models.each do |attr| %> - - - - - <% end %> -
    <%= attr.i18n_variable[I18n.locale] %> - <% if attr["locale"] && attr["markup"] == 'text_field' %> - <%= user_role["#{attr.key}_#{I18n.locale}"] %> - <% else %> - <%= user_role["#{attr.key}"] %> - <% end %> -
    + <%= t('panel.infos') %> + <% @user_info_models.each do |am| %> + <%= render :partial => 'show_user_attribute', + :object => @user.get_info_from_model_key(am.key), + :locals => {:am => am} %> + <% end -%>
    -<% end -%> +<% end %> + +<% if @user.active_roles.size > 0 %> +
    + <%= t('panel.roles') %> + <% @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 -%> +
    +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 11a85ac2..b659af5e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -27,7 +27,6 @@ en: action: Action announcement: Announcement asset: Asset - attribute: Attribute attributes: Attributes class: Class create_success_home: Homepage was successfully created. @@ -45,7 +44,8 @@ en: editing_link: Editing link editing_page: Editing page 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 file_name: Filename file_size: File size @@ -60,7 +60,8 @@ en: list_items: Items list list_layouts: Layouts 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_up: Move up multilingual: Multilingual @@ -74,30 +75,35 @@ en: new_link: New link new_page: New page 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 options: Options orig_upload_file: Original filename position: Position published?: Published? + info: Information + role: Role title: Title translation: Translation type: Type - user_attribute: User attribute update_success_home: Homepage was successfully updated. update_success_layout: Layout was successfully updated. update_success_link: Link was successfully updated. update_success_page: Page was successfully updated. update_success_snippet: Snippet was successfully updated. + user_info: User information + user_role: User role panel: action: Action - attributes: Attributes email: Email home: Home list_users: Users list my_avatar: My Avatar name: Name new_user: New user + infos: Information + roles: Roles user: User user_panel: User panel diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index c2f0b0e4..f6495949 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -24,7 +24,6 @@ zh_tw: action: 行動 announcement: 公告 asset: 資產 - attribute: 屬性 attributes: 屬性 class: 階級 content: 內容 @@ -42,7 +41,8 @@ zh_tw: editing_link: 編輯連結 editing_page: 編輯頁面 editing_snippet: 編輯片段 - editing_user_attribute: 編輯人物屬性 + editing_user_info: 編輯用戶資料 + editing_user_role: 編輯用戶角色 enable_language: 啟用語言 file_name: 檔名 file_size: 檔案大小 @@ -57,7 +57,8 @@ zh_tw: list_items: 項目清單 list_layouts: 佈局清單 list_snippets: 斷片清單 - list_user_attributes: 人物屬性清單 + list_user_infos: 用戶資料清單 + list_user_roles: 用戶角色清單 move_down: 往下移 move_up: 往上移 multilingual: 多種語言 @@ -71,31 +72,36 @@ zh_tw: new_link: 新增連結 new_page: 新增頁面 new_snippet: 新增片段 - new_user_attribute: 新增人物屬性 + new_user_info: 新增用戶資料 + new_user_role: 新增用戶角色 non_multilingual: 非多種語言 options: 選項 orig_upload_file: 原上傳檔名 position: 位置 published?: 發布? + info: 資料 + role: 角色 title: 標題 translation: 翻譯 type: 類型 - user_attribute: 人物屬性 update_success_home: 首頁已成功更新。 update_success_layout: 樣板已成功更新。 update_success_link: 連結已成功更新。 update_success_page: 頁面已成功更新。 update_success_snippet: 片段已成功更新。 + user_info: 用戶資料 + user_role: 用戶角色 panel: action: 行動 - attributes: 屬性 email: Email home: 首頁 list_users: 使用清單 my_avatar: 我的頭像 name: 名稱 new_user: 新增使用 + infos: 資料 + roles: 角色 user: 用戶 user_panel: 用戶面板 diff --git a/config/routes.rb b/config/routes.rb index b9a8e47d..378350c2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,7 +48,8 @@ PrototypeR4::Application.routes.draw do resources :homes resources :snippets resources :translations - resources :user_attribute_models + resources :user_info_models + resources :user_role_models end namespace :panel do