SignUp/script/script.js

110 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-08-08 13:40:15 +00:00
/**
* /script/script.js
* @version 2.0
* @desc Javascript for ajax and for fancy tables
* @author Fándly Gergő Zoltán
* @copy 2017 Fándly Gergő Zoltán
*/
function ask(q, togo){
if(confirm(q)){
window.location=togo;
}
}
function prompt_go(question, value, todo){
var reply=prompt(question, value);
if(reply){
window.location=todo+reply;
}
}
function disposeMessageOverlay(){
$("#messageOverlay").html("");
$("#messageOverlay").css("display", "none");
}
jQuery(function($){
//loading overlay
$(document).ajaxStart(function(){
$("#loadingOverlay").css("display", "block");
});
$(document).ajaxComplete(function(){
$("#loadingOverlay").css("display", "none");
});
//footable
$(".table").footable();
//handle response
function setResponse(response){
$("#messageOverlay").html(response);
$("#messageOverlay").css("display", "block");
setTimeout(function(){
$("#messageOverlay").html("");
$("#messageOverlay").css("display", "none");
}, 5000);
}
//handle form submits
$(".ajaxform").submit(function(e){
e.preventDefault(); //turn off default handler
//run ajax request
$.ajax({
url: e.target.action+"?backend",
type: e.target.method,
data: $(this).serialize(),
success: function(response){
setResponse(response);
}
});
//reset form if data-noreset not specified
if($(this).data("noreset")==undefined){
e.target.reset();
}
});
//handle button presses
$(document).on("click", ".ajaxbutton", function(e){
e.preventDefault(); //turn off default handler
if($(this).data("confirm")==undefined || confirm($(this).data("confirm"))){ //check if confirmation needed
//prompt for input if needed
var reply="";
if($(this).data("prompt")!=undefined){
reply=prompt($(this).data("prompt"), '');
}
//build target url
var targetUrl=$(this).data("url")+reply;
if(targetUrl.indexOf("?")){
targetUrl+="&backend";
}
else{
targetUrl+="?backend";
}
//run ajax request
$.ajax({
url: targetUrl,
type: "GET",
success: function(response){
setResponse(response);
}
});
//delete caller button if data-kepp not specified
if($(this).data("keep")==undefined){
$(this).remove();
}
}
});
});