{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% load static %}

{% block modals%}
<div class="modal" id="mo_srv_get_info" tabindex="-1" role="dialog"></div>
<div class="modal" id="mo_srv_edit_info" tabindex="-1" role="dialog" data-backdrop="static"></div>
{% endblock %}

{% block script %}
<script type="text/javascript">
function srv_get_list() {
	var $list_srv_get_list = $('#srv_get_list');
	var get_search = document.getElementById("id_PSearch").value
	
	if (get_search.length >= 3) {
		$list_srv_get_list.html('<h3> <i class="fas fa-spinner fa-pulse fa-fw"></i> Loading...</h3>');
		$.ajax({
			type : 'GET',
			url: '/parc/api/serveurs/get_list?get_search='+get_search,
			success: function(feeds) { 
				$list_srv_get_list.html(feeds);
			}
		});
	}
	if (get_search.length == "") {
		$list_srv_get_list.html('<h3> <i class="fas fa-spinner fa-pulse fa-fw"></i> Loading...</h3>');
		$.ajax({
			type : 'GET',
			url: '/parc/api/serveurs/get_list',
			success: function(feeds) { 
				$list_srv_get_list.html(feeds);
			}
		});
	}
};
function bt_get_srv_info(id){
	$.ajax({
			type : 'GET',
			url: '/parc/api/serveurs/get_srv/'+id,
			success: function(data) {
				$('#mo_srv_get_info').html(data).modal('toggle');
			},
	});
};
function bt_edit_srv_info(id){
	var get_search = document.getElementById("id_PSearch").value
	$.ajax({
			type : 'GET',
			url: '/parc/api/serveurs/edit_srv/'+id+'?get_search='+get_search,
			success: function(data) {
				$('#mo_srv_edit_info').html(data).modal('toggle');
			},
	});
};
function bt_send_edit_srv_info(){
	document.getElementById("form_edit_server").submit();
};
function onloading() {
 	srv_get_list();
	{% if page.item_id %}bt_get_srv_info({{page.item_id}});{% endif %}
};

$(document).ready(function(){ onloading(); });
</script>
{% endblock %}

{% block main %}
<div class="card-body">
{% if not page.output or page.err %}
	{{page.p_contenu|safe}}
{% else %}
	{% if page.err %}{{page.err|safe}}{% endif %}
	{% if page.output and page.err %}<hr>{% endif %}
	{% if page.output %}{{page.output|safe|urlize}}{% endif %}
{% endif %}
</div>

<div id="srv_get_list"><h3><i class="fas fa-spinner fa-pulse fa-fw"></i> Loading...</h3></div>
{% endblock %}

{% block right_panel %}
<div class="card-body">

	<div id="div_id_PSearch" class="form-group">
		<label for="id_PSearch" class=" requiredField">Recherche d'un serveur (min 3 caractères) </label>
		<div class=""><input type="text" name="PSearch" maxlength="128" class="textinput textInput form-control" required="" id="id_PSearch" oninput="srv_get_list()" value="{{page.search}}"></div>
	</div>
	<p>{{page.p_right|safe}}</p>
	<div class="d-grid gap-2 mb-2"><a class="btn btn-success" href="#" onclick="bt_edit_srv_info(0)" role="button"><i class="far fa-plus-square"></i> Ajouter un Serveur</a></div>
	<div class="d-grid gap-2"><a class="btn btn-primary" href="/parc" role="button"><i class="fas fa-undo-alt"></i> Retour</a></div>
</div>
{% endblock %}


