deletionCandidateManager.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2009 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. // -----------------------------------------------------------------------------
  11. //
  12. // --- Deletion candidate ---
  13. //this hangs on to the current candidate for deletion
  14. //
  15. // -----------------------------------------------------------------------------
  16. var DIALOG_FRAME_ID = "dialogIFrame";
  17. var DISPLAY_NONE = "none";
  18. function DeletionCandidateManager(){
  19. this.current_candidate;
  20. this.candidate_type;
  21. }
  22. //return the object behind the id
  23. DeletionCandidateManager.prototype.getCandidateObject = function(){
  24. var candidate;
  25. if(this.getCandidate()){
  26. candidate = agsFormUtils.getElementByIdOrName(this.getCandidate());
  27. }
  28. return candidate;
  29. }
  30. //return the id
  31. DeletionCandidateManager.prototype.getCandidate = function(){
  32. return this.current_candidate;
  33. }
  34. DeletionCandidateManager.prototype.clearCandidate = function(){
  35. this.current_candidate = undefined;
  36. this.candidate_type = undefined;
  37. }
  38. /*
  39. * set the candidate for deletion
  40. * candidate - the candidate object
  41. * type - the candidate type, defined in constants.js. This is optional, when not
  42. * present the K_sControlCandidate is assigned
  43. * K_sFunctionCandidate - the candidate is a valid JS function
  44. * K_sControlCandidate - the candidate refers to an element
  45. */
  46. DeletionCandidateManager.prototype.setCandidate = function(candidate,type){
  47. if (arguments.length==2 && type != 'undefined') {
  48. this.candidate_type = type;
  49. }
  50. else {
  51. this.candidate_type = K_sControlCandidate;
  52. }
  53. this.current_candidate = candidate;
  54. }
  55. /*
  56. * Perform a delete. The deleted item will depending on the context.
  57. * The items in order of deletion are:
  58. * 1. selected text in the message frame
  59. * 2. selected query items/parameters/aggregations/calculations in the agent items tree
  60. * 3. selected attachments/links in the email task page
  61. * 4. agent tasks
  62. *
  63. * Note that for an item to be deleted it must not only be selected but also focused. This relates to tree nodes and selected text in input controls
  64. */
  65. DeletionCandidateManager.prototype.deleteSelectedItem = function() {
  66. if(applicationActionManager.isBlocked()){
  67. return;
  68. }
  69. //can delete text in the message frame or popup dialogs
  70. if(!this.deleteSelectedText()) {
  71. //do not delete tree items or agent tasks when a popup is displayed
  72. if (parent.popUpIsOpen()==false) {
  73. if (!this.deleteSelectedTreeItems()) {
  74. if (!this.deleteSelectedAttachmentsOrLinks()) {
  75. this.deleteSelectedAction();
  76. }
  77. }
  78. }
  79. }
  80. this.clearCandidate();
  81. }
  82. /*
  83. * Delete any selected text in an active control
  84. * return a boolean, true if the item was deleted
  85. */
  86. DeletionCandidateManager.prototype.deleteSelectedText = function() {
  87. var success = false;
  88. var msgFrame = getMessageIFrame();
  89. //check if the delete text function has been overridden
  90. if (msgFrame.deleteSelectedText) {
  91. msgFrame.deleteSelectedText();
  92. return true;
  93. }
  94. //get the selection control
  95. var control = getSelectionControl();
  96. if (control) {
  97. //get the selection object from the controls document
  98. //this needs to be done because in some case e.g. the HTML email body
  99. //the control contains a document itself and therefore has its own
  100. //selection object
  101. sel = getSelectionObject(control.ownerDocument);
  102. //check that some text has been selected
  103. if (isValidSelection(sel)) {
  104. clearSelectionText(sel);
  105. if (cf.browserCheck.isIE5Up()) {
  106. control.setActive();
  107. }
  108. success = true;
  109. }
  110. }
  111. return success;
  112. }
  113. /*
  114. * Delete selected agent items, parameters, calculations or aggregations from the agent items tree
  115. * return a boolean, true if the item was deleted
  116. */
  117. DeletionCandidateManager.prototype.deleteSelectedTreeItems = function() {
  118. var success = false;
  119. var control = this.getCandidate();
  120. var candidateObject = this.getCandidateObject();
  121. //Check if we have a deletion candidate and make sure
  122. //That it is not an element object. Tree candidate are
  123. //actual function calls and we need to eval them.
  124. //Check the candidate type, see Trakker bug 512301.0 - Get object error when attempting to delete an attachment/link
  125. if (this.candidate_type==K_sFunctionCandidate && control != null && (!candidateObject || candidateObject == "undefined")) {
  126. eval(control);
  127. success = true;
  128. }
  129. return success;
  130. }
  131. /*
  132. * Delete selected email attachments or links from the 'Specify the email to send' dialog
  133. * return a boolean, true if the item was deleted
  134. */
  135. DeletionCandidateManager.prototype.deleteSelectedAttachmentsOrLinks = function() {
  136. var success = false;
  137. var msgFrame = getMessageIFrame();
  138. if (msgFrame.deleteLinksAndAttachments != null) {
  139. success = msgFrame.deleteLinksAndAttachments();
  140. }
  141. //If success is true it means we have some links or attachments
  142. //selected and they need to be deleted.
  143. /*if (success) {
  144. //the email dialog will take care of removing the items, we just
  145. //need to resubmit the form
  146. msgFrame.pform.submit();
  147. }*/
  148. return success;
  149. }
  150. /*
  151. * Delete the selected agent task, ignore condition or schedule tasks
  152. * return a boolean, true if the item was deleted
  153. */
  154. DeletionCandidateManager.prototype.deleteSelectedAction = function(){
  155. var success = false;
  156. var msgFrame = getMessageIFrame();
  157. var msgDoc = getFrameDocument(msgFrame);
  158. var intended = /AgentTask-condition|AgentTask-schedule/;
  159. var candidate = this.getCandidateObject();
  160. //do not try and delete the condition or schedule
  161. if (candidate && candidate.value && candidate.name && candidate.name == "tabSelectedID" && !intended.test(candidate.value)) {
  162. //block until page is reloaded
  163. cf.applicationActionManager.blockActions();
  164. if(msgFrame.leavingDialog){
  165. //we are leaving this dialog for good.... unless you undo
  166. msgFrame.leavingDialog();
  167. }
  168. msgDoc.pform.agentItemOp.value = 'remove';
  169. msgDoc.pform.ps_nav_op.value = "maintain";
  170. success = true;
  171. msgDoc.pform.submit();
  172. }
  173. return success;
  174. }
  175. var deletionCandidateManager = new DeletionCandidateManager();