Avoid invalid domain name.
This commit is contained in:
parent
7ffcfc6431
commit
1588f93989
|
@ -76,7 +76,7 @@
|
||||||
<%= f.label :domain_name ,"Domain Name", :class => "control-label muted" %>
|
<%= f.label :domain_name ,"Domain Name", :class => "control-label muted" %>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<div class="domain_group">
|
<div class="domain_group">
|
||||||
<input type="text" onchange="change_domain_input(this)">
|
<input type="text" onchange="change_domain_input(this)" oninput="replace_domain_input(this)">
|
||||||
<span class="root_domain_text"><%= SiteServer.first.domain_names[0] %></span>
|
<span class="root_domain_text"><%= SiteServer.first.domain_names[0] %></span>
|
||||||
<%= hidden_field_tag nil,nil, :class => "domain_name",:id=>nil %>
|
<%= hidden_field_tag nil,nil, :class => "domain_name",:id=>nil %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -133,10 +133,12 @@
|
||||||
var $input = $('.domain_group').eq(index).find('input[type="text"]');
|
var $input = $('.domain_group').eq(index).find('input[type="text"]');
|
||||||
var current_root_domain_text = $('.root_domain_group').eq(index).find('select').val()
|
var current_root_domain_text = $('.root_domain_group').eq(index).find('select').val()
|
||||||
if ($input.val()==pre_site_name){
|
if ($input.val()==pre_site_name){
|
||||||
$input.val($("#site_name").val().replace("_","-") + ".");
|
if($("#site_name").val() != ""){
|
||||||
|
$input.val($("#site_name").val().replace("_","-") + ".");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$('.domain_group').eq(index).find('input[type="hidden"]').val($('.domain_group').eq(index).find('input[type="text"]').val()+current_root_domain_text)
|
$('.domain_group').eq(index).find('input[type="hidden"]').val($('.domain_group').eq(index).find('input[type="text"]').val()+current_root_domain_text)
|
||||||
$('.root_domain_text').eq(index).val(current_root_domain_text)
|
$('.root_domain_text').eq(index).html(current_root_domain_text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$("#school_name").on("blur",function(){
|
$("#school_name").on("blur",function(){
|
||||||
|
@ -162,7 +164,10 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
function add_change_event_for_root_domain(){
|
function add_change_event_for_root_domain(){
|
||||||
$(".root_domain").off('change')
|
$(".root_domain").off('change');
|
||||||
|
$(".root_domain").each(function(i,root_domain){
|
||||||
|
change_domain_name($(root_domain).index('.root_domain'));
|
||||||
|
})
|
||||||
$(".root_domain").change(function(){
|
$(".root_domain").change(function(){
|
||||||
change_domain_name($(this).index('.root_domain'));
|
change_domain_name($(this).index('.root_domain'));
|
||||||
})
|
})
|
||||||
|
@ -171,21 +176,25 @@
|
||||||
$('#site_construct_server_type').change(function(){
|
$('#site_construct_server_type').change(function(){
|
||||||
var domain_name = domain_name_relations[$(this).val()][0];
|
var domain_name = domain_name_relations[$(this).val()][0];
|
||||||
var domain_names = domain_name_relations[$(this).val()];
|
var domain_names = domain_name_relations[$(this).val()];
|
||||||
if ($(".root_domain").length>1){
|
|
||||||
for (var i=1;i<$(".root_domain").length;i++){
|
|
||||||
$(".root_domain").eq(i).remove()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$(".root_domain").find('option').remove()
|
$(".root_domain").find('option').remove()
|
||||||
$.each(domain_names,function(i,v){
|
$.each(domain_names,function(i,v){
|
||||||
var o = new Option(v, v);
|
var o = new Option(v, v);
|
||||||
/// jquerify the DOM object 'o' so we can use the html method
|
/// jquerify the DOM object 'o' so we can use the html method
|
||||||
$(o).html(v);
|
$(o).html(v);
|
||||||
$(".root_domain").eq(0).append(o);
|
for(var idx=0;idx<$(".root_domain").length;idx++){
|
||||||
|
var option = $(o.outerHTML);
|
||||||
|
$(".root_domain").eq(idx).append(option);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
if(domain_name == undefined){
|
||||||
|
$(".root_domain_text").html("");
|
||||||
|
}else{
|
||||||
|
$(".root_domain_text").html(domain_name);
|
||||||
|
}
|
||||||
if ($("#site_name").val()!=''){
|
if ($("#site_name").val()!=''){
|
||||||
change_domain_name(0);
|
change_domain_name(0);
|
||||||
}
|
}
|
||||||
|
add_change_event_for_root_domain();
|
||||||
//$('#domain_name').siblings('.hint').html('schoolname-deptname.'+domain_name+' eg: nctu-eed.'+domain_name);
|
//$('#domain_name').siblings('.hint').html('schoolname-deptname.'+domain_name+' eg: nctu-eed.'+domain_name);
|
||||||
})
|
})
|
||||||
$("#site_name").on("blur",function(){
|
$("#site_name").on("blur",function(){
|
||||||
|
@ -204,26 +213,30 @@
|
||||||
$("#path").val("/home/rulingcom/" + type);
|
$("#path").val("/home/rulingcom/" + type);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
function replace_domain_input(ele){
|
||||||
|
var correct_val = $(ele).val().match(/([0-9]||[a-z]||[-_.])*/gi).join("");
|
||||||
|
$(ele).val(correct_val.replace("_","-"));
|
||||||
|
}
|
||||||
function change_domain_input(ele){
|
function change_domain_input(ele){
|
||||||
change_domain_name($(ele).parents('.domain_group').index('.domain_group'))
|
change_domain_name($(ele).parents('.domain_group').index('.domain_group'))
|
||||||
}
|
}
|
||||||
$("#site_construct_site_type").val("School");
|
$("#site_construct_site_type").val("School");
|
||||||
function delete_domain(ele){
|
function delete_domain(ele){
|
||||||
$('.domain_group').eq($(ele).parents('.root_domain_group').index('.root_domain_group')).remove()
|
$('.domain_group').eq($(ele).parents('.root_domain_group').index('.root_domain_group')).remove();
|
||||||
$(ele).parents('.root_domain_group').remove()
|
$(ele).parents('.root_domain_group').remove();
|
||||||
}
|
}
|
||||||
$('#add_root_domain').click(function(){
|
$('#add_root_domain').click(function(){
|
||||||
var first_domain_group = $('#root_domain_group .root_domain_group').first()
|
var first_domain_group = $('#root_domain_group .root_domain_group').first();
|
||||||
var clone_domain_group = $(first_domain_group).clone()
|
var clone_domain_group = $(first_domain_group).clone();
|
||||||
clone_domain_group.find('select').val(clone_domain_group.find('select option:first').val())
|
clone_domain_group.find('select').val(clone_domain_group.find('select option:first').val());
|
||||||
clone_domain_group.append("<button class=\"btn btn-danger\" onclick=\"delete_domain(this)\">delete domain</button>")
|
clone_domain_group.append("<button class=\"btn btn-danger\" onclick=\"delete_domain(this)\">delete domain</button>");
|
||||||
$('#root_domain_group .root_domain_group').last().after(clone_domain_group)
|
$('#root_domain_group .root_domain_group').last().after(clone_domain_group);
|
||||||
var clone_input_group = $('.domain_group').last().clone()
|
var clone_input_group = $('.domain_group').last().clone();
|
||||||
clone_input_group.find('input[type="text"]').val(pre_site_name)
|
clone_input_group.find('input[type="text"]').val(pre_site_name);
|
||||||
clone_input_group.find('input[type="hidden"]').val(pre_site_name+clone_domain_group.find('select').val())
|
clone_input_group.find('input[type="hidden"]').val(pre_site_name+clone_domain_group.find('select').val());
|
||||||
clone_input_group.find('.root_domain_text').val(clone_domain_group.find('select').val())
|
clone_input_group.find('.root_domain_text').val(clone_domain_group.find('select').val())
|
||||||
$('.domain_group').last().after(clone_input_group)
|
$('.domain_group').last().after(clone_input_group);
|
||||||
//add_change_event_for_root_domain()
|
add_change_event_for_root_domain();
|
||||||
})
|
})
|
||||||
$("form.main-forms").submit(function(){
|
$("form.main-forms").submit(function(){
|
||||||
$("#domain_name").removeAttr('disabled');
|
$("#domain_name").removeAttr('disabled');
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<% @site.domain_name.split(' ').each_with_index do |domain_name,i| %>
|
<% @site.domain_name.split(' ').each_with_index do |domain_name,i| %>
|
||||||
<div class="domain_group">
|
<div class="domain_group">
|
||||||
<%= text_field_tag nil,domain_name,:class=>'domain_name',onchange: 'domain_name_change()' %>
|
<%= text_field_tag nil,domain_name,:class=>'domain_name',onchange: 'domain_name_change()',:oninput=>'replace_domain_input(this)' %>
|
||||||
<% if i != 0 %>
|
<% if i != 0 %>
|
||||||
<button class="btn btn-danger" onclick="delete_domain(this)">
|
<button class="btn btn-danger" onclick="delete_domain(this)">
|
||||||
delete domain
|
delete domain
|
||||||
|
@ -85,4 +85,8 @@
|
||||||
$('.domain_group').eq($(ele).parents('.domain_group').index('.domain_group')).remove()
|
$('.domain_group').eq($(ele).parents('.domain_group').index('.domain_group')).remove()
|
||||||
domain_name_change()
|
domain_name_change()
|
||||||
}
|
}
|
||||||
|
function replace_domain_input(ele){
|
||||||
|
var correct_val = $(ele).val().match(/([0-9]||[a-z]||[-_.])*/gi).join("");
|
||||||
|
$(ele).val(correct_val.replace("_","-"));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue