//Licensed Materials - Property of IBM //IBM Cognos Products: cpscrn //(C) Copyright IBM Corp. 2013 //US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. /* Note: The following must be included in any HTML page using this javascript */ function CMObjectSelect(selectorID, parentID, cancelCallback, okCallback, selectionTypes, context){ window[selectorID] = this; this.context = context; this.selectorID = selectorID; this.parentID = parentID; this.cancelCallback = cancelCallback; this.okCallback = okCallback; this.selectionTypes = selectionTypes; this.selection; this.objectPager; this.breadStack = new Array(); this.objectPagerURL = context.getProxiedURI(context.getGatewayURI() + '/atom/cm?json=true'); this.pagerWebcontent = context.getWebContentURI(); } CMObjectSelect.prototype = { render:function(){ var selectorDiv = document.createElement("div"); selectorDiv.id = this.selectorID; //We default the object selector to be hidden selectorDiv.style.display = "none"; var outerBreadcrumbDiv = document.createElement("div"); var outerPagerDiv = document.createElement("div"); var outerButtonDiv = document.createElement("div"); var breadcrumbDiv = document.createElement("div"); var pagerDiv = document.createElement("div"); var buttonDiv = document.createElement("div"); breadcrumbDiv.id = this.selectorID + "_breadcrumb"; pagerDiv.id = this.selectorID + "_objectPager"; buttonDiv.id = this.selectorID + "_selectbuttons"; outerBreadcrumbDiv.style.padding = "3px"; outerPagerDiv.style.padding = "3px"; outerButtonDiv.style.padding = "3px"; var parent = document.getElementById(this.parentID); parent.appendChild(selectorDiv); selectorDiv.appendChild(outerBreadcrumbDiv); selectorDiv.appendChild(outerPagerDiv); selectorDiv.appendChild(outerButtonDiv); outerBreadcrumbDiv.appendChild(breadcrumbDiv); outerPagerDiv.appendChild(pagerDiv); outerButtonDiv.appendChild(buttonDiv); this._initializeBreadcrumb(); this._createPager(); this._createButtons(); }, _cmObject:function(storeID, type, tooltip, iconLink, downloadLink, pathString) { this.storeID = storeID; this.type = type; this.tooltip = tooltip; this.iconLink = iconLink; this.downloadLink = downloadLink; this.pathString = pathString; }, _createPager:function() { var objectPagerLayout; var _self = this; objectPagerLayout = [ { field: 'title', name: 'Select Object', width: '100%', formatter: function(data, index) { var entry = _self.objectPager.getEntry(index); var storeID = _self._parseStoreID(entry.cm$storeID[0]); var type = entry.cm$objectClass[0]; var tooltip = data._text; var iconLink = _self.context.makeAbsolute(_self.pagerWebcontent,_self.objectPager.getEntryLink(entry, 'icon').href); var downloadLink = ""; if (_self.objectPager.getEntryLink(entry, 'alternate') != undefined && _self.objectPager.getEntryLink(entry, 'alternate').type == "application/atom+xml") { downloadLink = _self.context.getProxiedURI(_self.context.makeAbsolute(_self.context.getGatewayURI(),_self.objectPager.getEntryLink(entry, 'alternate').href)); } var burstKey = entry.cm$burstKeyDisplayString[0]; var markup = '
'; if (downloadLink != "") { markup += ''; markup += ''; markup += '
'; } else { markup += ''; markup += tooltip + ''; } return markup; } } ]; this.objectPager = new ps.pager({ id: this.selectorID + '_objectPager', webcontent: this.pagerWebcontent, url: this.objectPagerURL, layoutSpec: objectPagerLayout, rowAction: dojo.hitch(this, this._updateSelection), initialRowSelect:true}, this.selectorID + '_objectPager'); var temp = ''; }, _updateSelection:function(entry) { var downloadLink = ""; if (this.objectPager.getEntryLink(entry, 'alternate') != undefined && this.objectPager.getEntryLink(entry, 'alternate').type == "application/atom+xml") { downloadLink = this.context.getProxiedURI(this.context.getGatewayURI(),this.objectPager.getEntryLink(entry, 'alternate').href); } var pathString = this._buildStringPath(); var cmObj = new this._cmObject( this._parseStoreID(entry.cm$storeID[0]), entry.cm$objectClass[0], entry.title[0]._text, this.context.makeAbsolute(this.pagerWebcontent,this.objectPager.getEntryLink(entry, 'icon').href), downloadLink, pathString ); this.selection = cmObj; this._updateOKButton(); }, _createButtons:function() { var markup = ''; markup += ""; markup += "
"; markup += "\"\""; markup += "
"; markup += ""; markup += ""; markup += ""; markup += ""; markup += "
"; markup += "\"\""; markup += ""; markup += ""; markup += ""; markup += ""; markup += ""; markup += ""; markup += "
"; markup += "\"\"
"; markup += ""; markup += "
\"\" "; markup += "\"\"
"; markup += "\r\n"; markup += "
\"\"
"; document.getElementById(this.selectorID + "_selectbuttons").innerHTML = markup; }, _parseStoreID:function(originalID) { var location = originalID.indexOf('\'') + 1; var newID = originalID.substring(location, originalID.length); location = newID.indexOf('\''); newID = newID.substring(0, location); return newID; }, _digIntoObject:function(storeID, type, tooltip, iconLink, downloadLink, breadcrumbCall) { var cmObj = new this._cmObject(storeID, type, tooltip, iconLink, downloadLink); this._updateBreadcrumb(breadcrumbCall, cmObj); //update the pager this.objectPager.getData(downloadLink); }, _initializeBreadcrumb:function() { var root = new this._cmObject("","root","Cognos","", this.objectPagerURL); this.breadStack.push(root); document.getElementById(this.selectorID + "_breadcrumb").innerHTML = this._buildBreadcrumb();; }, _buildLink:function(cmObj) { var markup = ''; markup += '
'; return markup; }, _buildBreadcrumb:function() { var markup = ''; for(var i = 0; i < this.breadStack.length - 1; i++) { markup += this._buildLink(this.breadStack[i]); markup += " > "; } markup += this.breadStack[this.breadStack.length - 1].tooltip; return markup; }, _buildStringPath:function() { var markup = ''; for(var i = 0; i < this.breadStack.length; i++) { markup += this.breadStack[i].tooltip; markup += " > "; } return markup; }, _updateBreadcrumb:function(isBreadcrumbCall, newCMObj) { if (isBreadcrumbCall == true) { var flag = false; while (flag == false) { if (this.breadStack.length <= 0) { break; } var crumb = this.breadStack.pop(); if (crumb.storeID == newCMObj.storeID) { this.breadStack.push(newCMObj); flag = true; } } } else { this.breadStack.push(newCMObj); } var breadcrumb = this._buildBreadcrumb(); document.getElementById(this.selectorID + "_breadcrumb").innerHTML = breadcrumb; }, _updateOKButton:function() { if (this._arrayContains(this.selectionTypes, this.selection.type)) { //Allow button to be pressed document.getElementById(this.selectorID + "_obSelOK").disabled = false; document.getElementById(this.selectorID + "_obSelOK").setAttribute("class","commandButton"); } else { //Prevent button from being pressed document.getElementById(this.selectorID + "_obSelOK").disabled = true; document.getElementById(this.selectorID + "_obSelOK").setAttribute("class","commandButtonInactive"); } }, _arrayContains:function(array, item) { for(var i = 0; i < array.length; i++) { if (array[i] === item) { return true; } } return false }, _cancelSelection:function(){ this.cancelCallback(); }, _acceptSelection:function(){ this.okCallback(new Array(this.selection)); }, //Fixes issue where grid does not appear until window is resized resizePager:function(){ this.objectPager.grid.resize(); } }