Built-in user_attribute_models
This commit is contained in:
1 parent
509c106b3e
commit
83bbd77d96
14 files changed
+78
-20
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -20,8 +20,17 @@
|
||||
<% 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_models][][should_destroy]", nil , :class => 'should_destroy' %>
|
||||
|
||||
<% if attribute_model.is_built_in? %>
|
||||
<a href="#" class="change_built_in" id="<%= attribute_model.id %>">
|
||||
<span style="display:<%= attribute_model.is_disabled? ? 'none' : 'inline' %>"><%= t(:disable) %></span>
|
||||
<span style="display:<%= attribute_model.is_disabled? ? 'inline' : 'none' %>"><%= t(:enable) %></span>
|
||||
</a>
|
||||
<%= hidden_field_tag "user_#{@attribute}_model[attribute_models][][disabled]", attribute_model.is_disabled? , :class => 'built_in_state' %>
|
||||
<% else %>
|
||||
<a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a>
|
||||
<%= hidden_field_tag "user_#{@attribute}_model[attribute_models][][should_destroy]", nil , :class => 'should_destroy' %>
|
||||
<% end %>
|
||||
<%= f.hidden_field :id %>
|
||||
<%= f.hidden_field :key %>
|
||||
<% end %>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -19,8 +19,14 @@
|
||||
<td><%= user_attribute_model.key %></td>
|
||||
<td>
|
||||
<%= 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 %>
|
||||
</td>
|
||||
<% if user_attribute_model.is_built_in? %>
|
||||
<%= link_to t(:disable), eval("admin_user_#{@attribute}_model_path(user_attribute_model, :authenticity_token => form_authenticity_token, :user_#{@attribute}_model => {:disabled => true})"), :remote => true, :method => :put, :id => "disable_#{user_attribute_model.id}", :style => "display:#{user_attribute_model.is_disabled? ? 'none' : 'inline'}" %>
|
||||
<%= link_to t(:enable), eval("admin_user_#{@attribute}_model_path(user_attribute_model, :authenticity_token => form_authenticity_token, :user_#{@attribute}_model => {:disabled => false})"), :remote => true, :method => :put, :id => "enable_#{user_attribute_model.id}", :style => "display:#{user_attribute_model.is_disabled? ? 'inline' : 'none'}" %>
|
||||
<% else %>
|
||||
<%= link_to t(:delete), eval("admin_user_#{@attribute}_model_path(user_attribute_model)"), :confirm => t('sure?'), :method => :delete %>
|
||||
<% end %>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
@@ -0,0 +1,2 @@
|
||||
$("#enable_<%= @user_attribute_model.id %>").toggle();
|
||||
$("#disable_<%= @user_attribute_model.id %>").toggle();
|
||||
@@ -7,6 +7,7 @@
|
||||
<%= yield :page_specific_link %>
|
||||
<%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
|
||||
<%= stylesheet_link_tag "easyprint", :media => "print" %>
|
||||
<%= javascript_include_tag :defaults %>
|
||||
<!--[if IE]>
|
||||
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
|
||||
<![endif]-->
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<%= yield :page_specific_link %>
|
||||
<%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
|
||||
<%= stylesheet_link_tag "easyprint", :media => "print" %>
|
||||
<%= javascript_include_tag :defaults %>
|
||||
<!--[if IE]>
|
||||
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
|
||||
<![endif]-->
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<fieldset>
|
||||
<legend><%= am.i18n_variable[I18n.locale] %></legend>
|
||||
<table>
|
||||
<% am.attribute_models.each do |attr| %>
|
||||
<% am.get_enabled_attribute_models.each do |attr| %>
|
||||
<tr>
|
||||
<td><%= attr.i18n_variable[I18n.locale] %></td>
|
||||
<td>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
<% ua.attribute_models.each do |attr| %>
|
||||
<% ua.get_enabled_attribute_models.each do |attr| %>
|
||||
<% value = user_attribute.attribute_values.detect{|v| v.key == attr.key } %>
|
||||
<%= hidden_field_tag "user[user_#{type}s][][attributes][][id]", value.id rescue nil %>
|
||||
<%= hidden_field_tag "user[user_#{type}s][][attributes][][key]", attr.key %>
|
||||
|
||||
Reference in new issue
Block a user