FlexParameterUI.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. if (typeof bobj.crv.params.FlexParameterUI == 'undefined') {
  3. bobj.crv.params.FlexParameterUI = {};
  4. }
  5. /*
  6. ================================================================================
  7. FlexParameterUI
  8. Base functionality for flex prompting UI
  9. ================================================================================
  10. */
  11. bobj.crv.params.FlexParameterUI = function() {
  12. var _swfID = [];
  13. var _swf = [];
  14. var _promptData = [];
  15. var _paramCtrl = [];
  16. var _currentIParam = [];
  17. var _closeDialogCallBack = [];
  18. var _viewerLayoutType = [];
  19. var _moveArea;
  20. // Holder for information about interactive parameters
  21. var _iParamsPromptUnitData = [];
  22. var _iParamsParamData = [];
  23. };
  24. bobj.crv.params.FlexParameterUI.setViewerLayoutType = function(viewerName, layout) {
  25. if (!this._viewerLayoutType) {
  26. this._viewerLayoutType = [];
  27. }
  28. this._viewerLayoutType[viewerName] = layout;
  29. };
  30. bobj.crv.params.FlexParameterUI.setPromptData = function(viewerName, promptData) {
  31. if (!this._promptData) {
  32. this._promptData = [];
  33. }
  34. this._promptData[viewerName] = promptData;
  35. };
  36. bobj.crv.params.FlexParameterUI.setCurrentIParamInfo = function(viewerName, paramCtrl, param) {
  37. if (!this._paramCtrl) {
  38. this._paramCtrl = [];
  39. }
  40. if (!this._currentIParam) {
  41. this._currentIParam = [];
  42. }
  43. this._paramCtrl[viewerName] = paramCtrl;
  44. this._currentIParam[viewerName] = param;
  45. };
  46. bobj.crv.params.FlexParameterUI.setCloseDialogCallBack = function(viewerName, closeDialogCallBack) {
  47. if (!this._closeDialogCallBack) {
  48. this._closeDialogCallBack = [];
  49. }
  50. this._closeDialogCallBack[viewerName] = closeDialogCallBack;
  51. };
  52. bobj.crv.params.FlexParameterUI.addIParamPromptUnitData = function (viewerName, promptUnitID, paramNames, promptData)
  53. {
  54. if (!this._iParamsPromptUnitData) {
  55. this._iParamsPromptUnitData = [];
  56. }
  57. if (!this._iParamsPromptUnitData[viewerName]) {
  58. this._iParamsPromptUnitData[viewerName] = [];
  59. }
  60. if (!this._iParamsParamData) {
  61. this._iParamsParamData = [];
  62. }
  63. if (!this._iParamsParamData[viewerName]) {
  64. this._iParamsParamData[viewerName] = [];
  65. }
  66. this._iParamsPromptUnitData[viewerName][promptUnitID] = promptData;
  67. for(var i = 0, len = paramNames.length; i < len; i++) {
  68. var paramName = paramNames[i];
  69. this._iParamsParamData[viewerName][paramName] = promptUnitID;
  70. }
  71. };
  72. bobj.crv.params.FlexParameterUI.getSWF = function(viewerName) {
  73. if (!this._swfID || !this._swfID[viewerName]) {
  74. return;
  75. }
  76. if (!this._swf) {
  77. this._swf = [];
  78. }
  79. if(this._swf[viewerName]) {
  80. return this._swf[viewerName];
  81. } else {
  82. var swf = document.getElementById(this._swfID[viewerName]);
  83. if (!swf) {
  84. return;
  85. }
  86. this._swf[viewerName] = swf;
  87. return swf;
  88. }
  89. };
  90. bobj.crv.params.FlexParameterUI.getInstallHTML = function () {
  91. return L_bobj_crv_FlashRequired.replace("{0}", "<br><a href='http://www.adobe.com/go/getflash/' target='_blank'>") + "</a>";
  92. };
  93. bobj.crv.params.FlexParameterUI.checkFlashPlayer = function () {
  94. return swfobject.hasFlashPlayerVersion("9.0.0");
  95. };
  96. /**
  97. * Creates the swf and replaces the div specified with the flash object.
  98. */
  99. bobj.crv.params.FlexParameterUI.createSWF = function(viewerName, divID, servletURL, isIParamDialog) {
  100. if (!this._swfID) {
  101. this._swfID = [];
  102. }
  103. bobj.crv.logger.info('Create the SWF');
  104. if (this.checkFlashPlayer()){
  105. var lang = bobj.crv.getLangCode ();
  106. var swfBaseURL = bobj.crvUri("../../swf/");
  107. var swfPath = swfBaseURL + "prompting.swf";
  108. var swfID = bobj.uniqueId();
  109. var flashvars = {"eventTarget":viewerName, "locale":lang, "isIParamDialog":isIParamDialog, "baseURL":swfBaseURL, "servletURL":servletURL};
  110. // 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
  111. // the swf when viewing using the embedded browser in eclipse.
  112. var params = {menu:"false", wmode:"window", allowscriptaccess:"sameDomain"};
  113. var attributes = {id:swfID, name:swfID, style:'z-index:' + bobj.constants.modalLayerIndex};
  114. // Does not work in IE for some reason, used in other browsers to hide the
  115. // dialog until it has been positioned properly to prevent snapping.
  116. if (!MochiKit.Base.isIE()){
  117. document.getElementById(divID).parentNode.style.visibility = 'hidden';
  118. }
  119. swfobject.embedSWF(swfPath, divID, "360", "50", "9.0.0", "", flashvars, params, attributes);
  120. this._swfID[viewerName] = swfID;
  121. var v = getWidgetFromID(viewerName);
  122. if (v && v._reportProcessing){
  123. v._reportProcessing.delayedShow(false);
  124. }
  125. } else {
  126. document.getElementById(divID).innerHTML = "<p>" + this.getInstallHTML() +"</p>";
  127. }
  128. };
  129. /**
  130. * This function will initialize the data in the flex swf with the
  131. * current state of the parameter ui. The Flex swf will call back to
  132. * this method when it has first been created and all external interface
  133. * connections have been setup. If the swf has already been created this will
  134. * be called when showing the parameter UI.
  135. */
  136. bobj.crv.params.FlexParameterUI.init = function (viewerName) {
  137. if (!viewerName || !this._swfID || !this._swfID[viewerName]) {
  138. return;
  139. }
  140. bobj.crv.logger.info('Init the SWF');
  141. var swf = this.getSWF(viewerName);
  142. if (!swf) {
  143. return;
  144. }
  145. var v = getWidgetFromID(viewerName);
  146. if (v && v._reportProcessing){
  147. v._reportProcessing.cancelShow();
  148. }
  149. if (swf.setStateInfo){
  150. var toJSON = MochiKit.Base.serializeJSON;
  151. swf.setStateInfo(encodeURIComponent(toJSON(bobj.crv.stateManager.getCompositeState())));
  152. }
  153. if (swf.setIdealHeight){
  154. var lTypes = bobj.crv.Viewer.LayoutTypes;
  155. var layout = lTypes.CLIENT;
  156. if (this._viewerLayoutType && this._viewerLayoutType[viewerName]){
  157. layout = this._viewerLayoutType[viewerName];
  158. }
  159. var lDim = MochiKit.Style.getElementDimensions(getLayer(viewerName));
  160. var min = layout === lTypes.FIXED ? 0 : 400;
  161. swf.setIdealHeight(Math.max(min, lDim.h - 20));
  162. }
  163. if (this._currentIParam && this._currentIParam[viewerName]){
  164. if(!this._iParamsParamData || !this._iParamsParamData[viewerName] || !this._iParamsPromptUnitData || !this._iParamsPromptUnitData[viewerName] ) {
  165. this.setPromptData(viewerName, null);
  166. }
  167. else {
  168. var promptUUID = this._iParamsParamData[viewerName][this._currentIParam[viewerName].paramName];
  169. if (!promptUUID){
  170. this.setPromptData(viewerName, null);
  171. }
  172. var promptData = this._iParamsPromptUnitData[viewerName][promptUUID];
  173. this.setPromptData(viewerName, promptData);
  174. }
  175. }
  176. if(this._promptData && this._promptData[viewerName] && swf.setPromptData){
  177. swf.setPromptData(this._promptData[viewerName]);
  178. }
  179. };
  180. /**
  181. * Flex callback for setting the values from the flex widget
  182. */
  183. bobj.crv.params.FlexParameterUI.setIParamValues = function(viewerName, isCascading, vals, updatedXMLData)
  184. {
  185. if (!this._paramCtrl || !this._currentIParam || !this._iParamsParamData || !this._iParamsPromptUnitData) {
  186. return;
  187. }
  188. var cParam = this._currentIParam[viewerName];
  189. var pCtrl = this._paramCtrl[viewerName];
  190. var pData = this._iParamsParamData[viewerName];
  191. var pUnitData = this._iParamsPromptUnitData[viewerName];
  192. if (!cParam || !pCtrl || !pData || !pUnitData) {
  193. return;
  194. }
  195. var cParamName = cParam.paramName;
  196. if (isCascading){
  197. for(var i = 0, len = vals.length; i < len; i++) {
  198. var value = vals[i];
  199. if (!value.name || !value.values){
  200. continue;
  201. }
  202. pCtrl.updateParameter(value.name, value.values);
  203. }
  204. } else {
  205. pCtrl.updateParameter(cParamName, vals);
  206. }
  207. pCtrl._updateToolbar();
  208. var uid = pData[cParamName];
  209. if (uid){
  210. pUnitData[uid] = updatedXMLData;
  211. }
  212. this.closeIParamDialog(viewerName);
  213. };
  214. /**
  215. * Flex callback for closing the current dialog window.
  216. */
  217. bobj.crv.params.FlexParameterUI.closeIParamDialog = function (viewerName)
  218. {
  219. if (this._closeDialogCallBack && this._closeDialogCallBack[viewerName]) {
  220. this._closeDialogCallBack[viewerName]();
  221. }
  222. };
  223. /**
  224. * Flex callback for adjusting the size of the swf to fit the number of
  225. * prompts being displayed.
  226. */
  227. bobj.crv.params.FlexParameterUI.resize = function (viewerName, height, width)
  228. {
  229. var swf = this.getSWF(viewerName);
  230. if (swf){
  231. bobj.crv.logger.info('Resizing the SWF h:' + height + ' w:' + width);
  232. swf.style.width = width + 'px';
  233. swf.style.height = height + 'px';
  234. var P_STYLE = swf.parentNode.style;
  235. P_STYLE.position = 'absolute';
  236. P_STYLE.visibility = 'visible';
  237. }
  238. };
  239. /**
  240. * Flex callback for adjusting the size of the swf to fit the number of
  241. * prompts being displayed.
  242. */
  243. bobj.crv.params.FlexParameterUI.center = function (viewerName, wOnly)
  244. {
  245. var swf = this.getSWF(viewerName);
  246. if (swf){
  247. var LOG = bobj.crv.logger;
  248. LOG.info('Centering the SWF');
  249. var l = getLayer(viewerName);
  250. if (!l){
  251. LOG.error('Could not find the viewer:' + viewerName);
  252. return;
  253. }
  254. var vPos = MochiKit.Style.getElementPosition(l);
  255. var vDim = MochiKit.Style.getElementDimensions(l);
  256. var sDim = MochiKit.Style.getElementDimensions(swf);
  257. var P_STYLE = swf.parentNode.style;
  258. if (!wOnly){
  259. P_STYLE.top = Math.max(vPos.y, vPos.y + (vDim.h / 2) - (sDim.h / 2)) + 'px';
  260. }else {
  261. P_STYLE.top = (vPos.y + 10) + 'px';
  262. }
  263. P_STYLE.left = Math.max(vPos.x, vPos.x + (vDim.w / 2) - (sDim.w / 2)) + 'px';
  264. if (swf.focus != undefined){
  265. swf.focus();
  266. }
  267. }
  268. };
  269. /**
  270. * Flex callback to start moving the dialog
  271. */
  272. bobj.crv.params.FlexParameterUI.startMove = function (viewerName)
  273. {
  274. var swf = this.getSWF(viewerName);
  275. if (swf){
  276. if (this._moveArea){
  277. return;
  278. }
  279. this._moveArea = document.createElement('div');
  280. this._moveArea.id = bobj.uniqueId();
  281. MOVE_STYLE = this._moveArea.style;
  282. var STYLE = swf.style;
  283. var P_STYLE = swf.parentNode.style;
  284. MOVE_STYLE.top = P_STYLE.top;
  285. MOVE_STYLE.left = P_STYLE.left;
  286. MOVE_STYLE.width = STYLE.width;
  287. MOVE_STYLE.height = STYLE.height;
  288. MOVE_STYLE.border = '1px';
  289. MOVE_STYLE.borderStyle = 'solid';
  290. MOVE_STYLE.borderColor = '#000000';
  291. MOVE_STYLE.backgroundColor = '#FFFFFF';
  292. MOVE_STYLE.position = 'absolute';
  293. MOVE_STYLE.opacity = 0.50;
  294. MOVE_STYLE.filter = 'alpha(opacity=50)';
  295. MOVE_STYLE.zIndex = bobj.constants.modalLayerIndex - 1;
  296. document.body.appendChild(this._moveArea);
  297. document.body.style.cursor = 'move';
  298. }
  299. };
  300. /**
  301. * Flex callback when finished moving the dialog
  302. */
  303. bobj.crv.params.FlexParameterUI.stopMove = function (viewerName)
  304. {
  305. var swf = this.getSWF(viewerName);
  306. if (swf){
  307. var pos = MochiKit.Style.getElementPosition(this._moveArea);
  308. MochiKit.Style.setElementPosition(swf.parentNode, pos);
  309. document.body.removeChild(this._moveArea);
  310. delete this._moveArea;
  311. document.body.style.cursor = 'default';
  312. }
  313. };
  314. /**
  315. * Flex callback for moving the dialog.
  316. * x is the amount to move on the x axis, -:left +:right
  317. * y is the amount to move on the y axis, -:up +:down
  318. */
  319. bobj.crv.params.FlexParameterUI.Move = function (viewerName, x, y)
  320. {
  321. var swf = this.getSWF(viewerName);
  322. if (swf){
  323. var LOG = bobj.crv.logger;
  324. LOG.info('doMove Called viewer:' + viewerName + ' x:' + x + ' y:' + y);
  325. var l = getLayer(viewerName);
  326. if (!l){
  327. LOG.error('Shifting SWF could not find the viewer:' + viewerName);
  328. return;
  329. }
  330. var m = this._moveArea;
  331. if (!m){
  332. LOG.error('Unable to move SWF, no move area available');
  333. return;
  334. }
  335. var mX = m.offsetLeft;
  336. var mY = m.offsetTop;
  337. var mH = m.offsetHeight;
  338. var mW = m.offsetWidth;
  339. var vX = l.offsetLeft;
  340. var vY = l.offsetTop;
  341. var vH = l.offsetHeight;
  342. var vW = l.offsetWidth;
  343. var newX = mX + x;
  344. var newY = mY + y;
  345. if (newY < vY){
  346. newY = vY;
  347. } else if (newY + mH > vY + vH){
  348. newY = vH - mH;
  349. }
  350. if (newX < vX){
  351. newX = vX;
  352. } else if (newX + mW > vX + vW){
  353. newX = vW - mW;
  354. }
  355. m.style.top = newY + 'px';
  356. m.style.left = newX + 'px';
  357. LOG.info('Moved the SWF to x:' + newX + ' y:' + newY);
  358. }
  359. };
  360. bobj.crv.params.FlexParameterUI.setParamValues = function (viewerName, paramData)
  361. {
  362. bobj.crv.logger.info('setting parameter values');
  363. bobj.event.publish('crprompt_flexparam', viewerName, paramData);
  364. };
  365. bobj.crv.params.FlexParameterUI.logon = function (viewerName, logonData)
  366. {
  367. bobj.crv.logger.info('logging on');
  368. bobj.event.publish('crprompt_flexlogon', viewerName, logonData);
  369. };