123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| BI and PM: prmt
- *| (C) Copyright IBM Corp. 2002, 2011
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- /**
- This script is used to provide interactivity for the PickTree prompt control
- This control primary purpose is to support SAP hierarchy variables
-
- @private
- @class
- */
- cognos.Prompt.Control.PickTree = cognos.Prompt.Control.f_extend({
- f_initialize: function( v_oProps ) {
- this._type_ = "cognos.Prompt.Control.PickTree";
- this.f_parent( v_oProps ); // call parent's initialize()
-
- var v_oPropsComponent = Object.f_extend( {}, v_oProps );
- v_oPropsComponent["@required"] = true;
- v_oPropsComponent["@hideAdornments"] = true;
- v_oPropsComponent.m_bIsAComponent = true;
- v_oPropsComponent.m_oOwner = this;
- v_oPropsComponent._id_ = this.f_getId();
-
- this.m_oTreeArguments = v_oPropsComponent;
- this.f_initCompleted();
- // initialize adornment image
- this.m_adornmentImg = 'spacer.gif';
- },
- //validate the input into the control
- checkData: function()
- {
- this.m_bValid = this.m_oTree.m_bValid;
- this.f_parent(); // call parent's checkData using saved reference.
- return this.m_bValid;
- },
- clearValues: function() {
- this.f_parent();
- this.f_clear();
- },
- f_drawCompleted: function()
- {
- this.m_oTree.f_drawCompleted();
- var v_oPickList = $(this.f_getId("PRMT_PT_HIERARCHIES_"));
- this.m_oPickList = v_oPickList;
- PRMTUtils.f_addEvent(v_oPickList, "change", this.f_onChangeTree.bind(this) );
- }
- });
- /**
- * Return the value of the control, which in this case is returning the tree selection
- */
- cognos.Prompt.Control.PickTree.prototype.f_getPV = function()
- {
- var v_oTree = this.m_oTree;
- var v_aPV = [];
- if ( v_oTree )
- {
- v_aPV = v_oTree.f_getPV();
- }
- return v_aPV;
- };
- /**
- * Draws the layout
- * <td><table><tr>
- * <td>Adornment</td>
- * <td>
- * <div>pickList</div>
- * <div>Tree</div>
- *
- * @private
- * @param {C_PromptElement} v_el Container.
- * @return {void}
- */
- cognos.Prompt.Control.PickTree.prototype.f_drawLayout = function( v_el )
- {
- var v_tdLayout = $CE( "td", {}, v_el );
- var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_tdLayout );
- if ( this[K_PRMT_sATTR_DISABLED] )
- {
- v_tbl.f_setProperty( "disabled", "disabled" );
- }
- var v_tbd = $CE( "tbody", {}, v_tbl );
- var v_tr = $CE( "tr", {}, v_tbd );
- var v_td = $CE( "td", {"vAlign":"top", "class": "clsControlLabel pc"}, v_tr );
- if ( this.isRequired() && !this["@hideAdornments"] )
- {
- var v_imgReq = $CE( "img", {
- "src": this.m_sSkin + "/prompting/images/icon_required.gif",
- "class": "clsErrorRequired",
- "vAlign": "top",
- "height": 10,
- "width": 10,
- "border": 0,
- "alt": ""
- }, v_td);
- }
- var v_tdControl = $CE( "td", {}, v_tr );
- this.f_drawPickList( v_tdControl );
- v_tr = $CE( "tr", {}, v_tbd );
- v_td = $CE( "td", {"vAlign":"top", "class": "clsControlLabel pc"}, v_tr );
- $CE("img", {"src": this.m_sSkin + "/prompting/images/spacer.gif", "width": 10, "height": 1, "border": 0, "alt": ""}, v_td);
- this.m_elPrompt = this.f_drawTree( v_tr );
- return (this.m_elPrompt);
- }
- /**
- * Draws the drop down to pick the hierarchy
- *
- * @private
- * @param {C_PromptElement} v_el Container.
- * @return {void}
- */
- cognos.Prompt.Control.PickTree.prototype.f_drawPickList = function( v_el )
- {
- var v_oContainer = $CE("div", {"id": this.f_getId("PRMT_PT_HIERARCHIES_BOX_")}, v_el);
- var v_oPickList = $CE("select",{"id": this.f_getId("PRMT_PT_HIERARCHIES_"), "class":"clsSelectControl pv"},v_oContainer);
- var v_firstOption = this["@columnName"] && this["@columnName"].length > 0 ? this["@columnName"]:this["@parameter"];
- // draw select options
- var v_choices = this.f_getChildByTagName( "selectHierarchyChoice" );
- var v_selectedHierarchy = ((v_choices && v_choices.c && v_choices.c.length > 0)? v_choices.c[0] : null);
- var v_options = this.f_getChildByTagName( "selectHierarchies" );
- var v_optionEl;
-
- // add the top two lines
- v_optionEl = $CE("option", {}, v_oPickList);
- v_optionEl.f_appendText( G_IsBidiEnabled && this["@contentTextDirection"] ? PRMT_BidiUtils.enforceBidiDirection(v_firstOption, this["@contentTextDirection"]) : v_firstOption );
- v_optionEl = $CE("option", {}, v_oPickList);
- v_optionEl.f_appendText("--------------------------------------------");
-
- if ( v_options && v_options.c && v_options.c.length > 0)
- {
- for (var i = 0; i < v_options.c.length; i++ )
- {
- var v_option = v_options.c[i];
- var v_optionAttr = {"value": v_option[K_PRMT_sATTR_USE_VALUE], "dv":v_option[K_PRMT_sATTR_DISPLAY_VALUE]};
- if (v_selectedHierarchy && v_option && v_option[K_PRMT_sATTR_USE_VALUE] == v_selectedHierarchy[K_PRMT_sATTR_USE_VALUE]) {
- v_optionAttr["selected"] = "true"
- }
- v_optionEl = $CE("option", v_optionAttr, v_oPickList);
- v_optionEl.f_appendText( (G_IsBidiEnabled && this["@contentTextDirection"] ? PRMT_BidiUtils.enforceBidiDirection(v_option[K_PRMT_sATTR_DISPLAY_VALUE], this["@contentTextDirection"]) : v_option[K_PRMT_sATTR_DISPLAY_VALUE]) );
- }
- }
- return v_oContainer;
- };
- /**
- * Draw the tree part of the control leveraging already existing Tree control
- */
- cognos.Prompt.Control.PickTree.prototype.f_drawTree = function( v_el )
- {
- var v_oContainer = $CE("div", {"id": this.f_getId("PRMT_PT_TREE_BOX_")}, v_el);
- var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_oContainer );
- var v_tbd = $CE( "tbody", {}, v_tbl );
- var v_tr = $CE( "tr", {}, v_tbd );
- this.f_cleanTreeArguments();
- var v_oTree = new cognos.Prompt.Control.Tree( this.m_oTreeArguments );
- v_oTree.f_drawLayout(v_tr);
- this.m_oTree = v_oTree;
- };
- /**
- * Clean the hierarchy list and choice from the tree arguments
- */
- cognos.Prompt.Control.PickTree.prototype.f_cleanTreeArguments = function( ) {
- // rm "selectHierarchies" and "selectHierarchyChoice", if selectOptions is missing or empty set canExpand to false;
- var v_treeArguments = this.m_oTreeArguments;
- if ( v_treeArguments.c && v_treeArguments.c.length )
- {
- for ( var i = 0, j = 0; i < v_treeArguments.c.length; i++ )
- {
- if ( v_treeArguments.c[i].n == "selectHierarchies" || v_treeArguments.c[i].n == "selectHierarchyChoice") {
- v_treeArguments.c.splice(i,1);
- i--;
- }
- }
- }
-
- };
- /**
- * Get the selected hierarchy from the hierarchy pick list
- */
- cognos.Prompt.Control.PickTree.prototype.f_getPickListSelection = function()
- {
- var result = null;
- var v_oPickList = this.m_oPickList;
- if (v_oPickList.options && v_oPickList.options.length > 0) {
- var v_oSelOption = v_oPickList.options[v_oPickList.selectedIndex];
- if (v_oSelOption) {
- result = v_oSelOption.getAttribute('value');
- if (result === null)
- {
- result = v_oSelOption.value;
- }
- // for embedded IE 9 "feature"
- if (!result && v_oSelOption.attributes && v_oSelOption.attributes['value']) {
- result = v_oSelOption.attributes['value'].value;
- }
- }
- }
- return result;
- };
- /**
- * Get the hierarchy options in XML format, like the example below:
- * <selectHierarchies>
- * <selectHierarchy useValue="[P].[D].[H1]" displayValue=" Hierarchy 1"/>
- * <selectHierarchy useValue="[P].[D].[H2]" displayValue=" Hierarchy 2"/>
- * <selectHierarchy useValue="[P].[D].[H3]" displayValue=" Hierarchy 3"/>
- * </selectHierarchies>
- */
- cognos.Prompt.Control.PickTree.prototype.f_getXMLHierachyValues = function()
- {
- var v_aOptionXml = ['<selectHierarchy', ' useValue="',K_PRMT_sEMPTY,'" displayValue="',K_PRMT_sEMPTY,'" />'];
- var result = "<selectHierarchies>";
- var v_oPickList = this.m_oPickList;
- if (v_oPickList.options && v_oPickList.options.length > 0) {
- //var v_oSelOption = v_oPickList.options[v_oPickList.selectedIndex];
- var v_option = null;
- var v_oPickListOptions = v_oPickList.options;
- // skip the first two options (header and separator)
- for ( var i = 2; i < v_oPickListOptions.length; i++ )
- {
- v_option = v_oPickListOptions[i];
- v_aOptionXml[2] = v_option.getAttribute('value');
- // for embedded IE 9 "feature"
- if (!v_aOptionXml[2] && v_option.attributes && v_option.attributes['value']) {
- v_aOptionXml[2] = v_option.attributes['value'].value;
- }
- v_aOptionXml[4] = v_option.getAttribute(K_PRMT_sDV);
- result += v_aOptionXml.join(K_PRMT_sEMPTY);
- }
- }
- result += "</selectHierarchies>";
- return result;
- };
- /**
- * Send a forward request to Report Server indicating that it is a reprompt and
- * the chosen hierarchy node will be included as a form-field variable:
- * - name : "_swt_"+ promptName + "_hierarchy";
- * - value: useValue for the selected hierarchy
- * and the list of hierarchies, so RSVP doesn't need to do another metadata request
- * to re-fill the hierarchies list.
- * - hierachies_name : "_swt_"+ promptName + "_hierarchies";
- * - value : the list of hierarchies in XML format (like the intermediateXML)
- */
- cognos.Prompt.Control.PickTree.prototype.f_onChangeTree = function()
- {
- var v_idName = this["@parameter"];
- var isNameUsedAsId = false;
- if (!v_idName || (v_idName.trim && v_idName.trim().length < 1)) {
- v_idName = ( this["@name"] ? this["@name"] : "");
- isNameUsedAsId = true;
- }
- var v_sName = "_swt_"+ v_idName + "_hierarchy";
- var v_sValue = this.f_getPickListSelection();
- // clear current tree selection if any
- this.m_oTree.clearValues();
- if ( v_sValue )
- {
- var oCV = this.f_getCV();
- var v_sSubmitType = K_ACTION_REPROMPT;
- var v_sHierarchiesName = "_swt_"+ v_idName + "_hierarchies";
- if (oCV && typeof oCV.submitPromptValues == K_PRMT_sFUNCTION && typeof ViewerDispatcherEntry == K_PRMT_sFUNCTION){
- var oReq = new ViewerDispatcherEntry(oCV);
- oReq.addFormField("ui.action", K_ACTION_FORWARD);
- oReq.addFormField(v_sName, v_sValue);
- oReq.addFormField(v_sHierarchiesName, this.f_getXMLHierachyValues());
- if (isNameUsedAsId) {
- oReq.addFormField("_promptIdBasedNames",true);
- }
- oReq.addFormField("_promptControl", K_ACTION_REPROMPT);
- oCV.submitPromptValues(oReq);
- } else {
- SetPromptMethod(K_ACTION_FORWARD);
- if (document.forms[0]) {
- var frm = document.forms[0];
- genHiddenInputHTML( frm.name, v_sName, v_sValue );
- genHiddenInputHTML( frm.name, v_sHierarchiesName, this.f_getXMLHierachyValues());
- if (isNameUsedAsId) {
- genHiddenInputHTML( frm.name,"_promptIdBasedNames",true);
- }
- }
- SetPromptControl( K_ACTION_REPROMPT );
- }
- }
- };
|