form validations and ajax check plus user approval done

This commit is contained in:
Harry Bomrah 2013-11-29 16:20:23 +08:00 committed by saurabhbhatia
parent 1584eeaf27
commit f1c2e29bf1
13 changed files with 245 additions and 23 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ uploads/**/*
*.supported *.supported
mongoid.yml mongoid.yml
*. *.
sftp-config.json

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1,10 +1,12 @@
.sign-up{ .sign-up{
margin: 150px auto 0; margin: 150px auto 0;
position: relative; position: relative;
text-align: center; /*text-align: center;*/
width: 500px; width: 600px;
}
.sign-up.facebook-form{
text-align: center;
} }
.sign-up .form{ .sign-up .form{
background-color: #FFFFFF; background-color: #FFFFFF;
box-shadow: 0 10px 20px #CBCBCB; box-shadow: 0 10px 20px #CBCBCB;
@ -52,10 +54,36 @@
margin-right: 10px; margin-right: 10px;
} }
.sign-up .notify{
font-size: 15px;
}
.notify.alert{
padding: 5px 10px 5px 3px;
}
.notify .icon-ok{
color: green;
margin-right: 3px;
margin-left: 3px;
}
.notify .icon-remove{
color: red;
margin-right: 3px;
margin-left: 3px;
}
.sign-up input[type=checkbox]{ .sign-up input[type=checkbox]{
margin-top: 0; margin-top: 0;
} }
.sign-up .error{
border-color: #E9322D;
box-shadow: 0 0 6px #F8B987;
color: #B94A48;
}
.line{ .line{
border-bottom: 1px solid #EDEDED; border-bottom: 1px solid #EDEDED;
} }
@ -64,3 +92,9 @@
text-align: left; text-align: left;
} }
.loader{
width:100px;
margin-left: 3px;
}

View File

@ -7,6 +7,18 @@ class Admin::UsersNewInterfaceController < OrbitMemberController
open_for_user :only => [:setting_account, :edit_user_data, :update] open_for_user :only => [:setting_account, :edit_user_data, :update]
open_for_visitor :only => [:index, :show] open_for_visitor :only => [:index, :show]
def registration_approval
page_num = params[:page] || 1
@users = User.approval_pending.page(page_num).per(12).desc("_id")
end
def approve_registration
user = User.find(params[:users_new_interface_id])
user.approved = true
user.save
redirect_to admin_users_new_interface_registration_approval_path
end
def index def index
get_tags get_tags
get_sub_roles get_sub_roles
@ -386,6 +398,8 @@ class Admin::UsersNewInterfaceController < OrbitMemberController
@users = User.not_guest_user @users = User.not_guest_user
end end
protected protected
def get_tags def get_tags
@sub_role_tags = SubRoleTag.all @sub_role_tags = SubRoleTag.all

View File

@ -35,4 +35,20 @@ class BasicInfosController < ApplicationController
end end
end end
def check_availability
response = {}
case params[:type]
when "user_id"
response["success"] = User.where(:user_id => params[:value]).count > 0 ? false : true
when "user_email"
response["success"] = User.where(:email => params[:value]).count > 0? false : true
end
render :json => response.to_json
end
end end

View File

@ -69,14 +69,12 @@ class FacebookController< ApplicationController
u.first_name_translations = firstname u.first_name_translations = firstname
u.last_name_translations = lastname u.last_name_translations = lastname
u.office_tel = user["phone"] u.office_tel = user["phone"]
u.email = user["email"]
# u.email = "xyz@zyx.com"
u.sex = user["gender"] || "unknown" u.sex = user["gender"] || "unknown"
u.remote_avatar_url = user["picture"] if user["picture"] u.remote_avatar_url = user["picture"] if user["picture"]
if u.save if u.save
render :json=>{"success"=>true,"user"=>user}.to_json render :json=>{"success"=>true,"user"=>user}.to_json
else else
render :json=>{"success"=>false,"message"=>"Email already occupied."}.to_json render :json=>{"success"=>false,"message"=>"There was an error imporing data."}.to_json
end end
else else

View File

@ -17,6 +17,7 @@ class User
field :last_name, localize: true field :last_name, localize: true
field :email field :email
field :sex, :default => 'unknown' field :sex, :default => 'unknown'
field :approved, type: Boolean, :default => false
field :office_tel field :office_tel
field :cache_dept,type: Hash field :cache_dept,type: Hash
field :status_record,type: Hash field :status_record,type: Hash
@ -56,7 +57,8 @@ class User
before_save :assign_default_position, :if => :assign_default_position? before_save :assign_default_position, :if => :assign_default_position?
before_save :rebuild_status_record before_save :rebuild_status_record
scope :remote_account, where(:nccu_id.ne => nil) scope :remote_account, where(:nccu_id.ne => nil)
scope :not_guest_user, all_of(:name.ne => "guest") scope :not_guest_user, all_of(:name.ne => "guest").and(:approved => true)
scope :approval_pending, where(:approved => false)
validates :user_id, validates :user_id,
:presence => { :message => I18n.t("users.user_id_not_null") } , :presence => { :message => I18n.t("users.user_id_not_null") } ,

View File

@ -0,0 +1,29 @@
<%
if not_approved_listing.sex == 'male'
@user_sex = 'gender-man'
elsif not_approved_listing.sex == 'female'
@user_sex = 'gender-woman'
else
@user_sex = 'gender-none'
end
%>
<tr id="<%= dom_id not_approved_listing %>">
<td class="<%= @user_sex %>"></td>
<td>
<% not_approved_listing.roles.each do |rf| %>
<% @roledata = Role.find(rf.id) %>
<span class="label label-info"><%= @roledata.title %></span>
<% end %>
</td>
<td>
<%= link_to (not_approved_listing.name && not_approved_listing.name != not_approved_listing.email ? not_approved_listing.name : not_approved_listing.user_id),admin_users_new_interface_path(not_approved_listing) %>
<div class="quick-edit">
<ul class="nav nav-pills">
<%= content_tag(:li, link_to(t(:edit),edit_admin_users_new_interface_path(not_approved_listing))) if is_admin? %>
<%= content_tag(:li, link_to(t(:approve),admin_users_new_interface_approve_registration_path(not_approved_listing))) if is_admin? %>
<%= content_tag(:li, link_to(t(:delete),admin_users_new_interface_path(not_approved_listing, :at=>params[:at]), :confirm => t(:sure?), :method => :delete, :class=>"text-error", :remote => true)) if is_admin? %>
</ul>
</div>
</td>
<td><%= not_approved_listing.email %></td>
</tr>

View File

@ -29,7 +29,7 @@
<%= content_tag :li, link_to((content_tag(:span, t(:all_member))), admin_users_new_interface_index_path), :class => active_for_action('users_new_interface', 'index') %> <%= content_tag :li, link_to((content_tag(:span, t(:all_member))), admin_users_new_interface_index_path), :class => active_for_action('users_new_interface', 'index') %>
<%= content_tag :li, link_to((content_tag(:span, t(:add_member))), new_admin_users_new_interface_path), :class => active_for_action('users_new_interface', 'new') if (is_admin? rescue nil) %> <%= content_tag :li, link_to((content_tag(:span, t(:add_member))), new_admin_users_new_interface_path), :class => active_for_action('users_new_interface', 'new') if (is_admin? rescue nil) %>
<%= content_tag :li, link_to((content_tag(:span, t(:member_authorization))), '#'), :class => active_for_action('users_new_interfacexx', 'index') if (is_admin? rescue nil) %> <%= content_tag :li, link_to((content_tag(:span, t(:member_authorization))), '#'), :class => active_for_action('users_new_interfacexx', 'index') if (is_admin? rescue nil) %>
<%= content_tag :li, link_to((content_tag(:span, t(:member_registration))), '#'), :class => active_for_action('users_new_interfacexx', 'index') if (is_admin? rescue nil) %> <%= content_tag :li, link_to((content_tag(:span, t(:member_registration))), admin_users_new_interface_registration_approval_path), :class => active_for_action('users_new_interface', 'registration_approval') if (is_admin? rescue nil) %>
<%= content_tag :li, link_to((content_tag(:span, t(:member_role))),admin_roles_path ), :class => active_for_action('roles', 'index') if (is_admin? rescue nil) %> <%= content_tag :li, link_to((content_tag(:span, t(:member_role))),admin_roles_path ), :class => active_for_action('roles', 'index') if (is_admin? rescue nil) %>
<%= content_tag :li, link_to((content_tag(:span, t(:member_info))), edit_admin_info_path(Info.first.id.to_s)), :class => active_for_action('users_new_interfacexx', 'index') if (is_admin? rescue nil) and Info.first %> <%= content_tag :li, link_to((content_tag(:span, t(:member_info))), edit_admin_info_path(Info.first.id.to_s)), :class => active_for_action('users_new_interfacexx', 'index') if (is_admin? rescue nil) and Info.first %>
<% end -%> <% end -%>

View File

@ -0,0 +1,31 @@
<% content_for :side_bar do %>
<%= render :partial => 'admin/users_new_interface/side_bar' %>
<% end %>
<%= render :partial => "js_and_css"%>
<div id="list-view">
<table id="member-list" class="table main-list">
<thead>
<tr class="sort-header">
<th class="gender"></th>
<th class="span3"><a href="#">Roles</a></th>
<th class="span4"><a href="#">Name</a></th>
<th><a href="#">Email</a></th>
</tr>
</thead>
<tbody>
<% if !@users.blank? %>
<%= render :partial => "not_approved_listing",:collection=> @users %>
<% else %>
<tr><td colspan="4" style="text-align:center">Hooray! No pending registration approvals left.</td></tr>
<% end %>
</tbody>
</table>
</div>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered">
<%= paginate @users, :params => {:inner => false} %>
</div>
</div>

View File

@ -1,6 +1,6 @@
<%= stylesheet_link_tag "sign_up" %> <%= stylesheet_link_tag "sign_up" %>
<section id="main-wrap"> <section id="main-wrap">
<div class="sign-up have-other-sign-in"> <div class="sign-up have-other-sign-in facebook-form">
<div class="form"> <div class="form">
<h3 class="login-logo">Please select a method for Basic Info</h3> <h3 class="login-logo">Please select a method for Basic Info</h3>
<div class="option-block"> <div class="option-block">

View File

@ -8,28 +8,41 @@
<div class="form"> <div class="form">
<h3 class="login-logo">Sign up with Orbit</h3> <h3 class="login-logo">Sign up with Orbit</h3>
<div class="form-block"> <div class="form-block option-block">
<div class="form-list clearfix"> <div class="form-list clearfix">
<%= form_for resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'content'} do |f| %> <%= form_for resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'content form-horizontal'} do |f| %>
<label for="user_email">User ID</label>
<div class="control-group clear"> <div class="control-group clear">
<%= f.text_field :user_id, :placeholder => t("users.user_id"), :id=>"user_email" %> <label class="control-label" for="user_email">User ID</label>
<div class="controls">
<%= f.text_field :user_id, :placeholder => t("users.user_id"), :id=>"user_id",:class=>"availibility" %>
<span class="loader hide"><img src="/assets/availability-check-loader.gif" /></span>
<span class="notify not-ok hide alert alert-danger"><i class="icon-remove"></i>Not Available</span>
<span class="notify ok alert hide alert-success"><i class="icon-ok"></i>Available</span>
</div>
</div>
<div class="control-group clear">
<label class="control-label" for="user_email">Email</label>
<div class="controls">
<%= f.email_field :email, :placeholder => t("users.email"), :id=>"user_email", :class=>"availibility" %>
<span class="loader hide"><img src="/assets/availability-check-loader.gif" /></span>
<span class="notify not-ok hide alert alert-danger"><i class="icon-remove"></i>Not Available</span>
<span class="notify ok hide alert alert-success"><i class="icon-ok"></i>Available</span>
</div>
</div> </div>
<label for="user_email">Email</label>
<div class="control-group clear">
<%= f.email_field :email, :placeholder => t("users.email"), :id=>"user_email" %>
</div>
<label for="user_password">Password</label>
<div class="control-group clear"> <div class="control-group clear">
<label class="control-label" for="user_password">Password</label>
<div class="controls">
<%= f.password_field :password, :placeholder => t(:dots), :id=>"user_password" %> <%= f.password_field :password, :placeholder => t(:dots), :id=>"user_password" %>
</div> </div>
<label for="user_password">Confirm Password</label> </div>
<div class="control-group clear"> <div class="control-group clear">
<label class="control-label" for="user_password">Confirm Password</label>
<div class="controls">
<%= f.password_field :password, :placeholder => t(:dots), :id=>"confirm_user_password" %> <%= f.password_field :password, :placeholder => t(:dots), :id=>"confirm_user_password" %>
</div> </div>
</div>
<h3 class="line"></h3> <h3 class="line"></h3>
<div class="pull-right"> <div class="pull-right">
<%= content_tag :button, t(:register), :type => :submit, :class => 'btn btn-primary' %> <%= content_tag :button, t(:register), :type => :submit, :class => 'btn btn-primary' %>
@ -45,3 +58,82 @@
</div> </div>
</section> </section>
<script type="text/javascript">
(function(){
var validated = false;
$("form.content").submit(function(event) {
var form = $(this);
form.find("input").removeClass('error');
form.find("input[type=text], input[type=email], input[type=password]").each(function(){
validated = $(this).val() ? true : false;
if(!validated){
return false;
}
})
if(validated){
form.find("span.not-ok").each(function(){
validated = $(this).hasClass('hide') ? true : false;
if(!validated)return false;
})
}
if(validated){
validated = form.find("input[type=password]:eq(0)").val() == form.find("input[type=password]:eq(1)").val() ? true : false;
if(!validated){
form.find("input[type=password]").addClass('error');
}
}
if(!validated){
return false;;
}
});
$(".availibility").blur(function(){
var type = $(this).attr("id"),
loader = $(this).parent().find('.loader'),
elem = $(this),
value = $(this).val() || null;
elem.parent().find("span").addClass('hide');
var checkAvailability = function(){
loader.removeClass('hide');
elem.removeClass('error');
$.ajax({
url : "<%= basic_infos_check_availability_path %>",
data : {"type" : type, "value" : value},
dataType : "json",
type : "get",
success : function(data){
loader.addClass('hide');
if( data.success == true ){
elem.parent().find(".ok").removeClass('hide');
}else{
elem.parent().find(".not-ok").removeClass('hide');
elem.addClass('error');
}
}
})
}
if( value ){
if(type == "user_email" && validateEmail(value)){
checkAvailability();
}else if(type == "user_id"){
checkAvailability();
}else{
elem.addClass('error');
}
}
})
var validateEmail = function(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
})();
</script>

View File

@ -20,6 +20,7 @@ Orbit::Application.routes.draw do
get 'basic_infos' => "basic_infos#index" get 'basic_infos' => "basic_infos#index"
get 'basic_infos/form' => "basic_infos#form_page" get 'basic_infos/form' => "basic_infos#form_page"
get 'basic_infos/role_page' => "basic_infos#role_page" get 'basic_infos/role_page' => "basic_infos#role_page"
get 'basic_infos/check_availability' => "basic_infos#check_availability"
post 'basic_infos/role_update' => "basic_infos#role_update" post 'basic_infos/role_update' => "basic_infos#role_update"
match 'basic_infos/basic_info_update' => "basic_infos#basic_info_update" match 'basic_infos/basic_info_update' => "basic_infos#basic_info_update"
# routes for admin # routes for admin
@ -220,6 +221,8 @@ Orbit::Application.routes.draw do
end end
resources :users resources :users
match "users_new_interface/registration_approval" => "users_new_interface#registration_approval"
resources :users_new_interface do resources :users_new_interface do
member do member do
get 'temp_edit' get 'temp_edit'
@ -234,6 +237,8 @@ Orbit::Application.routes.draw do
match "edit_user_data" => "users_new_interface#edit_user_data" ,:as => :edit_user_data match "edit_user_data" => "users_new_interface#edit_user_data" ,:as => :edit_user_data
match "setting_account" => "users_new_interface#setting_account" ,:as => :setting_account match "setting_account" => "users_new_interface#setting_account" ,:as => :setting_account
match "edit_privilege" => "users_new_interface#edit_privilege" ,:as => :edit_privilege match "edit_privilege" => "users_new_interface#edit_privilege" ,:as => :edit_privilege
match "approve_registration" => "users_new_interface#approve_registration", :as => :approve_registration
end end
resources :member_selects do resources :member_selects do