81 lines
2.4 KiB
JavaScript
81 lines
2.4 KiB
JavaScript
/// BookSystem JavaScript Utility Library.
|
|
/// HC TECH 2017 Kiritow.
|
|
/// Under MIT License
|
|
|
|
/// Check Login
|
|
function mustLogin() {
|
|
$.post("/cgi-bin/booksys/doCheckLogin",{},function(data){
|
|
console.log("CheckLogin Ajax Success");
|
|
if(data.success!=1)
|
|
{
|
|
console.log("Not Logged in.");
|
|
location.href="login.html";
|
|
}
|
|
else
|
|
{
|
|
console.log("Logged in.");
|
|
}
|
|
},"json").fail(function(err){
|
|
console.log("Failed to check login. err:",err);
|
|
});
|
|
}
|
|
|
|
/// Check Permission
|
|
/// If level does not matches required_level, callback will be called.
|
|
function checkPermission(required_level,callback_failure,callback_success) {
|
|
$.post("/cgi-bin/booksys/doCheckPermission",{required:required_level},function(data){
|
|
console.log("CheckPermission: Ajax Success");
|
|
if(data.success!=1) {
|
|
console.log("CheckPermission: Permission Denied.")
|
|
if(callback_failure!=null) callback_failure();
|
|
} else {
|
|
console.log("CheckPermission: Permission OK.");
|
|
if(callback_success!=null) callback_success();
|
|
}
|
|
},"json").fail(function(err){
|
|
console.log("CheckPermission Ajax Failed.");
|
|
});
|
|
}
|
|
|
|
|
|
/// jQueryUI Wrapper
|
|
function createHighlight(obj){
|
|
obj.removeClass('ui-state-highlight ui-state-error ui-corner-all');
|
|
obj.addClass('ui-state-highlight ui-corner-all');
|
|
obj.html('<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right:.3em;"></span>'+obj.html()+'</p>');
|
|
}
|
|
|
|
function createError(obj){
|
|
obj.removeClass('ui-state-highlight ui-state-error ui-corner-all');
|
|
obj.addClass('ui-state-error ui-corner-all');
|
|
obj.html('<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right:.3em;"></span>'+obj.html()+'</p>');
|
|
}
|
|
|
|
/// URI Resolver
|
|
function GetRequest() {
|
|
var url = decodeURI(location.search);
|
|
var theRequest = new Object();
|
|
if (url.indexOf("?") != -1) {
|
|
var str = url.substr(1);
|
|
strs = str.split("&");
|
|
for(var i = 0; i < strs.length; i ++) {
|
|
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
|
|
}
|
|
}
|
|
return theRequest;
|
|
}
|
|
|
|
/// Route back in browser
|
|
function GoBack() {
|
|
window.history.back();
|
|
window.location.reload();
|
|
/// Chrome?
|
|
return false;
|
|
}
|
|
|
|
function GoBackWith(n) {
|
|
window.history.go(-(n));
|
|
window.location.reload();
|
|
/// Chrome?
|
|
return false;
|
|
} |