diff --git a/app/controllers/admin/user_info_models_controller.rb b/app/controllers/admin/user_info_models_controller.rb index 5c9c0613..7660d699 100644 --- a/app/controllers/admin/user_info_models_controller.rb +++ b/app/controllers/admin/user_info_models_controller.rb @@ -34,8 +34,10 @@ class Admin::UserInfoModelsController < ApplicationController def update @user_attribute_model = UserInfoModel.find(params[:id]) @user_attribute_model.update_attributes(params[:user_info_model]) - - redirect_to :action => :index + respond_to do |format| + format.html { redirect_to :action => :index } + format.js { render 'admin/user_attribute_models/toggle_enable' } + end end def destroy diff --git a/app/controllers/admin/user_role_models_controller.rb b/app/controllers/admin/user_role_models_controller.rb index 90f2070d..b4145a8f 100644 --- a/app/controllers/admin/user_role_models_controller.rb +++ b/app/controllers/admin/user_role_models_controller.rb @@ -35,7 +35,10 @@ class Admin::UserRoleModelsController < ApplicationController @user_attribute_model = UserRoleModel.find(params[:id]) @user_attribute_model.update_attributes(params[:user_role_model]) - redirect_to :action => :index + respond_to do |format| + format.html { redirect_to :action => :index } + format.js { render 'admin/user_attribute_models/toggle_enable' } + end end def destroy diff --git a/app/controllers/panel/users_controller.rb b/app/controllers/panel/users_controller.rb index d0b177df..c0a2f526 100644 --- a/app/controllers/panel/users_controller.rb +++ b/app/controllers/panel/users_controller.rb @@ -9,13 +9,12 @@ class Panel::UsersController < ApplicationController def show @user = User.find(params[:id]) - @user_info_models = UserInfoModel.all.entries + get_info_role_models end def new @user = User.new - @user_info_models = UserInfoModel.all.entries - @user_role_models = UserRoleModel.all.entries + get_info_role_models end def create @@ -38,8 +37,7 @@ class Panel::UsersController < ApplicationController def edit @user = User.find(params[:id]) - @user_info_models = UserInfoModel.all.entries - @user_role_models = UserRoleModel.all.entries + get_info_role_models end def update @@ -56,8 +54,7 @@ class Panel::UsersController < ApplicationController flash[:notice] = t('panel.update_success_user') redirect_to :action => :index else - @user_info_models = UserInfoModel.all.entries - @user_role_models = UserRoleModel.all.entries + get_info_role_models render :action => :edit end end @@ -73,4 +70,11 @@ class Panel::UsersController < ApplicationController redirect_to :action => :index end + protected + + def get_info_role_models + @user_info_models = UserInfoModel.excludes('disabled' => true) + @user_role_models = UserRoleModel.excludes('disabled' => true) + end + end diff --git a/app/models/attribute_model.rb b/app/models/attribute_model.rb index aad944b5..5cc11aa2 100644 --- a/app/models/attribute_model.rb +++ b/app/models/attribute_model.rb @@ -8,6 +8,8 @@ class AttributeModel field :markup field :locale, :type => Boolean field :list_options, :type => Array + field :built_in, :type => Boolean, :default => false + field :disabled, :type => Boolean, :default => false embedded_in :user_attribute_model, :inverse_of => :attribute_models validates_uniqueness_of :key @@ -47,5 +49,13 @@ class AttributeModel def should_destroy? should_destroy.to_i == 1 rescue nil end + + def is_built_in? + self.built_in + end + + def is_disabled? + self.disabled + end end diff --git a/app/models/user_attribute_model.rb b/app/models/user_attribute_model.rb index b55e38a7..a70c9f85 100644 --- a/app/models/user_attribute_model.rb +++ b/app/models/user_attribute_model.rb @@ -5,6 +5,8 @@ class UserAttributeModel field :key field :i18n_variable_id, :type => BSON::ObjectId, :index => true + field :built_in, :type => Boolean, :default => false + field :disabled, :type => Boolean, :default => false embeds_many :attribute_models @@ -46,6 +48,18 @@ class UserAttributeModel @i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil end + def is_built_in? + self.built_in + end + + def is_disabled? + self.disabled + end + + def get_enabled_attribute_models + self.attribute_models.excludes('disabled' => true) + end + protected # Destroy the i18n_variable for each attribute_models if marked to destroy diff --git a/app/views/admin/user_attribute_models/_attribute_model.html.erb b/app/views/admin/user_attribute_models/_attribute_model.html.erb index 88098505..e8ad4854 100644 --- a/app/views/admin/user_attribute_models/_attribute_model.html.erb +++ b/app/views/admin/user_attribute_models/_attribute_model.html.erb @@ -20,8 +20,17 @@ <% if attribute_model.new_record? %> (<%= t(:delete) %>) <% else %> - (<%= t(:delete) %>) - <%= hidden_field_tag "user_#{@attribute}_model[attribute_models][][should_destroy]", nil , :class => 'should_destroy' %> + + <% if attribute_model.is_built_in? %> + + <%= t(:disable) %> + <%= t(:enable) %> + + <%= hidden_field_tag "user_#{@attribute}_model[attribute_models][][disabled]", attribute_model.is_disabled? , :class => 'built_in_state' %> + <% else %> + (<%= t(:delete) %>) + <%= hidden_field_tag "user_#{@attribute}_model[attribute_models][][should_destroy]", nil , :class => 'should_destroy' %> + <% end %> <%= 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 94c92615..3b8a0b5f 100644 --- a/app/views/admin/user_attribute_models/_form.html.erb +++ b/app/views/admin/user_attribute_models/_form.html.erb @@ -52,6 +52,12 @@ $(this).next('.should_destroy').attr('value', 1); $(this).parent().parent().hide(); }); + + $('#field_set_attributes a.change_built_in').click(function(){ + $(this).children().toggle(); + var $am = $(this).next('.built_in_state') + $am.attr('value', ($am.attr('value') == "false") ? "true" : "false"); + }); $('.select_mulitlingual input').live('click', function(){ $(this).next().attr('value', this.checked); diff --git a/app/views/admin/user_attribute_models/index.html.erb b/app/views/admin/user_attribute_models/index.html.erb index 4e758f17..fed40700 100644 --- a/app/views/admin/user_attribute_models/index.html.erb +++ b/app/views/admin/user_attribute_models/index.html.erb @@ -19,8 +19,14 @@