var gateid
var gatename
var infotimeout
function odswiez(){
location.reload();
}
function OpenGate(GateID, GateName, Confirm){
Confirm = (typeof Confirm !== 'undefined') ? Confirm : 1;
gatename=GateName;
gateid=GateID;
if (Confirm){
ShowInfo(`Czy potwierdzasz otwarcie ${gatename}`, showbutton=true, confirm=true, timeout=10);
} else {
SendData()
}
}
function SendData(){
ShowInfo(`Otwieram ${gatename}`, showbutton=false, confirm=false, timeout=-1)
var dane={'gateid':gateid}
$.post( "/opengate", dane , function( result ) {
if (result.OK == 0){
CloseInfo();
}else{
ShowInfo(`Error ${result.error}`);
}
}, dataType='json')
.fail(function() {
ShowInfo(`No communication with the server`);
})
};
function CloseInfo(){
if ($('#dialog').is(':visible')){
$('#dialog').hide('slow');
$('.eventbutton').css('cursor', 'pointer');
//$('.negative').removeClass('negative')
}
}
function ShowInfo(info, showbutton, confirm, timeout){
showbutton = (typeof showbutton !== 'undefined') ? showbutton : true;
confirm = (typeof confirm !== 'undefined') ? confirm : false;
timeout = (typeof timeout !== 'undefined') ? timeout : 5;
clearTimeout(infotimeout);
$('#info').html(info);
if (showbutton){
$('#animacja').hide();
$('#closebutton').show();
if (confirm) {
$('#confirmbutton').show();
} else {
$('#confirmbutton').hide();
};
}else{
$('#closebutton').hide();
$('#confirmbutton').hide();
$('#animacja').show();
};
if (!$('#dialog').is(':visible')){
$('.eventbutton').css('cursor','default');
$('#dialog').show('slow');
};
//if (!confirm) {
// $('#dialog').on( "click", CloseInfo);
//} else {
// $('#dialog').off('click');
//}
if (timeout>0 && showbutton){ //&& !confirm){
infotimeout = setTimeout(CloseInfo, timeout*1000);
};
}
/*
$(document).ready(function() {
//$('#dialog').on( "click", function() {
// CloseInfo();
//});
});
*/