123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| BI and PM: prmt
- *| (C) Copyright IBM Corp. 2002, 2011, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- /**
- Should be accessed through <tt>cognos.Report.prompt</tt>.
- @fileOverview Managing Prompts.
- @namespace cognos.Prompt
- @class Manager class for prompts.
- */
- cognos.Prompt = function()
- {
- this.m_aControls = [];
- this.m_aParameters = [];
- };
- /**
- Adds a prompt control to the manager.
- @private
- @param {object} v_oProps properties of the object
- @param {object} v_oExtra Extra properties to add to the object, like <i>CVId</i>.
- @return {cognos.Prompt.Control} Newly created object.
- */
- cognos.Prompt.prototype.F_Add = function( v_oProps, v_oExtra )
- {
- Object.f_extend( v_oProps, v_oExtra );
- var v_o = this.f_create( v_oProps );
- if ( v_o )
- {
- v_o.f_setPromptManager(this);
- this.m_aControls.push( v_o );
- window[ v_o.f_getId("p_") ] = v_o;
- var cv = v_o.f_getCV();
- if (cv)
- {
- if (typeof cv.setHasPrompts == "function")
- {
- cv.setHasPrompts(true);
- }
- var v_aPP = cv.preProcessControlArray;
- if ( v_aPP )
- {
- v_aPP.push( v_o );
- }
- }
- }
- return ( v_o );
- };
- /**
- Adds a prompt control to the manager.
- @private
- @param {object} v_oProps properties of the object
- @param {object} v_oExtra Extra properties to add to the object, like <i>CVId</i>.
- @return {cognos.Prompt.Control} Newly created object.
- */
- cognos.Prompt.prototype.f_create = function( v_oProps )
- {
- var v_o = null;
- if ( v_oProps )
- {
- var isHTML5 = this.isHTML5(v_oProps);
- if ( v_oProps["@range"] )
- {
- v_o = new cognos.Prompt.Control.Range( v_oProps, this );
- } else if ( v_oProps["@parameterizedTree"] && ( v_oProps["@parameterizedTree"] == true )) {
- v_o = new cognos.Prompt.Control.PickTree( v_oProps );
- } else {
- switch( v_oProps.n )
- {
- case "textBox": v_o = new cognos.Prompt.Control.Text( v_oProps ); break;
- case "selectFile": v_o = new cognos.Prompt.Control.SelectFile( v_oProps ); break;
- case "selectValue": v_o = new cognos.Prompt.Control.SelectValue( v_oProps ); break;
- case "selectInterval": v_o = new cognos.Prompt.Control.Interval( v_oProps, this ); break;
- case "selectDate":
- v_o = ((isHTML5 && this.browserSupportsHTML5Input(v_oProps.n))? new cognos.Prompt.Control.SelectHTML5Date( v_oProps ) : new cognos.Prompt.Control.Date( v_oProps ));
- break;
- case "selectTime":
- v_o = ((isHTML5 && this.browserSupportsHTML5Input(v_oProps.n))? new cognos.Prompt.Control.SelectHTML5Time( v_oProps ) : new cognos.Prompt.Control.Time( v_oProps ));
- break;
- case "selectDateTime":
- v_o = ((isHTML5 && this.browserSupportsHTML5Input(v_oProps.n))? new cognos.Prompt.Control.SelectHTML5DateTime( v_oProps ) : new cognos.Prompt.Control.DateTime( v_oProps ));
- break;
- case "selectWithTree": v_o = new cognos.Prompt.Control.Tree( v_oProps ); break;
- case "selectWithSearch": v_o = new cognos.Prompt.Control.Search( v_oProps ); break;
- }
- }
- }
- return ( v_o );
- };
- cognos.Prompt.prototype.browserSupportsHTML5Input = function(sInputType)
- {
- var bIsSupported = true;
- var inputEle = document.createElement("input");
- switch(sInputType)
- {
- case "selectDate":
- inputEle.setAttribute("type", "date");
- bIsSupported = inputEle.type !== "text";
- break;
- case "selectTime":
- inputEle.setAttribute("type", "time");
- bIsSupported = inputEle.type !== "text";
- break;
- case "selectDateTime":
- /*PRMT doesn't use the HTML5 datetime or datetime-local input type, instead we generate a composite control composed of HTML5 date and time controls, so we can support a datetime control as long as both the individual HTML5 date and time input types are supported.*/
- inputEle.setAttribute("type", "date");
- bIsSupported = inputEle.type !== "text";
- inputEle.setAttribute("type", "time");
- bIsSupported = (inputEle.type !== "text") && bIsSupported;
- break;
- }
-
- return bIsSupported;
- };
- cognos.Prompt.prototype.isHTML5 = function( v_oProps )
- {
- var result = false;
- if ((typeof G_PRMT_HTML5PromptControls) != K_PRMT_sUNDEFINED && G_PRMT_HTML5PromptControls) {
- result = true;
- }
- else {
- var reHTML5 = new RegExp("^_html5", "im");
- if ( v_oProps["@name"] && ( v_oProps["@name"].match(reHTML5) ) ) {
- result = true;
- }
- }
- return result;
- }
- /**
- Returns the control object associated to a name.
- @param {String} sName Prompt Control ID. It could be the <tt>name</tt> property set for the control in Report Studio.
- @return {cognos.Prompt.Control} Object associated to sName. Return <tt>null</tt> if it doesn't exists.
- */
- cognos.Prompt.prototype.getControlByName = function(sName)
- {
- return this.getPromptControl(sName);
- };
- /**
- Returns an array of all controls associated to this report.
- @return {cognos.Prompt.Control[]}
- */
- cognos.Prompt.prototype.getControls = function() { return this.m_aControls; };
- /**
- Returns the parameter object associated to a name.
- @param {String} sName Parameter Name.
- @return {cognos.Prompt.Parameter} Parameter associated to sName. Creates a new Parameter is it doesn't exists.
- */
- cognos.Prompt.prototype.getParameterByName = function(sName)
- {
- if ( sName instanceof cognos.Prompt.Parameter )
- {
- return sName;
- }
- for (var v_idx = 0; v_idx < this.m_aParameters.length; v_idx++)
- {
- if ( this.m_aParameters[v_idx].getName() == sName )
- {
- return (this.m_aParameters[v_idx]);
- }
- }
- var v_oParameter = new cognos.Prompt.Parameter(sName);
- this.m_aParameters.push(v_oParameter);
- return v_oParameter;
- };
- /**
- Returns an array of all parameters associated to this report.
- @return {cognos.Prompt.Parameter[]}
- */
- cognos.Prompt.prototype.getParameters = function() { return this.m_aParameters; };
- /**
- Returns the object associated to an ID.
- @private
- @param {string} sID Prompt Control ID. It could be the <tt>name</tt> property set for the control in Report Studio.
- @return {cognos.Prompt.Control} Object associated to sID. Return <tt>null</tt> if it doesn't exists.
- */
- cognos.Prompt.prototype.getPromptControl = function( sID )
- {
- var v_aPrompts = this.m_aControls;
- var v_oPrompt = null;
- for (var v_idx = 0; v_idx < v_aPrompts.length; v_idx++)
- {
- var v_oTemp = v_aPrompts[ v_idx ];
- var v_sID = v_oTemp.f_getId();
- if ( v_sID == sID ) {
- v_oPrompt = v_oTemp;
- break;
- }
- }
- // didn't find using _id_, try with @id
- if ( v_oPrompt === null )
- {
- for (v_idx = 0; v_idx < v_aPrompts.length; v_idx++)
- {
- var v_oTemp = v_aPrompts[ v_idx ];
- var v_sID = v_oTemp["@id"];
- if ( v_sID == sID ) {
- v_oPrompt = v_oTemp;
- break;
- }
- }
- }
- // try with @name
- if ( v_oPrompt === null )
- {
- for (v_idx = 0; v_idx < v_aPrompts.length; v_idx++)
- {
- var v_oTemp = v_aPrompts[ v_idx ];
- var v_sID = v_oTemp["@name"];
- if ( v_sID == sID ) {
- v_oPrompt = v_oTemp;
- break;
- }
- }
- }
- return v_oPrompt;
- };
- /**
- Return <tt>true</tt> if parameter sParameterName is satisfied.
- @private
- @param {String} [sParameterName] Parameter to validate. If omitted, returns true if <i>ALL</i> parameters are valid.
- @return {boolean}
- */
- cognos.Prompt.prototype.isValid = function( sParameterName )
- {
- var v_bValid = true;
- for ( var v_idx = 0; v_bValid && v_idx < this.m_aParameters.length; v_idx++ ) {
- v_bValid &= this.m_aParameters[ v_idx ].isValid();
- }
- return v_bValid;
- };
- /**
- Associate a custom control to a parameter.
- ** <u>For future use</u> - It's only here to show our intention to support this kind of action - <i>Still need to be worked out.</i>
- @param {String|cognos.Prompt.Parameter} parameter Parameter or Parameter Name to associate with the control.
- @param {cognos.Prompt.Control} control The control.
- @return {void}
- @example var <tt>ctrl</tt> = new CustomMapControl(); // based on a cognos.Prompt.Control
- <br/>var <tt>prmtr</tt> = cognos.Prompt.getParameterByName('Country');
- <br/>cognos.Prompt.registerControl( <tt>prmtr</tt>, <tt>ctrl</tt> );
- */
- cognos.Prompt.prototype.registerControl = function(parameter, control)
- {
- var v_oParameter = this.getParameterByName( parameter );
- if ( v_oParameter )
- {
- v_oParameter.f_addControl( control );
- }
- this.m_aControls.push( control );
- };
- /**
- Returns XML representation for parameter names and values.
- @private
- @return {string} XML string.
- */
- cognos.Prompt.prototype.toXML = function( )
- {
- var v_aXML = [];
- for ( var v_idx = 0; v_idx < this.m_aParameters.length; v_idx++ )
- {
- var sName = this.m_aParameters[v_idx].getName();
- v_aXML.push('<param name="');
- v_aXML.push( sName.f_xmlSafe() );
- v_aXML.push('">');
- v_aXML.push( this.m_aParameters[v_idx].getXML() );
- v_aXML.push('</param>');
- }
- return ( v_aXML.join(K_PRMT_sEMPTY) );
- };
- var C_PromptManager = cognos.Prompt; // Keep old reference for backward compatibility with custom scripts.
|