agentItemsTree.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2021 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. /* ****************************************
  11. TO DO - TO DO - TO DO - TO DO - TO DO - TO DO - TO DO
  12. - getFolderChild() instead of _.ref+"_Child"
  13. **************************************** */
  14. var agentItemsTree = null;
  15. var agentParameterTree = null;
  16. function initDataItems()
  17. {
  18. if (agentItemsTree == null)
  19. {
  20. if (browserCheck.isNav6Up())
  21. {
  22. document.getElementById("agentItemsTreeContainer").addEventListener("mouseup", function(e) {if(e.target.toString().indexOf("XULElement") > -1){e.cancelBubble = true;return false;}}, true);
  23. document.getElementById("agentItemsTreeContainer").addEventListener("dragover", function(e) {cancelBub(e);}, true);
  24. document.getElementById("agentItemsTreeContainer").addEventListener("dragdrop", function(e) {cancelBub(e);}, true);
  25. }
  26. var agentItemsTreeNode = document.getElementById("agentItemsTreeContainer");
  27. // at this point - this is the only node with this id
  28. agentItemsTreeNode.setAttribute("container", "true");
  29. agentItemsTreeNode.setAttribute("tabindex", "-1");
  30. // now create and render the tree
  31. agentItemsTree = new CTree (agentItemsTreeNode, "", false, true, "agentItemsTree");
  32. agentItemsTree.setSelectionMode(CONTIGUOUS_TREE_SELECTION);
  33. agentItemsTree.setSelectTreeUI(NORMAL_TREE);
  34. agentItemsTree.setAllowDragDrop(true);
  35. agentItemsTree.setOnDragStart(onDragStartF);
  36. agentItemsTree.setOnDrag(onDragF);
  37. agentItemsTree.setOnDragEnd(onDragEndF);
  38. agentItemsTree.setContextMenu(showContextMenu);
  39. agentItemsTree.setTrackSelectionOrder(true);
  40. agentItemsTree.setDoubleClickFunc(processDoubleClick);
  41. agentItemsTree.setSingleClickFunc(singleClickedDataItemsTree);
  42. agentItemsTree.setHideOuterTable(true);
  43. agentItemsTree.setAllowSelectionToggle(true);
  44. // define the root of the tree
  45. agentItemsTree.getRootNode().setName(agentItemsRoot_string);
  46. agentItemsTree.getRootNode().setCanHaveChildren(true);
  47. agentItemsTree.setRootNodeType(tntAgentRoot);
  48. agentItemsTree.drawAll();
  49. agentItemsTree.checkData();
  50. }
  51. }
  52. function initParameterItems()
  53. {
  54. if (agentParameterTree == null)
  55. {
  56. if (browserCheck.isNav6Up())
  57. {
  58. document.getElementById("agentParameterTreeContainer").addEventListener("mouseup", function(e) {if(e.target.toString().indexOf("XULElement") > -1){e.cancelBubble = true;return false;}}, true);
  59. document.getElementById("agentParameterTreeContainer").addEventListener("dragover", function(e) {e.preventBubble();}, true);
  60. document.getElementById("agentParameterTreeContainer").addEventListener("dragdrop", function(e) {e.preventBubble();}, true);
  61. }
  62. var agentParameterTreeNode = document.getElementById("agentParameterTreeContainer");
  63. // at this point - this is the only node with this id
  64. agentParameterTreeNode.setAttribute("container", "true");
  65. agentParameterTreeNode.setAttribute("tabindex", "-1");
  66. // now create and render the tree
  67. agentParameterTree = new CTree (agentParameterTreeNode, "", false, true, "agentParameterTree");
  68. agentParameterTree.setSelectionMode(CONTIGUOUS_TREE_SELECTION);
  69. agentParameterTree.setSelectTreeUI(NORMAL_TREE);
  70. agentParameterTree.setAllowDragDrop(true);
  71. agentParameterTree.setOnDragStart(onDragStartF);
  72. agentParameterTree.setOnDrag(onDragF);
  73. agentParameterTree.setOnDragEnd(onDragEndF);
  74. agentParameterTree.setContextMenu(showContextMenu);
  75. agentParameterTree.setTrackSelectionOrder(true);
  76. agentParameterTree.setDoubleClickFunc(processDoubleClick);
  77. agentParameterTree.setSingleClickFunc(singleClickedParametersTree);
  78. agentParameterTree.setHideOuterTable(true);
  79. agentParameterTree.setAllowSelectionToggle(true);
  80. // define the root of the tree
  81. agentParameterTree.getRootNode().setName(agentItemsParameters_string);
  82. agentParameterTree.getRootNode().setCanHaveChildren(true);
  83. agentParameterTree.setRootNodeType(tntAgentRoot);
  84. agentParameterTree.drawAll();
  85. agentParameterTree.checkData();
  86. }
  87. }
  88. function processDoubleClick(){
  89. addSelectedDblClick();
  90. }
  91. function singleClickedDataItemsTree() {
  92. parent.deletionCandidateManager.setCandidate("deleteAgentItems()",K_sFunctionCandidate);
  93. }
  94. function singleClickedParametersTree(){
  95. parent.deletionCandidateManager.setCandidate("deleteParameters()",K_sFunctionCandidate);
  96. }
  97. function resetAgentItems()
  98. {
  99. resetDataItems();
  100. resetParameterItems();
  101. }
  102. function resetDataItems()
  103. {
  104. if (agentItemsTree != null) {
  105. // we have to remove the tree
  106. agentItemsTree = null;
  107. // remove the rendering of the tree
  108. removeTreeRendering("agentItemsTreeContainer");
  109. }
  110. // re-init the agent Items tree
  111. initDataItems();
  112. }
  113. function resetParameterItems()
  114. {
  115. if (agentParameterTree != null) {
  116. // we have to remove the tree
  117. agentParameterTree = null;
  118. // remove the rendering of the tree
  119. removeTreeRendering("agentParameterTreeContainer");
  120. }
  121. // re-init the agent Items tree
  122. initParameterItems();
  123. }
  124. /*
  125. * Delete selected agent parameters from the tree
  126. */
  127. function deleteParameters() {
  128. if(confirm(parameterDeleteWarning)) {
  129. deleteFromTree(getParametersTree());
  130. }
  131. }
  132. /*
  133. * Delete selected agent items from the tree
  134. */
  135. function deleteAgentItems()
  136. {
  137. if(confirm(agentItemsDeleteWarning)) {
  138. deleteFromTree(getDataItemsTree());
  139. }
  140. }
  141. function deleteDataItem(dataItemDropValue,undo) {
  142. var tree = getDataItemsTree();
  143. var deleteNode = getNodeFromTreeWithValue(dataItemDropValue,'getDropValue()',getTreeChildNodes(tree));
  144. return deleteDataItemNode(deleteNode,undo);
  145. }
  146. function deleteDataItemNode(deleteNode,undo) {
  147. var tree = getDataItemsTree();
  148. if (deleteNode) {
  149. deleteNode.detach();
  150. //redraw the parent
  151. redrawTreeNode(tree.getRootNode(),false);
  152. if(!undo){
  153. //store the ref obj in case we need to undo the delete
  154. getRedoUndoManager().getActionHistory().push(new DeleteItemEditAction(deleteNode));
  155. }
  156. parent.deletionCandidateManager.clearCandidate();
  157. }
  158. return deleteNode;
  159. }
  160. function redrawTreeNode(node,isSelected){
  161. //UnSelect all.
  162. node.getTree().deSelectAll();
  163. //This doing it the ahrd way to update the name.
  164. //redraw the whole caboudle
  165. node.getTree().drawAll();
  166. if (isSelected) {
  167. //Now we set it to selected
  168. node.setSelected(true);
  169. node.updateParent();
  170. //And need to redraw again
  171. node.getTree().redraw();
  172. }
  173. //validate the result
  174. node.getTree().checkData();
  175. }
  176. /*
  177. takes a string and searches it for agent items
  178. and returns the agent items that it found
  179. */
  180. function findTopicsInContent(content, excludeCalculations){
  181. var topic_map = new Object();
  182. var topics = new Array();
  183. var items = getTreeValues(getDataItemsTree());
  184. for(var i = 0; i < items.length; i++){
  185. if(!topic_map[items[i].getDropValue()] && content.indexOf(items[i].getDropValue()) != -1){
  186. if(!excludeCalculations){
  187. topic_map[items[i].getDropValue()];
  188. topics.push(items[i].getDropValue());
  189. }
  190. }
  191. }
  192. return topics;
  193. }
  194. /*
  195. * Create a ref obj agent item. Called when loading an agent from load_agent.xts
  196. */
  197. function generateAgentItem(name, ref, aggregate, displayType)
  198. {
  199. var obj = null;
  200. var newTreeNode = null;
  201. var displayTypeCode = null;
  202. if (displayType.match(/textItem/)) {
  203. displayTypeCode = "0";
  204. } else if (displayType.match(/image/)) {
  205. displayTypeCode = "1";
  206. } else if (displayType.match(/hyperlink/)) {
  207. displayTypeCode = "2";
  208. } else {
  209. displayTypeCode = "0";
  210. }
  211. // we have an agent item
  212. obj = new aiDataItem(name, ref, aggregate, displayType);
  213. // add this to the tree - we can call addAgentItem - which will actually make a copy
  214. // but the addAgentItem call will make sure that names are unique.
  215. addAgentItem(obj);
  216. return obj;
  217. }
  218. function updateParameter(obj, node) {
  219. var itemNode = node;
  220. if (!node || node == 'undefined') {
  221. itemNode = getNodeFromTree(obj,"name",getParametersTree());
  222. }
  223. if (itemNode) {
  224. var item = itemNode.getValue();
  225. item.name = obj.name;
  226. item.acceptRange = obj.acceptRange;
  227. itemNode.setName(obj.name);
  228. itemNode.setValue(item);
  229. } else {
  230. //Ok smarty. Item is not in the tree add it.
  231. itemNode = addParameter(obj);
  232. }
  233. //UnSelect all.
  234. //itemNode.getTree().deSelectAll();
  235. //itemNode.setSelected(true);
  236. redrawTreeNode(itemNode,true);
  237. //update the agent changed state, we have added/updated a data item
  238. cf.agentHasChanged(true);
  239. return itemNode;
  240. }
  241. function updateDataItem(obj, node) {
  242. var dataItemNode = node;
  243. if (!node || node == 'undefined') {
  244. dataItemNode = getNodeFromTree(obj,"name",getDataItemsTree());
  245. }
  246. if (dataItemNode) {
  247. var dataItem = dataItemNode.getValue();
  248. dataItem.name = obj.name;
  249. dataItem.ref = obj.ref;
  250. dataItemNode.setName(obj.name);
  251. dataItemNode.setValue(dataItem);
  252. if (obj.isIndicator()) {
  253. dataItemNode.setIndicator(obj.getIndicator());
  254. }
  255. } else {
  256. //Ok smarty. Item is not in the tree add it.
  257. dataItemNode = addAgentItem(obj);
  258. }
  259. redrawTreeNode(dataItemNode,true);
  260. //update the agent changed state, we have added/updated a data item
  261. cf.agentHasChanged(true);
  262. return dataItemNode;
  263. }
  264. /*
  265. * Generate the name for the agentItem. Algorith is to see if the name is used -
  266. * if it is - add a numeric onto the end - continue doing so until you get to a name which isn't used
  267. */
  268. function generateName(obj)
  269. {
  270. var i = 1;
  271. var currentName = obj.name;
  272. //Check if Item is there with this name.
  273. while (getNodeFromTreeWithValue(currentName,"name",getTreeChildNodes(getDataItemsTree()))) {
  274. // generate a new name
  275. currentName = obj.name + i;
  276. // up the index
  277. i++;
  278. }
  279. // return the generated name
  280. return currentName;
  281. }
  282. function createDataItemObj(name,value,aggregate) {
  283. if (!aggregate || aggregate == 'undefined') {
  284. aggregate = 'automatic';
  285. }
  286. var obj = new aiDataItem(name, value, aggregate, '0');
  287. return obj;
  288. }
  289. function createParameterObj(name,acceptRange)
  290. {
  291. // create the new object
  292. var obj = new aiParameter(name, acceptRange);
  293. return obj;
  294. }
  295. /*
  296. * Add an agent item
  297. * obj - the object that we want to add
  298. */
  299. function addAgentItem(obj, undo)
  300. {
  301. //check if item already there, and get the Node.
  302. var ret_value = getNodeFromTree(obj,"name",getDataItemsTree());
  303. //We found it. Now check if the ref is the same
  304. if (ret_value) {
  305. //We have the node so use it. This is a bit faster and straight.
  306. ret_value = getNodeFromTreeWithValue(obj.ref,"ref",new Array(ret_value));
  307. }
  308. // create the agentItem if the ref is not there
  309. if (!ret_value || ret_value == "undefined") {
  310. if (obj.usage && !obj.usage.match(/fact/i)) {
  311. //This is to work around the problem where
  312. //the usage is an 'attribute' and not a 'fact',
  313. //hence you want to set aggregate as 'none'
  314. //Because this is what ReportServer would
  315. //expect it to be for an 'attribute' type usage.
  316. //Bug
  317. obj.regularAggregate = 'none';
  318. }
  319. // may have to rename them though
  320. var itemName = generateName(obj);
  321. // get the agentItemObject
  322. var agentItemObj = new aiDataItem(itemName, obj.ref, obj.regularAggregate, obj.displayType);
  323. // get the type for the tree
  324. var agentItemTreeType = generateAgentItemTreeType(obj.regularAggregate);
  325. // build a new tree node
  326. var newTreeNode = new cf.CTreeNode(getDataItemsTree().getRootNode(), agentItemTreeType, false, itemName, agentItemObj, false);
  327. //Set the tree location of this item. A bit nasty that we have to toString the integer value.
  328. //CTree should deal with this and set the treeref to a string value always and not int in one case
  329. //and strign in another especially if it is the top level of the tree.
  330. agentItemObj.treeRef = newTreeNode.getTreeRef().toString();
  331. // check to see what sort of node we're adding - folder nodes don't want toggles.
  332. newTreeNode.setCanHaveChildren(false);
  333. // update the tree
  334. if(newTreeNode.getTree() != null)
  335. newTreeNode.getTree().redraw();
  336. // return the aiDataItem created
  337. ret_value = newTreeNode;
  338. if(!undo){
  339. if(getRedoUndoManager().isEditActionBatching()){
  340. getRedoUndoManager().getEditActionBatch().push(new AddItemEditAction(newTreeNode));
  341. }else{
  342. getRedoUndoManager().getActionHistory().push(new AddItemEditAction(newTreeNode));
  343. }
  344. //adding a new item, clears the redo cache
  345. getRedoUndoManager().getUndoneHistory().clear();
  346. }
  347. }
  348. return ret_value;
  349. }
  350. function addParameter(obj, undo)
  351. {
  352. var newTreeNode = getNodeFromTree(obj,"name",getParametersTree());
  353. //guard clause to check if we can add this item
  354. if (!newTreeNode) {
  355. // build a new tree node
  356. newTreeNode = new CTreeNode(getParametersTree().getRootNode(), tntParameter, false, obj.name, obj, false);
  357. // update the tree
  358. newTreeNode.getTree().redraw();
  359. if(!undo){
  360. getRedoUndoManager().getActionHistory().push(new AddItemEditAction(newTreeNode));
  361. //adding a new item, clears the redo cache
  362. getRedoUndoManager().getUndoneHistory().clear();
  363. }
  364. }
  365. return newTreeNode;
  366. }
  367. /**
  368. * This is used by agentItemListener.js to add items back to the tree
  369. * during undo/redo.
  370. */
  371. function addUnknownItem(obj, undo){
  372. var added;
  373. if (obj instanceof aiParameter){
  374. added = addParameter(obj, undo);
  375. }else if (obj instanceof aiDataItem){
  376. added = addAgentItem(obj, undo);
  377. }
  378. return added;
  379. }
  380. function setIndicator(name) {
  381. var node = getNodeFromTreeWithValue(name,"getDropValue()", getTreeChildNodes(getDataItemsTree()));
  382. if (node && node != 'undefined') {
  383. var obj = node.getValue();
  384. node.setIndicator(obj.getIndicator());
  385. redrawTreeNode(getDataItemsTree().getRootNode());
  386. }
  387. }
  388. function removeIndicator(name) {
  389. var node = getNodeFromTreeWithValue(name,"getDropValue()", getTreeChildNodes(getDataItemsTree()));
  390. if (node && node != 'undefined') {
  391. node.setIndicator(null);
  392. redrawTreeNode(getDataItemsTree().getRootNode());
  393. }
  394. }
  395. /**
  396. * Get the values for a particular tree.
  397. * optionally you can pass an object with a "match" function that
  398. * takes a tree node as an argument
  399. */
  400. function getTreeValues(tree, searcher) {
  401. var items = new Array();
  402. //Default to agentItems
  403. var children = getTreeChildNodes(tree);
  404. for(var i=0; i < children.length;i++) {
  405. if((searcher && searcher.match(children[i].getValue())) || !searcher){
  406. //only add the item if you dont have a searcher, or the searcher matches the item
  407. items.push(children[i].getValue());
  408. }
  409. }
  410. return items;
  411. }
  412. /**
  413. * Get the values for a particular tree.
  414. */
  415. function getTreeChildNodes(tree) {
  416. return tree.getRootNode().getChildren();
  417. }
  418. /**
  419. * For a given aiDataITem or aiPArameter get the correpsonding
  420. * Node from the tree.
  421. */
  422. function getNodeFromTree(obj,property, tree) {
  423. return getItemFromTreeWithObject(obj,property,getTreeChildNodes(tree));
  424. }
  425. /**
  426. * Get item from tree when you have an object such as aiDataItem or aiParameter.
  427. */
  428. function getItemFromTreeWithObject(obj,property, children) {
  429. return getNodeFromTreeWithValue(obj[property],property,children);
  430. }
  431. /**
  432. * Get a Node from tree with a given value like name, ref etc...
  433. */
  434. function getNodeFromTreeWithValue(value,property, children) {
  435. for(var i=0; i < children.length;i++) {
  436. var treeObj = children[i].getValue();
  437. if (treeObj && eval("treeObj" + "." + property) == value) {
  438. //We found the object in the tree so we
  439. //return it.
  440. return children[i];
  441. }
  442. }
  443. return null;
  444. }
  445. function getDataItemsTree() {
  446. return agentItemsTree;
  447. }
  448. function getParametersTree() {
  449. return agentParameterTree;
  450. }
  451. function deleteFromTree(tree) {
  452. var rootNode = tree.getRootNode();
  453. var selectedNodes = tree.getSelectedLeafNodes(rootNode);
  454. //remove the ui nodes
  455. if(selectedNodes.length > 0) {
  456. rootNode.removeChildren(selectedNodes);
  457. var delete_stack = new Array();
  458. var agentDef = parent.getAgentDefinition();
  459. for(var i = 0; i < selectedNodes.length; i++){
  460. delete_stack.push(new DeleteItemEditAction(selectedNodes[i]));
  461. // delete any extra topic from summry event keys
  462. if(agentDef!=null && agentDef.summaryEventKey!=null && agentDef.summaryEventKey.containsItem('['+selectedNodes[i].getName()+'];'))
  463. {
  464. agentDef.summaryEventKey.removeItem('['+selectedNodes[i].getName()+'];');
  465. }
  466. }
  467. getRedoUndoManager().getActionHistory().push(new EditActionBundle(delete_stack));
  468. //re write the tree... I dont know, I have to do everything round here
  469. redrawTreeNode(rootNode,false);
  470. // delete any extra topic from summry event keys
  471. if(agentDef!=null){
  472. agentDef.removeInvalidFilterTopics();
  473. }
  474. //getActionTopicFilterElementProcessor().updateList();
  475. //update the agent changed state, we have added/updated a data item
  476. cf.agentHasChanged(true);
  477. }
  478. }
  479. // get the property from the given object
  480. function getObjProp(obj, prop)
  481. {
  482. return obj[prop];
  483. }
  484. // get the name for the object - this is mutated to give a unique name
  485. function getObjPropName(obj)
  486. {
  487. return getObjProp(obj, "name");
  488. }
  489. function generateAgentItemTreeType(aggregate)
  490. {
  491. // this is an integer value - have found the following values defined in FM -
  492. // where all the other values are defined I don't know
  493. // any = 10 --> "none"
  494. // average = 5 --> "average"
  495. // averageNonZero = 11 --> "none"
  496. // automatic = 18 --> "none"
  497. // calculated = 12 --> "none"
  498. // count = 6 --> "count"
  499. // countDistinct = 13 --> "none"
  500. // countNonZero = 14 --> "none"
  501. // external = 0 --> "none"
  502. // maximum = 4 --> "maximum"
  503. // median = 17 --> "none"
  504. // minimum = 3 --> "minimum"
  505. // standardDeviation= 15 --> "none"
  506. // sum = 2 --> "total"
  507. // variance = 16 --> "none"
  508. var type = tntDataItem;
  509. switch ( aggregate ) {
  510. case "total":
  511. type = tntDataItemTotal;
  512. break;
  513. case "count":
  514. type = tntDataItemCount;
  515. break;
  516. case "average":
  517. type = tntDataItemAverage;
  518. break;
  519. case "minimum":
  520. type = tntDataItemMinimum;
  521. break;
  522. case "maximum":
  523. type = tntDataItemMaximum;
  524. break;
  525. case "countDistinct":
  526. type = tntDataItemCntDistinct;
  527. break;
  528. case "median":
  529. type = tntDataItemMedian;
  530. break;
  531. case "standardDeviation":
  532. type = tntDataItemStdDeviation;
  533. break;
  534. case "variance":
  535. type = tntDataItemVariance;
  536. break;
  537. case "calculated":
  538. type = tntDataItemCalc;
  539. break;
  540. case "automatic":
  541. type = tntDataItemAutomatic;
  542. break;
  543. case "aggregate":
  544. type = tntDataItemAggregate;
  545. break;
  546. case "none":
  547. type = tntDataItemNone;
  548. break;
  549. case "notApplicable":
  550. type = tntDataItemNotApplicable;
  551. break;
  552. default:
  553. type = tntDataItem;
  554. break;
  555. }
  556. // default case
  557. return type;
  558. }
  559. function encode(text)
  560. {
  561. // seeing as this is destined for XML - and it could hold anything - escape
  562. // any dodgy characters
  563. var amp_re = /&/g;
  564. var lt_re = /</g;
  565. var gt_re = />/g;
  566. var ap_re = /\'/g;
  567. var qu_re = /\"/g;
  568. text = text.replace(amp_re, "&amp;");
  569. text = text.replace(lt_re, "&lt;");
  570. text = text.replace(gt_re, "&gt;");
  571. text = text.replace(ap_re, "&apos;");
  572. text = text.replace(qu_re, "&quot;");
  573. return text;
  574. }
  575. function stripSpaces(text)
  576. {
  577. return text.replace(/^\s+/,'').replace(/\s+$/,'');
  578. }
  579. function buildFilterExpressions(detailFilterValue,summaryFilterValue)
  580. {
  581. var detailFilter = generateFilter(new Array(detailFilterValue), "detail");
  582. var summaryFilter = generateFilter(new Array(summaryFilterValue), "summary");
  583. return detailFilter + summaryFilter;
  584. }
  585. function generateFilter(filters,filterType) {
  586. var builtFilter = "";
  587. var builtFilterFlag = false;
  588. // add the filter condition if we have one
  589. if (filters!= null && filters.length > 0) {
  590. builtFilter += "<" + filterType + "Filters>";
  591. // loop over the filters
  592. for (var i = 0; i < filters.length; ++i) {
  593. // get the filter
  594. var filter = filters[i];
  595. // add if we have a filter
  596. if (filter != null && stripSpaces(filter).length > 0) {
  597. if (filterType=="detail") {
  598. builtFilter += "<" + filterType + "Filter use=\"required\" postAutoAggregation=\"false\">";
  599. } else {
  600. builtFilter += "<" + filterType + "Filter use=\"required\">";
  601. }
  602. builtFilter += "<filterExpression>" + encode(filter) + "</filterExpression>";
  603. builtFilter += "</" + filterType + "Filter>";
  604. builtFilterFlag = true;
  605. }
  606. }
  607. builtFilter += "</" + filterType + "Filters>";
  608. //If we have built at least one filter then we keep filter as is
  609. //otherwise if flag is false then we should remove the wrapping tags
  610. // <detailFilters> or <summaryFilters>
  611. if (!builtFilterFlag) {
  612. builtFilter = "";
  613. }
  614. }
  615. return builtFilter;
  616. }
  617. function buildFilterCondition()
  618. {
  619. //The AgentTask-condition holds an XML encoded blob of the summary and details
  620. //filter. We have a hidden input in the defineCondtion.xts that is always updated
  621. //when the summary and detail filter changes.
  622. var filters = "";
  623. var msgFrame = getMessageIFrame();
  624. var msgDoc = getFrameDocument(msgFrame);
  625. // get the task condition element
  626. var conditionElement = msgDoc.pform.elements['AgentTask-condition'];
  627. // if we have an element - get it's value
  628. if (conditionElement != null && conditionElement.value != "") {
  629. //ensure single quotes are encoded, these are generate when a value is inserted into the condition using the selectValues dialog
  630. var filterValue = "";
  631. var aposRegEx = /\'/g;
  632. filterValue = conditionElement.value.replace(aposRegEx, "&apos;");
  633. // condition element MIGHT be 2 elements if we have both summary and detail filters, so create a dummy root node.
  634. var filters_xml = new XMLParser("<filter>"+filterValue+"</filter>");
  635. if (filters_xml != null && filters_xml.childNodes != null && filters_xml.childNodes.length > 0) {
  636. //shouldnt have any attributes.. they are probably xts ones which cause report server validation death
  637. filters_xml.attributes = new Array();
  638. // handle the filters and combine as one string
  639. for (var i = 0; i < filters_xml.childNodes.length; i++) {
  640. filters_xml.childNodes[i].attributes = new Array();
  641. filters = filters + filters_xml.childNodes[i].toString();
  642. }
  643. }
  644. }
  645. // return the filters
  646. return filters;
  647. }
  648. function noDataItems()
  649. {
  650. var dataItemsTree = getTreeValues(getDataItemsTree());
  651. if (dataItemsTree.length < 1) {
  652. return true;
  653. }
  654. else return false;
  655. }