/******************************************************************************************************************************** * Licensed Materials - Property of IBM * * * * IBM Cognos Products: AGS * * * * (C) Copyright IBM Corp. 2005, 2009 * * * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * *********************************************************************************************************************************/ // ----------------------------------------------------------------------------- // // --- Deletion candidate --- //this hangs on to the current candidate for deletion // // ----------------------------------------------------------------------------- var DIALOG_FRAME_ID = "dialogIFrame"; var DISPLAY_NONE = "none"; function DeletionCandidateManager(){ this.current_candidate; this.candidate_type; } //return the object behind the id DeletionCandidateManager.prototype.getCandidateObject = function(){ var candidate; if(this.getCandidate()){ candidate = agsFormUtils.getElementByIdOrName(this.getCandidate()); } return candidate; } //return the id DeletionCandidateManager.prototype.getCandidate = function(){ return this.current_candidate; } DeletionCandidateManager.prototype.clearCandidate = function(){ this.current_candidate = undefined; this.candidate_type = undefined; } /* * set the candidate for deletion * candidate - the candidate object * type - the candidate type, defined in constants.js. This is optional, when not * present the K_sControlCandidate is assigned * K_sFunctionCandidate - the candidate is a valid JS function * K_sControlCandidate - the candidate refers to an element */ DeletionCandidateManager.prototype.setCandidate = function(candidate,type){ if (arguments.length==2 && type != 'undefined') { this.candidate_type = type; } else { this.candidate_type = K_sControlCandidate; } this.current_candidate = candidate; } /* * Perform a delete. The deleted item will depending on the context. * The items in order of deletion are: * 1. selected text in the message frame * 2. selected query items/parameters/aggregations/calculations in the agent items tree * 3. selected attachments/links in the email task page * 4. agent tasks * * 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 */ DeletionCandidateManager.prototype.deleteSelectedItem = function() { if(applicationActionManager.isBlocked()){ return; } //can delete text in the message frame or popup dialogs if(!this.deleteSelectedText()) { //do not delete tree items or agent tasks when a popup is displayed if (parent.popUpIsOpen()==false) { if (!this.deleteSelectedTreeItems()) { if (!this.deleteSelectedAttachmentsOrLinks()) { this.deleteSelectedAction(); } } } } this.clearCandidate(); } /* * Delete any selected text in an active control * return a boolean, true if the item was deleted */ DeletionCandidateManager.prototype.deleteSelectedText = function() { var success = false; var msgFrame = getMessageIFrame(); //check if the delete text function has been overridden if (msgFrame.deleteSelectedText) { msgFrame.deleteSelectedText(); return true; } //get the selection control var control = getSelectionControl(); if (control) { //get the selection object from the controls document //this needs to be done because in some case e.g. the HTML email body //the control contains a document itself and therefore has its own //selection object sel = getSelectionObject(control.ownerDocument); //check that some text has been selected if (isValidSelection(sel)) { clearSelectionText(sel); if (cf.browserCheck.isIE5Up()) { control.setActive(); } success = true; } } return success; } /* * Delete selected agent items, parameters, calculations or aggregations from the agent items tree * return a boolean, true if the item was deleted */ DeletionCandidateManager.prototype.deleteSelectedTreeItems = function() { var success = false; var control = this.getCandidate(); var candidateObject = this.getCandidateObject(); //Check if we have a deletion candidate and make sure //That it is not an element object. Tree candidate are //actual function calls and we need to eval them. //Check the candidate type, see Trakker bug 512301.0 - Get object error when attempting to delete an attachment/link if (this.candidate_type==K_sFunctionCandidate && control != null && (!candidateObject || candidateObject == "undefined")) { eval(control); success = true; } return success; } /* * Delete selected email attachments or links from the 'Specify the email to send' dialog * return a boolean, true if the item was deleted */ DeletionCandidateManager.prototype.deleteSelectedAttachmentsOrLinks = function() { var success = false; var msgFrame = getMessageIFrame(); if (msgFrame.deleteLinksAndAttachments != null) { success = msgFrame.deleteLinksAndAttachments(); } //If success is true it means we have some links or attachments //selected and they need to be deleted. /*if (success) { //the email dialog will take care of removing the items, we just //need to resubmit the form msgFrame.pform.submit(); }*/ return success; } /* * Delete the selected agent task, ignore condition or schedule tasks * return a boolean, true if the item was deleted */ DeletionCandidateManager.prototype.deleteSelectedAction = function(){ var success = false; var msgFrame = getMessageIFrame(); var msgDoc = getFrameDocument(msgFrame); var intended = /AgentTask-condition|AgentTask-schedule/; var candidate = this.getCandidateObject(); //do not try and delete the condition or schedule if (candidate && candidate.value && candidate.name && candidate.name == "tabSelectedID" && !intended.test(candidate.value)) { //block until page is reloaded cf.applicationActionManager.blockActions(); if(msgFrame.leavingDialog){ //we are leaving this dialog for good.... unless you undo msgFrame.leavingDialog(); } msgDoc.pform.agentItemOp.value = 'remove'; msgDoc.pform.ps_nav_op.value = "maintain"; success = true; msgDoc.pform.submit(); } return success; } var deletionCandidateManager = new DeletionCandidateManager();