static.js.func.js Maven / Gradle / Ivy
$.ajaxSetup({
headers : {
Accept : "application/vnd.formkiq.v1+json, application/vnd.formkiq.admin"
}
});
function postRequest(sel, url, successmsg, failmsg, successcallback) {
var data = sel.serialize();
$.ajax({
type : 'POST',
url : url + "?" + data,
contentType: 'application/json; charset=utf-8',
dataType : 'json',
success : function(data) {
hidemessages();
showsuccess(sel, successmsg + data.message);
typeof successcallback === 'function' && successcallback(data);
},
error: function (data) {
hidemessages();
var text = JSON.parse(data.responseText);
showerror(sel, failmsg + text.message);
}
});
}
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
function hidemessages() {
$(".messagebox").hide();
}
function showerror(sel, msg) {
$(sel).before( $( "
" ) );
}
function showsuccess(sel, msg) {
$(sel).before( $( " " ) );
}
function showwarning(sel, msg) {
$(sel).before( $( " " ) );
}
function shownotice(sel, msg) {
$(sel).before( $( " " ) );
}
function deleteForm(sel) {
var type = $("#type").val();
var data = sel.serialize();
$.ajax({
type : 'POST',
url : "/api/" + type + "s/delete?" + data,
contentType: 'application/json; charset=utf-8',
dataType : 'json',
success : function(data) {
hidemessages();
showsuccess(sel, "Deleted was successful");
},
error: function (data) {
hidemessages();
var text = JSON.parse(data.responseText)
showerror(sel, "Unable to Delete - " + text.message);
}
});
}