// Licensed Materials - Property of IBM // // IBM Cognos Products: cpscrn // // (C) Copyright IBM Corp. 2005, 2013 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. function CCAppEditor(id, context){ this.id = id; this.context = context; window[id] = this; this.idGenCounter = 0; this.objectSelectMap = {}; } CCAppEditor.prototype = { _generateId: function(){ return this.id + this.idGenCounter++; }, getAppId: function (){ return this.id; }, getUniqueId: function (name){ return this.getAppId() + name; }, render: function(){ // Fetch the list of applications var _self = this; var xhr = this.context._getXHR({ onSuccess: function(obj){ try { var response = JSON.parse(obj.responseText); _self.applications = response.applications; var appId = _self.context.getSetting('app.id'); if (appId){ _self.renderApplicationSettings(appId); }else { _self.renderApplicationList(); } } catch (e) { console.log(e); } } }); xhr.open('GET', this.context.getProxiedURI(this.context.getGatewayURI() + '?b_action=xts.run&m=cps4/portlets/sdk2/service/getapps.xts')); xhr.send(); // Check the current App setting. }, _getApp:function(id){ var app = null; if (this.applications && this.applications.applicationList){ for (var i = 0 ; i< this.applications.applicationList.length; i++){ if (this.applications.applicationList[i].id == id ){ app = this.applications.applicationList[i]; break; } } } return app; }, renderApplicationSettings:function(appId){ var app = this._getApp(appId); this.currentApp = app; if (app){ var html = this._getEditPageHeader(app); html += this._getEditPageContent(app); } var mainDiv = document.getElementById(this.getUniqueId('EditorMain')); mainDiv.innerHTML = html; }, _getEditPageHeader:function(app){ var html = '
'; html+= this.htmlEncode(this._getMessageFromObject(app.title)); html+='
'; html+='Change selected application'; html+='
'; html+='
'; return html; }, _getEditPageContent:function(app){ var html = '
'; html +='
'; html += ''; html += ''; if (app.messagefile != undefined) { html += ''; } if (app.path != undefined) { html += ''; } if (app.features && app.features.featureList){ html += ''; } if (app.properties && app.properties.propertyGroupList){ for (var i = 0 ; i < app.properties.propertyGroupList.length; i++){ html+= this._getEditPageGroup(app.properties.propertyGroupList[i]); } } html += '
'; html += ''; html += '  '; html += ''; html += '  '; html += ''; html += '
'; html+='
'; html+='
'; return html; }, _getEditPageGroup: function(group){ var html = '
'; html += '
'; html += this.htmlEncode(this._getMessageFromObject(group.title)); html+='
'; if (group.propertyList){ for (var i = 0 ; i 0 ? valueList[0]: ''; // Text control html += '' + path + ''; html += ''; html += '' + tooltip + ''; html += 'Select an object... '; html += 'Clear'; html += ''; html += ''; html += ''; html += ''; } return html; }, _getChoice:function(property, choice, type, name, group, checked, isDisabled, id){ var choiceDependents = property.dependents[choice.value]; var hasDependents = choiceDependents && choiceDependents.length > 0; var html = ''; // Render dependent properties if (hasDependents){ html +='
'; for (var i = 0; i < choiceDependents.length; i++){ html += this._getEditPageProperty(choiceDependents[i], group); } html+='
'; } return html; }, _getPropertyValueList: function(property) { var value = this.context.getSettingValues(property.name); if(value === undefined && property.control){ value = property.control.defaultValueList; } if(value === undefined){ value = []; } return value; }, _getControlAttribute: function(property, attribute, defaultValue ){ var value; if(property.control){ value = property.control[attribute]; } if (!value){ value = defaultValue; } return value; }, _getPropertyById:function(id){ if (this.currentApp.properties && this.currentApp.properties.propertyGroupList ){ for (var i = 0 ; i< this.currentApp.properties.propertyGroupList.length; i++){ var group = this.currentApp.properties.propertyGroupList[i]; if (group.propertyList){ for (var i = 0 ; i '; var icon = this.applications.applicationList[i].icon; html += '' if (icon){ html += ''; }else{ html += ''; } html += '
'; html += ''; html += ''; html += ''; html += ''; html += '
'; html += this.htmlEncode(this._getMessageFromObject(this.applications.applicationList[i].title)); html += '
'; html += '
'; html += this.htmlEncode(this._getMessageFromObject(this.applications.applicationList[i].description)); html += '
'; html += '
'; html += ''; html +='
'; } } html+=''; var mainDiv = document.getElementById(this.getUniqueId('EditorMain')); mainDiv.innerHTML = html; var _self = this; var entries = this.getElementsByClassName(mainDiv, 'cogAppEntry'); for (var i = 0 ; i < entries.length; i++){ entries[i].onclick = function(event){ _self.renderApplicationSettings(this.id); }; } }, _objectSelectClear: function(selectorID) { document.getElementById(selectorID + "_path").innerHTML =''; document.getElementById(selectorID + "_icon").src = ''; document.getElementById(selectorID + "_tooltip").innerHTML = ''; document.getElementById(selectorID + "_clear").style.display = 'none'; document.getElementById(selectorID + "_input").value = ''; document.getElementById(selectorID + "_inputPath").value =''; document.getElementById(selectorID + "_inputImg").value = ''; document.getElementById(selectorID + "_inputName").value = ''; }, _objectSelect:function(selectorID) { document.getElementById(this.getUniqueId('EditorMain')).style.display = 'none'; document.getElementById(selectorID).style.display = 'block'; this.objectSelectMap[selectorID].resizePager(); }, /******* Utility functions ******/ scope: function(scope, func){ return function(){ func.apply(scope, arguments); } }, getElementsByClassName: function(node, className){ return node.getElementsByClassName(className); }, indexOf: function(array, value){ return array.indexOf(value +''); }, /*Not used so far */ replaceTokens:function(template, tokenValues){ for (var name in tokenValues){ template.replace('$'+name+'$', tokenValues[name]); } return template; }, /*Not used so far */ cancelEventBuble: function(e){ var evt = e ? e:window.event; if (evt.stopPropagation){ evt.stopPropagation(); } if (evt.cancelBubble!=null){ evt.cancelBubble = true; } }, htmlEncode: function(text) { return text.toString() .replace(/\&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); }, /*Not used so far */ getCssMapping: function(originalClass) { var newClass = this.context.getCssMapping(originalClass); if (!newClass) { return originalClass; } return newClass; } }