static.js.func.js Maven / Gradle / Ivy
$.ajaxSetup({
headers : {
Accept : "application/vnd.formkiq.v1+json"
}
});
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);
typeof successcallback === 'function' && successcallback(data);
},
error: function (data) {
hidemessages();
var text = JSON.parse(data.responseText)
showerror(sel, failmsg + text.message);
}
});
}
function makeid(size) {
var text = "";
var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < size; i++ ) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
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);
}
});
}