Toolbar.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. if (typeof(bobj.crv.Toolbar) == 'undefined') {
  3. bobj.crv.Toolbar = {};
  4. }
  5. if (typeof(bobj.crv.ToolbarButton) == 'undefined') {
  6. bobj.crv.ToolbarButton = {};
  7. }
  8. if (typeof(bobj.crv.SelectPageControl) == 'undefined') {
  9. bobj.crv.SelectPageControl = {};
  10. }
  11. if (typeof(bobj.crv.ZoomControl) == 'undefined') {
  12. bobj.crv.ZoomControl = {};
  13. }
  14. if (typeof(bobj.crv.SearchTextControl) == 'undefined') {
  15. bobj.crv.SearchTextControl = {};
  16. }
  17. /*
  18. * @return the Y location indicating the top of a toolbar icon in the combined image
  19. */
  20. bobj.crv.toolbarImageY = function (index)
  21. {
  22. // ALL images are 22 pixels height and set 3 pixels into their placeholder
  23. return index * 22 + 3;
  24. };
  25. // these are the indexes of icons in the toolbar.gif image
  26. bobj.crv.exportIconIndex = 0;
  27. bobj.crv.printIconIndex = 1;
  28. bobj.crv.groupTreeIconIndex = 2;
  29. bobj.crv.paramPanelIconIndex = 3;
  30. bobj.crv.firstIconIndex = 4;
  31. bobj.crv.prevIconIndex = 5;
  32. bobj.crv.nextIconIndex = 6;
  33. bobj.crv.lastIconIndex = 7;
  34. bobj.crv.refreshIconIndex = 8;
  35. bobj.crv.searchIconIndex = 9;
  36. /**
  37. * Toolbar Constructor
  38. */
  39. bobj.crv.newToolbar = function(kwArgs) {
  40. var UPDATE = MochiKit.Base.update;
  41. kwArgs = UPDATE({
  42. id: bobj.uniqueId(),
  43. visualStyle : {
  44. className : null,
  45. backgroundColor : null,
  46. borderWidth : null,
  47. borderStyle : null,
  48. borderColor : null,
  49. fontFamily : null,
  50. fontWeight : null,
  51. textDecoration : null,
  52. color : null,
  53. width : null,
  54. height : null,
  55. fontStyle : null,
  56. fontSize : null
  57. }
  58. }, kwArgs);
  59. var o = newPaletteContainerWidget(kwArgs.id);
  60. o.margin = 0;
  61. bobj.fillIn(o, kwArgs);
  62. o._rightZoneWgts = [];
  63. o.widgetType = 'Toolbar';
  64. // Attach member functions (since we can't use prototypes)
  65. o.initOld = o.init;
  66. UPDATE(o, bobj.crv.Toolbar);
  67. o.palette = newPaletteWidget(o.id + "_palette");
  68. o.add(o.palette);
  69. return o;
  70. };
  71. /**
  72. * Adds a widget to the toolbar and attaches callbacks to known types.
  73. *
  74. * @param widget [Widget] The control to be displayed in the toolbar.
  75. */
  76. bobj.crv.Toolbar.addChild = function(widget) {
  77. var SIGNAL = MochiKit.Signal.signal;
  78. var PARTIAL = MochiKit.Base.partial;
  79. var BIND = MochiKit.Base.bind;
  80. // Connect callbacks that broadcast events as signals
  81. switch (widget.widgetType) {
  82. case 'ExportButton':
  83. this.exportButton = widget;
  84. widget.clickCB = PARTIAL(SIGNAL, this, 'export');
  85. break;
  86. case 'PrintButton':
  87. this.printButton = widget;
  88. widget.clickCB = PARTIAL(SIGNAL, this, 'print');
  89. break;
  90. case 'ParamPanelToggleButton':
  91. this.paramPanelToggleButton = widget;
  92. widget.toggleCB = BIND(this._onToggleButtonClick, this, widget);
  93. break;
  94. case 'GroupPanelToggleButton':
  95. this.groupPanelToggleButton = widget;
  96. widget.toggleCB = BIND(this._onToggleButtonClick, this, widget);
  97. break;
  98. case 'FirstPageButton':
  99. this.firstPageButton = widget;
  100. widget.clickCB = PARTIAL(SIGNAL, this, 'firstPage');
  101. break;
  102. case 'PrevPageButton':
  103. this.prevPageButton = widget;
  104. widget.clickCB = PARTIAL(SIGNAL, this, 'prevPage');
  105. break;
  106. case 'NextPageButton':
  107. this.nextPageButton = widget;
  108. widget.clickCB = PARTIAL(SIGNAL, this, 'nextPage');
  109. break;
  110. case 'LastPageButton':
  111. this.lastPageButton = widget;
  112. widget.clickCB = PARTIAL(SIGNAL, this, 'lastPage');
  113. break;
  114. case 'RefreshButton':
  115. this.refreshButton = widget;
  116. widget.clickCB = PARTIAL(SIGNAL, this, 'refresh');
  117. break;
  118. case 'ZoomControl':
  119. this.zoomControl = widget;
  120. widget.zoomCB = PARTIAL(SIGNAL, this, 'zoom');
  121. break;
  122. case 'SelectPageControl':
  123. this.selectPageControl = widget;
  124. widget.selectPageCB = PARTIAL(SIGNAL, this, 'selectPage');
  125. break;
  126. case 'SearchTextControl':
  127. this.searchTextControl = widget;
  128. widget.searchTextCB = PARTIAL(SIGNAL, this, 'search');
  129. break;
  130. case 'DrillUpButton':
  131. this.drillUpButton = widget;
  132. widget.clickCB = PARTIAL(SIGNAL, this, 'drillUp');
  133. break;
  134. default:
  135. break;
  136. }
  137. // Delay adding right-aligned widgets due to the semantics of the palette
  138. if (widget.layoutAlign == 'right') {
  139. this._rightZoneWgts.push(widget);
  140. }
  141. else {
  142. this.palette.add(widget);
  143. }
  144. };
  145. bobj.crv.Toolbar.init = function() {
  146. this.initOld();
  147. bobj.setVisualStyle(this.layer,this.visualStyle);
  148. this.palette.init();
  149. this._updateNavButtons();
  150. };
  151. bobj.crv.Toolbar.write = function() {
  152. this._addRightZone();
  153. this.begin();
  154. this.palette.write();
  155. this.end();
  156. document.write(bobj.crv.getInitHTML(this.widx));
  157. };
  158. /**
  159. * Overrides parent. Opens the toolbar's tags.
  160. */
  161. bobj.crv.Toolbar.beginHTML = function()
  162. {
  163. return bobj.html.openTag('div', {
  164. id: this.id,
  165. 'class':'dialogzone',
  166. style:{
  167. overflow:'hidden',
  168. margin:this.margin+'px'}});
  169. };
  170. bobj.crv.Toolbar.getHTML = function() {
  171. this._addRightZone();
  172. return (this.beginHTML()
  173. + this.palette.getHTML()
  174. + this.endHTML()
  175. + bobj.crv.getInitHTML(this.widx) );
  176. };
  177. bobj.crv.Toolbar.getWidth = function() {
  178. var itemLayer;
  179. var width =0;
  180. var items = this.palette.items;
  181. for(var i = 0, len = items.length; i < len; i++) {
  182. itemLayer = items[i].layer;
  183. if(itemLayer.offsetWidth) {
  184. width += itemLayer.offsetWidth;
  185. }
  186. if(itemLayer.offsetLeft) {
  187. width += (itemLayer.offsetLeft * 2);
  188. }
  189. }
  190. return width;
  191. };
  192. /**
  193. * Private. Adds right-aligned widgets to the right zone of the palette
  194. */
  195. bobj.crv.Toolbar._addRightZone = function() {
  196. this.palette.beginRightZone();
  197. var w = null;
  198. while (w = this._rightZoneWgts.pop()) {
  199. this.palette.add(w);
  200. }
  201. delete this._rightZoneWgts;
  202. };
  203. /**
  204. * Private. Updates the enabled state of navigation buttons based on the
  205. * current page number and the number of pages.
  206. */
  207. bobj.crv.Toolbar._updateNavButtons = function() {
  208. if (this.selectPageControl) {
  209. var curPg = this.selectPageControl.getCurrentPage();
  210. if (this.firstPageButton) {
  211. this.firstPageButton.setDisabled(curPg == 1);
  212. }
  213. if (this.prevPageButton) {
  214. this.prevPageButton.setDisabled(curPg == 1);
  215. }
  216. var numPgsStr = this.selectPageControl.getNumPages();
  217. var lastPgKnown = numPgsStr.indexOf('+') == -1;
  218. var numPgs = parseInt(numPgsStr, 10);
  219. var fwdDisabled = lastPgKnown && numPgs == curPg;
  220. if (this.nextPageButton) {
  221. this.nextPageButton.setDisabled(fwdDisabled);
  222. }
  223. if (this.lastPageButton) {
  224. this.lastPageButton.setDisabled(fwdDisabled);
  225. }
  226. }
  227. };
  228. bobj.crv.Toolbar._onToggleButtonClick = function(button, isChecked) {
  229. var showOrHide = (isChecked ? L_bobj_crv_Hide : L_bobj_crv_Show);
  230. if (this.paramPanelToggleButton === button) {
  231. if (this.groupPanelToggleButton) {
  232. this.groupPanelToggleButton.check(false);
  233. this.groupPanelToggleButton.changeTooltip(L_bobj_crv_Show + " " + L_bobj_crv_GroupTree);
  234. }
  235. this.paramPanelToggleButton.changeTooltip(showOrHide + " " + L_bobj_crv_ParamPanel);
  236. MochiKit.Signal.signal(this, 'showParamPanel', isChecked);
  237. }
  238. else if (this.groupPanelToggleButton === button) {
  239. if (this.paramPanelToggleButton) {
  240. this.paramPanelToggleButton.check(false);
  241. this.paramPanelToggleButton.changeTooltip(L_bobj_crv_Show + " " + L_bobj_crv_ParamPanel);
  242. }
  243. this.groupPanelToggleButton.changeTooltip(showOrHide + " " + L_bobj_crv_GroupTree);
  244. MochiKit.Signal.signal(this, 'showGroupTree', isChecked);
  245. }
  246. };
  247. bobj.crv.Toolbar.setPageNumber = function(curPage, numPages) {
  248. if (this.selectPageControl) {
  249. if (curPage) {
  250. this.selectPageControl.setCurrentPage(curPage);
  251. }
  252. if (numPages) {
  253. this.selectPageControl.setNumPages(numPages);
  254. }
  255. this._updateNavButtons();
  256. }
  257. };
  258. /**
  259. * public. Updates the Tool Panel buttons based on the Panel Type given.
  260. */
  261. bobj.crv.Toolbar.updateToolPanelButtons = function(panelType) {
  262. var Type = bobj.crv.ToolPanelType;
  263. var groupPanelButtonChecked = false;
  264. var paramPanelButtonChecked = false;
  265. if (Type.GroupTree == panelType) {
  266. groupPanelButtonChecked = true;
  267. }
  268. else if (Type.ParameterPanel == panelType) {
  269. paramPanelButtonChecked = true;
  270. }
  271. if (this.groupPanelToggleButton) {
  272. this.groupPanelToggleButton.check(groupPanelButtonChecked);
  273. var showOrHide = groupPanelButtonChecked ? L_bobj_crv_Hide : L_bobj_crv_Show;
  274. this.groupPanelToggleButton.changeTooltip(showOrHide + " " + L_bobj_crv_GroupTree);
  275. }
  276. if (this.paramPanelToggleButton) {
  277. this.paramPanelToggleButton.check(paramPanelButtonChecked);
  278. var showOrHide = paramPanelButtonChecked ? L_bobj_crv_Hide : L_bobj_crv_Show;
  279. this.paramPanelToggleButton.changeTooltip(showOrHide + " " + L_bobj_crv_ParamPanel);
  280. }
  281. };
  282. bobj.crv.Toolbar.update = function(update,updatePack) {
  283. if(update) {
  284. for(var childNum in update.children) {
  285. var child = update.children[childNum];
  286. if(child) {
  287. switch(child.cons) {
  288. case "bobj.crv.newSelectPageControl":
  289. if(this.selectPageControl) {
  290. this.selectPageControl.update(child, updatePack);
  291. this._updateNavButtons();
  292. }
  293. break;
  294. case "bobj.crv.newSearchTextControl":
  295. if(this.searchTextControl) {
  296. this.searchTextControl.update(child, updatePack);
  297. }
  298. break;
  299. }
  300. }
  301. }
  302. }
  303. };
  304. /**
  305. * Constructor. Base class for toolbar buttons.
  306. */
  307. bobj.crv.newToolbarButton = function(kwArgs) {
  308. kwArgs = MochiKit.Base.update({
  309. id: bobj.uniqueId(),
  310. icon: null,
  311. tooltip: null,
  312. text: null,
  313. isDisabled: false,
  314. isToggleButton: false,
  315. isChecked: false,
  316. clickCB: null,
  317. width: 16,
  318. height: 16,
  319. dx: 3,
  320. dy: 3,
  321. disDx: 25,
  322. disDy: 3
  323. }, kwArgs);
  324. var cons = kwArgs.isToggleButton ? newIconCheckWidget : newIconWidget;
  325. var o = cons.call(null,
  326. kwArgs.id,
  327. kwArgs.icon,
  328. kwArgs.clickCB,
  329. kwArgs.text,
  330. kwArgs.tooltip,
  331. kwArgs.width,
  332. kwArgs.height,
  333. kwArgs.dx,
  334. kwArgs.dy,
  335. kwArgs.disDx,
  336. kwArgs.disDy);
  337. o._tbBtnOldInit = o.init;
  338. o._tbBtnKwArgs = kwArgs;
  339. MochiKit.Base.update(o, bobj.crv.ToolbarButton);
  340. return o;
  341. };
  342. bobj.crv.ToolbarButton.init = function() {
  343. this._tbBtnOldInit();
  344. var kwArgs = this._tbBtnKwArgs;
  345. this.setDisabled(kwArgs.isDisabled);
  346. };
  347. /**
  348. * FirstPageButton constructor
  349. */
  350. bobj.crv.newFirstPageButton = function(kwArgs) {
  351. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  352. icon: bobj.crvUri('images/toolbar.gif'),
  353. tooltip: L_bobj_crv_FirstPage,
  354. dy: bobj.crv.toolbarImageY (bobj.crv.firstIconIndex),
  355. disDy: bobj.crv.toolbarImageY (bobj.crv.firstIconIndex)
  356. }, kwArgs));
  357. o.widgetType = 'FirstPageButton';
  358. return o;
  359. };
  360. /**
  361. * PrevPageButton constructor
  362. */
  363. bobj.crv.newPrevPageButton = function(kwArgs) {
  364. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  365. icon: bobj.crvUri('images/toolbar.gif'),
  366. tooltip: L_bobj_crv_PrevPage,
  367. dy: bobj.crv.toolbarImageY (bobj.crv.prevIconIndex),
  368. disDy: bobj.crv.toolbarImageY (bobj.crv.prevIconIndex)
  369. }, kwArgs));
  370. o.widgetType = 'PrevPageButton';
  371. return o;
  372. };
  373. /**
  374. * NextPageButton constructor
  375. */
  376. bobj.crv.newNextPageButton = function(kwArgs) {
  377. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  378. icon: bobj.crvUri('images/toolbar.gif'),
  379. tooltip: L_bobj_crv_NextPage,
  380. dy: bobj.crv.toolbarImageY (bobj.crv.nextIconIndex),
  381. disDy: bobj.crv.toolbarImageY (bobj.crv.nextIconIndex)
  382. }, kwArgs));
  383. o.widgetType = 'NextPageButton';
  384. return o;
  385. };
  386. /**
  387. * LastPageButton constructor
  388. */
  389. bobj.crv.newLastPageButton = function(kwArgs) {
  390. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  391. icon: bobj.crvUri('images/toolbar.gif'),
  392. tooltip: L_bobj_crv_LastPage,
  393. dy: bobj.crv.toolbarImageY (bobj.crv.lastIconIndex),
  394. disDy: bobj.crv.toolbarImageY (bobj.crv.lastIconIndex)
  395. }, kwArgs));
  396. o.widgetType = 'LastPageButton';
  397. return o;
  398. };
  399. /**
  400. * DrillUp constructor
  401. */
  402. bobj.crv.newDrillUpButton = function(kwArgs) {
  403. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  404. icon: bobj.crvUri('images/up.gif'),
  405. tooltip: L_bobj_crv_DrillUp
  406. }, kwArgs));
  407. o.widgetType = 'DrillUpButton';
  408. return o;
  409. };
  410. /**
  411. * PanelToggleButton constructor
  412. */
  413. bobj.crv.newPanelToggleButton = function(kwArgs) {
  414. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  415. icon: bobj.crvUri('images/toolbar.gif'),
  416. text: L_bobj_crv_Parameters,
  417. isToggleButton: true,
  418. clickCB: function() {
  419. if (this.toggleCB) {
  420. this.toggleCB(this.isChecked());
  421. }
  422. },
  423. dy: bobj.crv.toolbarImageY (bobj.crv.paramPanelIconIndex),
  424. disDy: bobj.crv.toolbarImageY (bobj.crv.paramPanelIconIndex)
  425. }, kwArgs));
  426. o.widgetType = 'ParamPanelToggleButton';
  427. return o;
  428. };
  429. /**
  430. * GroupTreeToggleButton constructor
  431. */
  432. bobj.crv.newGroupTreeToggleButton = function(kwArgs) {
  433. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  434. icon: bobj.crvUri('images/toolbar.gif'),
  435. text: L_bobj_crv_GroupTree,
  436. isToggleButton: true,
  437. clickCB: function() {
  438. if (this.toggleCB) {
  439. this.toggleCB(this.isChecked());
  440. }
  441. },
  442. dy: bobj.crv.toolbarImageY (bobj.crv.groupTreeIconIndex),
  443. disDy: bobj.crv.toolbarImageY (bobj.crv.groupTreeIconIndex)
  444. }, kwArgs));
  445. o.widgetType = 'GroupPanelToggleButton';
  446. return o;
  447. };
  448. /**
  449. * RefreshButton constructor
  450. */
  451. bobj.crv.newRefreshButton = function(kwArgs) {
  452. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  453. icon: bobj.crvUri('images/toolbar.gif'),
  454. tooltip: L_bobj_crv_Refresh,
  455. dy: bobj.crv.toolbarImageY (bobj.crv.refreshIconIndex),
  456. disDy: bobj.crv.toolbarImageY (bobj.crv.refreshIconIndex)
  457. }, kwArgs));
  458. o.widgetType = 'RefreshButton';
  459. return o;
  460. };
  461. /**
  462. * ExportButton constructor
  463. */
  464. bobj.crv.newExportButton = function(kwArgs) {
  465. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  466. icon: bobj.crvUri('images/toolbar.gif'),
  467. tooltip: L_bobj_crv_Export,
  468. dy: bobj.crv.toolbarImageY (bobj.crv.exportIconIndex),
  469. disDy: bobj.crv.toolbarImageY (bobj.crv.exportIconIndex)
  470. }, kwArgs));
  471. o.widgetType = 'ExportButton';
  472. return o;
  473. };
  474. /**
  475. * PrintButton constructor
  476. */
  477. bobj.crv.newPrintButton = function(kwArgs) {
  478. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  479. icon: bobj.crvUri('images/toolbar.gif'),
  480. tooltip: L_bobj_crv_Print,
  481. dy: bobj.crv.toolbarImageY (bobj.crv.printIconIndex),
  482. disDy: bobj.crv.toolbarImageY (bobj.crv.printIconIndex)
  483. }, kwArgs));
  484. o.widgetType = 'PrintButton';
  485. return o;
  486. };
  487. /**
  488. * LogoButton constructor
  489. */
  490. bobj.crv.newLogoButton = function(kwArgs) {
  491. var o = bobj.crv.newToolbarButton(MochiKit.Base.update({
  492. icon: bobj.crvUri('images/logo.gif'),
  493. tooltip: "SAP Crystal Reports",
  494. clickCB: function() {window.location.href = 'http://www.businessobjects.com/ipl/default.asp?destination=ViewerLogoLink&product=crystalreports&version=12.0';},
  495. width: 120,
  496. height: 20,
  497. dx: 0,
  498. dy: 0,
  499. disDx: 0,
  500. disDy: 0
  501. }, kwArgs));
  502. o.layoutAlign = 'right';
  503. o.widgetType = 'LogoButton';
  504. return o;
  505. };
  506. /**
  507. * ToolbarSeparator constructor
  508. */
  509. bobj.crv.newToolbarSeparator = function() {
  510. return newPaletteVerticalSepWidget(bobj.uniqueId());
  511. };
  512. /**
  513. * ZoomControl Constructor
  514. */
  515. bobj.crv.newZoomControl = function(kwArgs) {
  516. var UPDATE = MochiKit.Base.update;
  517. kwArgs = UPDATE({
  518. initialZoom: '100%',
  519. id: bobj.uniqueId()
  520. }, kwArgs);
  521. if (bobj.isNumber(kwArgs.initialZoom)) {
  522. kwArgs.initialZoom = kwArgs.initialZoom + '%';
  523. }
  524. var o = newTextComboWidget(
  525. kwArgs.id,
  526. 5, // max chars
  527. L_bobj_crv_Zoom, // tooltip
  528. 60, // width
  529. bobj.crv.ZoomControl._zoomChangeCB, // change CB
  530. null, // check CB
  531. null, // beforeShow CB
  532. null // form name
  533. );
  534. var zoomList = ['400%','300%','200%','150%','125%','100%','75%','50%','25%'];
  535. for (var i = 0, len = zoomList.length; i < len; ++i) {
  536. var zoomLevel = zoomList[i];
  537. o.add(zoomLevel, zoomLevel, (zoomLevel == kwArgs.initialZoom));
  538. }
  539. o.text.setValue(kwArgs.initialZoom);
  540. o.zoomCB = null;
  541. o.widgetType = 'ZoomControl';
  542. o.initOld = o.init;
  543. o._initZoom = kwArgs.initialZoom;
  544. UPDATE(o, bobj.crv.ZoomControl);
  545. return o;
  546. };
  547. bobj.crv.ZoomControl.init = function() {
  548. this.initOld();
  549. this.setZoom(this._initZoom);
  550. };
  551. bobj.crv.ZoomControl.setZoom = function(lvl) {
  552. var zoomVal = parseInt(lvl, 10);
  553. if (bobj.isNumber(zoomVal)) {
  554. zoomVal += '%';
  555. this.valueSelect(zoomVal);
  556. var si = this.selectedItem;
  557. if (si && si.val != zoomVal) {
  558. si.check(false);
  559. this.selectedItem = null;
  560. }
  561. this._lastValue = zoomVal;
  562. return true;
  563. }
  564. return false;
  565. };
  566. bobj.crv.ZoomControl._zoomChangeCB = function() {
  567. var zoomLvl = parseInt(this.text.getValue(), 10);
  568. if (bobj.isNumber(zoomLvl)) {
  569. if(zoomLvl < 10) {
  570. zoomLvl = 10;
  571. } else if (zoomLvl > 400) {
  572. zoomLvl = 400;
  573. }
  574. }
  575. if (!this.setZoom(zoomLvl)) {
  576. this.setZoom(this._lastValue);
  577. }
  578. else if (this.zoomCB){
  579. this.zoomCB(zoomLvl);
  580. }
  581. };
  582. /**
  583. * SelectPageControl constructor
  584. *
  585. * @param kwArgs.curPage [String|Int] Current page number
  586. * @param kwArgs.numPages [String|Int] Number of pages in report
  587. */
  588. bobj.crv.newSelectPageControl = function(kwArgs) {
  589. var UPDATE = MochiKit.Base.update;
  590. kwArgs = UPDATE({id: bobj.uniqueId()}, kwArgs);
  591. var o = newWidget(kwArgs.id);
  592. // Constructor args
  593. o.curPage = kwArgs.curPage;
  594. o.numPages = kwArgs.numPages;
  595. // Constants
  596. o.margin = 1;
  597. o.space = 0;
  598. o.fieldWidth = 30;
  599. o.labelWidth = 13 + o.space;
  600. // Construct the input box
  601. o.intField = newIntFieldWidget(
  602. o.id + "_intField",
  603. null,
  604. null,
  605. null,
  606. function() {
  607. if (o.selectPageCB){
  608. o.selectPageCB(o.getCurrentPage());
  609. }
  610. },
  611. true,
  612. L_bobj_crv_SelectPage,
  613. o.fieldWidth);
  614. // Construct a label to display numPages
  615. o.label = NewLabelWidget (o.id + "_label", " / " + o.numPages);
  616. // Attach member functions
  617. o.initOld = o.init;
  618. o.selectPageCB = null;
  619. UPDATE(o, bobj.crv.SelectPageControl);
  620. o.widgetType = 'SelectPageControl';
  621. return o;
  622. };
  623. bobj.crv.SelectPageControl.update = function(update, updatePack) {
  624. if(update && update.cons == "bobj.crv.newSelectPageControl") {
  625. this.setCurrentPage(update.args.curPage);
  626. this.setNumPages(update.args.numPages);
  627. }
  628. };
  629. bobj.crv.SelectPageControl.getHTML = function() {
  630. var h = bobj.html;
  631. var labelStyle = {
  632. cursor: 'default',
  633. 'padding-left': this.space + 'px',
  634. width: this.labelWidth + 'px'
  635. };
  636. return h.TABLE({
  637. id: this.id,
  638. cellspacing: 0,
  639. cellpadding: 0,
  640. border: 0,
  641. style: {margin: this.margin + 'px'}
  642. },
  643. h.TBODY(null,
  644. h.TR(null,
  645. h.TD(null, this.intField.getHTML()),
  646. h.TD({style: labelStyle}, this.label.getHTML() ))));
  647. };
  648. /**
  649. * @return [Int] Returns the current page number
  650. */
  651. bobj.crv.SelectPageControl.getCurrentPage = function() {
  652. return this.intField.getValue();
  653. };
  654. bobj.crv.SelectPageControl.setCurrentPage = function(val) {
  655. this.intField.setValue(val);
  656. };
  657. /**
  658. * @return [String] Returns the number of pages label
  659. */
  660. bobj.crv.SelectPageControl.getNumPages = function() {
  661. var text = this.label.text || '';
  662. return text.substring(3); // remove ' / ' from the return value
  663. };
  664. bobj.crv.SelectPageControl.setNumPages = function(val) {
  665. this.label.text = ' / ' + val;
  666. var labelNode = getLayer(this.label.id);
  667. labelNode.innerHTML = convStr(this.label.text, false);
  668. };
  669. bobj.crv.SelectPageControl.init = function() {
  670. this.initOld();
  671. this.intField.init();
  672. this.intField.setMin(1);
  673. this.intField.setValue(this.curPage);
  674. this.label.init();
  675. };
  676. /**
  677. * searchTextControl constructor
  678. *
  679. * @param kwArgs.searchText [String] Search Text
  680. */
  681. bobj.crv.newSearchTextControl = function(kwArgs) {
  682. var UPDATE = MochiKit.Base.update;
  683. kwArgs = UPDATE({id: bobj.uniqueId()}, kwArgs);
  684. var o = newWidget(kwArgs.id);
  685. bobj.fillIn(o, kwArgs);
  686. // Construct the input box
  687. o.textField = newTextFieldWidget(
  688. o.id + "_textField",
  689. null,
  690. null,
  691. null,
  692. MochiKit.Base.bind(bobj.crv.SearchTextControl._searchTextCB, o),
  693. true,
  694. L_bobj_crv_SearchText,
  695. 100);
  696. o.searchButton = newIconWidget(
  697. o.id + "_button",
  698. bobj.crvUri('images/toolbar.gif'),
  699. MochiKit.Base.bind(bobj.crv.SearchTextControl._searchTextCB, o),
  700. null,
  701. L_bobj_crv_SearchText,
  702. 16,16,3,bobj.crv.toolbarImageY (bobj.crv.searchIconIndex), bobj.crv.toolbarImageY (bobj.crv.searchIconIndex),3);
  703. // Attach member functions
  704. o.initOld = o.init;
  705. o.searchTextCB = null;
  706. UPDATE(o, bobj.crv.SearchTextControl);
  707. o.widgetType = 'SearchTextControl';
  708. return o;
  709. };
  710. bobj.crv.SearchTextControl.update = function(update, updatePack) {
  711. if(update && update.cons == "bobj.crv.newSearchTextControl") {
  712. this.textField.setValue(update.args.searchText);
  713. }
  714. };
  715. bobj.crv.SearchTextControl.init = function() {
  716. this.initOld();
  717. this.textField.init();
  718. this.textField.setValue(this.searchText);
  719. this.searchButton.init();
  720. };
  721. bobj.crv.SearchTextControl.getHTML = function() {
  722. var h = bobj.html;
  723. var labelStyle = {
  724. cursor: 'default',
  725. 'padding-left': this.space + 'px',
  726. width: this.labelWidth + 'px'
  727. };
  728. return h.TABLE({
  729. id: this.id,
  730. cellspacing: 0,
  731. cellpadding: 0,
  732. border: 0,
  733. style: {margin: this.margin + 'px'}
  734. },
  735. h.TBODY(null,
  736. h.TR(null,
  737. h.TD(null, this.textField.getHTML()),
  738. h.TD(null, this.searchButton.getHTML() ))));
  739. };
  740. bobj.crv.SearchTextControl._searchTextCB = function() {
  741. var text = this.textField.getValue();
  742. if ((text !== "" || this.searchText != text) && bobj.isFunction(this.searchTextCB)) {
  743. this.searchTextCB(text);
  744. }
  745. };