| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- /* Copyright (c) Business Objects 2006. All rights reserved. */
- if (typeof bobj.crv.params.FlexParameterUI == 'undefined') {
- bobj.crv.params.FlexParameterUI = {};
- }
- /*
- ================================================================================
- FlexParameterUI
- Base functionality for flex prompting UI
- ================================================================================
- */
- bobj.crv.params.FlexParameterUI = function() {
- var _swfID = [];
- var _swf = [];
- var _promptData = [];
- var _paramCtrl = [];
- var _currentIParam = [];
- var _closeDialogCallBack = [];
- var _viewerLayoutType = [];
- var _moveArea;
-
- // Holder for information about interactive parameters
- var _iParamsPromptUnitData = [];
- var _iParamsParamData = [];
- };
- bobj.crv.params.FlexParameterUI.setViewerLayoutType = function(viewerName, layout) {
- if (!this._viewerLayoutType) {
- this._viewerLayoutType = [];
- }
-
- this._viewerLayoutType[viewerName] = layout;
- };
- bobj.crv.params.FlexParameterUI.setPromptData = function(viewerName, promptData) {
- if (!this._promptData) {
- this._promptData = [];
- }
-
- this._promptData[viewerName] = promptData;
- };
- bobj.crv.params.FlexParameterUI.setCurrentIParamInfo = function(viewerName, paramCtrl, param) {
- if (!this._paramCtrl) {
- this._paramCtrl = [];
- }
-
- if (!this._currentIParam) {
- this._currentIParam = [];
- }
-
- this._paramCtrl[viewerName] = paramCtrl;
- this._currentIParam[viewerName] = param;
- };
- bobj.crv.params.FlexParameterUI.setCloseDialogCallBack = function(viewerName, closeDialogCallBack) {
- if (!this._closeDialogCallBack) {
- this._closeDialogCallBack = [];
- }
- this._closeDialogCallBack[viewerName] = closeDialogCallBack;
- };
- bobj.crv.params.FlexParameterUI.addIParamPromptUnitData = function (viewerName, promptUnitID, paramNames, promptData)
- {
- if (!this._iParamsPromptUnitData) {
- this._iParamsPromptUnitData = [];
- }
-
- if (!this._iParamsPromptUnitData[viewerName]) {
- this._iParamsPromptUnitData[viewerName] = [];
- }
-
- if (!this._iParamsParamData) {
- this._iParamsParamData = [];
- }
-
- if (!this._iParamsParamData[viewerName]) {
- this._iParamsParamData[viewerName] = [];
- }
-
- this._iParamsPromptUnitData[viewerName][promptUnitID] = promptData;
- for(var i = 0, len = paramNames.length; i < len; i++) {
- var paramName = paramNames[i];
- this._iParamsParamData[viewerName][paramName] = promptUnitID;
- }
- };
- bobj.crv.params.FlexParameterUI.getSWF = function(viewerName) {
- if (!this._swfID || !this._swfID[viewerName]) {
- return;
- }
- if (!this._swf) {
- this._swf = [];
- }
- if(this._swf[viewerName]) {
- return this._swf[viewerName];
- } else {
- var swf = document.getElementById(this._swfID[viewerName]);
- if (!swf) {
- return;
- }
- this._swf[viewerName] = swf;
- return swf;
- }
- };
- bobj.crv.params.FlexParameterUI.getInstallHTML = function () {
- return L_bobj_crv_FlashRequired.replace("{0}", "<br><a href='http://www.adobe.com/go/getflash/' target='_blank'>") + "</a>";
- };
- bobj.crv.params.FlexParameterUI.checkFlashPlayer = function () {
- return swfobject.hasFlashPlayerVersion("9.0.0");
- };
- /**
- * Creates the swf and replaces the div specified with the flash object.
- */
- bobj.crv.params.FlexParameterUI.createSWF = function(viewerName, divID, servletURL, isIParamDialog) {
- if (!this._swfID) {
- this._swfID = [];
- }
-
- bobj.crv.logger.info('Create the SWF');
-
- if (this.checkFlashPlayer()){
- var lang = bobj.crv.getLangCode ();
- var swfBaseURL = bobj.crvUri("../../swf/");
- var swfPath = swfBaseURL + "prompting.swf";
- var swfID = bobj.uniqueId();
-
- var flashvars = {"eventTarget":viewerName, "locale":lang, "isIParamDialog":isIParamDialog, "baseURL":swfBaseURL, "servletURL":servletURL};
-
- // Important: Do not specify play=true as one of the params. If this is set to true we could end up in an infinite loop reloading
- // the swf when viewing using the embedded browser in eclipse.
- var params = {menu:"false", wmode:"window", allowscriptaccess:"sameDomain"};
- var attributes = {id:swfID, name:swfID, style:'z-index:' + bobj.constants.modalLayerIndex};
- // Does not work in IE for some reason, used in other browsers to hide the
- // dialog until it has been positioned properly to prevent snapping.
- if (!MochiKit.Base.isIE()){
- document.getElementById(divID).parentNode.style.visibility = 'hidden';
- }
- swfobject.embedSWF(swfPath, divID, "360", "50", "9.0.0", "", flashvars, params, attributes);
- this._swfID[viewerName] = swfID;
-
- var v = getWidgetFromID(viewerName);
- if (v && v._reportProcessing){
- v._reportProcessing.delayedShow(false);
- }
- } else {
- document.getElementById(divID).innerHTML = "<p>" + this.getInstallHTML() +"</p>";
- }
- };
- /**
- * This function will initialize the data in the flex swf with the
- * current state of the parameter ui. The Flex swf will call back to
- * this method when it has first been created and all external interface
- * connections have been setup. If the swf has already been created this will
- * be called when showing the parameter UI.
- */
- bobj.crv.params.FlexParameterUI.init = function (viewerName) {
- if (!viewerName || !this._swfID || !this._swfID[viewerName]) {
- return;
- }
- bobj.crv.logger.info('Init the SWF');
-
- var swf = this.getSWF(viewerName);
- if (!swf) {
- return;
- }
-
- var v = getWidgetFromID(viewerName);
- if (v && v._reportProcessing){
- v._reportProcessing.cancelShow();
- }
-
- if (swf.setStateInfo){
- var toJSON = MochiKit.Base.serializeJSON;
- swf.setStateInfo(encodeURIComponent(toJSON(bobj.crv.stateManager.getCompositeState())));
- }
- if (swf.setIdealHeight){
- var lTypes = bobj.crv.Viewer.LayoutTypes;
- var layout = lTypes.CLIENT;
- if (this._viewerLayoutType && this._viewerLayoutType[viewerName]){
- layout = this._viewerLayoutType[viewerName];
- }
-
- var lDim = MochiKit.Style.getElementDimensions(getLayer(viewerName));
- var min = layout === lTypes.FIXED ? 0 : 400;
-
- swf.setIdealHeight(Math.max(min, lDim.h - 20));
- }
-
- if (this._currentIParam && this._currentIParam[viewerName]){
- if(!this._iParamsParamData || !this._iParamsParamData[viewerName] || !this._iParamsPromptUnitData || !this._iParamsPromptUnitData[viewerName] ) {
- this.setPromptData(viewerName, null);
- }
- else {
- var promptUUID = this._iParamsParamData[viewerName][this._currentIParam[viewerName].paramName];
- if (!promptUUID){
- this.setPromptData(viewerName, null);
- }
-
- var promptData = this._iParamsPromptUnitData[viewerName][promptUUID];
- this.setPromptData(viewerName, promptData);
- }
- }
-
- if(this._promptData && this._promptData[viewerName] && swf.setPromptData){
- swf.setPromptData(this._promptData[viewerName]);
- }
- };
- /**
- * Flex callback for setting the values from the flex widget
- */
- bobj.crv.params.FlexParameterUI.setIParamValues = function(viewerName, isCascading, vals, updatedXMLData)
- {
- if (!this._paramCtrl || !this._currentIParam || !this._iParamsParamData || !this._iParamsPromptUnitData) {
- return;
- }
-
- var cParam = this._currentIParam[viewerName];
- var pCtrl = this._paramCtrl[viewerName];
- var pData = this._iParamsParamData[viewerName];
- var pUnitData = this._iParamsPromptUnitData[viewerName];
-
- if (!cParam || !pCtrl || !pData || !pUnitData) {
- return;
- }
-
- var cParamName = cParam.paramName;
-
- if (isCascading){
- for(var i = 0, len = vals.length; i < len; i++) {
- var value = vals[i];
- if (!value.name || !value.values){
- continue;
- }
-
- pCtrl.updateParameter(value.name, value.values);
- }
- } else {
- pCtrl.updateParameter(cParamName, vals);
- }
- pCtrl._updateToolbar();
-
- var uid = pData[cParamName];
- if (uid){
- pUnitData[uid] = updatedXMLData;
- }
-
- this.closeIParamDialog(viewerName);
- };
- /**
- * Flex callback for closing the current dialog window.
- */
- bobj.crv.params.FlexParameterUI.closeIParamDialog = function (viewerName)
- {
- if (this._closeDialogCallBack && this._closeDialogCallBack[viewerName]) {
- this._closeDialogCallBack[viewerName]();
- }
- };
- /**
- * Flex callback for adjusting the size of the swf to fit the number of
- * prompts being displayed.
- */
- bobj.crv.params.FlexParameterUI.resize = function (viewerName, height, width)
- {
- var swf = this.getSWF(viewerName);
- if (swf){
- bobj.crv.logger.info('Resizing the SWF h:' + height + ' w:' + width);
- swf.style.width = width + 'px';
- swf.style.height = height + 'px';
-
- var P_STYLE = swf.parentNode.style;
- P_STYLE.position = 'absolute';
- P_STYLE.visibility = 'visible';
- }
- };
- /**
- * Flex callback for adjusting the size of the swf to fit the number of
- * prompts being displayed.
- */
- bobj.crv.params.FlexParameterUI.center = function (viewerName, wOnly)
- {
- var swf = this.getSWF(viewerName);
- if (swf){
- var LOG = bobj.crv.logger;
- LOG.info('Centering the SWF');
-
- var l = getLayer(viewerName);
- if (!l){
- LOG.error('Could not find the viewer:' + viewerName);
- return;
- }
-
- var vPos = MochiKit.Style.getElementPosition(l);
- var vDim = MochiKit.Style.getElementDimensions(l);
- var sDim = MochiKit.Style.getElementDimensions(swf);
-
- var P_STYLE = swf.parentNode.style;
- if (!wOnly){
- P_STYLE.top = Math.max(vPos.y, vPos.y + (vDim.h / 2) - (sDim.h / 2)) + 'px';
- }else {
- P_STYLE.top = (vPos.y + 10) + 'px';
- }
-
- P_STYLE.left = Math.max(vPos.x, vPos.x + (vDim.w / 2) - (sDim.w / 2)) + 'px';
-
- if (swf.focus != undefined){
- swf.focus();
- }
- }
- };
- /**
- * Flex callback to start moving the dialog
- */
- bobj.crv.params.FlexParameterUI.startMove = function (viewerName)
- {
- var swf = this.getSWF(viewerName);
- if (swf){
-
- if (this._moveArea){
- return;
- }
-
- this._moveArea = document.createElement('div');
- this._moveArea.id = bobj.uniqueId();
- MOVE_STYLE = this._moveArea.style;
-
- var STYLE = swf.style;
- var P_STYLE = swf.parentNode.style;
-
- MOVE_STYLE.top = P_STYLE.top;
- MOVE_STYLE.left = P_STYLE.left;
- MOVE_STYLE.width = STYLE.width;
- MOVE_STYLE.height = STYLE.height;
- MOVE_STYLE.border = '1px';
- MOVE_STYLE.borderStyle = 'solid';
- MOVE_STYLE.borderColor = '#000000';
- MOVE_STYLE.backgroundColor = '#FFFFFF';
- MOVE_STYLE.position = 'absolute';
- MOVE_STYLE.opacity = 0.50;
- MOVE_STYLE.filter = 'alpha(opacity=50)';
- MOVE_STYLE.zIndex = bobj.constants.modalLayerIndex - 1;
-
- document.body.appendChild(this._moveArea);
- document.body.style.cursor = 'move';
- }
- };
- /**
- * Flex callback when finished moving the dialog
- */
- bobj.crv.params.FlexParameterUI.stopMove = function (viewerName)
- {
- var swf = this.getSWF(viewerName);
- if (swf){
-
- var pos = MochiKit.Style.getElementPosition(this._moveArea);
- MochiKit.Style.setElementPosition(swf.parentNode, pos);
-
- document.body.removeChild(this._moveArea);
- delete this._moveArea;
-
- document.body.style.cursor = 'default';
- }
- };
- /**
- * Flex callback for moving the dialog.
- * x is the amount to move on the x axis, -:left +:right
- * y is the amount to move on the y axis, -:up +:down
- */
- bobj.crv.params.FlexParameterUI.Move = function (viewerName, x, y)
- {
- var swf = this.getSWF(viewerName);
- if (swf){
- var LOG = bobj.crv.logger;
- LOG.info('doMove Called viewer:' + viewerName + ' x:' + x + ' y:' + y);
-
- var l = getLayer(viewerName);
- if (!l){
- LOG.error('Shifting SWF could not find the viewer:' + viewerName);
- return;
- }
-
- var m = this._moveArea;
- if (!m){
- LOG.error('Unable to move SWF, no move area available');
- return;
- }
-
- var mX = m.offsetLeft;
- var mY = m.offsetTop;
- var mH = m.offsetHeight;
- var mW = m.offsetWidth;
- var vX = l.offsetLeft;
- var vY = l.offsetTop;
- var vH = l.offsetHeight;
- var vW = l.offsetWidth;
-
- var newX = mX + x;
- var newY = mY + y;
-
- if (newY < vY){
- newY = vY;
- } else if (newY + mH > vY + vH){
- newY = vH - mH;
- }
-
- if (newX < vX){
- newX = vX;
- } else if (newX + mW > vX + vW){
- newX = vW - mW;
- }
-
- m.style.top = newY + 'px';
- m.style.left = newX + 'px';
-
- LOG.info('Moved the SWF to x:' + newX + ' y:' + newY);
-
- }
- };
- bobj.crv.params.FlexParameterUI.setParamValues = function (viewerName, paramData)
- {
- bobj.crv.logger.info('setting parameter values');
- bobj.event.publish('crprompt_flexparam', viewerName, paramData);
- };
- bobj.crv.params.FlexParameterUI.logon = function (viewerName, logonData)
- {
- bobj.crv.logger.info('logging on');
- bobj.event.publish('crprompt_flexlogon', viewerName, logonData);
- };
|