ParameterPanel.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. if (typeof bobj.crv.params.ParameterPanel == 'undefined') {
  3. bobj.crv.params.ParameterPanel = {};
  4. bobj.crv.params.ParameterPanelToolbar = {};
  5. bobj.crv.params.ParameterTab = {};
  6. bobj.crv.params.ParameterDialog = {};
  7. }
  8. /*
  9. ================================================================================
  10. ParameterPanel
  11. ================================================================================
  12. */
  13. /**
  14. * Constructor
  15. */
  16. bobj.crv.params.newParameterPanel = function(kwArgs) {
  17. kwArgs = MochiKit.Base.update({
  18. id: bobj.uniqueId() + '_IPPanel'
  19. }, kwArgs);
  20. var o = newWidget(kwArgs.id);
  21. o.widgetType = 'ParameterPanel';
  22. // Update instance with constructor arguments
  23. bobj.fillIn(o, kwArgs);
  24. // Update instance with member functions
  25. MochiKit.Base.update(o, bobj.crv.params.ParameterPanel);
  26. o._tabPanel = bobj.crv.newStackedPanel({
  27. id: o.id + '_ParamtersStack'
  28. });
  29. o._selected = null;
  30. o._toolbar = bobj.crv.params.newParameterPanelToolbar({
  31. id: o.id + '_IPToolbar'
  32. });
  33. return o;
  34. };
  35. bobj.crv.params.ParameterPanel.setToolbarCallBacks = function(delClickCB,applyClickCB)
  36. {
  37. if(this._toolbar) {
  38. this._toolbar.delClickCB = delClickCB;
  39. this._toolbar.applyClickCB = applyClickCB;
  40. }
  41. };
  42. bobj.crv.params.ParameterPanel.init = function() {
  43. Widget_init.call(this);
  44. this._toolbar.init();
  45. if (this._tabPanel) {
  46. this._tabPanel.init();
  47. }
  48. };
  49. bobj.crv.params.ParameterPanel.getHTML = function() {
  50. var DIV = bobj.html.DIV;
  51. var layerStyle = this._getCommonLayerStyle();
  52. layerStyle.overflow = 'hidden';
  53. var innerHTML = this._toolbar.getHTML();
  54. if (this._tabPanel) {
  55. innerHTML += this._tabPanel.getHTML();
  56. }
  57. return DIV({id: this.id, style: layerStyle}, innerHTML);
  58. };
  59. bobj.crv.params.ParameterPanel._getErrorMsgContent = function(errMsg) {
  60. var DIV = bobj.html.DIV;
  61. var layerStyle = this._getCommonLayerStyle();
  62. return DIV({id: this.id, style: layerStyle}, errMsg);
  63. };
  64. bobj.crv.params.ParameterPanel._getCommonLayerStyle = function() {
  65. var layerStyle = {};
  66. if (this.height) {
  67. layerStyle.height = bobj.unitValue(this.height);
  68. }
  69. if (this.width) {
  70. layerStyle.width = bobj.unitValue(this.width);
  71. }
  72. return layerStyle;
  73. };
  74. /**
  75. * Show error message in the panel.
  76. *
  77. * @param errMsg [string] Error message to be shown
  78. */
  79. bobj.crv.params.ParameterPanel.showError = function(errMsg) {
  80. if (errMsg) {
  81. this.setHTML(this._getErrorMsgContent(errMsg));
  82. }
  83. };
  84. /**
  85. * Resize the panel
  86. *
  87. * @param w [int - optional] Width in pixels
  88. * @param h [int - optional] Height in pixels
  89. */
  90. bobj.crv.params.ParameterPanel.resize = function(w, h) {
  91. Widget_resize.call(this, w, h);
  92. if (this._toolbar) {
  93. w = this.layer.clientWidth;
  94. this._toolbar.resize(w);
  95. if (this._tabPanel) {
  96. h = this.layer.clientHeight - this._toolbar.getHeight();
  97. this._tabPanel.resize(w, h);
  98. }
  99. }
  100. };
  101. /**
  102. * Add a ParameterUI instance to the panel
  103. *
  104. * @param paramUI [ParameterUI]
  105. * @param label [String] Parameter title
  106. * @param isDataFetching [bool] Shows the data fetching icon when true
  107. * @param isDirty [bool] Shows the dirty icon when true
  108. */
  109. bobj.crv.params.ParameterPanel.addParameter = function(kwArgs) {
  110. kwArgs = MochiKit.Base.update({
  111. paramUI: null,
  112. label: null,
  113. isDataFetching: false,
  114. isDirty: false,
  115. isReadOnly: false,
  116. selectCB: null,
  117. openAdvCB: null,
  118. minMaxTooltip: null,
  119. id: this._tabPanel.id + '_P' + (this._tabPanel.getNumTabs() + 1)
  120. },kwArgs);
  121. if (kwArgs.paramUI) {
  122. var paramTab = bobj.crv.params.newParameterTab(kwArgs);
  123. paramTab.setContent(kwArgs.paramUI);
  124. this._tabPanel.addTab(paramTab);
  125. }
  126. };
  127. /**
  128. * Remove a ParameterUI instance from the panel
  129. *
  130. * @param index [int] Index of the widget
  131. */
  132. bobj.crv.params.ParameterPanel.removeParameter = function(index) {
  133. this._tabPanel.removeTab(index);
  134. };
  135. /**
  136. * @return [int] The width, in pixels, of the panel
  137. */
  138. bobj.crv.params.ParameterPanel.getWidth = function() {
  139. if (this.layer) {
  140. return this.layer.offsetWidth;
  141. }
  142. return this.width;
  143. };
  144. bobj.crv.params.ParameterPanel.setDeleteButtonEnabled = function(isEnabled) {
  145. this._toolbar.delButton.setDisabled(!isEnabled);
  146. };
  147. bobj.crv.params.ParameterPanel.setApplyButtonEnabled = function(isEnabled) {
  148. this._toolbar.applyButton.setDisabled(!isEnabled);
  149. };
  150. bobj.crv.params.ParameterPanel.getIndex = function(paramUI) {
  151. var numTabs = this._tabPanel.getNumTabs();
  152. for (var idx = 0; idx < numTabs; ++idx) {
  153. var tab = this._tabPanel.getTab(idx);
  154. if (tab.getContent() === paramUI) {
  155. return idx;
  156. }
  157. }
  158. return -1;
  159. };
  160. bobj.crv.params.ParameterPanel.getParameter = function(index) {
  161. var tab = this._tabPanel.getTab(index);
  162. if (tab) {
  163. return tab.getContent();
  164. }
  165. return null;
  166. };
  167. bobj.crv.params.ParameterPanel.setDirty = function(index, isDirty) {
  168. var tab = this._tabPanel.getTab(index);
  169. if (tab) {
  170. tab.setDirty(isDirty);
  171. tab.getContent().setBgColor ();
  172. }
  173. };
  174. bobj.crv.params.ParameterPanel.isDirty = function(index) {
  175. var tab = this._tabPanel.getTab(index);
  176. if (tab) {
  177. return tab.isDirty();
  178. }
  179. return false;
  180. };
  181. bobj.crv.params.ParameterPanel.setSelected = function(index, isSelected) {
  182. var tab = this._tabPanel.getTab(index);
  183. if (tab) {
  184. if (this._selected) {
  185. this._selected.setSelected(false);
  186. }
  187. tab.setSelected(isSelected);
  188. this._selected = tab;
  189. }
  190. };
  191. bobj.crv.params.ParameterPanel.expand = function(index) {
  192. var tab = this._tabPanel.getTab(index);
  193. if (tab) {
  194. tab.expand();
  195. }
  196. };
  197. /*
  198. ================================================================================
  199. ParameterPanelToolbar
  200. Contains the Delete and Run buttons
  201. ================================================================================
  202. */
  203. // these are the Y offsets of the icons in the param_panel.gif image
  204. bobj.crv.paramPanelIcon = bobj.crvUri('images/param_panel.gif');
  205. bobj.crv.paramDataFetchingIconYOffset = 32; // param_datafetching.gif
  206. bobj.crv.paramDirtyIconYOffset = 48; // param_dirty.gif
  207. bobj.crv.paramInfoIconYOffset = 64; // param_info.gif
  208. bobj.crv.paramsApplyIconYOffset = 80; // param_run.gif
  209. bobj.crv.paramsDeleteIconYOffset = 102; // delete.gif
  210. /**
  211. * Constructor
  212. */
  213. bobj.crv.params.newParameterPanelToolbar = function(kwArgs) {
  214. kwArgs = MochiKit.Base.update({
  215. id: bobj.uniqueId()
  216. }, kwArgs);
  217. var o = newPaletteContainerWidget(kwArgs.id);
  218. bobj.fillIn(o, kwArgs);
  219. o.widgetType = 'ParameterPanelToolbar';
  220. // Attach member functions
  221. o._paletteContainerInit = o.init;
  222. MochiKit.Base.update(o, bobj.crv.params.ParameterPanelToolbar);
  223. o._palette = newPaletteWidget(o.id + "_palette");
  224. o.add(o._palette);
  225. var bind = MochiKit.Base.bind;
  226. o.delButton = newIconWidget(
  227. o.id + '_delBtn',
  228. bobj.crv.paramPanelIcon,
  229. bind(o._onDelClick, o), //clickCB,
  230. L_bobj_crv_ParamsDelete,//text,
  231. L_bobj_crv_ParamsDeleteTooltip,//tooltip,
  232. 16, 16, 3, 3 + bobj.crv.paramsDeleteIconYOffset, 25, 3 + bobj.crv.paramsDeleteIconYOffset); //width, height, dx, dy, disDx, disDy
  233. o.applyButton = newIconWidget(
  234. o.id + '_applyBtn',
  235. bobj.crv.paramPanelIcon,
  236. bind(o._onApplyClick, o), //clickCB,
  237. L_bobj_crv_ParamsApply, //text
  238. L_bobj_crv_ParamsApplyTip,//tooltip,
  239. 16, 16, 3, 3 + bobj.crv.paramsApplyIconYOffset, 25, 3 + bobj.crv.paramsApplyIconYOffset); //width, height, dx, dy, disDx, disDy
  240. o._palette.add(o.applyButton);
  241. o._palette.add(); // separator
  242. o._palette.add(o.delButton);
  243. return o;
  244. };
  245. bobj.crv.params.ParameterPanelToolbar.init = function() {
  246. this._paletteContainerInit();
  247. this._palette.init();
  248. this.delButton.setDisabled(true);
  249. this.applyButton.setDisabled(true);
  250. };
  251. /**
  252. * Overrides parent. Opens the toolbar's tags.
  253. */
  254. bobj.crv.params.ParameterPanelToolbar.beginHTML = function()
  255. {
  256. return bobj.html.openTag('div', {
  257. id: this.id,
  258. 'class':'dialogzone',
  259. style:{overflow:'hidden', margin:'0'}});
  260. };
  261. bobj.crv.params.ParameterPanelToolbar.getHTML = function() {
  262. return (this.beginHTML() +
  263. this._palette.getHTML() +
  264. this.endHTML() );
  265. };
  266. bobj.crv.params.ParameterPanelToolbar._onDelClick = function() {
  267. if (this.delClickCB) {
  268. bobj.crv.logger.info('UIAction ParameterPanel.Delete');
  269. this.delClickCB();
  270. }
  271. };
  272. bobj.crv.params.ParameterPanelToolbar._onApplyClick = function() {
  273. if (this.applyClickCB) {
  274. bobj.crv.logger.info('UIAction ParameterPanel.Apply');
  275. this.applyClickCB();
  276. }
  277. };
  278. /*
  279. ================================================================================
  280. ParameterTab
  281. Internal class. Stackable container for a prompt UI. Draws the prompt Title over
  282. the content.
  283. ================================================================================
  284. */
  285. bobj.crv.params.newParameterTab = function(kwArgs) {
  286. kwArgs = MochiKit.Base.update({
  287. label: null,
  288. isDataFetching: false,
  289. isDirty: false,
  290. isReadOnly: false,
  291. minMaxTooltip: null,
  292. openAdvCB: null,
  293. selectCB: null,
  294. id: null
  295. }, kwArgs);
  296. kwArgs.iconPos = "right";
  297. kwArgs.expandImgPos = "right";
  298. var o = bobj.crv.newStackedTab(kwArgs);
  299. // Update instance with constructor arguments
  300. bobj.fillIn(o, kwArgs);
  301. o._isDirtyInit = kwArgs.isDirty;
  302. // Update instance with member functions
  303. MochiKit.Base.update(o, bobj.crv.params.ParameterTab);
  304. o._dirtyId = o.id + '_dirty';
  305. o.addIcon(bobj.crv.paramPanelIcon, 0, bobj.crv.paramDirtyIconYOffset, L_bobj_crv_ParamsDirtyTip, false, o._isDirtyInit, o._dirtyId);
  306. if(kwArgs.minMaxTooltip || kwArgs.isReadOnly) {
  307. var tooltip = "";
  308. if(kwArgs.isReadOnly && kwArgs.minMaxTooltip) {
  309. tooltip = L_bobj_crv_ParamsReadOnly + "<BR>" + kwArgs.minMaxTooltip;
  310. }
  311. else if(kwArgs.minMaxTooltip) {
  312. tooltip = kwArgs.minMaxTooltip;
  313. }
  314. else if(kwArgs.isReadOnly) {
  315. tooltip = L_bobj_crv_ParamsReadOnly;
  316. }
  317. o.addIcon(bobj.crv.paramPanelIcon, 0, bobj.crv.paramInfoIconYOffset,tooltip, false, true, o.id + '_icnInfo');
  318. }
  319. if (o.isDataFetching) {
  320. o.addIcon(bobj.crv.paramPanelIcon, 0, bobj.crv.paramDataFetchingIconYOffset, L_bobj_crv_ParamsDataTip, true, true, null);
  321. }
  322. return o;
  323. };
  324. /**
  325. * Set whether dirty icon is displayed
  326. *
  327. * @param isDirty [bool] True shows the icon. False hides it.
  328. */
  329. bobj.crv.params.ParameterTab.setDirty = function(isDirty) {
  330. if (isDirty) {
  331. this.showIcon.call(this, this._dirtyId);
  332. }
  333. else {
  334. this.hideIcon.call(this, this._dirtyId);
  335. }
  336. };
  337. /**
  338. * @return [boolean] True if the dirty icon is showing
  339. */
  340. bobj.crv.params.ParameterTab.isDirty = function() {
  341. if (this.layer) {
  342. return this.isIconShowing(this._dirtyId);
  343. }
  344. else {
  345. return this._isDirtyInit;
  346. }
  347. };
  348. /**
  349. * @return [boolean] True if the tab is selected.
  350. */
  351. bobj.crv.params.ParameterTab.isSelected = function() {
  352. return MochiKit.DOM.hasElementClass(this._labelCtn, 'iactParamLabelSel');
  353. };
  354. /**
  355. * Select or deselect the tab
  356. *
  357. * @param isSelected [bool] True selects the tab. False deselects it.
  358. */
  359. bobj.crv.params.ParameterTab.setSelected = function(isSelected) {
  360. if (isSelected) {
  361. MochiKit.DOM.addElementClass(this._labelCtn, 'iactParamLabelSel');
  362. }
  363. else {
  364. MochiKit.DOM.removeElementClass(this._labelCtn, 'iactParamLabelSel');
  365. }
  366. };
  367. /*
  368. ================================================================================
  369. ParameterDialog
  370. Advanced Dialog for editing parameters using the prompt engine
  371. ================================================================================
  372. */
  373. bobj.crv.params.newParameterDialog = function(kwArgs) {
  374. kwArgs = MochiKit.Base.update({
  375. id: bobj.uniqueId(),
  376. prompt: null,
  377. promptHTML: '',
  378. showCB : null,
  379. hideCB : null
  380. }, kwArgs);
  381. var o = newDialogBoxWidget(
  382. kwArgs.id,
  383. L_bobj_crv_ParamsDlgTitle,
  384. kwArgs.width,
  385. kwArgs.height /*,defaultCB,cancelCB,noCloseButton*/);
  386. // Update instance with constructor arguments
  387. bobj.fillIn(o, kwArgs);
  388. // Update instance with member functions
  389. o._showDialogBox = o.show;
  390. o._initDialogBox = o.init;
  391. MochiKit.Base.update(o, bobj.crv.params.ParameterDialog);
  392. return o;
  393. };
  394. bobj.crv.params.ParameterDialog.init = function() {
  395. this._initDialogBox();
  396. this._form = document.getElementById(this.id + '_form');
  397. };
  398. bobj.crv.params.ParameterDialog._checkInitialization= function() {
  399. if(!this.layer) {
  400. targetApp(this.getHTML());
  401. this.init();
  402. }
  403. };
  404. bobj.crv.params.ParameterDialog.show = function(show) {
  405. if (show) {
  406. this._checkInitialization();
  407. this.setResize(MochiKit.Base.noop);
  408. this._showDialogBox(true);
  409. }
  410. else if (this.layer){
  411. this._showDialogBox(false);
  412. }
  413. if(show && this.showCB) {
  414. this.showCB();
  415. }
  416. else if(!show && this.hideCB) {
  417. this.hideCB();
  418. }
  419. };
  420. bobj.crv.params.ParameterDialog.isVisible = function() {
  421. return (this.initialized() && this.isDisplayed());
  422. };
  423. bobj.crv.params.ParameterDialog.setPromptHTML = function(html) {
  424. if (html) {
  425. this._checkInitialization();
  426. if(this.isDisplayed()) {
  427. this._showDialogBox(false);
  428. }
  429. this._deleteScripts();
  430. var ext = bobj.html.extractHtml(html);
  431. this.promptHTML = ext.html;
  432. if (this._form) {
  433. this._form.innerHTML = '<div style="overflow:auto">' + this.promptHTML + '</div>';
  434. }
  435. var links = ext.links;
  436. for(var iLinks = 0, linksLen = links.length; iLinks < linksLen; ++iLinks)
  437. {
  438. bobj.includeLink(links[iLinks]);
  439. }
  440. var winScroll_before = {x: getScrollX() , y : getScrollY()};
  441. var scripts = ext.scripts;
  442. for (var iScripts = 0, scriptsLen = scripts.length; iScripts < scriptsLen; ++iScripts) {
  443. var script = scripts[iScripts];
  444. if (!script) {continue;}
  445. if (script.text) {
  446. bobj.evalInWindow(script.text);
  447. }
  448. }
  449. var winScroll_after = {x: getScrollX() , y : getScrollY()};
  450. if(winScroll_before.x != winScroll_after.x || winScroll_before.y != winScroll_after.y) {
  451. _curWin.scrollTo(winScroll_before.x, winScroll_before.y);
  452. }
  453. }
  454. };
  455. /**
  456. * Private. Deletes global scope objects that were created for the dialog
  457. */
  458. bobj.crv.params.ParameterDialog._deleteScripts = function() {
  459. var form = this._form;
  460. if (form && form.ContextHandleID) {
  461. var prefix = form.ContextHandleID.value;
  462. for (var i in window) {
  463. if (i.indexOf(prefix) === 0) {
  464. delete window[i];
  465. }
  466. }
  467. }
  468. };
  469. bobj.crv.params.ParameterDialog.getHTML = function(html) {
  470. var FORM = bobj.html.FORM;
  471. var onsubmit = 'eventCancelBubble(event);return false;';
  472. return this.beginHTML() +
  473. FORM({id: this.id + '_form', onsubmit: onsubmit}, this.promptHTML) +
  474. this.endHTML();
  475. };