增加域名唯一性判断

This commit is contained in:
ouyangxuhua 2016-01-18 10:43:22 +08:00
parent c6aaaff8d1
commit 03df9abfeb
5 changed files with 35 additions and 6 deletions

View File

@ -27,7 +27,11 @@ class OrgSubfieldsController < ApplicationController
@sort = ""
@order = ""
@is_remote = false
@organization = Organization.find(params[:id])
if params[:id]
@organization = Organization.find(params[:id])
else
@organization = Organization.where("domain=?",request.subdomain).first
end
@org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+
"subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+
" org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first

View File

@ -136,6 +136,10 @@ class OrganizationsController < ApplicationController
end
end
def check_uniq_domain
@is_exist = (Organization.where("domain=?", params[:org_domain]).count > 0)
end
def find_organization
@organization = Organization.find(params[:id])
end

View File

@ -0,0 +1,5 @@
<% if @is_exist %>
$is_exist = true;
<% else %>
$is_exist = false;
<% end %>

View File

@ -149,18 +149,33 @@
if ($("#subfield_name").val().trim() != "")
$("#add_subfield_form").submit();
}
var $is_exist = false;
function apply_subdomain(id, domain){
var reg = new RegExp("^[a-zA-Z0-9_]{1,}$");
if (reg.exec(domain)){
$.ajax({
url:"<%= apply_subdomain_organization_path %>",
type:'post',
url: "<%= check_uniq_domain_organizations_path %>",
type: 'get',
data:{
id:id,
domain:domain
org_domain:domain
},
success:function(){
$("#apply_hint").text("您的申请已提交,系统会以消息的形式通知您结果");
if(!$is_exist){
$.ajax({
url:"<%= apply_subdomain_organization_path %>",
type:'post',
data:{
id:id,
domain:domain
},
success:function(){
$("#apply_hint").text("您的申请已提交,系统会以消息的形式通知您结果");
}
});
}
else{
$("#apply_hint").text("您申请的子域名已存在,请重新输入");
}
}
});
}

View File

@ -66,6 +66,7 @@ RedmineApp::Application.routes.draw do
end
collection do
get 'check_uniq'
get 'check_uniq_domain'
get 'autocomplete_search'
post 'hide_org_subfield'
post 'show_org_subfield'