123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| BI and PM: prmt
- *| (C) Copyright IBM Corp. 2002, 2016
- *|
- *| 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 SelectFile prompt control
- @private
- @class
- */
- cognos.Prompt.Control.SelectFile = cognos.Prompt.Control.f_extend({
- f_initialize: function( v_oProps ) {
- this._type_ = "cognos.Prompt.Control.SelectFile";
- this.f_parent( v_oProps ); // call parent's initialize()
- this.f_initCompleted();
- // initialize adornment image
- this.m_adornmentImg = 'spacer.gif';
- },
- //validate the input into the control
- checkData: function()
- {
- // We keep a reference to the parent function
- // Calling this.m_oFrom functions seems to have a side effect on this.f_parent().
- var v_fnParent = this.f_parent;
- this.m_bValid = false;
- // it's valid when the response from upload returns valid, the response should be as follows
- // <pdSpec> <dataSet type="XML"> <name>$FILE_NAME</name>....
- var v_aMatchResult = null;
- if ( this.getValue() && this.m_sProcessResponse && this.m_sProcessResponse.length > 0 ) {
- v_aMatchResult = this.decodeHTML(this.m_sProcessResponse).match(/^.*<pdSpec>[^<]*<dataSet[^>]+>[^<]*<name>([^>]+)</);
- if (v_aMatchResult !== null && v_aMatchResult.length > 0) {
- // this.getValue() should match v_aMatchResult[1]
- this.m_bValid = true;
- } else {
- //console.log("no match in checkData");
- }
-
- }
- this.f_parent = v_fnParent; // call parent's checkData using saved reference.
- 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()
- {
- var v_oIframeContainer = $(this.f_getId("PRMT_SF_CONTAINER_"));
- var v_oIFrame = new PRMTFormIframe(v_oIframeContainer, this.f_getId("iframe_"), this.getWebContentRoot() + '/prompting/selectfileBlank.html');
- if (v_oIFrame !== null) {
- var v_oDoc = v_oIFrame.doc;
- if (v_oDoc) {
- PRMTUtils.f_addEvent(v_oIFrame, "load", this.f_fillIframe.bind(this) );
- }
- }
- }
- });
- /**
- * Fill the content of the iframe
- *
- * @private
- * @return {void}
- */
- cognos.Prompt.Control.SelectFile.prototype.f_fillIframe = function()
- {
- var iframeId = this.f_getId("iframe_");
- var iframeDoc = (window.ie ? window[iframeId].document : document.getElementById(iframeId).contentDocument);
- if (iframeDoc) {
- var guiDir = PRMT_BidiUtils.lookupDirection($( this.f_getId(this.m_sDivPrefix) ));
- if (guiDir) {
- iframeDoc.body.dir = guiDir;
- }
- var outerDiv = iframeDoc.getElementById('outerdivSF');
- // get doc lang
- var mainDocLang = document.documentElement.getAttribute("lang");
- iframeDoc.documentElement.setAttribute("lang",mainDocLang);
-
- // set the Global Report Style CSS for the iframe body background
- var cssRef = iframeDoc.createElement("link");
- cssRef.setAttribute("rel", "stylesheet");
- cssRef.setAttribute("type", "text/css");
- var docHead = iframeDoc.getElementsByTagName("head")[0];
- cssRef.setAttribute("href", this.f_findGlobalReportStyle());
- docHead.appendChild(cssRef);
- // add the prompt css
- cssRef = cssRef.cloneNode(true);
- cssRef.setAttribute("href", this.m_sSkin + '/prompting/promptCommon.css');
- docHead.appendChild(cssRef);
- // add bux css if exists
- if (this.f_isBUX()) {
- var buxCss = this.f_findBuxStyle();
- if (buxCss) {
- cssRef = cssRef.cloneNode(true);
- cssRef.setAttribute("href", buxCss);
- docHead.appendChild(cssRef);
-
- iframeDoc.body.className = "icdUI";
- }
- }
- if (outerDiv) {
- outerDiv.innerHTML = this.f_uploadPageContent();
- this.m_elPrompt = iframeDoc.getElementById(this.f_getId(K_PRMT_SF_INPUT_PREFIX));
- if (this.m_elPrompt)
- {
- PRMTUtils.f_addEvent(this.m_elPrompt, "change", this.f_selectFileChange.bind(this) );
- }
- }
- }
- };
- /**
- * Find the GlobalReportStyle used in the page
- *
- * @private
- * @return {String}
- */
- cognos.Prompt.Control.SelectFile.prototype.f_findGlobalReportStyle = function()
- {
- var result = this.getWebContentRoot() + '/schemas/GlobalReportStyles_10.css';
- var links = document.getElementsByTagName("link");
- var link = null;
- var globalStyleRE = new RegExp(/GlobalReportStyles/);
- for (i=0; i < links.length; i++)
- {
- link = links[i];
- if (link.type == "text/css" && link.href.match(globalStyleRE)) {
- result = link.href;
- }
- }
- return result;
- };
- /**
- * Find the GlobalReportStyle used in the page
- *
- * @private
- * @return {String}
- */
- cognos.Prompt.Control.SelectFile.prototype.f_findBuxStyle = function()
- {
- // http://localhost/ibmCognos/webcontent/rv/bux.css
- var result = null;
- var links = document.getElementsByTagName("link");
- var link = null;
- var buxStyleRE = new RegExp(/rv\/bux\.css/);
- for (i=0; i < links.length; i++)
- {
- link = links[i];
- if (link.type == "text/css" && link.href.match(buxStyleRE)) {
- result = link.href;
- }
- }
- return result;
- };
- cognos.Prompt.Control.SelectFile.prototype.f_getPV = function()
- {
- return this.getValue();
- };
- /**
- * Draws the container for the iframe, the iframe is rendered in the drawComplete method
- *
- * @private
- * @param {C_PromptElement} v_el Container.
- * @return {void}
- */
- cognos.Prompt.Control.SelectFile.prototype.f_drawInput = function( v_el )
- {
- var v_oContainer = $CE("div", {"id": this.f_getId("PRMT_SF_CONTAINER_"), "class":"clsPromptComponent"}, v_el);
- v_oContainer.f_appendText(K_PRMT_sEMPTY);
- return v_oContainer;
- };
- /**
- * Override superclass(Control) because for SelectFile the adornment should be render
- * in the iframe. It just prepare the image that will used as adorment.
- *
- * @private
- * @param {HTMLelement} v_el Container for this control.
- * @param {boolean} [v_bSkipRequired] Skips rendering of the required flag. Used when controls are set as children of another control (like in ranges). The parent control will handle the 'Required' UI.
- * @return {C_PromptElement}
- */
- cognos.Prompt.Control.SelectFile.prototype.f_drawAdornments = function(v_el, v_bSkipRequired) {
- // draw an empty cell, the real rendering happens inside the iframe
- var v_td0 = $CE( "td", {"vAlign": "top", "width": "1px"}, v_el );
- var v_img = $CE( "img", {
- "src": this.m_sSkin + "/prompting/images/spacer.gif",
- "height": 1,
- "width": 1,
- "border": 0,
- "alt": ""
- }, v_td0);
- if ( this.isRequired() && !v_bSkipRequired )
- {
- this.m_adornmentImg = 'icon_required.gif';
- }
- return v_td0;
- }
- /**
- * HTML form with a File input element to be rendered in the visible iframe
- *
- */
- cognos.Prompt.Control.SelectFile.prototype.f_uploadPageContent = function() {
- var inputFileId = this.f_getId(K_PRMT_SF_INPUT_PREFIX);
- var webContentURL = getWebContentURI();
- var iconSrc = (this.isRequired() && (!(this["@hideAdornments"] || this.m_bSkipAdornments)) ? 'icon_required.gif' : 'spacer.gif');
- var requiredImgHTML = '<img class="clsErrorRequired" height="10" border="0" width="10" valign="top" alt="" src="' + webContentURL + '/prompting/reportskin/prompting/images/' + iconSrc + '" />';
- var direction = PRMT_BidiUtils.lookupDirection($( this.f_getId(this.m_sDivPrefix) ));
- var result = ' <div> ' +
- ' <form action="" enctype="multipart/form-data" method="post"> ' +
- ' <p class="clsDialogIntroduction">' + PMT_SF_INTROTEXT + '</p>' +
- ' <p class="clsDialogIntroduction">' + PMT_SF_TIP + '<span class="clsControlLabel" >'+ (G_IsBidiEnabled ? PRMT_BidiUtils.formatFilePath(this["@defaultPath"]) : this["@defaultPath"]) + '</span></p>' +
- ' <table cellspacing="0" cellpadding="0" border="0"><tbody><tr>' +
- ' <td class="clsControlLabel" valign="top">' + requiredImgHTML +
- ' <label for="'+ inputFileId + '">' + PMT_SF_LABEL + '</label> ' +
- ' </td></tr></tbody></table>' +
- ' <input id="'+ inputFileId +'" type="file" style="' + (G_IsBidiEnabled ? 'position:absolute' : 'width:580px') + '" name="pdsContent" size="80" accept="*.csv;*.xml;*.xls"';
- if (this["@defaultPath"] && this["@defaultPath"].length >0 ) {
- result += ' defaultValue="' + this["@defaultPath"] + '" ';
- }
- if (G_IsBidiEnabled)
- {
- result += 'onchange="PRMT_BidiUtils.onFileChange(this, \'fake' + inputFileId + '\', \'FILEPATH\')" onkeydown="return PRMT_BidiUtils.focusElement(\'fake' + inputFileId + '\');"';
- result += 'onfocus="PRMT_BidiUtils.onFileFocus(this, \'fake' + inputFileId + '\', \'FILEPATH\')" onmousedown="return PRMT_BidiUtils.focusElement(\'fake' + inputFileId + '\');"';
- }
- result +='> ';
- if (G_IsBidiEnabled)
- {
- result += '<input id="fake'+ inputFileId +'" type="text" dir="ltr" style="position:relative;z-index:2;background-color:#C0C0C0" name="fakePdsContent" size="80"';
- result += 'onkeydown="return PRMT_BidiUtils.onFakeKeyDown(event, \'' + inputFileId + '\');" oncopy="PRMT_BidiUtils.processCopy(this);" ';
- result += 'onpaste="return false;" oncut="return false;"';
- result +='> ';
- }
- result += '<input type="hidden" name="inSpec" id="inSpec"/> ' +
- ' </form> ' +
- ' </div> ';
- return result;
- };
- /**
- * Build the visible iframe to contain the form with the File input element
- */
- function PRMTFormIframe(parentElement, iframeId, src) {
- var iframe = document.createElement('iframe');
- iframe.setAttribute("id", iframeId);
- iframe.src = src;
- iframe.width = "720px";
- iframe.height = "150";
- iframe.scrolling = "no";
- iframe.setAttribute("title","blank");
- iframe.setAttribute("frameBorder","0");
- iframe.setAttribute("noresize","noresize");
- parentElement.appendChild(iframe);
- // Depending on browser platform get the iframe's document, this is only
- // available if the iframe has already been appended to an element which
- // has been added to the document
- if(iframe.contentDocument) {
- // Firefox, Opera
- iframe.doc = iframe.contentDocument;
- } else if(iframe.contentWindow) {
- // Internet Explorer
- iframe.doc = iframe.contentWindow.document;
- } else if(iframe.document) {
- // Others?
- iframe.doc = iframe.document;
- }
- // Return the iframe, now with an extra property iframe.doc containing the
- // iframe's document
- return iframe;
- }
- /**
- * Event handler for change the file in the file input control.
- * It prepares the form and submit it to the metadata service
- *
- */
- cognos.Prompt.Control.SelectFile.prototype.f_selectFileChange = function()
- {
- var inputElem = this.m_elPrompt;
- var v_sFileName = inputElem.value;
- var v_aNameSegments = v_sFileName.split(".");
- var v_fileExtension = v_aNameSegments[v_aNameSegments.length - 1].toLowerCase();
- var v_sPersonalDataFormat="";
- if ( v_fileExtension == "xml" ) {
- v_sPersonalDataFormat="XML";
- } else if ( v_fileExtension == "csv" ) {
- v_sPersonalDataFormat="CSV";
- } else if ( v_fileExtension == "xls" ) {
- v_sPersonalDataFormat="Excel2003";
- } else if ( v_fileExtension == "xlsx" ) {
- v_sPersonalDataFormat="Excel2003";
- }
- var v_oForm = inputElem.form;
- var v_sInSpec = '<input>';
- v_sInSpec += "<baseModelSearchPath>" + sXmlEncode(this["@baseModelSearchPath"]) + "</baseModelSearchPath>" ;
- v_sInSpec += '<dataSet type="' + v_sPersonalDataFormat + '">' ;
- v_sInSpec += "<name>" + sXmlEncode(this["@parameter"]) + "</name>" ;
- v_sInSpec += "<sourcePath>" + sXmlEncode(v_sFileName) + "</sourcePath>" ;
- v_oForm.inSpec.value = v_sInSpec + "</dataSet></input>";
- this.m_sFolderName ="";
- v_oForm.action = this.getGateway() + '/metadataUIService?pid=pdm_process&c=processPersonalData';
- var v_sIFrameId = this.f_CreateUploadIFrame();
- this.m_sUploadFrameId = v_sIFrameId;
- v_oForm.setAttribute('target', v_sIFrameId);
- v_oForm.submit();
- };
- cognos.Prompt.Control.SelectFile.prototype.f_CreateUploadIFrame = function ()
- {
- var v_sIFrameId = 'IFrame' + Math.floor(Math.random() * 11111);
- var v_oEle = document.createElement('DIV');
- v_oEle.innerHTML = '<iframe style="display:none" src="about:blank" content="text/xml" id="'+v_sIFrameId+'" name="'+ v_sIFrameId + '"></iframe>';
- document.body.appendChild(v_oEle);
- var iFrame = document.getElementById(v_sIFrameId);
- PRMTUtils.f_addEvent(iFrame, "load", this.f_UploadCallback.bind(this) );
- return v_sIFrameId;
- };
- cognos.Prompt.Control.SelectFile.prototype.f_UploadCallback = function (v_sIFrameId)
- {
- // complete the upload
- v_sIFrameId = this.m_sUploadFrameId;
- var v_oIFrameEle = document.getElementById(v_sIFrameId);
- var v_oDoc = window.frames[v_sIFrameId].document;
- if (v_oIFrameEle.contentDocument)
- {
- v_oDoc = v_oIFrameEle.contentDocument;
- }
- else if (v_oIFrameEle.contentWindow)
- {
- v_oDoc = v_oIFrameEle.contentWindow.document;
- }
- if (v_oDoc.location.href == "about:blank")
- {
- return;
- }
- this.f_CompleteUpload(v_oDoc);
- };
- /*Helper function to convert HTML entities into actual tags*/
- cognos.Prompt.Control.SelectFile.prototype.decodeHTML = function(htmlText) {
- var doDecode = function(htmlText) {
- var txt = document.createElement("textarea");
- txt.innerHTML = htmlText;
- return txt.value;
- };
- try {
- return doDecode(htmlText);
- } catch (e) {
- try {
- return doDecode(htmlText.replace(/</g, "<").replace(/>/g, ">"));
- } catch (e) {
- return htmlText;
- }
- }
- };
- cognos.Prompt.Control.SelectFile.prototype.f_CompleteUpload = function (v_oUploadResponseXML) {
- var xmlDoc = null;
- var v_sXMLString = null;
- if (v_oUploadResponseXML.implementation && v_oUploadResponseXML.implementation.createDocument)
- {
- //For Firefox & Safari
- try
- {
- var v_oSerializer = new XMLSerializer();
- if (window.XML) {
- xmlDoc = XML(v_oSerializer.serializeToString(v_oUploadResponseXML));
- v_sXMLString = xmlDoc.toXMLString();
- } else // Safari
- {
- v_sXMLString = v_oSerializer.serializeToString(v_oUploadResponseXML);
- }
- }
- catch (e)
- {
- var sError = v_oUploadResponseXML.body.textContent;
- var n1 = sError.indexOf("Mandatory parameter \"");
- var n2 = sError.indexOf("\" has not been specified");
- if (n1>=0 && n2>=0 && n2>n1)
- {
- alert(sError.substring(n1+21,n2));
- } else {
- alert("Error 1! "+sError);
- }
- return;
- }
- }
- else if ("ActiveXObject" in window)
- {
- //for IE
- if (null != v_oUploadResponseXML.XMLDocument)
- {
- xmlDoc = v_oUploadResponseXML.XMLDocument;
- // var v_sXMLString = v_oUploadResponseXML.XMLDocument.xml;
- v_sXMLString = xmlDoc.xml;
- } else {
- var sContent = v_oUploadResponseXML.body.innerText;
- if (sContent.match(/^.*\r?\n?.*<pdSpec>\r?\n?.*<dataSet/)) {
- v_sXMLString = sContent;
- } else {
- var n1 = sContent.indexOf("Mandatory parameter \"");
- var n2 = sContent.indexOf("\" has not been specified");
- if (n1>=0 && n2>=0 && n2>n1)
- {
- alert(sContent.substring(n1+21,n2));
- } else {
- alert("Error 2! "+sContent);
- }
- return;
- }
- }
- }
- this.m_sProcessResponse = v_sXMLString.replace(/.*<output>/g,"").replace(/<\/output>/g,""); // there should be no "output" element anymore but I'm going to leave this here just to be safe...
- this.checkData();
- };
- cognos.Prompt.Control.SelectFile.prototype.getValue = function()
- {
- return this.m_elPrompt.value;
- };
|