member for THU

This commit is contained in:
Matthew K. Fu JuYuan 2012-10-18 18:36:21 +08:00
parent 0babd5f302
commit 13ae2602cd
14 changed files with 162 additions and 123 deletions

View File

@ -310,6 +310,9 @@
.user-role .staff h4 .gender {
border-color: #139E2F transparent transparent #139E2F;
}
.user-role .tab-content, .user-role .tabs-right > .nav-tabs {
.user-role .tab-content, .user-role .nav-pills {
float: left;
}
.user-role .nav-pills {
margin-left: 10px;
}

View File

@ -33,19 +33,25 @@ class Admin::UsersNewInterfaceController < ApplicationController
@student_data = []
@staff_data = []
@user.attribute_values.each{|att_val|
attribute_values = @user.attribute_values.reject{|att_val|
# binding.pry if(att_val.id.to_s == '507fa1295789b52a540000e0')
!att_val.attribute_field.locale and (att_val.attribute_field.neutral_for != I18n.locale.to_s)
}
attribute_values.each{|att_val|
@profile_data.push({:name => att_val.attribute_field.title,:value =>att_val.get_value_by_locale(I18n.locale)}) if att_val.attribute_field.attribute.key=="profile" rescue false
}
@user.attribute_values.each{|att_val|
attribute_values.each{|att_val|
@teacher_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="teacher"rescue false
}
@user.attribute_values.each{|att_val|
attribute_values.each{|att_val|
@student_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="student"rescue false
}
@user.attribute_values.each{|att_val|
attribute_values.each{|att_val|
@staff_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="staff_data"rescue false
}
@ -75,19 +81,20 @@ class Admin::UsersNewInterfaceController < ApplicationController
def new
@user = User.new
@disable_all_field = true
@form_index = 0
get_info_and_roles
end
def create
puts params.to_yaml
attribute_valuesp_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_valuesp_key)
# binding.pry
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key)
@user = User.new(params["user"])
attribute_values.to_hash.each{|key,value|
@user.attribute_values.build(value)
}
@user.rebuild_sub_roles_from_attribute_values!(attribute_values)
if @user.save
flash[:notice] = t('admin.create_success_user')
redirect_to :action => :index
@ -104,6 +111,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
end
def edit
@disable_all_field = false
@user = User.find(params[:id])
@form_index = 0
get_info_and_roles
@ -112,6 +120,9 @@ class Admin::UsersNewInterfaceController < ApplicationController
def update
@user = User.find(params[:id])
@user.update_attributes(params[:user])
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key)
@user.rebuild_sub_roles_from_attribute_values!(attribute_values)
@user.save
redirect_to :action => :show
# # Update changes to the avatar

View File

@ -7,79 +7,20 @@ class SessionsController < Devise::SessionsController
# login_password = params[:user][:password]
# login_uid = params[:user][:nccu_ldap_uid]
login_password = params[:user][:password]
login_uid = params[:user][:nccu_ldap_uid]
login_email = params[:user][:login]
result = false
ldap_filter = "(uid=#{login_uid})"
if /@rulingcom.com$/.match(login_uid).nil?
MiddleSiteConnection.establish
NccuLdapConnection.establish
if ($nccu_ldap_connection.bind rescue false)
logger.info "=LDAP Binded password ok..."
result =check_auth_with_ldap(login_uid,login_password)
if result && login_password!=''
logger.info "==LDAP password passed..."
nccu_id = get_nccu_id_from_mid_site(login_uid)
resource = nccu_id.nil? ? nil : (User.first(conditions:{ nccu_ldap_uid: nccu_id }))
# resource = env['warden'].authenticate!(:check_nccu_ldap)
# resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
if (resource.nil? || nccu_id.nil?)
logger.error "===LDAP passed local block... resource:#{resource.inspect}\n nccu_id:#{nccu_id} \t login_uid:#{login_uid}"
flash[:notice] = t('devise.failure.ldap_pass_but_account_not_in_orbit')
render :action => "new"
else
logger.info "===ALL passed"
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
end
else
logger.error "==password LDAP fail..."
flash[:notice] = t('devise.failure.ldap_invalid')
render :action => "new"
end
else
logger.error "=LDAP fail..."
flash[:notice] = t('devise.failure.ldap_connection_failed')
render :action => "new"
end
else #if rulingcom account
logger.info "=======Rulingcom account======"
resource = User.first(conditions:{email: login_uid})
if resource.valid_password?(login_password)
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
else
logger.error "==password Local fail..."
flash[:notice] = t('devise.failure.invalid')
render :action => "new"
end
end
logger.info "=======End Debugging======"
resource = User.first(conditions:{ email: login_email })
set_flash_message(:notice, :signed_in) if is_navigational_format?
if resource.nil?
logger.error "Can't find user #{login_email}"
flash[:notice] = t('devise.failure.invalid')
render :action => "new"
else
logger.info "=== passed"
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
end
private
def check_auth_with_ldap(login_uid,login_password)
ldap_filter = "(uid=#{login_uid})"
$nccu_ldap_connection.bind_as(:base => NccuLdapConnection::BASE,:filter => ldap_filter,:password=> login_password) rescue false
end
def get_nccu_id_from_mid_site(ldap_id)
nccu_id = $mid_site_connection.query("SELECT nccu_id FROM rss_aaldap_view WHERE ldap_id='#{ldap_id}' LIMIT 1").first['nccu_id'] rescue nil
#
# if nccu_id.nil?
# #show_error
# p 'account not exist'
# #should return?
# end
# # User.first(conditions: { })
# rss_pautlst_ut = $mid_site_connection.query("SELECT * FROM rss_pautlst_ut WHERE nccu_id='#{nccu_id}' LIMIT 1").first rescue nil
# # rss_paunit = client.query("SELECT * FROM rss_paunit LIMIT 1").first rescue nil
# user = User.find_or_create_by(:nccu_id => nccu_id)
# p user
# # p rss_paunit
#
end
end

View File

@ -1,7 +1,9 @@
module ApplicationHelper
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
def check_user_role_enable(attribute_fields)
@user.attribute_values.collect{|t| attribute_fields.include?(t.attribute_field) }.include?(true) rescue false
end
def show_attribute_value(value)
if value.kind_of? Hash
result = []

View File

@ -8,8 +8,9 @@ module AttributeFieldsHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::RenderingHelper
def block_helper(user,index)
def block_helper(user,index,disable = false)
@index = index
@markup_options = markup_options.merge(:disabled=>disable)
@user = user
@attribute_value = @user.get_value_from_field_id(id)
@new_attribute = @attribute_value.nil?
@ -29,10 +30,10 @@ module AttributeFieldsHelper
if(add_more and value.is_a?(Array))
values = value
result << values.each_with_index.collect do |value,index|
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,markup_options)
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options)
end.join.html_safe
else
result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options)
result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,@markup_options)
end
result << ('<a href="#'+self.key+'-edit" class="btn" type="button" data-toggle="modal"><i class="icon-edit"></i></a>').html_safe
@ -43,15 +44,16 @@ module AttributeFieldsHelper
end
def render_checkbox
markup_value = eval(self.markup_value) rescue {}
control_group_wrapper do
markup_value.collect do |key,value|
label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],markup_options.merge(:class=>"control-label"))
label_tag(key,check_box_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
end.join rescue ""
end
end
def render_date
control_group_wrapper{date_select(get_field_name_base+"[value]",@prefiled_value,markup_options,:class=>"input-small")}
control_group_wrapper{date_select(get_field_name_base+"[value]",nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
end
def render_date_durnation #Need re-write low priority
@ -59,36 +61,51 @@ module AttributeFieldsHelper
end
def render_radio_button
markup_value = eval(self.markup_value) rescue {}
control_group_wrapper do
markup_value.collect do |key,value|
label_tag(key,radio_button_tag(get_field_name_base, value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],markup_options.merge(:class=>"control-label"))
label_tag(key,radio_button_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
end.join rescue ""
end
end
def render_select
control_group_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),markup_options)} rescue ""
markup_value = eval(self.markup_value) rescue {}
control_group_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),@markup_options)} rescue ""
end
def render_text_area
control_group_wrapper{|key,value|text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options)}
end
def render_text_field
control_group_wrapper do |key,value|
control_group_wrapper do |key,value|
if(add_more and value.is_a?(Hash))
values = value
values.each_with_index.collect do |value,index|
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,markup_options)
text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options)
end.join.html_safe
else
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options)
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
key = can_muti_lang_input ? "[#{key}]" : "[value]"
text_area_tag(get_field_name_base + key, value,@markup_options)
end
end
end
def render_text_field
control_group_wrapper do |key,value|
if(add_more and value.is_a?(Hash))
values = value
values.each_with_index.collect do |value,index|
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options)
end.join.html_safe
else
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
key = can_muti_lang_input ? "[#{key}]" : "[value]"
text_field_tag(get_field_name_base + key, value,@markup_options)
end
end
end
protected
def lang_panel_control_wrapper(&block)
result = '<div class="tabbable tabs-right">'
result = '<div class="tabbable">'
result << '<div class="tab-content">'
result << controls_wrapper{yield}
result << '</div>'
@ -99,7 +116,7 @@ protected
def controls_wrapper(&block)
result = "<div class='controls'>"
if can_muti_lang_input
result << "<div class='tabbable tabs-right'>"
result << "<div class='tabbable'>"
result << "<div class='tab-content'>"
VALID_LOCALES.collect do |key|
value = @prefiled_value[key.to_s] rescue nil
@ -108,7 +125,7 @@ protected
result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}")
end
result << "</div>"
result << "<ul class='nav nav-tabs'>"
result << "<ul class='nav nav-pills'>"
VALID_LOCALES.each do |key|
result << content_tag(:li,link_to(I18n.t("langs."+key),"#tab"+id.to_s+"_#{key}",:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil))
end
@ -141,9 +158,9 @@ protected
def end_block
if @new_attribute
hidden_field_tag(get_field_name_base+"[attribute_field_id]",id)
hidden_field_tag(get_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}")
else
hidden_field_tag(get_field_name_base+"[id]",@attribute_value.id)
hidden_field_tag(get_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}")
end
end

View File

@ -18,6 +18,7 @@ class AttributeField
field :locale_title, localize: true
field :neutral_title
field :neutral_for
belongs_to :attribute
# belongs_to :role

View File

@ -30,17 +30,20 @@ class AttributeValue
when "text_field"
self.attribute_field.locale ? self[locale] : self[:value]
when "select"
self.attribute_field.markup_value[self[:value]][locale.to_s] || NoData
markup_values = eval(self.attribute_field.markup_value)
markup_values[self[:value]][locale.to_s] rescue 'NoData'
when "text_area"
#self[:value]
self.attribute_field.locale ? self[locale] : self[:value]
when "date"
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i)
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i) rescue nil
when "addr"
self[:value]
when "radio_button"
self[:value]
markup_values = eval(self.attribute_field.markup_value)
markup_values[self[:value].first[0]][locale.to_s]
when "checkbox"
self[:value]
markup_values = eval(self.attribute_field.markup_value)
self[:value].keys.collect{|key| markup_values[key][locale.to_s] }.join(",")
when "date_durnation"
self[:value]
else
@ -49,10 +52,18 @@ class AttributeValue
end
def get_values
if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"]
return Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
unless ['select','checkbox','radio_button'].include?(self.attribute_field.markup )
if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"]
return Hash[VALID_LOCALES.collect{|lang| [lang,get_value_by_locale(lang.to_sym)]}]
else
return get_value_by_locale("")
end
else
return self[:value]
if self.attribute_field.markup == "select"
self[:value]
else
self[:value].keys
end
end
end

View File

@ -35,10 +35,22 @@ class User
before_create :initialize_desktop
before_save :check_status_record
before_save :save_roles
scope :remote_account, where(:nccu_id.ne => nil)
validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
# def new_attribute_values=(vars)
# binding.pry
# end
# def new_attribute_values(vars)
# binding.pry
# end
def rebuild_sub_roles_from_attribute_values!(attribute_values)
# attribute_fields = AttributeField.find attribute_values.collect{|t| t[1][:attribute_field_id]}
# self.sub_roles = attribute_fields.collect{|t| t.attribute if t.attribute.is_a? SubRole}.compact.uniq
end
def set_sub_role(sub_role_id,status_id)
self.sub_roles << SubRole.find(sub_role_id)
@ -131,6 +143,9 @@ class User
end
protected
def save_roles
self.roles = self.sub_roles.collect{|t| t.role}.uniq
end
def check_status_record
roles = sub_roles.collect{|t| t.role}.uniq #get all role from sub_roles

View File

@ -19,6 +19,7 @@
<li>disabled<%= f.check_box :disabled,{},true,false %></li>
<li>add_more<%= f.check_box :add_more,{},true,false %></li>
<li>neutral_title<%= f.text_field :neutral_title,:size=>50 %></li>
<li>neutral_for<%= f.select :neutral_for, VALID_LOCALES, {}, {:style => "width:90px"} %> </li>
<!--
<li><%#= attribute_field[:markup].eql?('select') ? nil : "style='display:none'"%> </li>
<li><%#= t('admin.options') %>: <%#= f.text_field :markup_value%></li>

View File

@ -16,4 +16,39 @@
</div>
<%= render :partial=>"infos"%>
<%= render :partial=>"roles"%>
<%#= render :partial=>"roles"%>
<% content_for :page_specific_javascript do -%>
<script type="text/javascript">
$(document).ready(function(){
// $("a.submit_btn").click(function(){
// value = $("a.submit_btn").parents("form").find("input[disabled='disabled']")
// jQuery.each(value, function() {
// index = $(this).attr("for");
// console.log(index);
// $("input[for='"+ index +"']").remove();
// });
// value.remove();
// $(this).parents("form")[0].submit();
// });
$(".onoff").click(function(){
var dom = $(this).attr("for");
if($(this).hasClass("disabled")){
$(".controls-block[for="+dom+"] input").removeAttr("disabled");
$(".controls-block[for="+dom+"]").slideDown();
$(this).removeClass("disabled");
$(this).text("OFF");
}else{
$(this).addClass("disabled");
$(".controls-block[for="+dom+"]").slideUp();
$(".controls-block[for="+dom+"] input").attr("disabled","disabled");
$(this).text("ON");
}
return false;
})
})
</script>
<% end -%>

View File

@ -3,12 +3,14 @@
<div class="form-horizontal">
<% role.sub_roles.each do |sub_role| %>
<div id="le">
<legend><button class="onoff pull-right">ON</button><%= sub_role.title %></legend>
<% role.sub_roles.each do |sub_role| %>
<% sub_role_disable = @disable_all_field ? true : !check_user_role_enable(sub_role.attribute_fields) %>
<%#= hidden_field_tag("[user][new_attribute_values][sub_role][disable][#{sub_role.id}]",sub_role_disable)%>
<legend><button for=<%=@form_index%> class="onoff pull-right <%= sub_role_disable ? 'disabled' : '' %> "><%= sub_role_disable ? 'ON' : 'OFF' %></button><%= sub_role.title %></legend>
<div class="controls-block <%= sub_role_disable ? 'hide' : '' %>" for=<%=@form_index%> >
<% sub_role.attribute_fields.each do |af|%>
<%= af.block_helper(@user,@form_index)%>
<%= af.block_helper(@user,@form_index,sub_role_disable)%>
<% @form_index = @form_index +1 %>
<% end %>
</div>

View File

@ -51,9 +51,9 @@
<div class="viewport">
<div class="overview">
<%= render :partial=> "user_role",:locals=>{:role_class=>"basic",:i18n=>"admin.new_admin.users.profile",:items=>@profile_data} %>
<%= render :partial=> "user_role",:locals=>{:role_class=>"teacher",:i18n=>"admin.new_admin.users.roles.teacher",:items=>@teacher_data} %>
<%= render :partial=> "user_role",:locals=>{:role_class=>"student",:i18n=>"admin.new_admin.users.roles.student",:items=>@student_data}%>
<%= render :partial=> "user_role",:locals=>{:role_class=>"staff",:i18n=>"admin.new_admin.users.roles.staff",:items=>@staff_data} %>
<%#= render :partial=> "user_role",:locals=>{:role_class=>"teacher",:i18n=>"admin.new_admin.users.roles.teacher",:items=>@teacher_data} %>
<%#= render :partial=> "user_role",:locals=>{:role_class=>"student",:i18n=>"admin.new_admin.users.roles.student",:items=>@student_data}%>
<%#= render :partial=> "user_role",:locals=>{:role_class=>"staff",:i18n=>"admin.new_admin.users.roles.staff",:items=>@staff_data} %>
</div>
<div>
</div>

View File

@ -11,8 +11,8 @@
<p class="alert hide">You need to sign in or sign up before continuing.</p>
<div class="main">
<div class="control-group clear">
<%= f.label :nccu_ldap_uid ,t("nccu_c.nccu_ldap_uid")%>
<%= f.text_field :nccu_ldap_uid, :placeholder => t("nccu_c.nccu_ldap_uid"), :style => "width: 330px;" %>
<%= f.label :login ,t("admin.user_new_interface.email")%>
<%= f.text_field :login, :placeholder => t("admin.user_new_interface.email"), :style => "width: 330px;" %>
<span class="help-inline">Please correct the error</span>
</div>
<div class="control-group clear">

View File

@ -24,12 +24,12 @@ markups:
checkbox:
muti_lang_input_supprt: false
ext_support: false
date_durnation:
muti_lang_input_supprt: false
ext_support: false
address:
muti_lang_input_supprt: true
ext_support: true
# date_durnation:
# muti_lang_input_supprt: false
# ext_support: false
# address:
# muti_lang_input_supprt: true
# ext_support: true
public_r_tags: