Users can now be saved with sub_roles

This commit is contained in:
chris2tof committed 2011-12-20 14:35:28 +08:00
1 parent 4108ebf06d
commit afbffe37d5
16 files changed
+125 -88

No files matched your search

+10 -16
View File
@@ -16,32 +16,26 @@
</label>
<label>
<span><%= t('admin.role') %>:</span>
<%= f.select :active_role, @roles.sort_by{|role| role.key }.collect {|role| [ role.i18n_variable[I18n.locale], role.key ]}, :selected => (@user.active_role || 'student') %>
<%= f.select :role_id, @roles.sort_by{|role| role.key }.collect {|role| [ role.i18n_variable[I18n.locale], role.id ]}, :selected => (@user.role_id || Role.get_role_from_key('student')) %>
</label>
</div>
<% @infos.each do |ua| %>
<div id="basic_block" class="attributes_block <%= @class %>">
<h2><%= ua.i18n_variable[I18n.locale] %></h2>
<hr>
<%= render :partial => 'attribute',
:object => (@user.infos.detect {|u| u.key == ua.key } || @user.infos.build),
:locals => {:ua => ua, :type => 'info'} %>
</div>
<% end -%>
<%= render :partial => 'info', :collection => @infos, :locals => {:f => f} %>
<div id='roles'>
<% @roles.each do |ua| %>
<div id="<%= ua.key %>_block" class="attributes_block <%= @class %>" <%= raw(' style="display: none;"') unless ((@user.active_role.eql?(ua.key) rescue nil) || (ua.key.eql?('student') && @user.new_record?)) %>>
<h2><%= ua.i18n_variable[I18n.locale] %></h2>
<% @roles.each do |role| %>
<div id="<%= role.id %>_block" class="attributes_block <%= @class %>" <%= raw(' style="display: none;"') unless ((@user.role.id.eql?(role.id) rescue nil) || (role.key.eql?('student') && @user.new_record?)) %>>
<h2><%= role.i18n_variable[I18n.locale] %></h2>
<hr>
<%= render :partial => 'attribute',
:object => (@user.roles.detect {|u| u.key == ua.key } || @user.roles.build),
:locals => {:ua => ua, :type => 'role'} %>
<%= render :partial => 'sub_role_selector', :locals => {:f => f, :role => role} %>
<%= render :partial => 'sub_role', :collection => role.sub_roles, :locals => {:f => f, :role => role} %>
</div>
<% end -%>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "user_form" %>
<% end -%>
+40
View File
@@ -0,0 +1,40 @@
<div id="basic_block" class="attributes_block <%= @class %>">
<h2><%= info.i18n_variable[I18n.locale] %></h2>
<hr>
<div class="info_input">
<table border="0" cellspacing="0" cellpadding="0">
<thead class="list_head">
<tr>
<td><%= t("admin.key") %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
<% end %>
</tr>
</thead>
<tbody>
<% info.get_enabled_attribute_fields.each do |attr| %>
<%= f.fields_for :attribute_values, @user.get_value_from_field_id(attr.id) do |f| %>
<tr class="list_item">
<td><%= attr.i18n_variable[I18n.locale] %></td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<% @site_valid_locales.each do |locale| %>
<td><%= f.text_field locale %></td>
<% end %>
<% else %>
<td colspan=<%= @site_valid_locales.size %>>
<% if attr["markup"] == "text_field" %>
<%= f.text_field :non_locale %>
<% elsif attr["markup"] == "select" %>
<%= f.select :non_locale, options_for_select(attr["options"], value['non_locale']) %>
<% end -%>
</td>
<% end -%>
<%= f.hidden_field :attribute_field_id, :value => attr.id %>
<%= f.hidden_field :key, :value => attr.key %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
</div>
@@ -7,7 +7,7 @@
<% end %>
</thead>
<tbody>
<% a.get_enabled_attribute_fields.each do |attr| %>
<% show_attribute.get_enabled_attribute_fields.each do |attr| %>
<tr class="list_item">
<td><%= attr.i18n_variable[I18n.locale] %></td>
<% @site_valid_locales.each do |locale| %>
@@ -0,0 +1,4 @@
<div id="sub_role_<%= show_sub_role.id %>" class="info_input">
<h2><%= show_sub_role.i18n_variable[I18n.locale] %></h2>
<%= render :partial => 'show_attribute', :object => show_sub_role %>
</div>
+37
View File
@@ -0,0 +1,37 @@
<div id="sub_role_<%= sub_role.id %>" class="info_input" <%= raw(' style="display: none;"') unless @user.sub_role_ids.include?(sub_role.id) %>>
<h2><%= sub_role.i18n_variable[I18n.locale] %></h2>
<table border="0" cellspacing="0" cellpadding="0">
<thead class="list_head">
<tr>
<td><%= t("admin.key") %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
<% end %>
</tr>
</thead>
<tbody>
<% sub_role.get_enabled_attribute_fields.each do |attr| %>
<%= f.fields_for :attribute_values, @user.get_value_from_field_id(attr.id) do |f| %>
<tr class="list_item">
<td><%= attr.i18n_variable[I18n.locale] %></td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<% @site_valid_locales.each do |locale| %>
<td><%= f.text_field locale %></td>
<% end %>
<% else %>
<td colspan=<%= @site_valid_locales.size %>>
<% if attr["markup"] == "text_field" %>
<%= f.text_field :non_locale %>
<% elsif attr["markup"] == "select" %>
<%= f.select :non_locale, options_for_select(attr["options"], value['non_locale']) %>
<% end -%>
</td>
<% end -%>
<%= f.hidden_field :attribute_field_id, :value => attr.id %>
<%= f.hidden_field :key, :value => attr.key %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
@@ -0,0 +1,4 @@
<% role.sub_roles.each do |sub_role| %>
<%= sub_role.i18n_variable[I18n.locale] %>
<%= check_box_tag "user[sub_role_ids][]", sub_role.id, @user.sub_role_ids.include?(sub_role.id), :class => 'sub_role_select' %>
<% end %>
@@ -1,44 +0,0 @@
<%= fields_for "user[#{type}s]", attribute, :index => nil do |f| %>
<%= f.hidden_field :key, :value => ua.key %>
<%= f.hidden_field :id unless attribute.new_record? %>
<div class="info_input">
<table border="0" cellspacing="0" cellpadding="0">
<thead class="list_head">
<tr>
<td><%= t("admin.key") %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
<% end %>
</tr>
</thead>
<tbody>
<% ua.get_enabled_attribute_fields.each do |attr| %>
<% value = attribute.attribute_values.detect{|v| v.key == attr.key } %>
<%= hidden_field_tag "user[#{type}s][][attribute_values][][id]", value.id rescue nil %>
<%= hidden_field_tag "user[#{type}s][][attribute_values][][key]", attr.key %>
<tr class="list_item">
<td><%= attr.i18n_variable[I18n.locale] %></td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<%= hidden_field_tag "user[#{type}s][][attribute_values][][non_locale]", nil %>
<% @site_valid_locales.each do |locale| %>
<td>
<%= text_field_tag "user[#{type}s][][attribute_values][][#{locale}]", (value[locale] rescue nil) %>
</td>
<% end -%>
<% else %>
<td colspan=<%= @site_valid_locales.size %>>
<% if attr["markup"] == "text_field" %>
<%= text_field_tag "user[#{type}s][][attribute_values][][non_locale]", (value['non_locale'] rescue nil) %>
<% elsif attr["markup"] == "select" %>
<%= select_tag "user[#{type}s][][attribute_values][][non_locale]", options_for_select(attr["options"], value['non_locale']) %>
<% end -%>
</td>
<% end -%>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
+6 -5
View File
@@ -5,24 +5,25 @@
<div id="profile" class="clear">
<div id="person">
<% if @user.avatar? %>
<%= image_tag(@user.avatar.thumb.url) %>
<% if @user.avatar? %>
<%= image_tag(@user.avatar.thumb.url) %>
<% else %>
<%= image_tag "person.png" %>
<%= image_tag "person.png" %>
<% end %>
<label><span><%= @user.email %></span></label>
</div>
<% @infos.each do |a| %>
<div id="basic_block" class="attributes_block <%= @class %>">
<h2><%= a.i18n_variable[I18n.locale] %></h2>
<hr>
<%= render :partial => 'show_attribute', :locals => {:a => a} %>
<%= render :partial => 'show_attribute', :object => a %>
</div>
<% end -%>
<div id="<%= @user.role.key %>_block" class="attributes_block <%= @class %>">
<h2><%= @user.role.i18n_variable[I18n.locale] %></h2>
<hr>
<%#= render :partial => 'show_attribute', :locals => {:a => active_role, :object => @user.get_role_from_key(active_role.key)} %>
<%= render :partial => 'show_sub_role', :collection => @user.sub_roles %>
</div>
<div class="button_bar">
<%= link_to t(:edit), edit_admin_user_path(@user) %>