org.javasimon.console.resource.js.javasimon-service.js Maven / Gradle / Ivy
"use strict";
var javasimon=window.javasimon||{};
window.javasimon=javasimon;
(function($, tns) {
tns.fnDefaultAjaxErrorCallback=function(content) {
window.alert("Server request failed:" +content);
};
/**
* Service to reset Simons through Ajax HTTP requests
*/
tns.ResetService={
sUrl:"data/reset",
/**
* Reset one or more Simons. A confirmation dialog appears before.
* @param oData {object} Filter
* @param fnAjaxCallback {function} Callback
*/
fnResetAll: function(oData, fnAjaxCallback) {
if (window.confirm("Are you sure you want to reset all monitors?")) {
this.fnReset(oData, fnAjaxCallback);
}
},
/**
* Reset one Simons.
* @param sName {string} Simon name
* @param fnAjaxCallback {function} Callback
*/
fnResetOne: function(sName, fnAjaxCallback) {
this.fnReset({name:sName}, fnAjaxCallback);
},
/**
* Reset one or more Simons.
* @param oData {object} Filter
* @param fnAjaxCallback {function} Callback
*/
fnReset: function(oData, fnAjaxCallback) {
$.post(this.sUrl, oData, fnAjaxCallback, tns.fnDefaultAjaxErrorCallback);
}
};
/**
* Service to clear Simons through Ajax HTTP requests
*/
tns.ClearService={
sUrl:"data/clear",
/**
* Clear all simons. A confirmation dialog appears before.
* @param fnAjaxCallback {function} Callback
*/
fnClearAll: function(fnAjaxCallback) {
if (window.confirm("Are you sure you want to clear the Manager? This will delete all the monitors.")) {
this.fnClear(fnAjaxCallback);
}
},
/**
* Clear all Simons.
* @param fnAjaxCallback {function} Callback
*/
fnClear: function(fnAjaxCallback) {
$.post(this.sUrl, {}, fnAjaxCallback, tns.fnDefaultAjaxErrorCallback);
}
};
/**
* Service to get Simon data as flat list through Ajax HTTP requests
*/
tns.TableService={
sUrl:"data/table",
fnGetDataAsXxx:function(sExt, oParam) {
var lsUrl=this.sUrl+"."+sExt+"?_";
if (oParam.sPattern) {
lsUrl = lsUrl + "&pattern=" + oParam.sPattern;
}
if (oParam.asTypes) {
for(var i=0; i=0) {
sCookieValue=asCookieValueParts[i].substring(iPrefixPos+7, asCookieValueParts[i].length);
}
}
if (!sCookieValue) {
return;
}
// Parse cookie value
var asTypes=[];
var sType, sTimeFormat, iDataTableLength;
if (sCookieValue) {
var asCookieValue=sCookieValue.split(",");
// Version
if (asCookieValue.length>=4 && asCookieValue[0]===this.sVersion) {
// Types
for(var i=0;i0) {
this.oSettings.asTypes=asTypes;
}
// Time format
sTimeFormat=this.getConstant(undefined, asCookieValue[2]);
if (sTimeFormat) {
this.oSettings.sTimeFormat=sTimeFormat;
}
// Data table length
iDataTableLength=asCookieValue[3];
if (iDataTableLength) {
this.oSettings.iDataTableLength=iDataTableLength;
}
}
}
},
/**
* Save settings into a cookie
*/
save:function(oDocument) {
oDocument = oDocument || document;
var sCookieValuePart;
// Version
var sCookieValue=this.sVersion;
// Expiration date J+30
var dCookieExpire = new Date();
dCookieExpire.setTime(dCookieExpire.getTime()+(30*24*60*60*1000));
// Type
sCookieValue=sCookieValue+",";
for(var i=0;i