ParameterUI.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. if (typeof bobj.crv.params.ParameterUI == 'undefined') {
  3. bobj.crv.params.ParameterUI = {};
  4. bobj.crv.params.ParameterValueRow = {};
  5. bobj.crv.params.ParamValueButton = {};
  6. bobj.crv.params.ParamRowCreator = {};
  7. bobj.crv.params.TextField = {};
  8. bobj.crv.params.TextCombo = {};
  9. bobj.crv.params.ScrollMenuWidget = {};
  10. bobj.crv.params.HelperRow = {};
  11. }
  12. /*
  13. ================================================================================
  14. ParameterUI
  15. Widget for displaying and editing parameter values. Contains one or many
  16. ParameterValueRows and, optionally, UI that allows rows to be added.
  17. ================================================================================
  18. */
  19. bobj.crv.params.newParameterUI = function(kwArgs) {
  20. kwArgs = MochiKit.Base.update({
  21. id: bobj.uniqueId(),
  22. canChangeOnPanel: false,
  23. allowCustom: false,
  24. canAddValues: false,
  25. isPassword : false,
  26. valueRequired: true,
  27. isReadOnlyParam: true,
  28. values: [],
  29. defaultValues: null,
  30. hasRowButtons: false,
  31. rowButtonsUrl: null,
  32. width: '200px',
  33. changeValueCB: null,
  34. addValueCB: null,
  35. selectValueCB: null,
  36. enterPressCB: null,
  37. clickRowButtonCB: null,
  38. openAdvDialogCB: null,
  39. maxNumParameterDefaultValues: 200,
  40. tooltip : null
  41. }, kwArgs);
  42. var o = newWidget(kwArgs.id);
  43. // Update instance with constructor arguments
  44. bobj.fillIn(o, kwArgs);
  45. // Update instance with member functions
  46. MochiKit.Base.update(o, bobj.crv.params.ParameterUI);
  47. o._selectedRow = null;
  48. o._createMenu();
  49. o._rows = [];
  50. o._numRowsChanged = false;
  51. return o;
  52. };
  53. /**
  54. * Creates single menubar for all parameter value rows of current param UI
  55. */
  56. bobj.crv.params.ParameterUI._createMenu = function() {
  57. var dvLength = this.defaultValues.length;
  58. if(dvLength > 0 ) {
  59. var kwArgs = {originalValues: this.defaultValues};
  60. if (dvLength == this.maxNumParameterDefaultValues) {
  61. kwArgs.originalValues[this.maxNumParameterDefaultValues] = L_bobj_crv_ParamsMaxNumDefaultValues;
  62. MochiKit.Base.update(kwArgs, {
  63. openAdvDialogCB: this.openAdvDialogCB,
  64. maxNumParameterDefaultValues: this.maxNumParameterDefaultValues
  65. });
  66. }
  67. this._defaultValuesMenu = bobj.crv.params.newScrollMenuWidget(kwArgs);
  68. }
  69. else {
  70. this._defaultValuesMenu = null;
  71. }
  72. };
  73. bobj.crv.params.ParameterUI.init = function() {
  74. Widget_init.call(this);
  75. var rows = this._rows;
  76. for(var i = 0, len = rows.length; i < len; ++i) {
  77. rows[i].init();
  78. }
  79. if (this._rowCreator) {
  80. this._rowCreator.init();
  81. }
  82. if(this._helperRow) {
  83. this._helperRow.init();
  84. }
  85. };
  86. bobj.crv.params.ParameterUI.getHTML = function() {
  87. var rowsHtml = '';
  88. var values = this.values;
  89. var rows = this._rows;
  90. for (var i = 0, len = values.length; i < len; ++i) {
  91. rows.push(this._getRow(values[i], this._getBgColor(i)));
  92. rowsHtml += rows[i].getHTML();
  93. }
  94. var rowCreatorHtml = '';
  95. if (this._canAddRowCreater()) {
  96. this._rowCreator = this._getRowCreator();
  97. rowCreatorHtml = this._rowCreator.getHTML();
  98. }
  99. var helperRowHtml = '';
  100. if(this._canAddHelperRow()) {
  101. this._helperRow = bobj.crv.params.newHelperRow({message : L_bobj_crv_ParamsNoValue});
  102. helperRowHtml = this._helperRow.getHTML();
  103. }
  104. return bobj.html.DIV({id: this.id, style:{width:bobj.unitValue(this.width)}},
  105. rowsHtml,helperRowHtml,rowCreatorHtml);
  106. };
  107. bobj.crv.params.ParameterUI._canAddRowCreater = function() {
  108. return (this.canAddValues || (!this.valueRequired && this.values.length === 0 && !this.isReadOnlyParam));
  109. };
  110. bobj.crv.params.ParameterUI._canAddHelperRow = function() {
  111. return (this.isReadOnlyParam && this.values.length === 0 );
  112. };
  113. bobj.crv.params.ParameterUI._getRow = function(value, color) {
  114. var Colors = bobj.crv.params.BackgroundColor;
  115. var row = bobj.crv.params.newParameterValueRow ({
  116. value: value,
  117. defaultValues: this.defaultValues,
  118. width: this.width,
  119. bgColor: color,
  120. isReadOnlyParam: this.isReadOnlyParam,
  121. canChangeOnPanel: this.canChangeOnPanel,
  122. allowCustom: this.allowCustom,
  123. isPassword: this.isPassword,
  124. hasButton: this.hasRowButtons,
  125. buttonUrl: this.rowButtonsUrl,
  126. openAdvDialogCB: this.openAdvDialogCB,
  127. defaultValuesMenu : this._defaultValuesMenu,
  128. tooltip : this.tooltip
  129. });
  130. var bind = MochiKit.Base.bind;
  131. row.changeCB = bind(this._onChangeValue, this, row);
  132. row.selectCB = bind(this._onSelectValue, this, row);
  133. row.enterCB = bind(this._onEnterValue, this, row);
  134. row.buttonClickCB = bind(this._onClickRowButton, this, row);
  135. return row;
  136. };
  137. bobj.crv.params.ParameterUI._addRow = function(value) {
  138. var row = this._getRow(value, this._getBgColor(this._rows.length));
  139. this._rows.push(row);
  140. this._numRowsChanged = true;
  141. if (this._rowCreator) {
  142. this._rowCreator.setBgColor(this._getBgColor(this._rows.length));
  143. insBefore2(this._rowCreator.layer, row.getHTML());
  144. row._valueWidget.setAlwaysDirty ();
  145. }
  146. else {
  147. append(this.layer, row.getHTML());
  148. }
  149. row.init();
  150. row.setBgColor();
  151. return row;
  152. };
  153. bobj.crv.params.ParameterUI._onChangeValue = function(row) {
  154. if (this.changeValueCB) {
  155. this.changeValueCB(this._getRowIndex(row), row.getValue());
  156. }
  157. };
  158. bobj.crv.params.ParameterUI._onSelectValue = function(row) {
  159. if (this._selectedRow !== row) {
  160. this.deselect();
  161. this._selectedRow = row;
  162. }
  163. if (this.selectValueCB) {
  164. this.selectValueCB(this._getRowIndex(row));
  165. }
  166. };
  167. bobj.crv.params.ParameterUI._onEnterValue = function(row) {
  168. if (this.enterPressCB) {
  169. this.enterPressCB(this._getRowIndex(row));
  170. }
  171. };
  172. bobj.crv.params.ParameterUI._onClickRowButton = function(row, x, y) {
  173. if (this.clickRowButtonCB) {
  174. this.clickRowButtonCB(this._getRowIndex(row), x, y);
  175. }
  176. };
  177. bobj.crv.params.ParameterUI.showRowCreater =function(show) {
  178. if(!this._rowCreator && show) {
  179. this._rowCreator = this._getRowCreator();
  180. append(this.layer, this._rowCreator.getHTML());
  181. this._rowCreator.init();
  182. }
  183. if(this._rowCreator) {
  184. this._rowCreator.show(show);
  185. }
  186. };
  187. bobj.crv.params.ParameterUI.showHelperRow = function(show) {
  188. if(!this._helperRow && show) {
  189. this._helperRow = bobj.crv.params.newHelperRow({message : L_bobj_crv_ParamsNoValue});
  190. if(this._rowCreator) {
  191. insBefore2(this._rowCreator.layer, this._helperRow.getHTML());
  192. }
  193. else {
  194. append(this.layer, this._helperRow.getHTML());
  195. }
  196. this._helperRow.init();
  197. }
  198. if(this._helperRow) {
  199. this._helperRow.show(show);
  200. }
  201. };
  202. bobj.crv.params.ParameterUI._onCreateRow = function() {
  203. if((!this.canChangeOnPanel) && (!this.isReadOnlyParam)) {
  204. // TODO this is not reachable
  205. this.selectValueCB(-1);
  206. this.openAdvDialogCB();
  207. }
  208. else {
  209. var val = '';
  210. if (!this.allowCustom && this.defaultValues.length > 0) {
  211. val = this.defaultValues[0];
  212. }
  213. var row = this._addRow(val);
  214. this.setSelected(this._rows.length - 1);
  215. this._onSelectValue(row);
  216. if (this.addValueCB) {
  217. this.addValueCB(row.getValue());
  218. }
  219. // if parameter is single value and optional, remove row creater
  220. if(!this.canAddValues && !this.valueRequired) {
  221. this.showRowCreater(false);
  222. }
  223. }
  224. };
  225. bobj.crv.params.ParameterUI._getRowIndex = function(row) {
  226. if (row) {
  227. var rows = this._rows;
  228. for (var i = 0, len = rows.length; i < len; ++i) {
  229. if (rows[i] === row) {
  230. return i;
  231. }
  232. }
  233. }
  234. return -1;
  235. };
  236. bobj.crv.params.ParameterUI._getRowCreator = function() {
  237. var cb = MochiKit.Base.bind(this._onCreateRow, this);
  238. return bobj.crv.params.newParamRowCreator({activateCB: cb});
  239. };
  240. bobj.crv.params.ParameterUI._getBgColor = function(index) {
  241. var Colors = bobj.crv.params.BackgroundColor;
  242. var dirty = false;
  243. if (this._rows.length > index) {
  244. dirty = this._rows[index].isDirty();
  245. }
  246. if (dirty){
  247. if (index % 2) {
  248. return Colors.dirtyAlternate;
  249. }
  250. else {
  251. return Colors.dirty;
  252. }
  253. } else
  254. {
  255. if (index % 2) {
  256. return Colors.alternate;
  257. }
  258. else {
  259. return Colors.standard;
  260. }
  261. }
  262. return Colors.standard;
  263. };
  264. bobj.crv.params.ParameterUI.isDirty = function() {
  265. if (this._numRowsChanged) {
  266. return true;
  267. }
  268. for (var i = 0, len = this._rows.length; i < len; ++i) {
  269. if (this._rows[i].isDirty()) {
  270. return true;
  271. }
  272. }
  273. return false;
  274. };
  275. bobj.crv.params.ParameterUI.getNumValues = function() {
  276. return this._rows.length;
  277. };
  278. bobj.crv.params.ParameterUI.getValueAt = function(index) {
  279. var row = this._rows[index];
  280. if (row) {
  281. return row.getValue();
  282. }
  283. return null;
  284. };
  285. bobj.crv.params.ParameterUI.getValues = function() {
  286. var values = [];
  287. for (var i = 0, len = this._rows.length; i < len; ++i) {
  288. values.push(this._rows[i].getValue());
  289. }
  290. return values;
  291. };
  292. bobj.crv.params.ParameterUI.getSelectedIndex = function() {
  293. return this._getRowIndex(this._selectedRow);
  294. };
  295. bobj.crv.params.ParameterUI.setValueAt = function(index, value) {
  296. var row = this._rows[index];
  297. if (row) {
  298. row.setValue(value);
  299. }
  300. };
  301. bobj.crv.params.ParameterUI.setValues = function(values) {
  302. if (!values) {return;}
  303. var valuesLen = values.length;
  304. var rowsLen = this._rows.length;
  305. // TODO Post Titan, Justin: We could get fancier here for multi value
  306. // parameters so that we keep the rows that are unchanged.
  307. for (var i = 0; i < valuesLen && i < rowsLen; ++i) {
  308. this._rows[i].setValue(values[i]);
  309. }
  310. if (rowsLen > valuesLen) {
  311. for (var i = rowsLen - 1; i >= valuesLen; --i) {
  312. // delete from the end to minimize calls to setBgColor
  313. this.deleteValue(i);
  314. }
  315. }
  316. else if (valuesLen > rowsLen) {
  317. for (var i = rowsLen; i < valuesLen; ++i) {
  318. this._addRow( values[i] );
  319. this._rows[i]._valueWidget.setAlwaysDirty ();
  320. }
  321. }
  322. };
  323. bobj.crv.params.ParameterUI.setCleanValue = function(index, value) {
  324. var row = this._rows[index];
  325. if (row) {
  326. row.setCleanValue(value);
  327. }
  328. };
  329. bobj.crv.params.ParameterUI.setBgColor = function () {
  330. var rowsLen = this._rows.length;
  331. for (var i = 0; i < rowsLen; ++i) {
  332. this._rows[i].setBgColor(this._getBgColor(i));
  333. }
  334. }
  335. bobj.crv.params.ParameterUI.deleteValue = function(index) {
  336. if (index >= 0 && index < this._rows.length) {
  337. var row = this._rows[index];
  338. row.layer.parentNode.removeChild(row.layer);
  339. _widgets[row.widx] = null;
  340. this._rows.splice(index, 1);
  341. this._numRowsChanged = true;
  342. var rowsLen = this._rows.length;
  343. for (var i = index; i < rowsLen; ++i) {
  344. this._rows[i].setBgColor(this._getBgColor(i));
  345. }
  346. if (this._rowCreator) {
  347. this._rowCreator.setBgColor(this._getBgColor(rowsLen));
  348. }
  349. }
  350. };
  351. bobj.crv.params.ParameterUI.setWarning = function(index, warning) {
  352. var row = this._rows[index];
  353. if (row) {
  354. row.setWarning(warning);
  355. }
  356. };
  357. bobj.crv.params.ParameterUI.getWarning = function(index) {
  358. var row = this._rows[index];
  359. if (row) {
  360. return row.getWarning();
  361. }
  362. };
  363. bobj.crv.params.ParameterUI.setSelected = function(index) {
  364. var row = this._rows[index];
  365. if (row && this._selectedRow != row) {
  366. if(this._getRowIndex(this._selectedRow) != -1) {
  367. this.deselect(); // deselect only if the selected row is not removed from rows list
  368. }
  369. this._selectedRow = row;
  370. row.select();
  371. }
  372. };
  373. bobj.crv.params.ParameterUI.deselect = function() {
  374. if (this._selectedRow) {
  375. this._selectedRow.deselect();
  376. this._selectedRow = null;
  377. }
  378. };
  379. bobj.crv.params.ParameterUI.resize = function(w) {
  380. if (w !== null) {
  381. this.width = w;
  382. if (this.layer) {
  383. bobj.setOuterSize(this.layer, w);
  384. }
  385. }
  386. };
  387. /*
  388. ================================================================================
  389. BackgroundColor
  390. Enum for parameter value row background colors
  391. ================================================================================
  392. */
  393. bobj.crv.params.BackgroundColor = {
  394. standard: 0,
  395. dirty: 1,
  396. alternate: 2,
  397. dirtyAlternate: 3
  398. };
  399. /*
  400. ================================================================================
  401. ParameterValueRow
  402. Internal class for use by ParameterUI. Darws a UI for a single parameter value.
  403. ================================================================================
  404. */
  405. // these are the Y offsets of the icons in the param_panel.gif image
  406. bobj.crv.paramPanelIcon = bobj.crvUri('images/param_panel.gif');
  407. bobj.crv.paramWarningIconYOffset = 0; // param_warning.gif
  408. bobj.crv.paramAdvIconYOffset = 124; //param_adv.gif
  409. bobj.crv.params.newParameterValueRow = function(kwArgs) {
  410. kwArgs = MochiKit.Base.update({
  411. id: bobj.uniqueId(),
  412. value: '',
  413. defaultValues: null,
  414. bgColor: bobj.crv.params.BackgroundColor.standard,
  415. isReadOnlyParam: true,
  416. canChangeOnPanel: false,
  417. allowCustom: false,
  418. isPassword: false,
  419. hasButton: false,
  420. buttonUrl: null,
  421. changeCB: null,
  422. selectCB: null,
  423. enterCB: null,
  424. buttonClickCB: null,
  425. openAdvDialogCB: null,
  426. defaultValuesMenu: null,
  427. tooltip : null
  428. }, kwArgs);
  429. var o = newWidget(kwArgs.id);
  430. o.widgetType = 'ParameterValueRow';
  431. o._prevValueString = kwArgs.value;
  432. o._warning = null;
  433. // Update instance with constructor arguments
  434. bobj.fillIn(o, kwArgs);
  435. // Update instance with member functions
  436. MochiKit.Base.update(o, bobj.crv.params.ParameterValueRow);
  437. return o;
  438. };
  439. bobj.crv.params.ParameterValueRow.init = function() {
  440. Widget_init.call(this);
  441. this._valueWidget.init();
  442. if (this._button) {
  443. this._button.init();
  444. }
  445. this._valueCtn = getLayer(this.id + '_vc');
  446. this._rightCtn = getLayer(this.id + '_rc');
  447. this._icon = this._rightCtn.firstChild;
  448. this._btnCtn = getLayer(this.id + '_bc');
  449. this._valBtnCtn = getLayer(this.id + '_vab');
  450. this._advBtnCtn = getLayer(this.id + '_adv_ctn');
  451. if (this._advButton) {
  452. this._advButton.init();
  453. }
  454. if (MochiKit.Base.isIE()) {
  455. // IE's 100% is different than other browsers, even in standards compliant mode....
  456. var marg = parseInt(MochiKit.Style.computedStyle(this._valueCtn, 'margin-right'), 10);
  457. if (bobj.isNumber(marg)) {
  458. this._valueWidget.layer.style.marginRight = (-1 * marg) + 'px';
  459. }
  460. }
  461. this.layer.onmousedown = MochiKit.Base.bind(this._onMouseDown, this);
  462. };
  463. bobj.crv.params.ParameterValueRow.getHTML = function() {
  464. if (!this._valueWidget) {
  465. this._valueWidget = this._getValueWidget();
  466. }
  467. if (this.hasButton && !this._button) {
  468. var clickCB = MochiKit.Base.bind(this._onButtonClick, this);
  469. this._button = bobj.crv.params.newParamValueButton({url: this.buttonUrl, clickCB: clickCB});
  470. }
  471. var DIV = bobj.html.DIV;
  472. var IMG = bobj.html.IMG;
  473. var cssClass = this._getBgColorClass(this.bgColor) + ' iactParamRow';
  474. if (MochiKit.Base.isIE() && bobj.isQuirksMode()) {
  475. cssClass += ' ' + 'iactParamRowIE';
  476. }
  477. return DIV({id: this.id, 'class': cssClass},
  478. this.hasButton ? this._getValueAndButtonHTML() : this._getValueHTML(),
  479. DIV({id: this.id+'_rc', 'class': 'iactParamRight'},
  480. imgOffset(bobj.crv.paramPanelIcon,16,16,0,bobj.crv.paramWarningIconYOffset,this.id + '_icn',
  481. 'class="iactParamValueWarningIcon"','','display:none',''),this._getAdvButtonHTML ()));
  482. };
  483. bobj.crv.params.ParameterValueRow._getAdvButtonHTML = function () {
  484. this._advButton = bobj.crv.params.newParamValueButton ({
  485. id: this.id + '_adv_icn',
  486. url: bobj.crv.paramPanelIcon,
  487. clickCB: this.openAdvDialogCB,
  488. tooltip: L_bobj_crv_ParamsAdvDlg,
  489. dx:0,
  490. dy:bobj.crv.paramAdvIconYOffset});
  491. var DIV = bobj.html.DIV;
  492. return DIV({id:this.id + "_adv_ctn", style:{display:"none", position:"absolute", right:"0", top:"0", cursor:_hand}},
  493. this._advButton.getHTML());
  494. };
  495. /**
  496. * @return [String] Returns HTML for the the value
  497. */
  498. bobj.crv.params.ParameterValueRow._getValueHTML = function() {
  499. var DIV = bobj.html.DIV;
  500. var style = {};
  501. if(MochiKit.Base.isIE() && bobj.isQuirksMode()) {
  502. style.position = "absolute";
  503. style.top = "0px";
  504. style.left= "0px";
  505. }
  506. return DIV({id: this.id + '_vc', 'class': 'iactParamValue', style: style}, this._valueWidget.getHTML());
  507. };
  508. /**
  509. * @return [String] Returns HTML for the value and a button beside it
  510. */
  511. bobj.crv.params.ParameterValueRow._getValueAndButtonHTML = function() {
  512. var style = {};
  513. if (MochiKit.Base.isIE() && bobj.isQuirksMode()) {
  514. style.width = '100%';
  515. }
  516. var DIV = bobj.html.DIV;
  517. var html = DIV({id: this.id + "_vab", style: style, 'class': "iactParamValueAndButton"},
  518. this._getValueHTML(),
  519. DIV({id:this.id + "_bc", 'class':"iactValueIcon", style:{position:"absolute", right:"0", top:"0", cursor:_hand}},
  520. this._button.getHTML()));
  521. return html;
  522. };
  523. /**
  524. * Creates a widget to display/edit the value.
  525. *
  526. * @return [Widget]
  527. */
  528. bobj.crv.params.ParameterValueRow._getValueWidget = function() {
  529. var showDefVals = this.defaultValuesMenu !== null && !this.isReadOnlyParam && this.canChangeOnPanel;
  530. var typeCons = showDefVals ? 'newTextCombo' : 'newTextField';
  531. var bind = MochiKit.Base.bind;
  532. var widget = bobj.crv.params[typeCons]({
  533. password: this.isPassword,
  534. cleanValue: this.value,
  535. editable: this.allowCustom && this.canChangeOnPanel,
  536. enterCB: bind(this._onEnterPress, this),
  537. keyUpCB: bind(this._onKeyUp, this),
  538. bgColor: this.bgColor,
  539. tooltip : this.tooltip
  540. });
  541. if(showDefVals) {
  542. widget.setMenu(this.defaultValuesMenu);
  543. widget.changeCB = bind(this._onChange, this);
  544. }
  545. return widget;
  546. };
  547. bobj.crv.params.ParameterValueRow.getValue = function() {
  548. if (this._valueWidget) {
  549. return this._valueWidget.getValue();
  550. }
  551. return this.value;
  552. };
  553. bobj.crv.params.ParameterValueRow.setValue = function(value) {
  554. if (this._valueWidget) {
  555. this._valueWidget.setValue(value);
  556. }
  557. };
  558. bobj.crv.params.ParameterValueRow.setCleanValue = function(value) {
  559. if (this._valueWidget) {
  560. this._valueWidget.setCleanValue(value);
  561. }
  562. };
  563. /**
  564. * Set keyboard focus to the widget and mark it as selected
  565. */
  566. bobj.crv.params.ParameterValueRow.select =
  567. bobj.crv.params.ParameterValueRow.focus = function() {
  568. this._select(true);
  569. if(this._valueWidget.widgetType == "TextCombo") {
  570. this._valueWidget.text.focus();
  571. }
  572. else {
  573. this._valueWidget.focus();
  574. }
  575. };
  576. /**
  577. * Check if the widget is selected
  578. *
  579. * @return [boolean] True iff the widget is selected.
  580. */
  581. bobj.crv.params.ParameterValueRow.isSelected = function() {
  582. return this._isSelected;
  583. };
  584. /**
  585. * Deselects this parameter widget.
  586. */
  587. bobj.crv.params.ParameterValueRow.deselect = function() {
  588. this._select(false);
  589. };
  590. /**
  591. * Displays a thick border around the widget when it is selected.
  592. *
  593. * @param select [boolean] Border is displayed when true
  594. *
  595. */
  596. bobj.crv.params.ParameterValueRow._select = function(select) {
  597. this._isSelected = select ? true : false;
  598. if (select) {
  599. var addClass = MochiKit.DOM.addElementClass;
  600. addClass(this._rightCtn, 'iactParamRightSel');
  601. addClass(this.layer, 'iactParamRowSel');
  602. if (this._valBtnCtn) {
  603. addClass(this._valBtnCtn, 'iactParamValueAndButtonSel');
  604. }
  605. else {
  606. addClass(this._valueCtn, 'iactParamValueSel');
  607. }
  608. }
  609. else {
  610. var removeClass = MochiKit.DOM.removeElementClass;
  611. removeClass(this._rightCtn, 'iactParamRightSel');
  612. removeClass(this.layer, 'iactParamRowSel');
  613. if (this._valBtnCtn) {
  614. removeClass(this._valBtnCtn, 'iactParamValueAndButtonSel');
  615. }
  616. else {
  617. removeClass(this._valueCtn, 'iactParamValueSel');
  618. }
  619. }
  620. if(this._valueWidget && this._valueWidget.setSelected) {
  621. this._valueWidget.setSelected(select);
  622. }
  623. this._showAdvButton (select);
  624. };
  625. /**
  626. * Shows (or hides) the adv button icon
  627. */
  628. bobj.crv.params.ParameterValueRow._showAdvButton = function(visible) {
  629. if (this.isReadOnlyParam) {return;}
  630. if (visible === true) {
  631. this._advBtnCtn.style.display = '';
  632. }
  633. else {
  634. this._advBtnCtn.style.display = 'none';
  635. }
  636. };
  637. /**
  638. * Display a warning icon with a tooltip message
  639. *
  640. * @param warning [String] Tooltip message. If null, warning is hidden.
  641. */
  642. bobj.crv.params.ParameterValueRow.setWarning = function(warning) {
  643. if (warning) {
  644. bobj.crv.Tooltip.setElementTooltip(this._icon, warning.message);
  645. this._icon.style.display = '';
  646. }
  647. else {
  648. this._icon.style.display = 'none';
  649. }
  650. this._warning = warning;
  651. };
  652. bobj.crv.params.ParameterValueRow.getWarning = function() {
  653. return this._warning;
  654. };
  655. /**
  656. * Change the outer dimensions of the widget
  657. *
  658. * @param w [int, optional] Width in pixels
  659. * @param h [int, optional] Height in pixels
  660. */
  661. bobj.crv.params.ParameterValueRow.resize = function(w, h) {
  662. bobj.setOuterSize(this.layer, w, h);
  663. };
  664. /**
  665. * Check if the parameter value has been changed
  666. *
  667. * @return [boolean] True iff the value has been changed using the UI
  668. */
  669. bobj.crv.params.ParameterValueRow.isDirty = function() {
  670. return this._valueWidget.isDirty();
  671. };
  672. /**
  673. * Set the background color
  674. *
  675. * @param color [int] BackgroundColor enum member
  676. */
  677. bobj.crv.params.ParameterValueRow.setBgColor = function(color) {
  678. if (color !== this.bgColor) {
  679. if (this.layer) {
  680. var DOM = MochiKit.DOM;
  681. DOM.removeElementClass(this.layer, this._getBgColorClass(this.bgColor));
  682. DOM.addElementClass(this.layer, this._getBgColorClass(color));
  683. }
  684. this.bgColor = color;
  685. this._valueWidget.setBgColor(color);
  686. }
  687. };
  688. /**
  689. * @return [String] returns the css class for a background color
  690. */
  691. bobj.crv.params.ParameterValueRow._getBgColorClass = function(color) {
  692. var className = 'iactParamRowBg';
  693. var Colors = bobj.crv.params.BackgroundColor;
  694. if (color === Colors.alternate || color === Colors.dirtyAlternate) {
  695. className += 'Alt';
  696. }
  697. if (color === Colors.dirty || color === Colors.dirtyAlternate) {
  698. className += 'Dirty';
  699. }
  700. return className;
  701. };
  702. /**
  703. * Delete the current value
  704. */
  705. bobj.crv.params.ParameterValueRow.deleteValue = function() {
  706. this._valueWidget.setValue('', true);
  707. };
  708. /**
  709. * Handles events that cause this prompt to be selected.
  710. */
  711. bobj.crv.params.ParameterValueRow._onSelect = function() {
  712. var wasSelected = this.isSelected();
  713. if (!wasSelected && this.selectCB) {
  714. this.selectCB();
  715. }
  716. this._select(true);
  717. };
  718. /**
  719. * Handle keyUp events when editing values or using keyboard navigation.
  720. *
  721. * @param e [keyup event]
  722. */
  723. bobj.crv.params.ParameterValueRow._onKeyUp = function(e) {
  724. var event = new MochiKit.Signal.Event(src, e);
  725. var key = event.key().string;
  726. var newValueString = this._valueWidget.getValue();
  727. switch (key) {
  728. case "KEY_ESCAPE":
  729. this._valueWidget.setValue(this._valueWidget.cleanValue);
  730. if (this.changeCB) {
  731. this.changeCB();
  732. }
  733. this._onSelect();
  734. break;
  735. case "KEY_ARROW_LEFT":
  736. case "KEY_ARROW_RIGHT":
  737. case "KEY_HOME":
  738. case "KEY_END":
  739. case "KEY_TAB":
  740. this._onSelect();
  741. break;
  742. default:
  743. if (newValueString !== this._prevValueString) {
  744. this._onSelect();
  745. if (this.changeCB) {
  746. this.changeCB();
  747. }
  748. this._prevValueString = newValueString;
  749. }
  750. break;
  751. }
  752. };
  753. bobj.crv.params.ParameterValueRow._onChange = function() {
  754. if (this.changeCB) {
  755. this.changeCB();
  756. }
  757. };
  758. /**
  759. * Handles Enter key press events.
  760. */
  761. bobj.crv.params.ParameterValueRow._onEnterPress = function() {
  762. if (this.isSelected() && this.enterCB) {
  763. this.enterCB();
  764. }
  765. else {
  766. this._onSelect();
  767. }
  768. };
  769. /**
  770. * Selects this prompt when it's clicked.
  771. */
  772. bobj.crv.params.ParameterValueRow._onMouseDown = function() {
  773. this._onSelect();
  774. };
  775. bobj.crv.params.ParameterValueRow._onButtonClick = function() {
  776. if (this.buttonClickCB) {
  777. var absPos = getPosScrolled(this._button.layer);
  778. var x = absPos.x + this._button.getWidth();
  779. var y = absPos.y + this._button.getHeight() + 1;
  780. this.buttonClickCB(x, y);
  781. }
  782. };
  783. /*
  784. ================================================================================
  785. ParamValueButton
  786. Internal class. Button that fits inline with parameter values
  787. ================================================================================
  788. */
  789. bobj.crv.params.newParamValueButton = function(kwArgs) {
  790. kwArgs = MochiKit.Base.update({
  791. id: bobj.uniqueId(),
  792. url: null,
  793. clickCB: null,
  794. tooltip: this.tooltip,
  795. dx:0,
  796. dy:0
  797. }, kwArgs);
  798. var o = newIconWidget(
  799. kwArgs.id,
  800. kwArgs.url,
  801. kwArgs.clickCB,
  802. null,
  803. kwArgs.tooltip,
  804. 14,14,kwArgs.dx,kwArgs.dy,0,0);
  805. o.margin = 0;
  806. o.oldInit = o.init;
  807. // Update instance with member functions
  808. MochiKit.Base.update(o, bobj.crv.params.ParamValueButton);
  809. return o;
  810. };
  811. bobj.crv.params.ParamValueButton.init = function() {
  812. this.oldInit();
  813. this.layer.onfocus = IconWidget_realOverCB;
  814. this.layer.onblur = IconWidget_realOutCB;
  815. };
  816. bobj.crv.params.ParamValueButton.getHTML = function() {
  817. var imgCode;
  818. var h = bobj.html;
  819. if(this.src) {
  820. imgCode = h.DIV({style: {overflow: 'hidden', height: '16px', width : this.w + 'px'}},
  821. simpleImgOffset(this.src,
  822. this.w,
  823. this.h,
  824. this.dis ? this.disDx: this.dx,
  825. this.dis ? this.dixDy: this.dy,
  826. 'IconImg_' + this.id,
  827. null, //att
  828. this.alt,
  829. 'cursor:'+ _hand),
  830. this.extraHTML);
  831. }
  832. else {
  833. imgCode = h.DIV({'class' : 'icontext',
  834. 'style' : {width : '1px',height: (this.h + this.border) + 'px'}
  835. });
  836. }
  837. var divStyle = {margin: this.margin + 'px',
  838. padding : '1px'};
  839. if(this.width) {
  840. divStyle.width = this.width + 'px';
  841. }
  842. if(!this.disp) {
  843. divStyle.display = 'none';
  844. }
  845. return h.DIV({style : divStyle,
  846. id : this.id,
  847. 'class' : this.nocheckClass
  848. },
  849. (this.clickCB && _ie)? lnk(imgCode, null, null, null, ' tabIndex="-1"' ) : imgCode
  850. );
  851. };
  852. /*
  853. ================================================================================
  854. ParamRowCreator
  855. Internal class. UI for adding new values to a multi value parameter
  856. ================================================================================
  857. */
  858. bobj.crv.params.newParamRowCreator = function(kwArgs) {
  859. kwArgs = MochiKit.Base.update({
  860. id: bobj.uniqueId(),
  861. bgColor: null,
  862. activateCB : null
  863. }, kwArgs);
  864. var o = newWidget(kwArgs.id);
  865. o.widgetType = 'ParamRowCreator';
  866. // Update instance with constructor arguments
  867. bobj.fillIn(o, kwArgs);
  868. // Update instance with member functions
  869. MochiKit.Base.update(o, bobj.crv.params.ParamRowCreator);
  870. o._textField = o._createTextField();
  871. return o;
  872. };
  873. bobj.crv.params.ParamRowCreator.init = function() {
  874. Widget_init.call(this);
  875. this._textField.init();
  876. this.layer.onclick = MochiKit.Base.bind(this._onClick, this);
  877. };
  878. bobj.crv.params.ParamRowCreator.show = function(show) {
  879. if (show === false) {
  880. this.css.visibility = "hidden";
  881. this.css.display = "none";
  882. }
  883. else {
  884. this.css.visibility = "visible";
  885. this.css.display = "block";
  886. }
  887. };
  888. bobj.crv.params.ParamRowCreator.getHTML = function() {
  889. var DIV = bobj.html.DIV;
  890. cssClass = this._getBgColorClass() + ' iactParamRow';
  891. ieCssClass = 'iactParamRowIE';
  892. var valStyle = '';
  893. if (MochiKit.Base.isIE() && bobj.isQuirksMode()) {
  894. cssClass += ' ' + ieCssClass;
  895. valStyle.width = '100%';
  896. }
  897. return DIV({id: this.id, 'class': cssClass},
  898. DIV({'class': 'iactParamValue', style: valStyle}, this._textField.getHTML()),
  899. DIV({'class': 'iactParamRight'}));
  900. };
  901. bobj.crv.params.ParamRowCreator._getBgColorClass = bobj.crv.params.ParameterValueRow._getBgColorClass;
  902. bobj.crv.params.ParamRowCreator.setBgColor = function(color) {
  903. if (color !== this.bgColor) {
  904. if (this.layer) {
  905. MochiKit.DOM.removeElementClass(this.layer, this._getBgColorClass(this.bgColor));
  906. MochiKit.DOM.addElementClass(this.layer, this._getBgColorClass(color));
  907. }
  908. this.bgColor = color;
  909. this._textField.setBgColor(color);
  910. }
  911. };
  912. bobj.crv.params.ParamRowCreator._createTextField = function() {
  913. var text = bobj.crv.params.newTextField({
  914. cleanValue: L_bobj_crv_ParamsAddValue,
  915. editable: false,
  916. enterCB: MochiKit.Base.bind(this._onEnterPress, this)
  917. });
  918. return text;
  919. };
  920. bobj.crv.params.ParamRowCreator._onEnterPress = function() {
  921. if (this.activateCB) {
  922. this.activateCB();
  923. }
  924. };
  925. bobj.crv.params.ParamRowCreator._onClick = function() {
  926. if (this.activateCB) {
  927. this.activateCB();
  928. }
  929. };
  930. /**
  931. * Change the outer dimensions of the widget
  932. *
  933. * @param w [int, optional] Width in pixels
  934. * @param h [int, optional] Height in pixels
  935. */
  936. bobj.crv.params.ParamRowCreator.resize = function(w, h) {
  937. bobj.setOuterSize(this.layer, w, h);
  938. };
  939. /*
  940. ================================================================================
  941. TextField
  942. Internal class. Text box that renders correctly in a Parameter UI
  943. ================================================================================
  944. */
  945. /**
  946. * Constructor. TextField extends TextFieldWidget from the dhtmllib.
  947. */
  948. bobj.crv.params.newTextField = function(kwArgs) {
  949. kwArgs = MochiKit.Base.update({
  950. id: bobj.uniqueId(),
  951. cleanValue: '',
  952. width: '100%',
  953. maxChar: null,
  954. tooltip: null,
  955. disabled: false,
  956. editable: true,
  957. password: false,
  958. focusCB: null,
  959. blurCB: null,
  960. changeCB: null,
  961. keyUpCB: null,
  962. enterCB: null,
  963. bgColor: bobj.crv.params.BackgroundColor.standard,
  964. alwaysDirty: false
  965. }, kwArgs);
  966. var o = newTextFieldWidget(
  967. kwArgs.id,
  968. kwArgs.changeCB,
  969. kwArgs.maxChar,
  970. kwArgs.keyUpCB,
  971. kwArgs.enterCB,
  972. true, //nomargin
  973. kwArgs.tooltip,
  974. null, //width
  975. kwArgs.focusCB,
  976. kwArgs.blurCB);
  977. o.widgetType = 'TextField';
  978. // Update instance with constructor arguments
  979. bobj.fillIn(o, kwArgs);
  980. o.disabled = kwArgs.disabled;
  981. o.width = kwArgs.width;
  982. // Update instance with member functions
  983. MochiKit.Base.update(o, bobj.crv.params.TextField);
  984. if (kwArgs.cleanValue) {
  985. o.setValue(kwArgs.cleanValue);
  986. }
  987. return o;
  988. };
  989. bobj.crv.params.TextField.setAlwaysDirty = function() {
  990. this.alwaysDirty = true;
  991. };
  992. bobj.crv.params.TextField.getHTML = function() {
  993. var style = {
  994. width: bobj.unitValue(this.width)
  995. };
  996. var isIE = MochiKit.Base.isIE();
  997. var className = this._getBgColorClass(this.bgColor) + ' iactTextField';
  998. if (isIE && bobj.isQuirksMode()) {
  999. className += 'IE';
  1000. }
  1001. var attributes = {
  1002. type: this.password ? 'password' : 'text',
  1003. name: this.id,
  1004. id: this.id,
  1005. maxLength: this.maxChar,
  1006. style: style,
  1007. 'class': className,
  1008. oncontextmenu: "event.cancelBubble=true;return true",
  1009. onfocus: "TextFieldWidget_focus(this)",
  1010. onblur: "TextFieldWidget_blur(this)",
  1011. onchange: "TextFieldWidget_changeCB(event, this)",
  1012. onkeydown: "return TextFieldWidget_keyDownCB(event, this);",
  1013. onkeyup: "return TextFieldWidget_keyUpCB(event, this);",
  1014. onkeypress: "return TextFieldWidget_keyPressCB(event, this);",
  1015. ondragstart: "event.cancelBubble=true; return true;",
  1016. onselectstart: "event.cancelBubble=true; return true;"
  1017. };
  1018. if (this.disabled) {
  1019. attributes.disabled = "disabled";
  1020. }
  1021. if (!this.editable) {
  1022. attributes.readonly = "readonly";
  1023. if (isIE) {
  1024. style.filter = 'alpha(opacity=50)';
  1025. }
  1026. else {
  1027. style.opacity = '0.5';
  1028. }
  1029. }
  1030. if (this.tooltip) {
  1031. attributes.title = this.tooltip;
  1032. }
  1033. return bobj.html.INPUT(attributes);
  1034. };
  1035. /**
  1036. * Change the background color of the widget
  1037. *
  1038. * @param color [int] BackgroundColor enum value
  1039. */
  1040. bobj.crv.params.TextField.setBgColor = function(color) {
  1041. if (color !== this.bgColor) {
  1042. if (this.layer) {
  1043. var DOM = MochiKit.DOM;
  1044. DOM.removeElementClass(this.layer, this._getBgColorClass(this.bgColor));
  1045. DOM.addElementClass(this.layer, this._getBgColorClass(color));
  1046. }
  1047. this.bgColor = color;
  1048. }
  1049. };
  1050. bobj.crv.params.TextField.isDirty = function() {
  1051. return this.alwaysDirty === true || this.getValue() !== this.cleanValue;
  1052. };
  1053. bobj.crv.params.TextField.setValue = function(value) {
  1054. TextFieldWidget_setValue.call(this, value);
  1055. };
  1056. bobj.crv.params.TextField.setCleanValue = function(value) {
  1057. this.cleanValue = value;
  1058. };
  1059. bobj.crv.params.TextField._getBgColorClass = function(color) {
  1060. var className = 'iactTextFieldBg';
  1061. var Colors = bobj.crv.params.BackgroundColor;
  1062. if (color === Colors.alternate || color === Colors.dirtyAlternate) {
  1063. className += 'Alt';
  1064. }
  1065. if (color === Colors.dirty || color === Colors.dirtyAlternate) {
  1066. className += 'Dirty';
  1067. }
  1068. return className;
  1069. };
  1070. /*
  1071. ================================================================================
  1072. TextCombo
  1073. Internal class. Editable combo box that renders correctly in a Parameter UI
  1074. ================================================================================
  1075. */
  1076. /**
  1077. * Constructor. TextCombo extends TextComboWidget from the dhtmllib.
  1078. */
  1079. bobj.crv.params.newTextCombo = function(kwArgs) {
  1080. var UPDATE = MochiKit.Base.update;
  1081. var PARAMS = bobj.crv.params;
  1082. kwArgs = UPDATE({
  1083. id: bobj.uniqueId(),
  1084. width: '100%',
  1085. maxChar: null,
  1086. tooltip: null,
  1087. disabled: false,
  1088. editable: false,
  1089. changeCB: null,
  1090. enterCB: null,
  1091. keyUpCB: null,
  1092. selected: false,
  1093. bgColor: PARAMS.BackgroundColor.standard
  1094. }, kwArgs);
  1095. var o = newTextComboWidget(
  1096. kwArgs.id,
  1097. kwArgs.maxChar,
  1098. kwArgs.tooltip,
  1099. null, // width
  1100. kwArgs.changeCB,
  1101. null, // check CB
  1102. null, // beforeShowCB
  1103. null);// formName
  1104. o.widgetType = 'TextCombo';
  1105. // Update instance with constructor arguments
  1106. bobj.fillIn(o, kwArgs);
  1107. o.width = kwArgs.width;
  1108. // Update instance with member functions
  1109. o.init_TextCombo = o.init;
  1110. UPDATE(o, PARAMS.TextCombo);
  1111. o._createTextField(); // Override parent's text property
  1112. o._createArrow();
  1113. o.arrow.dy += 2; // Center the arrow
  1114. o.arrow.disDy += 2;
  1115. return o;
  1116. };
  1117. bobj.crv.params.TextCombo.setAlwaysDirty = function() {
  1118. this.text.setAlwaysDirty();
  1119. };
  1120. bobj.crv.params.TextCombo.setMenu = function(menu) {
  1121. this.menu = menu;
  1122. };
  1123. bobj.crv.params.TextCombo.init = function() {
  1124. var BIND = MochiKit.Base.bind;
  1125. this.init_TextCombo();
  1126. this.arrowContainer = getLayer(this.id + '_arrowCtn');
  1127. this.layer.onmouseover = BIND(this.showArrow, this,true);
  1128. this.layer.onmouseout = BIND(this.onMouseOut, this);
  1129. if(this.arrow) {
  1130. this.arrow.layer.onfocus = IconWidget_realOverCB;
  1131. this.arrow.layer.onblur = IconWidget_realOutCB;
  1132. }
  1133. this.text.setValue(this.cleanValue);
  1134. };
  1135. bobj.crv.params.TextCombo.onMouseOut = function() {
  1136. if(this.selected === false) {
  1137. this.showArrow(false);
  1138. }
  1139. };
  1140. bobj.crv.params.TextCombo.setSelected = function(selected) {
  1141. if(this.selected != selected) {
  1142. this.selected = selected;
  1143. this.showArrow(selected);
  1144. }
  1145. };
  1146. bobj.crv.params.TextCombo.showArrow = function(show) {
  1147. if(this.arrowContainer) {
  1148. this.arrowContainer.style.visibility = show ? "visible" : "hidden";
  1149. }
  1150. };
  1151. bobj.crv.params.TextCombo.showMenu = function() {
  1152. var menu = this.menu;
  1153. menu.parIcon = this;
  1154. menu.show(true);
  1155. menu.valueSelect(this.text.getValue() + '');
  1156. };
  1157. bobj.crv.params.TextCombo._createArrow = function() {
  1158. this.arrow = newIconWidget(this.id + "arrow_",
  1159. bobj.skinUri("menus.gif"),
  1160. MochiKit.Base.bind(this.showMenu,this),
  1161. null,
  1162. (_openMenuPart1 + (this.tooltip? this.tooltip: '' ) + _openMenuPart2),
  1163. 7,//w
  1164. 12, //h
  1165. 0, //dx
  1166. 83, //dy
  1167. 0, //disDx
  1168. 99); //disDy
  1169. this.arrow.setClasses("iconnocheck", "combobtnhover", "combobtnhover", "combobtnhover");
  1170. this.arrow.par = this;
  1171. };
  1172. bobj.crv.params.TextCombo._createTextField = function() {
  1173. this.text = bobj.crv.params.newTextField({
  1174. id: this.id + '_text',
  1175. cleanValue: this.cleanValue,
  1176. width: '100%',
  1177. maxChar: null,
  1178. tooltip: this.tooltip,
  1179. disabled: false,
  1180. editable: this.editable,
  1181. password: false,
  1182. focusCB: null,
  1183. blurCB: null,
  1184. keyUpCB: MochiKit.Base.bind(this._onKeyUp, this),
  1185. enterCB: this.enterCB,
  1186. alwaysDirty: false
  1187. });
  1188. };
  1189. bobj.crv.params.TextCombo.getHTML = function() {
  1190. var h = bobj.html;
  1191. var className = this._getBgColorClass(this.bgColor);
  1192. this.text.bgColor = this.bgColor;
  1193. var arrowClassName = 'iactTextComboArrow';
  1194. var arrowStyle = {};
  1195. arrowStyle.right = "0px";
  1196. arrowStyle.visibility = "hidden";
  1197. if (MochiKit.Base.isIE()) {
  1198. arrowStyle.height = "18px";
  1199. if(!bobj.isQuirksMode()) {
  1200. arrowStyle.right = "5px";
  1201. }
  1202. }
  1203. else {
  1204. arrowStyle.height = "16px" ;
  1205. }
  1206. var html = h.DIV({id: this.id, 'class': className, style: {width: "100%", position: "relative"}},
  1207. h.DIV({style:{position: "relative"}, 'class': 'iactTextComboTextField'},
  1208. this.text.getHTML()),
  1209. h.DIV({'class': arrowClassName, id : this.id + '_arrowCtn', style:arrowStyle},
  1210. this.arrow.getHTML()));
  1211. return html;
  1212. };
  1213. /**
  1214. * Set the content of the text box and update the menu selection
  1215. *
  1216. * @param text [String]
  1217. */
  1218. bobj.crv.params.TextCombo.setValue = function(text) {
  1219. this.text.setValue(text);
  1220. };
  1221. bobj.crv.params.TextCombo.setCleanValue = function(text) {
  1222. this.text.setCleanValue(text);
  1223. };
  1224. /**
  1225. * Private. Overrides parent.
  1226. */
  1227. bobj.crv.params.TextCombo.selectItem = function(item){
  1228. if (item) {
  1229. this.val = item.value;
  1230. this.text.setValue(item.value, true); // keep the previous clean value
  1231. this.menu.select(item.index);
  1232. }
  1233. };
  1234. /**
  1235. * Get the content on the text box
  1236. *
  1237. * @return [String]
  1238. */
  1239. bobj.crv.params.TextCombo.getValue = function() {
  1240. return this.text.getValue();
  1241. };
  1242. /**
  1243. * Change the background color of the widget
  1244. *
  1245. * @param color [int] BackgroundColor enum value
  1246. */
  1247. bobj.crv.params.TextCombo.setBgColor = function(color) {
  1248. if (color !== this.bgColor) {
  1249. if (this.layer) {
  1250. var DOM = MochiKit.DOM;
  1251. DOM.removeElementClass(this.layer, this._getBgColorClass(this.bgColor));
  1252. DOM.addElementClass(this.layer, this._getBgColorClass(color));
  1253. }
  1254. this.bgColor = color;
  1255. }
  1256. if (this.text) {
  1257. this.text.setBgColor(color);
  1258. }
  1259. };
  1260. bobj.crv.params.TextCombo._onKeyUp = function(e) {
  1261. var text = this.text.getValue();
  1262. if (this.keyUpCB) {
  1263. this.keyUpCB(e);
  1264. }
  1265. };
  1266. bobj.crv.params.TextCombo.isDirty = function() {
  1267. return this.text.isDirty();
  1268. };
  1269. bobj.crv.params.TextCombo._getBgColorClass = function(color) {
  1270. var className = 'iactTextComboBg';
  1271. var Colors = bobj.crv.params.BackgroundColor;
  1272. if (color === Colors.alternate || color === Colors.dirtyAlternate) {
  1273. className += 'Alt';
  1274. }
  1275. if (color === Colors.dirty || color === Colors.dirtyAlternate) {
  1276. className += 'Dirty';
  1277. }
  1278. return className;
  1279. };
  1280. bobj.crv.params.newScrollMenuWidget = function(kwArgs) {
  1281. kwArgs = MochiKit.Base.update({
  1282. id : bobj.uniqueId(),
  1283. originalValues: [],
  1284. hasProperWidth: false,
  1285. hasValueList: false,
  1286. maxVisibleItems: 10,
  1287. openAdvDialogCB: null,
  1288. maxNumParameterDefaultValues: null
  1289. },kwArgs);
  1290. var visibleLines = (kwArgs.originalValues.length >= kwArgs.maxVisibleItems) ? kwArgs.maxVisibleItems : kwArgs.originalValues.length;
  1291. if (visibleLines === 1) {
  1292. visibleLines++;
  1293. }
  1294. var o = newScrollMenuWidget(
  1295. "menu_"+ kwArgs.id, //id
  1296. bobj.crv.params.ScrollMenuWidget.onChange, //changeCB
  1297. false, //multi
  1298. null,
  1299. visibleLines, //lines
  1300. null, //tooltip
  1301. null,//dblClickCB
  1302. null, //keyUpCB
  1303. false, //showLabel
  1304. '', //label
  1305. '',//convBlanks
  1306. null, //beforeShowCB
  1307. null); //menuClickCB
  1308. o.oldShow = o.show;
  1309. MochiKit.Base.update(o,kwArgs, bobj.crv.params.ScrollMenuWidget);
  1310. return o;
  1311. };
  1312. bobj.crv.params.ScrollMenuWidget.onChange = function() {
  1313. var o = this.parIcon;
  1314. var item = this.getSelection();
  1315. if (item) {
  1316. if (this.maxNumParameterDefaultValues && item.index == this.maxNumParameterDefaultValues) {
  1317. if (this.openAdvDialogCB) {
  1318. this.openAdvDialogCB();
  1319. }
  1320. }
  1321. else {
  1322. o.val = item.value;
  1323. o.text.setValue(item.value);
  1324. }
  1325. }
  1326. else {
  1327. o.val = null;
  1328. o.text.setValue("");
  1329. }
  1330. if (o.changeCB) {
  1331. o.changeCB();
  1332. }
  1333. };
  1334. bobj.crv.params.ScrollMenuWidget.getPosition = function() {
  1335. if(this.parIcon === null) {
  1336. return;
  1337. }
  1338. var layer = this.parIcon.layer;
  1339. var getDimensions = MochiKit.Style.getElementDimensions;
  1340. var position = getPosScrolled(layer);
  1341. var xPos = position.x + 2;
  1342. var yPos = position.y + getDimensions(layer).h + 3;
  1343. if (MochiKit.Base.isIE()) {
  1344. xPos -= 1;
  1345. if(bobj.isQuirksMode()){
  1346. yPos -= 2;
  1347. }
  1348. }
  1349. return {x : xPos, y : yPos};
  1350. };
  1351. bobj.crv.params.ScrollMenuWidget.setProperWidth = function() {
  1352. if(this.hasProperWidth === false) {
  1353. this.css.display = "block";
  1354. this.orginalWidth = this.layer.offsetWidth;
  1355. this.css.display = "none";
  1356. this.hasProperWidth = true;
  1357. }
  1358. };
  1359. bobj.crv.params.ScrollMenuWidget.setValueList = function() {
  1360. if(this.hasValueList === false ) {
  1361. this.hasValueList = true;
  1362. var origValues = this.originalValues;
  1363. for(var i = 0, len = origValues.length; i < len; i++) {
  1364. this.add(origValues[i], origValues[i],false);
  1365. }
  1366. }
  1367. };
  1368. bobj.crv.params.ScrollMenuWidget.setFocus = function(focus) {
  1369. if(focus) {
  1370. var focusCB = MochiKit.Base.bind(this.list.focus,this.list);
  1371. setTimeout(focusCB,300);
  1372. }
  1373. else {
  1374. if(this.parIcon.selected === true) {
  1375. this.parIcon.arrow.focus();
  1376. }
  1377. }
  1378. };
  1379. bobj.crv.params.ScrollMenuWidget.show = function(show) {
  1380. if (this.layer===null) {
  1381. this.justInTimeInit();
  1382. }
  1383. if(this.hasValueList === false) {
  1384. this.setValueList();
  1385. }
  1386. if(this.parIcon === null) {
  1387. return;
  1388. }
  1389. if(this.hasProperWidth === false) {
  1390. this.setProperWidth();
  1391. }
  1392. if(this.parIcon && this.parIcon.layer) {
  1393. var layer = this.parIcon.layer;
  1394. if(layer.clientWidth > this.orginalWidth) {
  1395. this.css.width = layer.clientWidth + "px";
  1396. this.list.css.width = layer.clientWidth + "px";
  1397. }
  1398. else {
  1399. this.css.width = this.orginalWidth + "px";
  1400. this.list.css.width = this.orginalWidth + "px";
  1401. }
  1402. }
  1403. var pos = this.getPosition();
  1404. this.oldShow(show, pos.x, pos.y);
  1405. this.setFocus(show);
  1406. };
  1407. bobj.crv.params.newHelperRow = function(kwArgs) {
  1408. kwArgs = MochiKit.Base.update({
  1409. id: bobj.uniqueId(),
  1410. message : ''
  1411. }, kwArgs);
  1412. var o = newWidget(kwArgs.id);
  1413. o.widgetType = 'HelperRow';
  1414. // Update instance with constructor arguments
  1415. bobj.fillIn(o, kwArgs);
  1416. // Update instance with member functions
  1417. MochiKit.Base.update(o, bobj.crv.params.HelperRow);
  1418. return o;
  1419. };
  1420. bobj.crv.params.HelperRow.show = function(show) {
  1421. switch(show) {
  1422. case false:
  1423. this.css.visibility = "hidden";
  1424. this.css.display = "none";
  1425. break;
  1426. case true:
  1427. this.css.visibility = "visible";
  1428. this.css.display = "block";
  1429. break;
  1430. }
  1431. };
  1432. bobj.crv.params.HelperRow.getHTML = function() {
  1433. var DIV = bobj.html.DIV;
  1434. cssClass = this._getBgColorClass() + ' iactParamRow';
  1435. ieCssClass = 'iactParamRowIE';
  1436. var valStyle = '';
  1437. if (MochiKit.Base.isIE() && bobj.isQuirksMode()) {
  1438. cssClass += ' ' + ieCssClass;
  1439. valStyle.width = '100%';
  1440. }
  1441. return DIV({id: this.id, 'class': cssClass},
  1442. DIV({'class': 'iactParamValue', style: valStyle}, DIV({'class': 'helperRowMessage'}, "[" + this.message + "]")),DIV({'class': 'iactParamRight'}));
  1443. };
  1444. bobj.crv.params.HelperRow._getBgColorClass = bobj.crv.params.ParameterValueRow._getBgColorClass;
  1445. /**
  1446. * Change the outer dimensions of the widget
  1447. *
  1448. * @param w [int, optional] Width in pixels
  1449. * @param h [int, optional] Height in pixels
  1450. */
  1451. bobj.crv.params.HelperRow.resize = function(w, h) {
  1452. bobj.setOuterSize(this.layer, w, h);
  1453. };