Util.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** IBM Cognos Products: mdsrv
  5. **
  6. ** (C) Copyright IBM Corp. 2008, 2015
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *****************************************************************/
  10. //***********************************************************************************************
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. //
  14. // Component: Utility - helper objects and functions
  15. //***********************************************************************************************
  16. if ( ! UTIL )
  17. var UTIL = {};
  18. UTIL.bDebugMode = false;
  19. // The Key codes being passed down in the onkeydown event
  20. UTIL.KEYCODE_TAB = 9;
  21. UTIL.KEYCODE_ENTER = 13;
  22. UTIL.KEYCODE_ARROW_LEFT = 37;
  23. UTIL.KEYCODE_ARROW_RIGHT = 39;
  24. UTIL.KEYCODE_ARROW_UP = 38;
  25. UTIL.KEYCODE_ARROW_DOWN = 40;
  26. //========================================================================
  27. // Augment Javascript basic types
  28. //------------------------------------------------------------------------
  29. //------------------------------------------------------------------------
  30. // Inheritance support
  31. //------------------------------------------------------------------------
  32. Function.prototype.method = function ( name, func )
  33. {
  34. if ( ! this.prototype[name] )
  35. {
  36. this.prototype[name] = func;
  37. }
  38. return this;
  39. };
  40. Function.method( 'inherits', function ( Parent )
  41. {
  42. this.prototype = new Parent();
  43. return this;
  44. });
  45. //------------------------------------------------------------------------
  46. // String support
  47. //------------------------------------------------------------------------
  48. String.method( 'trim', function() {
  49. return this.replace(/^\s+|\s+$/g, '');
  50. });
  51. //========================================================================
  52. //------------------------------------------------------------------------
  53. function GetScreenResolution()
  54. {
  55. var size = new CSize();
  56. var size = { width: screen.width , height: screen.height };
  57. return size;
  58. }
  59. function getPropertyName( object, propValue )
  60. {
  61. var propName = "";
  62. for ( var i in object )
  63. {
  64. if ( object[ i ] === propValue )
  65. {
  66. propName = i;
  67. break;
  68. }
  69. }
  70. return propName;
  71. }
  72. //----------------------------------------------------------
  73. // addMethod - Method Overloading
  74. // Examples:
  75. /*----------------------------------------------------------
  76. function Users()
  77. {
  78. addMethod(this, "find", function(name)
  79. {
  80. // Find a user by name
  81. });
  82. addMethod(this, "find", function(first, last)
  83. {
  84. // Find a user by first and last name
  85. });
  86. }
  87. Or, if you wanted to use it with an object prototype:
  88. function Users(){}
  89. addMethod(Users.prototype, "find", function(name)
  90. {
  91. // Find a user by name
  92. });
  93. addMethod(Users.prototype, "find", function(first, last)
  94. {
  95. // Find a user by first and last name
  96. });
  97. -----------------------------------------------------------*/
  98. function addMethod(object, name, fn)
  99. {
  100. var old = object[ name ];
  101. object[ name ] = function()
  102. {
  103. if ( fn.length === arguments.length )
  104. return fn.apply( this, arguments );
  105. else if ( typeof old === 'function' )
  106. return old.apply( this, arguments );
  107. };
  108. }
  109. //------------------------------------------------------------------------
  110. function CElementStyleHelper ( elem )
  111. {
  112. this.setElem ( elem );
  113. return this;
  114. }
  115. CElementStyleHelper.prototype.getElem = function ()
  116. {
  117. return this.m_elem;
  118. }
  119. CElementStyleHelper.prototype.setElem = function ( elem )
  120. {
  121. ASSERT ( elem, "CElementStyleHelper: elem is NOT valid !!!" );
  122. if ( typeof elem === "string" )
  123. {
  124. this.m_elemId = elem;
  125. this.m_elem = document.getElementById( this.m_elemId );
  126. }
  127. else
  128. {
  129. this.m_elemId = elem.id;
  130. this.m_elem = elem;
  131. }
  132. ASSERT ( this.m_elem, "CElementStyleHelper: element " + this.m_elemId + " is NOT found !!!" );
  133. return this;
  134. }
  135. CElementStyleHelper.prototype.show = function ( bShow )
  136. {
  137. // One way - via the visibility property (does NOT seem to affect children's state !!!)
  138. // this.m_elem.style.visibility = bShow ? "visible" : "hidden";
  139. // Alternative way - via display property
  140. this.m_elem.style.display = bShow ? "block" : "none";
  141. }
  142. CElementStyleHelper.prototype.isShown = function ()
  143. {
  144. var bHidden = typeof this.m_elem.style.display !== "undefined" && this.m_elem.style.display === "none";
  145. return ! bHidden;
  146. }
  147. CElementStyleHelper.prototype.setZIndex = function ( zOrder )
  148. {
  149. this.m_elem.style.zIndex = zOrder;
  150. }
  151. CElementStyleHelper.prototype.setTextDecoration = function ( sDecoration )
  152. {
  153. this.m_elem.style.textDecoration = sDecoration;
  154. }
  155. CElementStyleHelper.prototype.setText = function ( sText )
  156. {
  157. this.m_elem.innerHTML = sText;
  158. }
  159. CElementStyleHelper.prototype.setTextBold = function ()
  160. {
  161. var sText = this.m_elem.innerHTML;
  162. this.m_elem.innerHTML = "<b>" + sText + "</b>";
  163. }
  164. CElementStyleHelper.prototype.setFontWeight = function ( sFontWeight )
  165. {
  166. this.m_elem.style.fontWeight = sFontWeight;
  167. }
  168. CElementStyleHelper.prototype.setFontStyle = function ( sFontStyle )
  169. {
  170. this.m_elem.style.fontStyle = sFontStyle;
  171. }
  172. CElementStyleHelper.prototype.setFontSize = function ( sFontSize )
  173. {
  174. this.m_elem.style.fontSize = sFontSize;
  175. }
  176. CElementStyleHelper.prototype.setColors = function ( color, bkColor )
  177. {
  178. if ( color )
  179. this.m_elem.style.color = color;
  180. if ( bkColor )
  181. this.m_elem.style.backgroundColor = bkColor;
  182. }
  183. CElementStyleHelper.prototype.getCursor = function ()
  184. {
  185. return this.m_elem.style.cursor;
  186. }
  187. CElementStyleHelper.prototype.setCursor = function ( sCursor )
  188. {
  189. this.m_elem.style.cursor = sCursor;
  190. }
  191. CElementStyleHelper.prototype.setOpacity = function ( elemOpacity )
  192. {
  193. this.m_elem.style.opacity = elemOpacity;
  194. // if ( this.m_elem.style.filter )
  195. // this.m_elem.style.filter = 'alpha(opacity=' elemOpacity + ')';
  196. }
  197. CElementStyleHelper.prototype.move = function ( left, top )
  198. {
  199. if ( left !== -1 )
  200. this.m_elem.style.left = left;
  201. if ( top !== -1 )
  202. this.m_elem.style.top = top;
  203. }
  204. CElementStyleHelper.prototype.moveToPos = function ( pos )
  205. {
  206. this.m_elem.style.left = pos.x;
  207. this.m_elem.style.top = pos.y;
  208. }
  209. CElementStyleHelper.prototype.resize = function ( width, height )
  210. {
  211. if ( width !== -1 )
  212. this.m_elem.style.width = width;
  213. if ( height !== -1 )
  214. this.m_elem.style.height = height;
  215. }
  216. CElementStyleHelper.prototype.setBorderStyle= function ( sStyle )
  217. {
  218. this.m_elem.style.borderStyle = sStyle;
  219. }
  220. CElementStyleHelper.prototype.addEvent = function ( evType, callback, useCapture )
  221. {
  222. addEvent ( this.m_elem, evType, callback, useCapture );
  223. }
  224. CElementStyleHelper.prototype.removeEvent = function ( evType, callback, useCapture )
  225. {
  226. removeEvent ( this.m_elem, evType, callback, useCapture );
  227. }
  228. CElementStyleHelper.prototype.setClass = function ( sNewClass )
  229. {
  230. this.m_elem.className = sNewClass;
  231. }
  232. CElementStyleHelper.prototype.addClass = function ( sNewClass )
  233. {
  234. if ( ! this.m_elem.className )
  235. {
  236. this.m_elem.className = sNewClass;
  237. }
  238. else
  239. {
  240. newClassName = this.m_elem.className;
  241. newClassName += " ";
  242. newClassName += sNewClass;
  243. this.m_elem.className = newClassName;
  244. }
  245. }
  246. CElementStyleHelper.prototype.getClientSize = function ()
  247. {
  248. var sizeClient = new CSize();
  249. var sizeScreen = { width: this.m_elem.clientWidth , height: this.m_elem.clientHeight };
  250. sizeClient.SetSize ( this.m_elem.clientWidth, this.m_elem.clientHeight );
  251. return sizeClient;
  252. }
  253. CElementStyleHelper.prototype.getScreenSize = function ()
  254. {
  255. var sizeScreen = this.getClientSize();
  256. sizeScreen.x = this.m_elem.offsetLeft;
  257. sizeScreen.y = this.m_elem.offsetTop;
  258. return sizeScreen;
  259. }
  260. CElementStyleHelper.prototype.getAbsPos = function ()
  261. {
  262. var left = 0;
  263. var top = 0;
  264. var obj = this.m_elem;
  265. if ( obj.offsetParent )
  266. {
  267. left = obj.offsetLeft;
  268. top = obj.offsetTop;
  269. while ( obj = obj.offsetParent )
  270. {
  271. left += obj.offsetLeft;
  272. top += obj.offsetTop;
  273. }
  274. }
  275. var pos = new CPosition ( left, top );
  276. return pos;
  277. }
  278. //======================================================================
  279. function ASSERT( condition, sErrorMessage )
  280. {
  281. if ( UTIL.bDebugMode )
  282. {
  283. if ( typeof condition === "undefined" || ! condition )
  284. alert( sErrorMessage );
  285. }
  286. }
  287. function alertTimeDiff ( timeStart, sFunctionName )
  288. {
  289. var timeCurr = new Date().getTime();
  290. var timediff = ( timeCurr - timeStart ) + " ms";
  291. alert ( sFunctionName + " : " + timediff );
  292. }
  293. //--------------------------------------------------------------------------------
  294. // EVENT functionality
  295. //--------------------------------------------------------------------------------
  296. function addEvent( elem, evType, callback, useCapture )
  297. {
  298. ASSERT( elem, 'addEvent: element is NOT valid !!!!' )
  299. // cross-browser event handling for IE5+ NS6+, Mozilla
  300. if ( elem )
  301. {
  302. if ( elem.addEventListener )
  303. {
  304. elem.addEventListener( evType, callback, useCapture );
  305. return true;
  306. }
  307. else
  308. if ( elem.attachEvent )
  309. {
  310. var r = elem.attachEvent( 'on' + evType, callback );
  311. return r;
  312. }
  313. else
  314. {
  315. elem[ 'on' + evType ] = callback;
  316. }
  317. }
  318. }
  319. function removeEvent ( elem, evType, callback, useCapture )
  320. {
  321. ASSERT( elem, 'removeEvent: element is NOT valid !!!!' )
  322. // cross-browser event handling for IE5+ NS6+, Mozilla
  323. if ( elem )
  324. {
  325. if ( elem.removeEventListener )
  326. {
  327. elem.removeEventListener( evType, callback, useCapture );
  328. }
  329. else
  330. if ( elem.detachEvent )
  331. {
  332. elem.detachEvent( "on" + evType, callback );
  333. }
  334. else
  335. {
  336. elem[ 'on' + evType ] = null;
  337. }
  338. }
  339. }
  340. function cancelEvent( ev )
  341. {
  342. if ( ev.preventDefault )
  343. ev.preventDefault();
  344. else
  345. if ( ev.returnValue )
  346. ev.returnValue = false;
  347. }
  348. function stopEvent( ev )
  349. {
  350. if ( ev.stopPropagation )
  351. ev.stopPropagation();
  352. else
  353. if ( ev.cancelBubble )
  354. ev.cancelBubble = true;
  355. }
  356. function getMousePosition ( evt )
  357. {
  358. // This is the correct script for detecting the mouse coordinates:
  359. var pos = new CPosition();
  360. var posx = 0;
  361. var posy = 0;
  362. if ( ! evt ) var evt = window.event;
  363. if ( evt.pageX || evt.pageY )
  364. {
  365. posx = evt.pageX;
  366. posy = evt.pageY;
  367. }
  368. else
  369. if ( evt.clientX || evt.clientY )
  370. {
  371. if (document.documentElement.clientHeight == 0) {
  372. posx = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
  373. posy = evt.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  374. }
  375. else {
  376. posx = evt.clientX + document.documentElement.scrollLeft + document.documentElement.scrollLeft;
  377. posy = evt.clientY + document.documentElement.scrollTop + document.documentElement.scrollTop;
  378. }
  379. }
  380. // posx and posy now contain the mouse position relative to the document
  381. pos.Set ( posx, posy );
  382. return pos;
  383. }
  384. function CKeyboardEvent ( evt )
  385. {
  386. if ( evt )
  387. this.evt = evt;
  388. else
  389. this.evt = window.event;
  390. if ( this.evt.which )
  391. this.key = this.evt.which; // Netscape/Firefox/Opera
  392. else
  393. this.key = this.evt.keyCode; // IE
  394. }
  395. function CMouseEvent ( evt )
  396. {
  397. if ( evt )
  398. this.evt = evt;
  399. else
  400. this.evt = window.event;
  401. if ( this.evt.pageX )
  402. this.x = this.evt.pageX;
  403. else
  404. this.x = this.evt.clientX;
  405. if ( this.evt.pageY )
  406. this.y = this.evt.pageY;
  407. else
  408. this.y = this.evt.clientY;
  409. if ( this.evt.target )
  410. this.target = this.evt.target;
  411. else
  412. this.target = this.evt.srcElement;
  413. }
  414. CMouseEvent.prototype.ClientToScreen = function (pos) {
  415. var posNew = pos;
  416. if (this.evt.pageX || this.evt.pageY) {
  417. posNew.x = this.evt.pageX;
  418. posNew.y = this.evt.pageY;
  419. }
  420. else
  421. if (this.evt.clientX || this.evt.clientY) {
  422. if (document.documentElement.clientHeight == 0) {
  423. posNew.x += document.body.scrollLeft + this.target.scrollLeft;
  424. posNew.y += document.body.scrollTop + this.target.scrollTop;
  425. }
  426. else {
  427. posNew.x += document.documentElement.scrollLeft + this.target.scrollLeft;
  428. posNew.y += document.documentElement.scrollTop + this.target.scrollTop;
  429. }
  430. }
  431. return posNew;
  432. }
  433. function addListener( elem, type, callback )
  434. {
  435. if ( elem.addEventListener )
  436. {
  437. elem.addEventListener( type, callback, false );
  438. }
  439. else
  440. if ( elem.attachEvent )
  441. {
  442. elem.attachEvent( "on"+type, callback, false );
  443. }
  444. }
  445. function removeListener ( elem, type, callback )
  446. {
  447. if ( elem.removeEventListener )
  448. {
  449. elem.removeEventListener( type, callback, false );
  450. }
  451. else
  452. if ( elem.detachEvent )
  453. {
  454. elem.detachEvent( "on" + type, callback, false );
  455. }
  456. }
  457. //---------------------------------------------------------------------
  458. // DEBUG API
  459. //---------------------------------------------------------------------
  460. function getLikeElements ( tagName, attrName, attrValue )
  461. {
  462. var startSet;
  463. var endSet = new Array( );
  464. if ( tagName )
  465. {
  466. startSet = document.getElementsByTagName(tagName);
  467. }
  468. else
  469. {
  470. startSet = (document.all) ? document.all : document.getElementsByTagName("*");
  471. }
  472. if ( attrName )
  473. {
  474. for ( var i = 0; i < startSet.length; i++ )
  475. {
  476. if ( startSet[i].getAttribute(attrName) )
  477. {
  478. if ( attrValue )
  479. {
  480. if ( startSet[i].getAttribute(attrName) === attrValue )
  481. {
  482. endSet[endSet.length] = startSet[i];
  483. }
  484. }
  485. else
  486. {
  487. endSet[endSet.length] = startSet[i];
  488. }
  489. }
  490. }
  491. }
  492. else
  493. {
  494. endSet = startSet;
  495. }
  496. return endSet;
  497. }
  498. function walkChildNodes ( objRef, bAllNodes, n )
  499. {
  500. var obj;
  501. if ( objRef )
  502. {
  503. if ( typeof objRef === "string" )
  504. {
  505. obj = document.getElementById( objRef );
  506. }
  507. else
  508. {
  509. obj = objRef;
  510. }
  511. }
  512. else
  513. {
  514. if (document.documentElement.clientHeight == 0)
  515. obj = (document.body.parentElement) ? document.body.parentElement : document.body.parentNode;
  516. else
  517. obj = (document.documentElement.parentElement) ? document.documentElement.parentElement : document.documentElement.parentNode;
  518. }
  519. var output = "";
  520. var indent = "";
  521. var i, group, txt;
  522. if ( n )
  523. {
  524. for (i = 0; i < n; i++)
  525. {
  526. indent += "+---";
  527. }
  528. }
  529. else
  530. {
  531. n = 0;
  532. output += "Child Nodes of <" + obj.tagName.toLowerCase( );
  533. output += ">\n= == == == == == == == == == ==\n";
  534. }
  535. group = obj.childNodes;
  536. for ( i = 0; i < group.length; i++ )
  537. {
  538. var elem = group[i];
  539. output += indent;
  540. switch ( elem.nodeType )
  541. {
  542. case 1:
  543. if ( bAllNodes || ( elem.id || elem.name ) )
  544. {
  545. output += "<" + elem.tagName.toLowerCase( );
  546. output += (elem.id) ? " ID=" + elem.id : "";
  547. output += (elem.name) ? " NAME=" + elem.name : "";
  548. output += ">\n";
  549. }
  550. break;
  551. case 3:
  552. txt = elem.nodeValue.substr( 0, 25 );
  553. output += "[ \"" + txt.replace(/[\r\n]/g,"<cr>");
  554. if ( elem.nodeValue.length > 25 )
  555. {
  556. output += "...";
  557. }
  558. output += "\" ]\n";
  559. break;
  560. case 8:
  561. output += "[!COMMENT!]\n";
  562. break;
  563. default:
  564. output += "[Node Type = " + elem.nodeType + "]\n";
  565. }
  566. if ( elem.childNodes.length > 0 )
  567. {
  568. output += walkChildNodes ( elem, bAllNodes, n+1 );
  569. }
  570. }
  571. return output;
  572. }
  573. //---------------------------------------------------------------------
  574. // TABLE API <W3C DOM>
  575. //---------------------------------------------------------------------
  576. /*
  577. function clearTBody()
  578. {
  579. var tbodies = this.getElementsByTagName( "tbody" );
  580. for ( var i = 0; i < tbodies.length; i++ )
  581. {
  582. while ( tbodies[ i ].rows.length > 0
  583. tbodies[ i ].deleteRow( 0 );
  584. }
  585. }
  586. HTMLTableElement.prototype.clear = clearTBody;
  587. */
  588. /* escape/encode/decodeHtml() functions are used to deal with the ', ", <, >, and & characters
  589. when dynamic HTML re-writing of form input values. These functions are client-side equivalent
  590. of the Java htmlEncode() method.
  591. Note: The & must be translated first to avoid translating it for other characters */
  592. function escapeHTML ( sInputString )
  593. {
  594. var sOutputString = "" + sInputString;
  595. if ((sOutputString === '0') || ((sInputString !== null) && (sInputString !== false)))
  596. {
  597. sOutputString = sOutputString.replace(/&/g, "&amp;");
  598. sOutputString = sOutputString.replace(/</g, "&lt;");
  599. sOutputString = sOutputString.replace(/>/g, "&gt;");
  600. sOutputString = sOutputString.replace(/"/g, "&quot;");
  601. sOutputString = sOutputString.replace(/'/g, "&#39;"); // the numeric value for "&apos;"
  602. }
  603. else if (sInputString === null)
  604. {
  605. //return empty string if the value is null or false
  606. sOutputString = "";
  607. }
  608. return sOutputString;
  609. };
  610. function getFormattedPropertyValue ( sValue )
  611. {
  612. var sStr1 = sValue.replace( /\n/g , "" );
  613. var sStr2 = sStr1.replace( /&apos;/g , "'" );
  614. var sStr3 = sStr2.replace( /&quot;/g , "\"" );
  615. var sFormattedValue = sStr3;
  616. var strArray = sFormattedValue.split( " " );
  617. if ( strArray.length > 1 )
  618. {
  619. sFormattedValue = "";
  620. for ( var j = 0; j < strArray.length; j++ )
  621. {
  622. if ( strArray[ j ] )
  623. {
  624. sFormattedValue += strArray[ j ] + " ";
  625. }
  626. }
  627. }
  628. return sFormattedValue;
  629. }
  630. function CPropertyTable ( idTable )
  631. {
  632. this.id = idTable;
  633. }
  634. CPropertyTable.prototype.Clear = function ()
  635. {
  636. var table = document.getElementById( this.id );
  637. var tbodies = table.getElementsByTagName( 'tbody' );
  638. ASSERT ( tbodies.length === 1, "AppendRow: <TBODY> element is missing in table " + this.id );
  639. var tbody = tbodies[0];
  640. if ( tbody )
  641. {
  642. var rows = tbody.getElementsByTagName( 'tr' );
  643. var numRows = rows.length;
  644. for ( var i = numRows - 1; i >= 0; i-- )
  645. {
  646. tbody.removeChild( rows[i] );
  647. }
  648. }
  649. }
  650. CPropertyTable.prototype.AppendList = function ( propertyList )
  651. {
  652. for ( var i in propertyList )
  653. {
  654. var propPair = new PropertyPair( propertyList[i][0], propertyList[i][1] );
  655. this.AppendRow( propPair );
  656. }
  657. }
  658. CPropertyTable.prototype.findPropertyValue = function ( obj, sPropName )
  659. {
  660. var sPropValue = "Unknown";
  661. var cProperties = this.getPropertyCount();
  662. for ( var i = 0; i < cProperties; i++ )
  663. {
  664. if ( obj.getPropertyName(i) === sPropName )
  665. {
  666. sPropValue = obj.getPropertyValue(i);
  667. break;
  668. }
  669. }
  670. return sPropValue;
  671. }
  672. CPropertyTable.prototype.AppendObjPropList = function ( obj )
  673. {
  674. for ( var i = 0; i < obj.getPropertyCount(); i++ )
  675. {
  676. // alert ( obj.getPropertyDisplayName(i) + ' = ' + obj.getPropertyValue(i) );
  677. var sFormattedValue = getFormattedPropertyValue ( obj.getPropertyValue(i) );
  678. var propPair = new PropertyPair( obj.getPropertyDisplayName(i), sFormattedValue );
  679. this.AppendRow( propPair );
  680. }
  681. }
  682. CPropertyTable.prototype.AppendRow = function ( propertyPair )
  683. {
  684. // Creating a new table row based on a PropertyPair
  685. var table = document.getElementById( this.id );
  686. var tbodies = table.getElementsByTagName( 'tbody' );
  687. ASSERT ( tbodies.length === 1, "AppendRow: <TBODY> element is missing in table " + this.id );
  688. var tbody = tbodies[0];
  689. // Re-use API oTR = object.insertRow( [iIndex])
  690. // Example: myNewRow = document.all.myTable.insertRow()
  691. var row = document.createElement( 'tr' );
  692. var col1 = document.createElement( 'td' );
  693. var attr11 = document.createAttribute( "width" );
  694. attr11.value = '20%';
  695. col1.setAttributeNode( attr11 );
  696. var attr12 = document.createAttribute( "class" );
  697. attr12.value = 'Col1';
  698. col1.setAttributeNode( attr12 );
  699. var col2 = document.createElement( 'td' );
  700. var attr21 = document.createAttribute( "width" );
  701. attr21.value = '80%';
  702. col2.setAttributeNode( attr21 );
  703. var attr22 = document.createAttribute( "class" );
  704. attr22.value = 'Col2';
  705. col2.setAttributeNode( attr22 );
  706. // adding text to nodes
  707. var text1 = document.createTextNode( propertyPair.name );
  708. col1.appendChild ( text1 );
  709. var text2 = document.createTextNode( propertyPair.value );
  710. col2.appendChild ( text2 );
  711. row.appendChild( col1 );
  712. row.appendChild( col2 );
  713. tbody.appendChild( row );
  714. }
  715. //---------------------------------------------------------------------
  716. // Creation helpers of various elements
  717. //---------------------------------------------------------------------
  718. function CreateLink ( elemId, parentId, className, text, left, top, fnOnClick )
  719. {
  720. var elemLink = document.createElement ( 'a' );
  721. var elemParent = document.getElementById( parentId );
  722. if ( ! elemLink || ! elemParent )
  723. {
  724. ASSERT( elemParent, 'CreateLink: elemParent is NOT valid !' );
  725. ASSERT( elemLink, 'CreateLink: elemLink is NOT valid !' );
  726. return null;
  727. }
  728. var elemText = document.createTextNode( text );
  729. elemLink.appendChild ( elemText );
  730. // elemLink.innerHTML = text;
  731. elemLink.id = elemId;
  732. elemLink.href = '#';
  733. if ( className )
  734. elemLink.className = className;
  735. elemLink.style.left = left + 'px';
  736. elemLink.style.top = top + 'px';
  737. addEvent( elemLink, 'click', fnOnClick, false );
  738. elemParent.appendChild ( elemLink );
  739. //----------------------------------------------------
  740. // Test the new element
  741. var AttrId = elemLink.getAttribute( "id" );
  742. var AttrClass = elemLink.getAttribute( "className" ) || "Unknown Class";
  743. // alert ( "CreateLink: " + AttrId + ", " + AttrClass );
  744. return elemLink;
  745. }
  746. function CreateDiv ( elemId, parentId, className, left, top, width, height )
  747. {
  748. var elemDiv = document.createElement ( 'div' );
  749. var elemParent = document.getElementById( parentId );
  750. if ( ! elemDiv || ! elemParent )
  751. {
  752. ASSERT( elemParent, 'CreateDiv: elemParent is NOT valid !' );
  753. ASSERT( elemDiv, 'CreateDiv: elemDiv is NOT valid !' );
  754. return null;
  755. }
  756. elemDiv.setAttribute( "id", elemId );
  757. elemDiv.id = elemId; // a hack for IE6 as it's setAttribute works incorrectly
  758. if ( className )
  759. elemDiv.className = className;
  760. elemDiv.style.left = left + 'px';
  761. elemDiv.style.top = top + 'px';
  762. if ( width )
  763. elemDiv.style.width = width + 'px';
  764. if ( height )
  765. elemDiv.style.height = height + 'px';
  766. elemParent.appendChild ( elemDiv );
  767. // Test the new element
  768. var AttrId = elemDiv.getAttribute( "id" );
  769. var AttrClass = elemDiv.getAttribute( "className" );
  770. var AttrWidth = elemDiv.getAttribute( "offsetWidth" );
  771. var AttrHeight = elemDiv.getAttribute( "offsetHeight" );
  772. // alert ( "CreateDIV: " + AttrId + ", " + AttrClass + ", width=" + AttrWidth + ", height=" + AttrHeight);
  773. return elemDiv;
  774. }
  775. function CreateText ( elemId, parentId, className, text, left, top, width, height )
  776. {
  777. var elemDiv = CreateDiv ( elemId, parentId, className, left, top, width, height );
  778. if ( ! elemDiv )
  779. {
  780. ASSERT( elemDiv, 'CreateText: elemDiv is NOT valid !' );
  781. return null;
  782. }
  783. elemDiv.innerHTML = text;
  784. return elemDiv;
  785. }
  786. function CreateImage ( elemId, parentId, sImageName, left, top, width, height )
  787. {
  788. var elemDiv = CreateDiv ( elemId, parentId, 'classImageHolder', left, top, width, height );
  789. var elemImage = document.createElement ( 'img' );
  790. if ( ! elemImage || ! elemDiv )
  791. {
  792. ASSERT( elemDiv, 'CreateImage: elemDiv is NOT valid !' );
  793. ASSERT( elemImage, 'CreateImage: elemImage is NOT valid !' );
  794. return null;
  795. }
  796. /*
  797. var attr1 = document.createAttribute( "id" );
  798. attr1.value = elemId;
  799. elemImage.setAttributeNode( attr1 );
  800. */
  801. var attr2 = document.createAttribute( "src" );
  802. attr2.value = sImageName;
  803. elemImage.setAttributeNode( attr2 );
  804. var attr3 = document.createAttribute( "width" );
  805. attr3.value = width;
  806. elemImage.setAttributeNode( attr3 );
  807. var attr4 = document.createAttribute( "height" );
  808. attr4.value = height;
  809. elemImage.setAttributeNode( attr4 );
  810. elemDiv.appendChild ( elemImage );
  811. // Test the new element
  812. var AttrId = elemImage.getAttribute( "id" );
  813. var AttrSrc = elemImage.getAttribute( "src" );
  814. var AttrWidth = elemImage.getAttribute( "offsetWidth" );
  815. var AttrHeight = elemImage.getAttribute( "offsetHeight" );
  816. // alert ( "CreateImage: " + AttrId + ", " + AttrSrc + ", " + AttrWidth + ", " + AttrHeight );
  817. return elemDiv;
  818. }
  819. //---------------------------------------------------------------------
  820. // Date / Time API
  821. //---------------------------------------------------------------------
  822. function GetReportTime()
  823. {
  824. var d, s, t;
  825. var MinMilli = 1000 * 60;
  826. var HrMilli = MinMilli * 60;
  827. var DyMilli = HrMilli * 24;
  828. d = new Date();
  829. t = d.getTime();
  830. var dash = "-";
  831. s = d.getFullYear() + dash;
  832. s += (d.getMonth() + 1) + dash;
  833. s += d.getDate() + " ";
  834. var c = ":";
  835. s += d.getHours() + c;
  836. s += d.getMinutes() + c;
  837. s += d.getSeconds();
  838. return(s);
  839. }
  840. //----------------------------------------------------------
  841. // CStringBuffer implementation
  842. //----------------------------------------------------------
  843. /* Usage:
  844. var buf = new CStringBuffer();
  845. buf.append("hello");
  846. buf.append("world");
  847. alert(buf.toString());
  848. ----------------------------------------------------------*/
  849. function CStringBuffer ( cStrings )
  850. {
  851. if ( typeof cStrings !== "undefined" && cStrings > 0 )
  852. this.buffer = new Array( cStrings );
  853. else
  854. this.buffer = new Array();
  855. }
  856. CStringBuffer.prototype.append = function append( string )
  857. {
  858. this.buffer.push( string );
  859. return this;
  860. }
  861. CStringBuffer.prototype.toString = function toString()
  862. {
  863. return this.buffer.join("");
  864. }
  865. CStringBuffer.prototype.cleanUp = function cleanUp()
  866. {
  867. return this.buffer.length = 0;
  868. }
  869. //----------------------------------------------------------
  870. // Array helpers
  871. //----------------------------------------------------------
  872. function find ( array, searchStr )
  873. {
  874. var returnArray = false;
  875. for ( var i = 0; i < array.length; i++ )
  876. {
  877. if ( array[i] === searchStr )
  878. {
  879. if ( ! returnArray )
  880. {
  881. returnArray = new Array();
  882. }
  883. returnArray.push(i);
  884. }
  885. }
  886. return returnArray;
  887. }
  888. function indexOf(array, value, startIndex)
  889. {
  890. var index = -1;
  891. for ( var i = startIndex || 0; i < array.length; i++ )
  892. {
  893. if ( array[i] === value )
  894. {
  895. index = i;
  896. break;
  897. }
  898. }
  899. return index;
  900. }
  901. Array.indexOf = indexOf;
  902. Array.find = find;
  903. //-------------------------------------------------------------------------------------
  904. // class CProgressControl
  905. //-------------------------------------------------------------------------------------
  906. // To run it you need to create:
  907. //
  908. // 1) The CSS classes .progressControl & .progressComponent
  909. // 2) the following HTML elements:
  910. /*
  911. <div id="id_progress_indicator" align=center style="position:relative; width:100%; height:100%;">
  912. <table width="100%" height=100%>
  913. <tbody>
  914. <tr><td align=center>
  915. <div id="id_progress_ctrl" class="progressControl" style="position:relative; width:105px; height:30px;">
  916. <div id="id_progress_ctrl_part1" class="progressComponent" style="position:absolute; left:5px; top:5px; width:20px; height:15px;">
  917. </div>
  918. <div id="id_progress_ctrl_part2" class="progressComponent" style="position:absolute; left:30px; top:5px; width:20px; height:15px;">
  919. </div>
  920. <div id="id_progress_ctrl_part3" class="progressComponent" style="position:absolute; left:55px; top:5px; width:20px; height:15px;">
  921. </div>
  922. <div id="id_progress_ctrl_part4" class="progressComponent" style="position:absolute; left:80px; top:5px; width:20px; height:15px;">
  923. </div>
  924. </div>
  925. </td></tr>
  926. </tbody>
  927. </table>
  928. </div>
  929. */
  930. //-------------------------------------------------------------------------------------
  931. var idProgressCtrl = null;
  932. var idProgressTimer = null;
  933. var nLastProgressPart = -1;
  934. var cProgressParts = 4;
  935. var progress_part_ids = ["id_progress_ctrl_part1", "id_progress_ctrl_part2", "id_progress_ctrl_part3", "id_progress_ctrl_part4"];
  936. var progress_part_elems = [];
  937. function busyWait( millis )
  938. {
  939. var stop = new Date().getTime() + millis;
  940. while( new Date().getTime() < stop )
  941. {
  942. // do nothing loop - just to yield control to the browser
  943. var elem = document.getElementById( idProgressCtrl );
  944. var html = elem.innerHTML;
  945. }
  946. }
  947. function runProgressBody ( )
  948. {
  949. for ( var i = 0; i < cProgressParts; i++ )
  950. {
  951. progress_part_elems[ i ].style.backgroundColor = "Lightgrey";
  952. }
  953. nLastProgressPart++;
  954. if ( nLastProgressPart > 3 )
  955. nLastProgressPart = 0;
  956. progress_part_elems[ nLastProgressPart ].style.backgroundColor = "blue";
  957. }
  958. function runProgressControl ( idProgressDiv )
  959. {
  960. idProgressCtrl = idProgressDiv;
  961. var cssHelper = new CElementStyleHelper ( idProgressCtrl );
  962. cssHelper.show ( true );
  963. for ( var i = 0; i < cProgressParts; i++ )
  964. {
  965. var elem = document.getElementById( progress_part_ids[ i ] );
  966. progress_part_elems[ i ] = elem;
  967. }
  968. // alert( progress_part_elems.length );
  969. idProgressTimer = setInterval ( "runProgressBody()", 500 );
  970. }
  971. function stopProgressControl ()
  972. {
  973. if ( idProgressTimer )
  974. {
  975. var cssHelper = new CElementStyleHelper ( idProgressCtrl );
  976. cssHelper.show ( false );
  977. clearInterval ( idProgressTimer );
  978. idProgressTimer = null;
  979. }
  980. }
  981. //-------------------------------------------------------------------------------------------------
  982. // Display helpers
  983. //-------------------------------------------------------------------------------------------------
  984. function CDisplayHelper()
  985. {}
  986. CDisplayHelper.prototype.hasAnyDigit = function ( str )
  987. {
  988. var ret = false;
  989. for (var i = str.length - 1; i >= 0; i--)
  990. {
  991. if (str.charAt(i) >= "0" && str.charAt(i) <= "9")
  992. {
  993. ret = true;
  994. break;
  995. }
  996. }
  997. if ((ret= true) && ((str.indexOf("+") > i) || (str.indexOf("-") > i)))
  998. ret = false;
  999. return ret;
  1000. }
  1001. CDisplayHelper.prototype.isNumber = function ( str )
  1002. {
  1003. var ret = false;
  1004. if ( isNaN(str) || str === null )
  1005. {
  1006. ret = false;
  1007. }
  1008. else
  1009. {
  1010. ret = true;
  1011. }
  1012. return ret;
  1013. }
  1014. CDisplayHelper.prototype.trimTrailingBlanks = function ( myStr )
  1015. {
  1016. var idx;
  1017. // ensure there really is a string to trim
  1018. if ( myStr !== null && myStr !== "undefined" )
  1019. {
  1020. while ( (myStr.length > 0) && ((idx = myStr.indexOf(" ")) === 0) )
  1021. {
  1022. myStr = myStr.substring(1);
  1023. }
  1024. while ( (myStr.length > 0) && ((idx = myStr.lastIndexOf(" ")) === (myStr.length -1)) )
  1025. {
  1026. myStr = myStr.substring(0,idx);
  1027. }
  1028. }
  1029. return myStr;
  1030. }
  1031. CDisplayHelper.prototype.printNewLine = function ()
  1032. {
  1033. return "\n";
  1034. }
  1035. CDisplayHelper.prototype.printTabs = function ( nLevel )
  1036. {
  1037. var sPrintXml = "";
  1038. for ( var i = 0; i < nLevel; i++ )
  1039. {
  1040. sPrintXml += "\t";
  1041. }
  1042. return sPrintXml;
  1043. }
  1044. CDisplayHelper.prototype.printTag = function ( sTag, nLevel, bPositionTag )
  1045. {
  1046. var sPrintXml = "";
  1047. if ( bPositionTag )
  1048. {
  1049. sPrintXml += "\n";
  1050. sPrintXml += this.printTabs( nLevel );
  1051. }
  1052. sPrintXml += sTag;
  1053. return sPrintXml;
  1054. }
  1055. CDisplayHelper.prototype.printValue = function ( sValue )
  1056. {
  1057. var sPrintXml = "";
  1058. if ( sValue.length > 0 )
  1059. {
  1060. sPrintXml += sValue;
  1061. }
  1062. return sPrintXml;
  1063. }
  1064. CDisplayHelper.prototype.printNode = function ( sXml, nLevel )
  1065. {
  1066. if ( sXml.length === 0 )
  1067. return "";
  1068. var sPrintXml = "";
  1069. var tag_name = ""
  1070. var sTagBegin = "<";
  1071. var iTagBegin = sXml.indexOf( sTagBegin );
  1072. if ( iTagBegin > -1 )
  1073. {
  1074. var iSelfTagEnd = sXml.indexOf( "/>" );
  1075. var iTagEnd = sXml.indexOf( ">" );
  1076. var iSpace = sXml.indexOf( " " );
  1077. var tag_contents = "";
  1078. if ( ( iSelfTagEnd !== -1 ) && ( iSelfTagEnd < iTagEnd ) )
  1079. {
  1080. tag_contents = sXml.slice( iTagBegin + 1, iSelfTagEnd );
  1081. var sSelfTag = "<" + tag_contents + "/>";
  1082. sPrintXml += this.printTag( sSelfTag, nLevel, true );
  1083. var iNodeEnd = iSelfTagEnd + 1;
  1084. if ( iNodeEnd < sXml.length )
  1085. {
  1086. sXml = sXml.slice( iNodeEnd + 1 );
  1087. sPrintXml += this.printNode ( sXml, nLevel );
  1088. }
  1089. return sPrintXml;
  1090. }
  1091. tag_contents = sXml.slice( iTagBegin + 1, iTagEnd );
  1092. if ( ( iSpace !== -1 ) && ( iSpace < iTagEnd ) )
  1093. {
  1094. tag_name = sXml.slice( iTagBegin + 1, iSpace );
  1095. }
  1096. else
  1097. {
  1098. tag_name = sXml.slice( iTagBegin + 1, iTagEnd );
  1099. }
  1100. // Print the opening tag
  1101. var sOpeningTag = "<" + tag_contents + ">";
  1102. sPrintXml += this.printTag( sOpeningTag, nLevel, true );
  1103. // Find the closing tag
  1104. var sClosingTag = "</" + tag_name + ">";
  1105. var iClosingTag = sXml.indexOf( sClosingTag );
  1106. if ( iClosingTag !== -1 )
  1107. {
  1108. // Continue with the node value
  1109. var sNodeValue = sXml.slice( iTagEnd + 1, iClosingTag );
  1110. var sPrintedValue = this.printNode ( sNodeValue, nLevel + 1 );
  1111. sPrintXml += sPrintedValue;
  1112. // Print the closing tag
  1113. var iTagInside = sPrintedValue.indexOf( "<" );
  1114. var bPositionTag = ( iTagInside === -1 ? false : true );
  1115. sPrintXml += this.printTag( sClosingTag, nLevel, bPositionTag );
  1116. // Print siblings if any
  1117. var iNodeEnd = iClosingTag + tag_name.length + 2;
  1118. if ( iNodeEnd < sXml.length )
  1119. {
  1120. sXml = sXml.slice( iNodeEnd + 1 );
  1121. sPrintXml += this.printNode ( sXml, nLevel );
  1122. }
  1123. }
  1124. else
  1125. {
  1126. // Error: closing tag not found - cut off the start tag and print the text as is !
  1127. var sNodeValue = sXml.slice( iTagEnd + 1 );
  1128. sPrintXml += this.printValue( sNodeValue );
  1129. }
  1130. }
  1131. else
  1132. {
  1133. sPrintXml += this.printValue( sXml );
  1134. }
  1135. return sPrintXml;
  1136. }
  1137. CDisplayHelper.prototype.prettyPrintXml = function ( sXml )
  1138. {
  1139. var sPrintXml = this.printNode ( sXml, 0 );
  1140. return sPrintXml;
  1141. }
  1142. //**********************************************************************
  1143. // Instantiate global helpers
  1144. //**********************************************************************
  1145. //----------------------------------------------------------------------
  1146. // Instantiate Element helper
  1147. //----------------------------------------------------------------------
  1148. UTIL.ElementHelper = new CElementStyleHelper ( '' );
  1149. //----------------------------------------------------------------------
  1150. // Instantiate Display helper
  1151. //----------------------------------------------------------------------
  1152. UTIL.DisplayHelper = new CDisplayHelper ();
  1153. //----------------------------------------------------------------------
  1154. //**********************************************************************
  1155. // tanko test
  1156. //**********************************************************************
  1157. function MDSRV_paneCallBack()
  1158. {
  1159. this.m_elRootPane = document.getElementById ( "id_HAL_root_pane_placeholder" );
  1160. this.m_nRootPane = G_ResManager.F_GetResource ( "id_HAL_root_pane" );
  1161. var heightOffset = document.getElementById( "id_lineage_view" ).offsetTop;
  1162. var width = 0;
  1163. var height = 0;
  1164. if (document.documentElement.clientHeight == 0)
  1165. {
  1166. width = document.body.clientWidth - 10;
  1167. height = document.body.clientHeight - ( heightOffset + 5 );
  1168. }
  1169. else
  1170. {
  1171. width = document.documentElement.clientWidth - 10;
  1172. height = document.documentElement.clientHeight - ( heightOffset + 5 );
  1173. }
  1174. this.m_oPaneManager = new C_PaneManager( this.m_elRootPane, this.m_nRootPane, this, width, height, false );
  1175. }
  1176. function MDSRV_initPaneMgr()
  1177. {
  1178. LNS.MDSRV_paneManager = new MDSRV_paneCallBack( );
  1179. LNS.MDSRV_paneManager.F_PaneManager_OnPaneResize = function( paneMgr, pane, width, heigth, resize)
  1180. {
  1181. var graphCanvasHeight = document.getElementById( "id_canvas_graph" ).offsetHeight;
  1182. var graphHeaderHeight = document.getElementById( "id_graph_header" ).offsetHeight;
  1183. document.getElementById( "id_graph" ).style.height = graphCanvasHeight - graphHeaderHeight;
  1184. }
  1185. }
  1186. window.onresize = function()
  1187. {
  1188. if ( LNS.MDSRV_paneManager )
  1189. {
  1190. var heightOffset = document.getElementById( "id_lineage_view" ).offsetTop;
  1191. var width = 0;
  1192. var height = 0;
  1193. if (document.documentElement.clientHeight == 0)
  1194. {
  1195. width = document.body.clientWidth - 10;
  1196. height = document.body.clientHeight - ( heightOffset + 5 );
  1197. }
  1198. else
  1199. {
  1200. width = document.documentElement.clientWidth - 10;
  1201. height = document.documentElement.clientHeight - ( heightOffset + 5 );
  1202. }
  1203. LNS.MDSRV_paneManager.m_oPaneManager.F_SetNewPaneSize( "id_HAL_root_pane", width, height );
  1204. }
  1205. }