/*********************************************************************************** * GLOBAL FUNCTIONS ***********************************************************************************/ /** * Get element x and y coordinates */ function getElementLocation(aElement) { function getNextAncestor(aElement) { var actualStyle; if (window.getComputedStyle) { actualStyle = getComputedStyle(aElement,null).position; } else if( aElement.currentStyle) { actualStyle = aElement.currentStyle.position; } else { //fallback for browsers with low support - only reliable for inline styles actualStyle = aElement.style.position; } if (actualStyle == 'absolute' || actualStyle == 'fixed') { //the offsetParent of a fixed position element is null so it will stop return aElement.offsetParent; } return aElement.parentNode; } if (typeof(aElement) == "string") aElement = elem(aElement); if (!aElement) return null; if (typeof(aElement.offsetParent) != 'undefined') { var originalElement = aElement; for (var posX = 0, posY = 0; aElement; aElement = aElement.offsetParent) { posX += aElement.offsetLeft; posY += aElement.offsetTop; } if (!originalElement.parentNode || !originalElement.style || typeof(originalElement.scrollTop) == 'undefined') { //older browsers cannot check element scrolling return {"x":posX, "y":posY}; } aElement = getNextAncestor(originalElement); while (aElement && aElement != document.body && aElement != document.documentElement) { posX -= aElement.scrollLeft; posY -= aElement.scrollTop; aElement = getNextAncestor(aElement); } return {"x":posX, "y":posY}; } else { return {"x":aElement.x, "y":aElement.y}; } } /** * Set element x and y coordinates */ function setElementLocation(element, x, y) { if (typeof(element) == "string") element = elem(element); if (!element) return; element.style.position = "absolute"; element.style.left = x + "px"; element.style.top = y + "px"; } /** * Get mouse x and y coordinates */ function getMouseLocation(event) { var result = new Object(); if (event) { result.x = event.clientX + document.body.scrollLeft; result.y = event.clientY + document.body.scrollTop; } else { result.x = window.event.clientX + document.body.scrollLeft; result.y = window.event.clientY + document.body.scrollTop; } return result; } /** * Get element dimension */ function getElementDimension(element) { if (typeof(element) == "string") element = elem(element); if (!element) return null; var result = new Object(); if (document.defaultView && document.defaultView.getComputedStyle) { result.w = parseInt(document.defaultView.getComputedStyle(element, "").getPropertyValue("width")); result.h = parseInt(document.defaultView.getComputedStyle(element, "").getPropertyValue("height")); } else { result.w = element.clientWidth; result.h = element.clientHeight; } return result; } /** * Set element width and height */ function setElementDimension(element, w, h) { if (typeof(element) == "string") element = elem(element); if (!element) return; element.style.width = w + "px"; element.style.height = h + "px"; } /** * Set opacity */ function setOpacity(element, value) { if (typeof(element) == "string") element = elem(element); if (!element) return; if (page.agent.isIE()) { element.style.filter = 'alpha(opacity=' + value + ')'; } else if (page.agent.isFirefox() || page.agent.isMozilla()) { element.style.opacity = value/100; } else { element.style.opacity = value/100; } } /** * Get element by id */ function elem(id) { return document.getElementById(id); } /** * Get element by id */ function e(eId) { return document.getElementById(eId); } /** * setHtml */ function setHtml(element, html) { if (typeof(element) == "string") { element = document.getElementById(element); } try { element.innerHTML = html; } catch(ex) { if (document.contentType == "application/xhtml+xml") { setHtmlThroughDOM(element, "" + html + ""); } } } /** * setHtmlThroughDOM */ function setHtmlThroughDOM(element, html) { if (typeof(element) == "string") { element = document.getElementById(element); } try { var children = element.childNodes; for (var i = 0; i < children.length; i++) { element.removeChild(children[i]); } var nodes = new DOMParser().parseFromString( html, 'text/xml' ).documentElement; var range = document.createRange(); range.selectNodeContents( element ); range.deleteContents(); for (var i = 0; i < nodes.childNodes.length; i++) { element.appendChild(document.importNode(nodes.childNodes[i], true)); } } catch(ex) { } } /** * Get object functions */ function getFunctions(obj) { var str = ""; for (i in obj) { if (i != "selectionStart" && i != "selectionEnd" && i != "domConfig") { if (typeof(obj[i]) == "function") { str = str + i + " => " + obj[i] + "\n"; } } } return str; } /** * print_r */ function print_r(mixed) { var innerHtml = ""; if (typeof(mixed) == "object") { for (i in mixed) { if (i != "selectionStart" && i != "selectionEnd" && i != "domConfig" && mixed[i]!=null && typeof(mixed[i]) != "function" && typeof(mixed[i]) != "unknown") { innerHtml = innerHtml + i + " => " + mixed[i] + "\n"; } } } else if (typeof(mixed) == "number") { innerHtml = "" + mixed; } else { innerHtml = mixed; } var elementTA = document.getElementById('print_r_TextArea'); if (elementTA) { elementTA.value = elementTA.value + "\n\n============================ new entry ============================\n\n" + innerHtml; return; } var e = document.createElement("div"); e.style.position = "absolute"; e.id = page.createUID(); document.body.appendChild(e); var btnCloseID = page.createUID(); var html = ""; html += ""; html += ""; html += ""; html += ""; html += "
Debug Window
"; setHtml(e, html); page.centerElement(e); document.getElementById(btnCloseID).onclick = function() { document.body.removeChild(e); } } /** * httpBuildQuery */ function httpBuildQuery(obj, args) { var str = ""; for (k in obj) { var v = obj[k]; if (v) { if (isArray(v)) { var arrstr = ""; for (var ind=0; ind 0) { str = str.substr(0, str.length-1); } return str; } /** * Parse query string */ function httpParseQuery(str) { var obj = {}; var arr = str.split("&"); for (var i=0; i 0; }, /** * Cover this document with opacity layer */ cover: function(aLayerId, opacityValue) { var layer = document.createElement("div"); layer.id = aLayerId; layer.style.position = "absolute"; if (opacityValue==null || (typeof opacityValue != "number") || opacityValue < 0 || opacityValue > 1) { opacityValue = 0.6; } var opacityStr = ""; var imageFile = "blank.gif"; if (opacityValue != 0) { imageFile = "disablepage.gif"; if (page.agent.isIE()) { opacityStr = "filter:alpha(opacity=100)"; } else { opacityStr = "opacity:" + opacityValue; } } var html = ""; html = html.replace("{width}", this.docWidth()); html = html.replace("{height}", (this.docHeight())); layer.style.top = "0px"; layer.style.left = "0px"; setHtml(layer, html); document.body.appendChild(layer); if (this.agent.isIE() && elem(aLayerId+"Child")) { elem(aLayerId+"Child").filters.alpha.opacity = Math.floor(opacityValue*100); } }, /** * Uncover this document from opacity layer */ uncover: function(aLayerId) { if (elem(aLayerId)) { document.body.removeChild(elem(aLayerId)); } }, /** * Toggle enable/disable mode, flag = true means to disable */ toggleEnableDisableMode: function(flag) { if (flag) { if (document.getElementById(this.lockId)) { return; } this.cover(this.lockId); } else { this.uncover(this.lockId); } }, /** * Sets disabled */ setDisabled: function() { this.toggleEnableDisableMode(true); }, /** * Sets enabled */ setEnabled: function() { this.toggleEnableDisableMode(false); }, /** * Checks to see if page is disabled */ isDisabled: function() { if (document.getElementById(this.lockId)) { return true; } return false; }, /** * Array of messages/errors to ordered list */ objectToOrderedList: function(arr) { var str = "
    "; var count = 0; var lastItem = null; for (var i in arr) { str += "
  1. " + arr[i] + "
  2. "; lastItem = arr[i]; count++; } str += "
"; return (count == 1 ? "
"+lastItem+"
" : str); }, /** * Shows messages */ showMessages: function(obj, onCloseHandler) { var content = ""; if (typeof(obj) == "string") { content = "
"+obj+"
"; } else if (typeof(obj) == "array" || typeof(obj) == "object") { content = this.objectToOrderedList(obj); } var dialog = new TDialog(); dialog.setClassName("cssDialogInfo"); dialog.setDraggable(true); dialog.setTitle(this.i18n("SYS_UI_PAGE_INFO_TITLE")); dialog.setContent(content); dialog.addButton(this.i18n("BTN_CLOSE"), function () { dialog.close(); if (onCloseHandler) onCloseHandler.call(); }); dialog.openModal(); dialog.bringToFront(); return dialog; }, /** * Shows message */ showMessage: function(obj, onCloseHandler) { return this.showMessages(obj, onCloseHandler); }, /** * Shows errors */ showErrors: function(obj, onCloseHandler) { var content = ""; if (typeof(obj) == "string") { content = "
"+obj+"
"; } else if (typeof(obj) == "array" || typeof(obj) == "object") { content = this.objectToOrderedList(obj); } var dialog = new TDialog(); dialog.setClassName("cssDialogError"); dialog.setDraggable(true); dialog.setTitle(this.i18n("SYS_UI_PAGE_ERRORS_TITLE")); dialog.setContent(content); dialog.addButton(this.i18n("BTN_CLOSE"), function () { dialog.close(); if (onCloseHandler) onCloseHandler.call(); }); dialog.openModal(); dialog.bringToFront(); return dialog; }, /** * Shows error message */ showError: function(obj, onCloseHandler) { return this.showErrors(obj, onCloseHandler); }, /** * Shows confirm message */ showConfirm: function(message, onYesHandler, onNoHandler) { var dialog = new TDialog(); dialog.setClassName("cssDialogInfo"); dialog.setDraggable(true); dialog.setTitle(this.i18n("SYS_UI_PAGE_CONFIRM_TITLE")); dialog.setContent("
"+message+"
"); dialog.addButton(this.i18n("BTN_YES"), function() { dialog.close(); if (onYesHandler) onYesHandler.call(); }); dialog.addButton(this.i18n("BTN_NO"), function() { dialog.close(); if (onNoHandler) onNoHandler.call(); }); dialog.openModal(); dialog.bringToFront(); return dialog; }, /** * Shows prompt message */ showPrompt: function(title, message, onOkHandler, onCancelHandler) { var tboxID = this.createUID(); var dialog = new TDialog(); dialog.setClassName("cssDialogInfo"); dialog.setDraggable(true); dialog.setTitle(title); dialog.setContent("
" + message + " " + "
"); dialog.addButton(this.i18n("BTN_OK"), function() { var val = elem(tboxID).value; dialog.close(); if (onOkHandler) onOkHandler.call(this, val); }); dialog.addButton(this.i18n("BTN_CANCEL"), function() { var val = elem(tboxID).value; dialog.close(); if (onCancelHandler) onCancelHandler.call(this, val); }); dialog.openModal(); dialog.bringToFront(); return dialog; }, /** * Wait */ wait: function(message) { var waitDlg = new TDialog(); waitDlg.showTitle(false); if (message) { waitDlg.setClassName("cssDialogWait"); waitDlg.setContent("
" + message + "

"); waitDlg.openModal(); } else { waitDlg.setClassName("cssNoExistingClass"); waitDlg.setContent(""); waitDlg.openModal(); waitDlg.getContentElement().style.textAlign = "center"; } var id = this.createUID(); this.fWaitDialogs[id] = waitDlg; return id; }, /** * Unwait */ unwait: function(id) { var dlg = this.fWaitDialogs[id]; if (dlg && dlg.isOpen()) { dlg.close(); } }, /** * Reload */ reload: function(milsec) { var uri = document.location.href; if (uri.indexOf("#") >= 0) uri = uri.substr(0, uri.indexOf("#")); if (milsec) setTimeout( function() { document.location.href = uri; }, milsec ); else { document.location.href = uri; } }, /** * Gets window height */ windowHeight: function() { if (this.agent.isIE()) { return (document.body.offsetHeight ? document.body.offsetHeight : document.body.clientHeight); } else { return window.innerHeight; } }, /** * Gets window width */ windowWidth: function() { if (this.agent.isIE()) { return (document.body.offsetWidth ? document.body.offsetWidth : document.body.clientWidth); } else { return window.innerWidth; } }, /** * Gets document height */ docHeight: function() { return Math.max(document.body.scrollHeight, document.body.clientHeight); }, /** * Gets document width */ docWidth: function() { return document.body.scrollWidth; }, /** * Bring to front */ bringElementToFront: function(element) { if (!element.style.zIndex || element.style.zIndex < page.topZIndex) element.style.zIndex = ++page.topZIndex; }, /** * Centers element */ centerElement: function(element) { if (element.clientHeight < this.windowHeight()) { element.style.top = document.body.scrollTop + (this.windowHeight() - element.clientHeight)/2 + "px"; } else { element.style.top = (this.docHeight() - element.clientHeight)/2 + "px"; } if (element.clientWidth < this.windowWidth()) { element.style.left = document.body.scrollLeft + (this.windowWidth() - element.clientWidth)/2 + "px"; } else { element.style.left = (this.docWidth() - element.clientWidth)/2 + "px"; } }, /** * Sets look and feel */ setLookAndFeel: function(uri) { if (elem("idLafCssLink")) { elem("idLafCssLink").href = uri; } }, /** * Sets cookie */ setCookie: function(name,value,expires) { var today = new Date(); today.setTime( today.getTime() ); if (expires != 0) { expires = expires * 1000; var expiresDate = new Date(today.getTime()+expires); document.cookie = name + "=" + escape(value) + ";expires=" + expiresDate.toGMTString(); } else { document.cookie = name + "=" + escape(value); } }, /** * Gets cookie */ getCookie: function(name) { if (document.cookie.length>0) { var startIndex = document.cookie.indexOf(name + "="); if (startIndex != -1) { startIndex = startIndex+name.length+1; var endIndex = document.cookie.indexOf(";",startIndex); if (endIndex == -1) endIndex = document.cookie.length; return unescape(document.cookie.substring(startIndex,endIndex)); } } return null; }, /** * Removes cookie */ removeCookie: function(name) { if (this.getCookie(name)) document.cookie = name + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT"; }, /** * Adds script file */ addScriptFile: function(uri, id) { var scriptElement; if (id && document.getElementById(id)) { scriptElement = document.getElementById(id); } else { scriptElement = document.createElement('script'); scriptElement.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(scriptElement); if (id) linkElement.id = id; } if (scriptElement) { page.scriptLoadingNumber++; if (this.agent.isIE()) { scriptElement.onreadystatechange = function () { if (this.readyState == 'loaded') { page.scriptLoadingNumber--; } } } else { scriptElement.onload = function() {page.scriptLoadingNumber--;}; } scriptElement.src = uri; } }, /** * Adds script content */ addScriptContent: function(content) { try { var scriptElement = document.createElement('script'); scriptElement.type = 'text/javascript'; scriptElement.text = content; document.getElementsByTagName('head')[0].appendChild(scriptElement); } catch(e) { alert(e); } }, /** * Adds css file */ addCssFile: function(uri, id) { var linkElement; if (id && document.getElementById(id)) { linkElement = document.getElementById(id); } else { linkElement = document.createElement('link'); linkElement.type = 'text/css'; linkElement.rel = 'stylesheet'; document.getElementsByTagName('head')[0].appendChild(linkElement); if (id) { linkElement.id = id; } } if (linkElement) { linkElement.href = uri; } }, /** * Safe execution of a script */ safeExec: function(content) { if (page.scriptLoadingNumber == 0) { eval(content); } else { setTimeout(function() {page.safeExec(content); }, 200); } }, /** * Redirect */ redirect: function(url, params, args) { if (!params && !args) { document.location.href = url; return; } var frm = document.createElement("FORM"); frm.action = url; if (args) { if (args['method']) { frm.method = args['method']; } if (args['target']) { frm.target = args['target']; } } if (params) { for (var k in params) { var v = params[k]; if (typeof(v) == "object" && v.constructor === Array) { for (var ind=0; ind= 0 && navigator.userAgent.indexOf("Opera") == -1 && navigator.userAgent.indexOf("Konqueror") == -1 ); }, /** * isMozilla */ isMozilla: function() { return ( navigator.userAgent.indexOf( "Mozilla" ) >= 0 && navigator.userAgent.indexOf( "Gecko" ) >= 0 && navigator.userAgent.indexOf( "MSIE" ) == -1 && navigator.userAgent.indexOf( "Firefox" ) == -1 && navigator.userAgent.indexOf( "Opera" ) == -1 && navigator.userAgent.indexOf( "Konqueror" ) == -1 && navigator.userAgent.indexOf( "Safari" ) == -1 && navigator.userAgent.indexOf( "Chrome" ) == -1 ); }, /** * isFirefox */ isFirefox: function() { return ( navigator.userAgent.indexOf( "Firefox" ) >= 0 ); }, /** * isOpera */ isOpera: function() { return ( navigator.userAgent.indexOf( "Opera" ) >= 0 ); }, /** * isKonqueror */ isKonqueror: function() { return ( navigator.userAgent.indexOf( "Konqueror" ) >= 0 ); }, /** * isSafari */ isSafari: function() { return (navigator.userAgent.indexOf("Safari") >= 0 && navigator.userAgent.indexOf("Chrome") == -1); }, /** * isChrome */ isChrome: function() { return (navigator.userAgent.indexOf("Chrome") >= 0); }, /** * isUnknown */ isUnknown: function() { return ( !this.isIE() && !this.isMozilla() && !this.isFirefox() && !this.isOpera() && !this.isKonqueror() && !this.isSafari() && !this.isChrome() ); } }); if(!this.JSON){this.JSON={};} (function(){function f(n){return n<10?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ f(this.getUTCMonth()+1)+'-'+ f(this.getUTCDate())+'T'+ f(this.getUTCHours())+':'+ f(this.getUTCMinutes())+':'+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';} function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} if(typeof rep==='function'){value=rep.call(holder,key,value);} switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i 0 ? "&" : "?") + "____dialogID=" + this.getName(); this.setContent(""); this.fIFrameContent = true; }, /** * Set child event listener */ setChildEventListener: function(aListener) { this.fChildEventListener = aListener; }, /** * Fire child data event */ fireChildDataEvent: function(data) { if (this.fChildEventListener) { this.fChildEventListener.call(this, data ? json_decode(data) : {}); } }, /** * Get content box id */ getContentBoxId: function() { return this.fContentElementID; }, /** * Get content element */ getContentElement: function() { return elem(this.fContentElementID); }, /** * Set content box dimension */ setContentBoxDimension: function(aWidth, aHeight, aOverflow) { this.fContentBoxConstraints = {}; this.fContentBoxConstraints['w'] = aWidth; this.fContentBoxConstraints['h'] = aHeight; if (aOverflow) { this.fContentBoxConstraints['overflow'] = aOverflow; } else { this.fContentBoxConstraints['overflow'] = "auto"; } }, /** * Set draggable mode */ setDraggable: function(aDraggableMode) { this.fDraggableMode = aDraggableMode; }, /** * Set resizable mode */ setResizable: function(aResizableMode) { this.fResizableMode = aResizableMode; }, /** * Show min button */ showMinButton: function(flag) { this.fShowMinButton = flag; }, /** * Show max buttons */ showMaxButton: function(flag) { this.fShowMaxButton = flag; }, /** * Show close button */ showCloseButton: function(flag, aHandler) { this.fShowCloseButton = flag; if (flag == true && aHandler) { this.fCloseHandler = aHandler; } }, /** * Show confirm on close */ showConfirmOnClose: function(flag) { this.fShowConfirmOnClose = flag; }, /** * Show title */ showTitle: function(flag) { this.fShowTitle = flag; }, /** * Go to */ goTo: function(x, y) { setElementLocation(elem(this.getName()), x, y); }, /** * Add button */ addButton: function(aLabel, aHandler) { var id = page.createUID(); this.fButtons.push({"id":id, "label":aLabel}); this.fButtonClickHandlers[id] = aHandler; return id; }, /** * Opens dialog */ open: function() { if (elem(this.getName())) { return; } var dialogElement = document.createElement("div"); dialogElement.style.visibility = "hidden"; // set id dialogElement.id = this.getName(); // set position dialogElement.style.position = "absolute"; // set class name dialogElement.className = this.getClassName() ? this.getClassName() : "cssDialogInfo"; // add element to document childs document.body.appendChild(dialogElement); setHtml(dialogElement, this.toHtml()); if (this.fContentBoxConstraints) { dialogElement.style.width = this.fContentBoxConstraints['w'] + "px"; } page.centerElement(dialogElement); var coordinates = getElementLocation(dialogElement); setElementLocation(dialogElement, coordinates.x + 8*page.availableDialogs, coordinates.y + 8*page.availableDialogs); dialogElement.style.visibility = "visible"; page.bringElementToFront(dialogElement); var _self = this; if (this.fShowTitle && this.fShowMinButton && elem(this.fSystemButton1)) { elem(this.fSystemButton1).onclick = function() {_self.minimize()} } if (this.fShowTitle && this.fShowMaxButton && elem(this.fSystemButton2)) { elem(this.fSystemButton2).onclick = function() {_self.maximize()} } if (this.fShowTitle && this.fShowCloseButton && elem(this.fSystemButton3)) { elem(this.fSystemButton3).onclick = function() { if (_self.fCloseHandler) { _self.fCloseHandler.call(); } else { _self.close(); } return false; } } // assign onclick event handler(s) to button(s) for (var index in this.fButtons) { var btnAttr = this.fButtons[index]; var btnElement = elem(btnAttr["id"]); if (btnElement) { btnElement.onclick = function() { var clickHandler = _self.fButtonClickHandlers[this.id]; if (clickHandler) clickHandler.call(); } } } // bring to top if (page.agent.isIE()) { dialogElement.attachEvent("onmousedown", function() { _self.bringToFront(); }); } else { dialogElement.addEventListener("mousedown", function(event) { _self.bringToFront(); }, false); } if (this.fDraggableMode && this.fShowTitle) { var targetElement = elem(this.fTitleElementID); if (page.agent.isIE()) { targetElement.attachEvent("onmousedown", function() { var eXY = getElementLocation(dialogElement); var mXY = getMouseLocation(); _self.fDragObject = {'off_x':mXY.x-eXY.x,'off_y':mXY.y-eXY.y}; document.body.style.cursor = "move"; }); document.attachEvent("onmousemove", function() { if (!_self.fDragObject) return; var mXY = getMouseLocation(); setElementLocation(dialogElement, mXY.x-_self.fDragObject.off_x, mXY.y-_self.fDragObject.off_y); }); document.attachEvent("onmouseup", function() { _self.fDragObject = null; document.body.style.cursor = "default"; }); } else { targetElement.addEventListener("mousedown", function(event) { var eXY = getElementLocation(dialogElement); var mXY = getMouseLocation(event); _self.fDragObject = {'off_x':mXY.x-eXY.x,'off_y':mXY.y-eXY.y}; document.body.style.cursor = "move"; }, false); document.addEventListener("mousemove", function(event) { if (!_self.fDragObject) return; var mXY = getMouseLocation(event); setElementLocation(dialogElement, mXY.x-_self.fDragObject.off_x, mXY.y-_self.fDragObject.off_y); }, false); document.addEventListener("mouseup", function() { _self.fDragObject = null; document.body.style.cursor = "default"; }, false); } } if (this.fResizableMode) { var contentElement = elem(this.fContentElementID); if (page.agent.isIE()) { dialogElement.attachEvent("onmousedown", function() { if (_self.inResizeBox) { var eWH = getElementDimension(dialogElement); var cWH = getElementDimension(contentElement); var mXY = getMouseLocation(event); _self.fResizeObject = {'dw':eWH.w,'ch':cWH.h,'mx':mXY.x,'my':mXY.y}; } }); dialogElement.attachEvent("onmousemove", function() { var mXY = getMouseLocation(event); var eXY = getElementLocation(dialogElement); var eWH = getElementDimension(dialogElement); if (eXY.x + eWH.w - 10 < mXY.x && eXY.y + eWH.h - 10 < mXY.y) { document.body.style.cursor = "nw-resize"; _self.inResizeBox = true; } else { document.body.style.cursor = "default"; _self.inResizeBox = false; } }); document.attachEvent("onmousemove", function() { if (!_self.fResizeObject) return; var mXY = getMouseLocation(event); var dialogWidth = _self.fResizeObject.dw + mXY.x-_self.fResizeObject.mx; var contentHeight = _self.fResizeObject.ch + mXY.y-_self.fResizeObject.my; if (dialogWidth < 200 || contentHeight < 5) return; dialogElement.style.width = dialogWidth + "px"; contentElement.style.height = contentHeight +"px"; if (_self.tmp['State'] == 'min' || _self.tmp['State'] == 'max') { if (elem(this.fSystemButton1)) elem(_self.fSystemButton1).style.visibility = 'visible'; if (elem(this.fSystemButton2)) elem(_self.fSystemButton2).src = '/image/max.gif'; _self.tmp['State'] = 'normal'; } }); document.attachEvent("onmouseup", function() { _self.fResizeObject = null; document.body.style.cursor = "default"; }); } else { dialogElement.addEventListener("mousedown", function(event) { if (_self.inResizeBox) { var eWH = getElementDimension(dialogElement); var cWH = getElementDimension(contentElement); var paddTop_px = document.defaultView.getComputedStyle(contentElement, "").getPropertyValue("padding-top"); var paddBottom_px = document.defaultView.getComputedStyle(contentElement, "").getPropertyValue("padding-bottom"); var paddTop = (paddTop_px?parseInt(paddTop_px.replace(/px/g, '')):0); var paddBottom = (paddBottom_px?parseInt(paddBottom_px.replace(/px/g, '')):0); var offsetHeight = paddTop+paddBottom; var mXY = getMouseLocation(event); _self.fResizeObject = {'dw':eWH.w,'ch':cWH.h,'mx':mXY.x,'my':mXY.y,'offsetHeight':offsetHeight}; } }, false); dialogElement.addEventListener("mousemove", function(event) { var mXY = getMouseLocation(event); var eXY = getElementLocation(dialogElement); var eWH = getElementDimension(dialogElement); if (eXY.x + eWH.w - 10 < mXY.x && eXY.y + eWH.h - 10 < mXY.y) { document.body.style.cursor = "nw-resize"; _self.inResizeBox = true; } else { document.body.style.cursor = "default"; _self.inResizeBox = false; } }, false); document.addEventListener("mousemove", function(event) { if (!_self.fResizeObject) return; var mXY = getMouseLocation(event); var dialogWidth = _self.fResizeObject.dw + mXY.x-_self.fResizeObject.mx; var contentHeight = _self.fResizeObject.ch + mXY.y-_self.fResizeObject.my; if (dialogWidth < 200 || contentHeight < 5) return; dialogElement.style.width = dialogWidth + "px"; contentElement.style.height = contentHeight - _self.fResizeObject.offsetHeight + "px"; if (_self.tmp['State'] == 'min' || _self.tmp['State'] == 'max') { if (elem(this.fSystemButton1)) elem(_self.fSystemButton1).style.visibility = 'visible'; if (elem(this.fSystemButton2)) elem(_self.fSystemButton2).src = '/image/max.gif'; _self.tmp['State'] = 'normal'; } }, false); document.addEventListener("mouseup", function() { _self.fResizeObject = null; document.body.style.cursor = "default"; }, false); } } if (this.fIFrameContent) { this.getContentElement().style.padding = "0 0 0 0"; page.registerWidget(this.getName(), this); } this.fModalDialog = false; page.availableDialogs = page.availableDialogs+1; }, /** * Opens modal dialog */ openModal: function() { if (elem(this.getName())) { return; } page.cover(this.fModalCoverId); page.bringElementToFront(elem(this.fModalCoverId)); this.open(); this.fModalDialog = true; }, /** * Opens url dialog */ openURL: function(width, height, title, url, childListener) { this.setContentBoxDimension(width, height, 'hidden'); this.setTitle(title); this.showTitle(title ? true : false); this.showMinButton(false); this.showMaxButton(false); var _self = this; this.showCloseButton(true, function() { if (_self.fShowConfirmOnClose) { page.showConfirm(page.i18n("SYS_MSG_ARE_YOU_SURE"), function() {_self.close();}, function() {}); } else { _self.close(); } }); this.setUrl(url); this.setDraggable(true); this.setResizable(false); this.openModal(); if (childListener) { this.setChildEventListener(childListener); } }, /** * Checks to see if it is opened */ isOpen: function() { if (elem(this.getName())) { return true; } return false; }, /** * Closes this dialog */ close: function() { if (this.fIFrameContent) { page.destroyWidget(this.getName()); } if (elem(this.getName())) { document.body.removeChild(e(this.getName())); if (this.fModalDialog) { page.uncover(this.fModalCoverId); } } page.availableDialogs = page.availableDialogs-1; }, /** * Hides this dialog */ show: function() { if (e(this.getName())) { e(this.getName()).style.visibility = 'visible'; if (this.fModalDialog && e(this.fModalCoverId)) { e(this.fModalCoverId).style.visibility = 'visible'; page.bringElementToFront(e(this.fModalCoverId)); } page.bringElementToFront(e(this.getName())); } }, /** * Hides this dialog */ hide: function() { if (this.fModalDialog && e(this.fModalCoverId)) { e(this.fModalCoverId).style.visibility = 'hidden'; } if (e(this.getName())) { e(this.getName()).style.visibility = 'hidden'; } }, /** * Bring to front */ bringToFront: function() { var dialogElement = elem(this.getName()); page.bringElementToFront(dialogElement); }, /** * Minimize */ minimize: function() { var dialogElement = this.getDialogElement(); var contentElement = this.getContentElement(); if (this.tmp['State'] == 'min') { return; } else { if (this.tmp['State'] == 'max') { } if (this.tmp['State'] == 'normal') { var dXY = getElementLocation(dialogElement); var dWH = getElementDimension(dialogElement); var cWH = getElementDimension(contentElement); this.tmp['x'] = dXY.x; this.tmp['y'] = dXY.y; this.tmp['w'] = dWH.w; this.tmp['h'] = cWH.h; } this.tmp['State'] = 'min'; if (elem(this.fSystemButton1)) elem(this.fSystemButton1).style.visibility = 'hidden'; if (elem(this.fSystemButton2)) elem(this.fSystemButton2).src = '/image/restore.gif'; //contentElement.style.height = "1px"; contentElement.style.display = "none"; } }, /** * Maximize */ maximize: function() { var dialogElement = this.getDialogElement(); var contentElement = this.getContentElement(); if (this.tmp['State'] == 'normal') { var dXY = getElementLocation(dialogElement); var dWH = getElementDimension(dialogElement); var cWH = getElementDimension(contentElement); this.tmp['x'] = dXY.x; this.tmp['y'] = dXY.y; this.tmp['w'] = dWH.w; this.tmp['h'] = cWH.h; this.tmp['State'] = 'max'; if (elem(this.fSystemButton2)) elem(this.fSystemButton2).src = '/image/restore.gif'; dialogElement.style.width = page.windowWidth()-16 + "px"; contentElement.style.height = page.windowHeight()-50 + "px"; dialogElement.style.left = "8px"; dialogElement.style.top = "5px"; } else if (this.tmp['State'] == 'min' || this.tmp['State'] == 'max') { this.restore(); } }, /** * Restore */ restore: function() { var dialogElement = this.getDialogElement(); var contentElement = this.getContentElement(); if (this.tmp['State'] == 'min' || this.tmp['State'] == 'max') { this.tmp['State'] = 'normal'; contentElement.style.display = "block"; dialogElement.style.width = this.tmp['w'] + "px"; contentElement.style.height = this.tmp['h'] + "px"; if (elem(this.fSystemButton1)) elem(this.fSystemButton1).style.visibility = 'visible'; if (elem(this.fSystemButton2)) elem(this.fSystemButton2).src = '/image/max.gif'; setElementLocation(dialogElement, this.tmp['x'], this.tmp['y']); } }, /** * To html */ toHtml: function() { var html = ""; html += ""; var systemButtons = ""; var tdWidth = "1px;"; if (this.fShowMinButton) { systemButtons += ""; } if (this.fShowMaxButton) { systemButtons += ""; } if (this.fShowCloseButton) { systemButtons += ""; } if (systemButtons != "") { tdWidth = "70px;"; } if (this.fShowTitle) { var insideTable = "
" + this.fTitle + "" + systemButtons + "
"; html += "" + insideTable + ""; } var contentStyle = ""; if (this.fContentBoxConstraints) { contentStyle = "height:" + this.fContentBoxConstraints['h'] + "px;overflow:" + this.fContentBoxConstraints['overflow']; } html += "
" + this.fContent + "
"; if (this.fButtons.length > 0) { html += ""; for (var index in this.fButtons) { var btnAttr = this.fButtons[index]; html += " "; } html = html.substr(0, html.length-6); html += ""; } html += ""; return html; }, /** * Destroy */ destroy: function() { }, /** * Get value */ getValue: function() { return null; } }); /************************************************************************************ * THttpAjaxData definition ************************************************************************************/ var THttpAjaxData = TClass.extend({}, { /** * Constructor */ initialize: function() { this.clear(); }, /** * Add parameter */ addParameter: function(key, value) { this.parameters[key] = value; }, /** * Add parameter */ addParam: function(key, value) { this.parameters[key] = value; }, /** * Get parameter */ getParameter: function(key, defaultValue) { var temp = this.parameters[key]; if (!temp && defaultValue) temp = defaultValue; return temp; }, /** * Get parameter */ getParam: function(key, defaultValue) { return this.getParameter(key, defaultValue); }, /** * Get parameter */ get: function(key, defaultValue) { return this.getParameter(key, defaultValue); }, /** * Remove parameter */ removeParameter: function(key) { if (this.parameters[key] != null) { delete this.parameters[key]; } }, /** * Get parameters */ getParameters: function() { var temp = {}; for (i in this.parameters) { temp[i] = this.parameters[i]; } return temp; }, /** * Add script file */ addScriptFile: function(scriptFile, id) { this.scriptFiles.push(scriptFile); if (id) this.tmp[scriptFile] = id; }, /** * Add script content */ addScriptContent: function(scriptContent) { this.scriptContents.push(scriptContent); }, /** * Add css file */ addCssFile: function(cssFile, id) { this.cssFiles.push(cssFile); if (id) this.tmp[cssFile] = id; }, /** * Add script code for execution */ addExecutionScriptCode: function(scriptCode) { this.executionScriptCodes.push(scriptCode); }, /** * Execute */ execute: function() { for (i in this.cssFiles) page.addCssFile(this.cssFiles[i], this.tmp[this.cssFiles[i]]); for (i in this.scriptFiles) page.addScriptFile(this.scriptFiles[i], this.tmp[this.scriptFiles[i]]); for (i in this.scriptContents) page.addScriptContent(this.scriptContents[i]); for (i in this.executionScriptCodes) page.safeExec(this.executionScriptCodes[i]); this.clearExecutableData(); }, /** * Clear */ clearExecutableData: function() { this.scriptFiles = Array(); this.scriptContents = Array(); this.executionScriptCodes = Array(); this.cssFiles = Array(); this.tmp = {}; }, /** * Clear */ clear: function() { this.parameters = {}; this.clearExecutableData(); }, /** * Debug */ debug: function() { var str = "Object (\n"; for (i in this.parameters) str += "\t" + i + "=" + this.parameters[i] + "\n"; str += ")"; if (this.Text) str = this.Text + "\n\n" + str; print_r(str); } }); /************************************************************************************ * THttpAjax definition ************************************************************************************/ var THttpAjax = TClass.extend({}, { /** * Constructor */ initialize: function() { this.fHttpRequest = false; this.fInitialized = false; this.fCallbacks = new Object(); this.fRequestInProgress = false; this.fRequestQueue = new Array(); this.TargetUri = page.submitUri; this.TargetMethod = 'post'; this.fRequestedAjaxControls = new Array(); this.debugMode = false; this.fUidNumber = 73641; if (typeof XMLHttpRequest == "undefined") { try { this.fHttpRequest = new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) { try { this.fHttpRequest = new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) { try { this.fHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { this.fHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { } } } } } else { this.fHttpRequest = new XMLHttpRequest(); } if (this.fHttpRequest) { this.fInitialized = true; } else { alert("Ajax can't be instantiated"); } }, /** * Do http get */ doHttpGet: function(text) { this.fRequestInProgress = true; this.fHttpRequest.open("GET", this.TargetUri + "?" + text, true); var self = this; this.fHttpRequest.onreadystatechange = function() { if (self.fHttpRequest.readyState == 4 && self.fHttpRequest.status == 200) { self.processResponse(self.fHttpRequest.responseText); self.fRequestInProgress = false; self.processPendingRequests(); } } this.fHttpRequest.send(null); }, /** * Do http post */ doHttpPost: function(text) { this.fRequestInProgress = true; var url = this.TargetUri + "?" + (this.fUidNumber++); this.fHttpRequest.open("POST", url, true); this.fHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); this.fHttpRequest.setRequestHeader("Content-length", text.length); this.fHttpRequest.setRequestHeader("Connection", "Затвори"); var self = this; this.fHttpRequest.onreadystatechange = function() { if (self.fHttpRequest.readyState == 4 && self.fHttpRequest.status == 200) { self.processResponse(self.fHttpRequest.responseText); self.fRequestInProgress = false; self.processPendingRequests(); } } this.fHttpRequest.send(text); }, /** * Free */ free: function() { this.fHttpRequest = null; }, /** * Make request */ request: function(data, aHandler, method) { if (!data) { data = new Object(); } data["_submit_type"] = "ajax"; if (data["_submit_handler"] == null) { data["_submit_handler"] = "OnAjaxRequest"; } var statefulProps = page.model.getStatefulPropertyList(); for (var propertyKey in statefulProps) { var propertyValue = statefulProps[propertyKey]; if (propertyValue && (typeof propertyValue == "string" || typeof propertyValue == "number")) { data["___model_" + propertyKey] = propertyValue; } } if (aHandler) { var trackID = page.createUID(); data["_data_trackID"] = trackID; this.fCallbacks[trackID] = aHandler; } if (method && method.toLowerCase() == 'get') { this.TargetMethod = 'get'; } this.fRequestQueue.push(httpBuildQuery(data, {'target':'ajax'})); this.processPendingRequests(); this.TargetMethod = 'post'; }, /** * Make url request */ makeURLRequest: function(url, data, aHandler, method) { var tmp = this.TargetUri; this.TargetUri = url; this.request(data, aHandler, method); this.TargetUri = tmp; }, /** * Call server method */ call: function(actionName, data, aHandler, method) { if (!data) data = new Object(); data["_submit_handler"] = actionName; this.request(data, aHandler, method); }, /** * Post back */ postback: function(actionName, actionParams) { page.submitAction("ajax", "hsdgfhsfgE2Sdfd1", actionName, actionParams); }, /** * Process pending requests */ processPendingRequests: function() { if (!this.fRequestInProgress) { if (this.fRequestQueue.length > 0) { if (this.TargetMethod == 'post') { this.doHttpPost(this.fRequestQueue.shift()); } else { this.doHttpGet(this.fRequestQueue.shift()); } } } }, /** * Process response */ processResponse: function(text) { if (page.devMode) { if (text != null && text.length > 0 && text.charAt(0) != "{") { print_r(text); } } if (this.debugMode) { print_r(text); } var result = new THttpAjaxData(); var temp = json_decode(text); var trackID; for (var key in temp) { if (key.indexOf("setcookie:;:") == 0) { var rawstr = key; rawstr = rawstr.replace("setcookie:;:", ""); var name = rawstr.substr(0,rawstr.indexOf(":;:")); var expires = rawstr.substr(rawstr.indexOf(":;:")+3); if (expires == -1 && temp[key] == "removeme") { page.removeCookie(name); } else { page.setCookie(name,temp[key],expires); } } else if (key.indexOf("___model_property:;:") == 0) { var tmp = key.replace("___model_property:;:", ""); if (tmp.indexOf("true:") == 0) { var propertyName = tmp.replace("true:", ""); page.model.setProperty(propertyName, temp[key], true); } else if (tmp.indexOf("false:") == 0) { var propertyName = tmp.replace("false:", ""); page.model.setProperty(propertyName, temp[key], false); } } else if (key.indexOf("___set_element_value:;:") == 0) { var id = key.replace("___set_element_value:;:", ""); setElementValue(id, temp[key]); } else if (key.indexOf("___addscript:;:") == 0) { var rawstr = key; rawstr = rawstr.replace("___addscript:;:", ""); var tmp = rawstr.split(':;:'); var id = (tmp.length == 2 && tmp[1] ? tmp[1] : null); result.addScriptFile(temp[key], id); } else if (key.indexOf("___addscript_c") == 0) { result.addScriptContent(temp[key]); } else if (key.indexOf("___addcss:;:") == 0) { var rawstr = key; rawstr = rawstr.replace("___addcss:;:", ""); var tmp = rawstr.split(':;:'); var id = (tmp.length == 2 && tmp[1] ? tmp[1] : null); result.addCssFile(temp[key], id); } else if (key.indexOf("___safe_exec") == 0) { result.addExecutionScriptCode(temp[key]); } else if (key.indexOf("_data_trackID") == 0) { trackID = temp[key]; } else { result.addParameter(key, temp[key]); } } result.execute(); if (trackID && this.fCallbacks[trackID]) { this.fCallbacks[trackID].call(this, result); delete this.fCallbacks[trackID]; } }, /** * Request ajax control */ requestControl: function(target, instName, widget, phpClass, args) { var req = {}; req["rc_target"] = target; req["rc_name"] = instName; req["rc_widget"] = widget; req["rc_phpclass"] = phpClass; req["rc_args"] = args ? args : {}; this.fRequestedAjaxControls.push(req); }, /** * Bind requested ajax controls */ bindRequestedControls: function() { if (this.fRequestedAjaxControls.length == 0) { return; } var tmpList = new Array(); for (var i=0; i