add multiple domain feature for one server
This commit is contained in:
parent
2322db910c
commit
1668d44c7c
|
@ -1,8 +1,9 @@
|
||||||
class SiteConstruct
|
class SiteConstruct
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
def self.server_types
|
||||||
SERVER_TYPES = SiteServer.all.map{|s| s.server_name}
|
SiteServer.all.map{|s| s.server_name}
|
||||||
|
end
|
||||||
SITE_TYPES = ["School","Gravity"]
|
SITE_TYPES = ["School","Gravity"]
|
||||||
|
|
||||||
field :server_type
|
field :server_type
|
||||||
|
|
|
@ -6,8 +6,21 @@ class SiteServer
|
||||||
include OrbitModel::Status
|
include OrbitModel::Status
|
||||||
field :server_name , type: String ,default: ''
|
field :server_name , type: String ,default: ''
|
||||||
field :domain_name , type: String ,default: ''
|
field :domain_name , type: String ,default: ''
|
||||||
|
field :domain_names, type: Array, default: []
|
||||||
field :ip , type: String ,default: ''
|
field :ip , type: String ,default: ''
|
||||||
field :account , type: String ,default: ''
|
field :account , type: String ,default: ''
|
||||||
field :password , type: String ,default: ''
|
field :password , type: String ,default: ''
|
||||||
field :active , type: Boolean ,default: true
|
field :active , type: Boolean ,default: true
|
||||||
|
def domain_names
|
||||||
|
if self.domain_name != ''
|
||||||
|
[self.domain_name]
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
before_save do
|
||||||
|
if self.domain_name != '' && self.domain_names.length !=0
|
||||||
|
self.domain_name = ''
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -23,7 +23,16 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<%= f.label :server_type ,"Server", :class => "control-label muted" %>
|
<%= f.label :server_type ,"Server", :class => "control-label muted" %>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.select :server_type, SiteConstruct::SERVER_TYPES %>
|
<%= f.select :server_type, SiteConstruct.server_types %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :root_domain ,"Root Domain", :class => "control-label muted" %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= select_tag :root_domain,
|
||||||
|
options_for_select(SiteServer.first.domain_names.collect{ |u| [u, u] }),
|
||||||
|
:id => "root_domain" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -53,8 +62,8 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<%= 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">
|
||||||
<%= f.text_field :domain_name, :id => "domain_name" %>
|
<%= f.text_field :domain_name, :id => "domain_name",:disabled => 'disabled' %>
|
||||||
<div class="hint">schoolname-deptname.pending.rulingcom.com eg: nctu-eed.pending.rulingcom.com</div>
|
<!--<div class="hint">schoolname-deptname.pending.rulingcom.com eg: nctu-eed.pending.rulingcom.com</div>-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -89,9 +98,12 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var domain_name_relations = {};
|
var domain_name_relations = {};
|
||||||
<% SiteServer.all.each do |server_server| %>
|
<% SiteServer.all.each do |server_server| %>
|
||||||
domain_name_relations['<%= server_server.server_name %>'] = '<%= server_server.domain_name %>';
|
domain_name_relations['<%= server_server.server_name %>'] = <%= server_server.domain_names.inspect.html_safe %>;
|
||||||
<% end %>
|
<% end %>
|
||||||
console.log(domain_name_relations);
|
console.log(domain_name_relations);
|
||||||
|
function change_domain_name(domain_name){
|
||||||
|
$("#domain_name").val($("#site_name").val().replace("_","-") + "."+domain_name);
|
||||||
|
}
|
||||||
$("#school_name").on("blur",function(){
|
$("#school_name").on("blur",function(){
|
||||||
var school = $(this).val().toLowerCase();
|
var school = $(this).val().toLowerCase();
|
||||||
if($("#site_name").val() == ""){
|
if($("#site_name").val() == ""){
|
||||||
|
@ -114,18 +126,31 @@
|
||||||
$("#path").val("/home/rulingcom/" + type);
|
$("#path").val("/home/rulingcom/" + type);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$('#site_construct_server_type').click(function(){
|
$("#root_domain").change(function(){
|
||||||
var domain_name = domain_name_relations[$(this).val()];
|
change_domain_name($(this).val());
|
||||||
$("#domain_name").val($("#site_name").val().replace("_","-") + "."+domain_name);
|
})
|
||||||
$('#domain_name').siblings('.hint').html('schoolname-deptname.'+domain_name+' eg: nctu-eed.'+domain_name);
|
$('#site_construct_server_type').change(function(){
|
||||||
|
var domain_name = domain_name_relations[$(this).val()][0];
|
||||||
|
var domain_names = domain_name_relations[$(this).val()];
|
||||||
|
$("#root_domain").find('option').remove()
|
||||||
|
$.each(domain_names,function(i,v){
|
||||||
|
var o = new Option(v, v);
|
||||||
|
/// jquerify the DOM object 'o' so we can use the html method
|
||||||
|
$(o).html(v);
|
||||||
|
$("#root_domain").append(o);
|
||||||
|
})
|
||||||
|
if ($("#site_name").val()!=''){
|
||||||
|
change_domain_name(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(){
|
||||||
var val = $(this).val(),
|
var val = $(this).val(),
|
||||||
type = $("#site_construct_site_type").val(),
|
type = $("#site_construct_site_type").val(),
|
||||||
school = $("#school_name").val(),
|
school = $("#school_name").val(),
|
||||||
domain_name = domain_name_relations[$('#site_construct_server_type').val()];
|
domain_name = $("#root_domain").val();
|
||||||
$('#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);
|
||||||
$("#domain_name").val(val.replace("_","-") + "."+domain_name);
|
change_domain_name(domain_name);
|
||||||
$("#db_name").val(val);
|
$("#db_name").val(val);
|
||||||
type = (type == "School" ? "school_sites" : "orbit_sites" );
|
type = (type == "School" ? "school_sites" : "orbit_sites" );
|
||||||
if(school != ""){
|
if(school != ""){
|
||||||
|
|
|
@ -1,6 +1,26 @@
|
||||||
<% content_for :page_specific_css do %>
|
<% content_for :page_specific_css do %>
|
||||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||||
<% end %>
|
<% end
|
||||||
|
delete_domain_button = button_tag("#{t('delete_')} domain", class: 'btn btn-danger',
|
||||||
|
:onclick=> "delete_domain(this)",
|
||||||
|
:type => 'button')
|
||||||
|
%>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function add_domain(ele){
|
||||||
|
var tp=$(ele);
|
||||||
|
var tp2=tp.parents('.controls').eq(0).find('.group');
|
||||||
|
var tp3=tp2.find('.domain_name').eq(0).clone();
|
||||||
|
tp3.val('');
|
||||||
|
tp2.append('<br>');
|
||||||
|
tp2.append(tp3);
|
||||||
|
tp2.append('<%= delete_domain_button %>')
|
||||||
|
}
|
||||||
|
function delete_domain(ele){
|
||||||
|
$(ele).prev('input').remove()
|
||||||
|
$(ele).prev('br').remove()
|
||||||
|
$(ele).remove()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<%= form_for @site_server ,:url=>{:action=>"edit_server_info",:type=>'update'},:method=>:post, :html => {:class=>"form-horizontal main-forms"} do |f|%>
|
<%= form_for @site_server ,:url=>{:action=>"edit_server_info",:type=>'update'},:method=>:post, :html => {:class=>"form-horizontal main-forms"} do |f|%>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<input type='hidden' name='id' value='<%=@site_server.id.to_s%>'/>
|
<input type='hidden' name='id' value='<%=@site_server.id.to_s%>'/>
|
||||||
|
@ -43,7 +63,20 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label muted" for="domain_name">Domain name:</label>
|
<label class="control-label muted" for="domain_name">Domain name:</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.text_field :domain_name,{:id=>'domain_name'} %>
|
<div class="group">
|
||||||
|
<%
|
||||||
|
tp = @site_server.domain_names
|
||||||
|
tp << '' if tp.length == 0
|
||||||
|
tp.each_with_index do |domain_name,i| %>
|
||||||
|
<%= '<br>'.html_safe if i !=0 %>
|
||||||
|
<%= text_field_tag "site_server[domain_names][]",domain_name,{:id=>nil,:class=>"domain_name"} %>
|
||||||
|
<% delete_domain_button if i !=0 %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<%= f.button "#{t('add')} domain", class: 'btn btn-info',
|
||||||
|
:onclick=> "add_domain(this)",
|
||||||
|
:type => 'button'
|
||||||
|
%>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
|
|
Loading…
Reference in New Issue