client_management/app/views/admin/site_panel/_sites_list_table.html.erb

204 lines
9.5 KiB
Plaintext

<table class="table main-list default footable-loaded">
<thead>
<tr>
<th>Server name</th>
<th>Domain name</th>
<th>Port</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<% status_relation = {"creating"=>"<span style=\"color: skyblue;\">creating</span>".html_safe,"error"=>"<span style=\"color: red;\">error</span>".html_safe,"finish"=>"<span style=\"color: darkseagreen;\">finish</span>".html_safe,"closed"=>"<span style=\"color: red;\">closed</span>".html_safe}%>
<% @sites.each do |site|%>
<tr>
<td><%=site.server_type%></td>
<td><a href="<%=((site.port.to_s == "443") ? "https" : "http")%>://<%=site.domain_name%><%=((site.port.to_s != '80' && site.port.to_s != '443') ? ':'+site.port.to_s : '')%>" title="open <%=((site.port.to_s == "443") ? "https" : "http")%>://<%=site.domain_name%><%=((site.port.to_s != '80' && site.port.to_s != '443') ? ':'+site.port.to_s : '')%> to new window" target="_blank"><%=site.domain_name%></a></td>
<td><%=site.port%></td>
<td class="site_status"><%= (site.status.blank? ? "not yet create" : status_relation[site.status]) %></td>
<td>
<a href="#" title="see infos for <%=site.domain_name%>" class="btn btn-primary see_infos" data-id="<%=site.id.to_s%>">See infos</a>
<% if site.status.blank? %>
<a href="#" title="create <%=site.domain_name%>" class="btn btn-primary create_site" data-id="<%=site.id.to_s%>">Create site</a>
<% elsif site.status == "error" || site.status == "finish" %>
<a href="#" title="recreate <%=site.domain_name%>" class="btn btn-primary create_site" data-id="<%=site.id.to_s%>">Recreate site</a>
<a href="#" title="Delete <%=site.domain_name%>" class="btn btn-primary delete_site" data-id="<%=site.id.to_s%>">Delete site</a>
<a href="#" title="Close <%=site.domain_name%>" class="btn btn-primary close_site" data-id="<%=site.id.to_s%>">Close site</a>
<a href="#" title="Restart <%=site.domain_name%>" class="btn btn-primary open_site" data-id="<%=site.id.to_s%>">Restart site</a>
<% elsif site.status == "closed" %>
<a href="#" title="Start <%=site.domain_name%>" class="btn btn-primary open_site" data-id="<%=site.id.to_s%>">Start site</a>
<% end%>
<a href="#" title="Exec commands on <%=site.domain_name%>" class="btn btn-primary exec_commands" data-id="<%=site.id.to_s%>">Exec commands</a>
<a href="<%=admin_site_panel_edit_site_path+"?id=#{site.id}&type=detail"%>" title="See <%=site.domain_name%> detail" class="btn btn-primary see_detail" data-id="<%=site.id.to_s%>">Detail</a>
<a href="<%=admin_site_panel_edit_site_path+"?id=#{site.id}&type=delete_from_list"%>" title="Delete <%=site.domain_name%> from list" class="btn btn-primary see_detail" data-id="<%=site.id.to_s%>">Delete from list</a>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pagination pagination-centered"><%=paginate(@sites)%></div>
<a class="btn btn-primary pull-right" href="<%=admin_site_panel_path%>" title="Create new web"><%=t(:add)%></a>
</div>
<script type="text/javascript">
$(document).ready(function(){
var close_info = false;
var timeout_id;
var status_relation = {"creating":"<span style=\"color: skyblue;\">creating</span>","error":"<span style=\"color: red;\">error</span>","finish": "<span style=\"color: darkseagreen;\">finish</span>","closed":"<span style=\"color: red;\">closed</span>"};
function see_infos(id){
if(!close_info){
var request = $.post("<%=admin_site_panel_site_infos_path%>",{"id":id});
request.done(function(data){
var infos = request.responseJSON.infos;
var status = request.responseJSON.status;
if($("#info_texts").length == 0)
return infos.join("<br>")
else{
$("#info_texts").html(infos.join("<br>"));
if(status == "")
var status_text = "not yet create";
else
var status_text = status_relation[status];
if(status == "finish"){
var params = {}
var params_text = window.location.search.split(/[?&]/).slice(1);
params_text.forEach(function(text){
if(text.split("=")[0] != "")
params[text.split("=")[0]] = text.split("=")[1].split("#")[0].split("&")[0];
});
var new_params_text = "?";
Object.keys(params).forEach(function(key){
var value = params[key];
if(key == "id"){
if(value != id){
new_params_text += (key+"="+value+"&")
}
}else
new_params_text += (key+"="+value+"&")
});
if(new_params_text[new_params_text.length -1] == "&")
new_params_text = new_params_text.substr(0,new_params_text.length - 1)
if(params["id"] == id){
close_info = true;
window.location.href = window.location.href.replace(window.location.search,new_params_text);
}
}
$(".see_infos[data-id="+id+"]").parent().siblings(".site_status").html(status_text);
//msg_end.scrollIntoView();
timeout_id = window.setTimeout(see_infos(id),1000);
}
})
}else{
window.clearTimeout(timeout_id);
}
};
function show_infos_dialog(item){
close_info = true;
window.clearTimeout(timeout_id);
close_info = false;
var id = $(item).attr("data-id");
if($("#dialog-confirm").length == 0){
$("#main-wrap").before("<div id='dialog-confirm' title='site infos'>"+
"<div style='clear:both;'></div><div id='info_texts'>"+see_infos(id)+"</div><div id='msg_end' style='height:0px; overflow:hidden'></div>"+
"</div>");
}else{
see_infos(id);
};
$( "#dialog-confirm" ).dialog({
resizable: true,
minHeight: 300,
maxHeight: 400,
modal: true,
width: '80%',
close: function(){$( this ).dialog( "close" );close_info = true;},
buttons: {
"<%= t('client_management.confirm') %>": function(){$( this ).dialog( "close" );close_info = true;},
"stop update": function(){close_info = true;}
}
});
}
$('.see_infos').click(function(){show_infos_dialog(this);});
$('.create_site').click(function(){
close_info = true;
window.clearTimeout(timeout_id);
close_info = false;
var id = $(this).attr("data-id");
var item = this;
$.post("<%= admin_site_panel_create_site_path %>",{'id': id}).done(function(){
show_infos_dialog(item);
})
});
$('.delete_site').click(function(){
var item = this;
if(window.confirm("Do you really want to delete this site?")){
if(window.confirm("Do you really want to delete this site?")){
$.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'delete'}).done(function(){
show_infos_dialog(item);
item.remove();
});
}
}
});
$('.close_site').click(function(){
var item = this;
$.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'close'}).done(function(){
show_infos_dialog(item);
item.remove();
});
});
$('.open_site').click(function(){
var item = this;
$.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'open'}).done(function(){
show_infos_dialog(item);
item.remove();
});
});
$('.exec_commands').click(function(){
show_exec_commands_block($(this).attr('data-id'));
});
function show_exec_commands_block(id){
if($("#exec-commands-dialog-confirm").length == 0){
$("#main-wrap").before("<div id='exec-commands-dialog-confirm' title='Commands to Exec'>"+
"<div style='clear:both;'></div><textarea style='height: 200px;width: 100%;' id='commands_area' data-id='"+id+"'></textarea>"+
"</div>");
}else{
$('#commands_area').attr('data-id',id);
};
$( "#exec-commands-dialog-confirm" ).dialog({
resizable: true,
minHeight: 300,
maxHeight: 400,
modal: true,
width: '80%',
close: function(){$( this ).dialog( "close" );},
buttons: {
"<%= t(:submit) %>": function(){$( this ).dialog( "close" );exec_commands()},
}
});
}
function exec_commands(){
var commands = $('#commands_area').val().replace("\r\n","////");
var id = $('#commands_area').attr('data-id');
console.log(id);
console.log(commands);
$.post("<%=admin_site_panel_edit_site_path%>",{'id':id,'commands':commands}).done(function(){
show_infos_dialog($('.see_infos[data-id="'+id+'"]').eq(0));
});
}
<% if !params[:id].blank? %>
see_infos("<%=params[:id]%>");
$( "#dialog-confirm" ).dialog({
resizable: true,
minHeight: 300,
maxHeight: 400,
width: '80%',
modal: true,
close: function(){$( this ).dialog( "close" );close_info = true;},
buttons: {
"<%= t('client_management.confirm') %>": function(){$( this ).dialog( "close" );close_info = true;},
"stop update": function(){close_info = true;}
}
});
<% end %>
})
</script>