123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Viewer
- *| (C) Copyright IBM Corp. 2001, 2013
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- dojo.provide("bux.reportViewer.Properties");
- dojo.declare("bux.reportViewer.Properties", null, {
- iWidget : null,
- masterDialogSpec : null,
- masterDialogSpecProperties : null,
- flashChartSpec : null,
- isFlashChartOptionEnabled: true,
- oldProperties: null, // will contain the last set of properties. Used to compare to see what's changed
- dialogDisplayValues : null, // will contain the current set of properties
- constructor: function( iWidget, properties )
- {
- this.isInitialized = false;
- this.initializeDialogDisplayValues();
- this.oldProperties = {};
- this.iWidget = iWidget;
- if( properties === "<empty>")
- {
- return;
- }
- var json = dojo.eval("[" + properties + "]");
- if( json && json[0] )
- {
- this.initializeWithSavedPropertyValues(json[0]);
- }
- },
- initializeDialogDisplayValues: function() {
- /**
- * canUndo: if set to true, changing this property will cause the action to be put into the undo stack
- * runReport: if true, changing this property will cause the report to rerun
- * refreshSavedOutput: if true, changing this property will cause the saved output to get redrawn
- */
- this.dialogDisplayValues = { flashCharts: { value: null, canUndo: true, runReport: true },
- rowsPerPage: { value: null, canUndo: true, runReport: true },
- promptUserOnLoad: { value: false },
- retrieveAll: { value: false, refreshSavedOutput: true },
- showExpandCollapseIcon: { value: null }
- };
- },
- clearDialogSpec: function() {
- this.masterDialogSpec = null;
- this.masterDialogSpecProperties = null;
- },
- /**
- * Initialize the property values with the values that were saved with the dashboard
- * @param {Object} properties
- */
- initializeWithSavedPropertyValues: function(properties)
- {
- // The structure that we're saving the properties in is a little different then
- // what's needed by the dialog
- for (var prop in properties) {
- if (typeof prop != "undefined" && prop != null) {
- if (this.dialogDisplayValues[prop]) {
- this.dialogDisplayValues[prop].value = properties[prop];
- } else {
- this.dialogDisplayValues[prop] = { value: properties[prop], canUndo: false };
- }
- }
- }
- },
- /**
- * Helper function to set a property value without knowing the structure needed by the parent class
- * @param {String} property
- * @param {String} value
- */
- setProperty: function(property, value)
- {
- this.dialogDisplayValues[property].value = value;
- },
- /**
- * Helper function to get a property without having to know the structure of the properties are saved in
- * @param {String} property
- * @return null if the property isn't found
- */
- getProperty: function(property)
- {
- if (this.dialogDisplayValues[property])
- {
- return this.dialogDisplayValues[property].value;
- }
- return null;
- },
- /**
- * Helper function to get a an old property without having to know the structure the properties are saved in
- * @param {String} property
- * @return null if the property isn't found
- */
- getOldProperty: function(property)
- {
- if (this.oldProperties && this.oldProperties[property])
- {
- return this.oldProperties[property].value;
- }
- return null;
- },
- /**
- * Returns the last set of properties
- */
- getOldProperties: function()
- {
- /**
- * Need to make a new copy of the oldProperties. If we simply returned this.oldProperties,
- * it would return it as a reference. So any time this.oldProperties got updated it would
- * also change the values in the undoRedo queue (not good).
- */
- var oldProps = {};
- for (var prop in this.oldProperties) {
- if (this.dialogDisplayValues[prop].canUndo === true) {
- oldProps[prop] = {};
- oldProps[prop].value = this.oldProperties[prop].value;
- }
- }
- return oldProps;
- },
- /**
- * Called right before the properties dialog is opened.
- */
- onGet: function()
- {
- // Keep track of the old properties. Will be used if the user hits Ok to know if something has changed
- this.copyPropertyValues(this.dialogDisplayValues, this.oldProperties);
- if (!this.masterDialogSpec) {
- this.initializeDialogSpec();
- } else {
- this.updateDialogSpec();
- }
- var _payload = {
- tabTitle: this._getReportWidgetTabTitle(),
- properties: this.dialogDisplayValues,
- propertiesDialogSpec: this.masterDialogSpec
- };
- return _payload;
- },
- _getReportWidgetTabTitle: function() {
- var reportWidgetTabTitle;
- if( this.iWidget && this.iWidget.getViewerObject() )
- {
- reportWidgetTabTitle = RV_RES.IDS_REPORT_WIDGET_PROPERTY_TAB_TITLE;
- }
- return reportWidgetTabTitle;
- },
- /**
- * Called the the user hits the Ok button
- * @param {Object} payload
- */
- onSet: function( payload )
- {
- if( this.isSavedOutput() )
- {
- this.updateSavedOutput();
- }
- else
- {
- if( !this.runReportWithNewOptions() ){
- this._updateReport();
- }
- }
- },
-
- /*
- * For some properties,like Show expand/collapse icon, there is no need to rerun the report in order for the property to be
- * applied. This function updates report without re-running it and should only be called in the case that the report had not ran.
- * If the report had ran, there is no need to call it.
- */
- _updateReport : function(){
- //update report without having to run it again
- var newShowExpandCollapseIconFlag = this.getProperty('showExpandCollapseIcon');
- if( this.getOldProperty('showExpandCollapseIcon') != newShowExpandCollapseIconFlag ){
- var oCV = this.iWidget.getViewerObject();
- if( newShowExpandCollapseIconFlag === true ){
- oCV.insertExpandIconsForAllCrosstabs();
- } else {
- oCV.removeExpandIconsForAllCrosstabs();
- }
- }
-
- },
- /**
- * Copies the properties from an object to another
- * @param {Object} from
- * @param {Object} to
- */
- copyPropertyValues: function(from, to) {
- for (var prop in from) {
- if (!to[prop]) {
- to[prop] = {};
- }
- to[prop].value = from[prop].value;
- }
- },
- /**
- * Update the properties with the values from the undo stack. Only the properties that are
- * undoable will be updated
- * @param {Object} properties
- */
- doUndo: function( properties )
- {
- this.copyPropertyValues(properties, this.dialogDisplayValues);
- },
- /**
- * Returns only the properties that can be undone
- */
- getUndoInfo : function()
- {
- // we need to make sure initialized was called before adding anything to the undo stack
- if (!this.isInitialized) {
- var oCV = this.iWidget.getViewerObject();
- this.initialize(oCV.envParams);
- }
- var undoInfo = {};
- for (var prop in this.dialogDisplayValues) {
- if (this.dialogDisplayValues[prop].canUndo === true) {
- undoInfo[prop] = { value: this.getProperty(prop) };
- }
- }
- return undoInfo;
- },
- /**
- * Checked to see if any of the properties that would cause the
- * report to get run have changed
- * @param {String} propertyToCheck: liveReport or savedOutput
- */
- shouldUpdateReport: function(propertyToCheck)
- {
- for (var prop in this.dialogDisplayValues) {
- if (this.dialogDisplayValues[prop][propertyToCheck] == true && this.getOldProperty(prop) != this.getProperty(prop)) {
- return true;
- }
- }
- return false;
- },
- runReportWithNewOptions: function()
- {
- // only rerun the report if needed
- if (this.shouldUpdateReport('runReport'))
- {
- var oCV = this.iWidget.getViewerObject();
- var runReport = oCV.getAction("RunReport");
- runReport.setReuseQuery(true);
- runReport.execute();
- this.iWidget.getUndoRedoQueue().initUndoObj({"tooltip" : this.getUndoHint(), "saveSpec" : this.saveSpecForUndo()});
- return true;
- }
- return false;
- },
- updateSavedOutput: function()
- {
- if (this.shouldUpdateReport('refreshSavedOutput')) {
- var savedOutput = this.iWidget.getSavedOutput();
- savedOutput.setPagedOutput( !this.getRetrieveAll() );
- savedOutput.render();
- }
- },
- /**
- * Builds a string representing the properties to use when we do a save
- */
- toString: function()
- {
- var str = "{";
- for (var prop in this.dialogDisplayValues) {
- var propertyData = this.getProperty(prop);
- if (propertyData != null && typeof propertyData !== "undefined") {
- if (str != "{") {
- str += ", ";
- }
- str += "\"" + prop + "\": ";
- str += (typeof(propertyData)=='string') ? propertyData.toString() : dojo.toJson(propertyData);
- }
- }
- str += "}";
- return str;
- },
- isSavedOutput: function()
- {
- return this.iWidget.getViewerObject().envParams["ui.action"] === 'view';
- },
- getUndoHint: function()
- {
- return RV_RES.IDS_JS_WIDGET_PROPERTIES;
- },
- saveSpecForUndo: function()
- {
- return false;
- },
- getRetrieveAll: function()
- {
- return this.getProperty("retrieveAll");
- },
- getPromptUserOnLoad: function()
- {
- return this.getProperty("promptUserOnLoad");
- },
- getFlashCharts: function()
- {
- return this.getProperty("flashCharts");
- },
- getRowsPerPage: function()
- {
- return this.getProperty("rowsPerPage");
- },
- getOriginalReportLocation: function(widget)
- {
- if(widget.getAttributeValue && !widget.getAttributeValue("originalReport")){
- return RV_RES.IDS_JS_PROPERTY_ORIGINAL_REPORT_LOCATION + " " + RV_RES.IDS_JS_PROPERTY_ORIGINAL_REPORT_LOCATION_UNAVAILABLE;
- }
- var sReportLocation = widget.getViewerObject().envParams["originalReportLocation"];
- if(typeof sReportLocation == "undefined" || sReportLocation == null || sReportLocation == "Unavailable")
- {
- return RV_RES.IDS_JS_PROPERTY_ORIGINAL_REPORT_LOCATION + " " + RV_RES.IDS_JS_PROPERTY_ORIGINAL_REPORT_LOCATION_UNAVAILABLE;
- }
- return (RV_RES.IDS_JS_PROPERTY_ORIGINAL_REPORT_LOCATION + " " + sReportLocation);
- },
- getShowExpandCollapseIconFlag : function()
- {
- return this.getProperty('showExpandCollapseIcon');
- },
-
- /**
- * This returns the Advanced Server settings in Cognos Admin for the specified property
- */
- getAdvancedServerProperty : function( property )
- {
- if( !this.iWidget && !this.iWidget.getViewerObject() ){ return null;}
-
- return this.iWidget.getViewerObject().getAdvancedServerProperty( property );
- },
-
- /**
- * If server setting is undefined - do not show the option, therefore, do not update the property value.
- * If server setting is defined, set the widget property value only there is no saved value.
- */
- initializeShowExpandCollapseIconFlag : function(){
- var sAdvancedServerPropertyValue = this.getAdvancedServerProperty( 'VIEWER_JS_EXPAND_COLLAPSE_CONTROLS_DEFAULT' );
- this.bHideExpandCollapseOption = (!sAdvancedServerPropertyValue );
- if( this.bHideExpandCollapseOption ){
- return;
- }
-
- if( this.getShowExpandCollapseIconFlag() === null ){
- this.setProperty( 'showExpandCollapseIcon', sAdvancedServerPropertyValue.toLowerCase() === 'on' );
- }
- },
-
- /**
- * The settings are updated based on server configuration.
- */
- initialize: function( envParams )
- {
- if( this.isInitialized )
- {
- return;
- }
- this.isInitialized = true;
- this.initializeFlashChartSettings( envParams.flashChartOption );
- this.initializeShowExpandCollapseIconFlag();
-
- if (this.getRowsPerPage() == null)
- {
- if (envParams["run.verticalElements"] != null)
- {
- this.setProperty("rowsPerPage", envParams["run.verticalElements"]);
- }
- else
- {
- // 20 is the default used in rsvp, so if we didn't find the vertical element in CM,
- // set it to the default of 20 so the UI matches the report
- this.setProperty("rowsPerPage", 20);
- }
- }
- this.initializeDialogSpec();
- },
- createViewReportSpecLink: function()
- {
- var oCV = this.iWidget.getViewerObject();
- var reportSpec = oCV.envParams["ui.spec"];
- // only show the link to get the report spec if the user is a report author
- // and he's not viewing saved output
- if (oCV.bCanUseReportStudio && reportSpec && reportSpec.length > 0 && oCV.envParams["ui.action"] != "view") {
- return {columns:
- [
- {
- propertyName: 'viewReportSpecification',
- uiElementType: 'link',
- label: RV_RES.IDS_JS_SHOW_REPORT_SPEC,
- eventHandler: this,
- onClickAction: dojo.hitch( this, this.onClickViewReportSpecification)
- }
- ]
- };
- }
- else {
- return {};
- }
- },
-
- isBlackListedOption : function( optionName ){
- return this.iWidget.getViewerObject().isBlacklisted( optionName );
- },
- createFlashChartOption: function()
- {
- var flashChartOptionSpec =
- [
- {
- columns:
- [
- {
- propertyName: 'flashCharts',
- uiElementType: "checkBox",
- label: RV_RES.IDS_JS_PROPERTY_FLASHCHARTS
- }
- ]
- },
- {
- columns:
- [
- {
- uiElementType: "hSpacer"
- }
- ]
- }
- ];
- return flashChartOptionSpec;
- },
-
- getShowExpandCollapseIconOptionSpec : function()
- {
- var spec = [
- {
- columns:
- [
- {
- propertyName: 'showExpandCollapseIcon',
- uiElementType: 'checkBox',
- label: RV_RES.IDS_JS_PROPERTY_SHOW_EXPAND_COLLAPSE_ICON
- }
- ]
- },
- {
- columns:
- [
- {
- uiElementType: 'hspacer'
- }
- ]
-
- }
- ];
-
- return spec;
- },
- generateDialogSpec : function(role)
- {
- var masterDialogSpecArray;
- if(role=='consume')
- {
- masterDialogSpecArray =
- [
- {
- columns:
- [
- {
- propertyName: 'rowsPerPage',
- uiElementType: 'textBox',
- type: 'number',
- label: RV_RES.IDS_JS_PROPERTY_ROWS_PER_PAGE
- }
- ]
- }
- ];
- this.masterDialogSpec = { rows: masterDialogSpecArray };
- }
- else
- {
- var viewReportSpecification = this.createViewReportSpecLink();
- masterDialogSpecArray =
- [
- {
- columns:
- [
- {
- propertyName: 'rowsPerPage',
- uiElementType: 'textBox',
- type: 'number',
- label: RV_RES.IDS_JS_PROPERTY_ROWS_PER_PAGE,
- constraints:{min:1,max:1000},
- required:true,
- invalidMessage: RV_RES.IDS_JS_PROPERTY_ROWS_PER_PAGE_ERROR
- }
- ]
- },
- {
- columns:
- [
- {
- uiElementType: 'hspacer'
- }
- ]
- },
- {
- columns:
- [
- {
- propertyName: 'promptUserOnLoad',
- uiElementType: 'checkBox',
- label: RV_RES.IDS_JS_PROPERTY_PROMPT_ON_LOAD
- }
- ]
- },
- {
- columns:
- [
- {
- propertyName: 'retrieveAll',
- uiElementType: 'checkBox',
- label: RV_RES.IDS_JS_PROPERTY_RETRIEVE_ENTIRE_REPORT
- }
- ]
- },
- viewReportSpecification,
- {
- columns:
- [
- {
- propertyName: 'originalReportLocation',
- uiElementType: 'text',
- label: this.getOriginalReportLocation(this.iWidget),
- allowWrapping: true
- }
- ]
- }
- ];
- if( this.isFlashChartOptionEnabled && !this.hasAVSChart() && role!== 'consume' )
- {
- var flashChartOption = this.createFlashChartOption();
- masterDialogSpecArray = flashChartOption.concat( masterDialogSpecArray );
-
- }
-
- if( !this.bHideExpandCollapseOption && !this.isBlackListedOption( 'ExpandMember' ) )
- {
- masterDialogSpecArray = this.getShowExpandCollapseIconOptionSpec().concat( masterDialogSpecArray );
- }
-
- this.masterDialogSpec = { rows: masterDialogSpecArray };
- }
- if(this.masterDialogSpec && this.masterDialogSpec.rows) {
- this.masterDialogSpecProperties = {};
- for(var r in this.masterDialogSpec.rows) {
- var row = this.masterDialogSpec.rows[r];
- if(row.columns) {
- for(var c in row.columns) {
- var col = row.columns[c];
- if(col.propertyName) {
- this.masterDialogSpecProperties[col.propertyName] = col;
- }
- }
- }
- }
- }
- },
- updateDialogSpec: function()
- {
- if(this.masterDialogSpecProperties) {
- if(this.masterDialogSpecProperties.originalReportLocation) {
- this.masterDialogSpecProperties.originalReportLocation.label = this.getOriginalReportLocation(this.iWidget);
- }
- }
- },
- initializeDialogSpec: function()
- {
- var userRole = this.iWidget.getUserRole();
- this.generateDialogSpec(userRole);
- },
- hasAVSChart: function()
- {
- if (this.iWidget == null || typeof this.iWidget.getViewerObject() == "undefined")
- {
- return false;
- }
- var oCV = this.iWidget.getViewerObject();
- if (typeof oCV == "undefined")
- {
- return false;
- }
- return oCV.hasAVSChart();
- },
- initializeFlashChartSettings: function( value )
- {
- if( !value )
- {
- return;
- }
- var json = ( typeof value === "string") ? (eval( value) ) : value ;
- var flashChartOptions = json[0];
- this.setProperty("flashCharts", flashChartOptions.defaultValue);
- this.isFlashChartOptionEnabled= !flashChartOptions.isOptionDisabled;
- },
- onClickViewReportSpecification: function()
- {
- var sUiSpec = this.iWidget.getViewerObject().envParams["ui.spec"];
- this._viewSpecInWindow(sUiSpec);
- },
- _getWindowOptions: function( w, h )
- {
- var sOptions = 'resizable=yes,scrollbars=yes,menubar=no,directories=no,location=no,status=no,toolbar=no,titlebar=no';
- var left = (screen.width - w)/2;
- var top = (screen.height - h)/2;
- sOptions += ',top=' + top;
- sOptions += ',left=' + left;
- sOptions += ',width=' + w;
- sOptions += ',height=' + h;
- return sOptions;
- },
- _viewSpecInWindow: function(sUiSpec)
- {
- var viewport = dijit.getViewport();
- var sWindowId = 'debugWindow' + this.iWidget.getViewerObject().getId();
- var sOptions = this._getWindowOptions(viewport.w, viewport.h);
- var oWindow = window.open("", sWindowId, sOptions);
- var head = '<html><body><table width="100%" cellspacing="0" cellpadding="0" border="0">' +
- '<tbody><tr><td>' +
- '<textarea wrap="off" style="font-family:arial; font-size: 10px; overflow: auto; width:100%; height:';
- head += viewport.h*0.95;
- head += 'px;">';
- var tail = '</textarea></td></tr></tbody></table></body></html>';
- oWindow.document.write( head + html_encode(sUiSpec) + tail );
- }
- });
|