dhtmlXGridCell.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /*
  2. * Copyright Scand LLC http://www.scbr.com To use this component please contact
  3. * info@scbr.com to obtain license
  4. */
  5. /**
  6. * @desc: dhtmlxGrid cell object constructor (shouldn't be accesed directly. Use
  7. * cells and cells2 methods of the grid instead)
  8. * @type: public
  9. * @returns: dhtmlxGrid cell
  10. */
  11. function dhtmlXGridCellObject(obj) {
  12. /**
  13. * @desc: desctructor, clean used memory
  14. * @type: public
  15. */
  16. this.destructor = function() {
  17. this.cell.obj = null;
  18. this.cell = null;
  19. this.grid = null;
  20. this.base = null;
  21. return null;
  22. }
  23. this.cell = obj;
  24. /**
  25. * @desc: gets Value of cell
  26. * @type: public
  27. */
  28. this.getValue = function() {
  29. return this.cell.innerHTML._dhx_trim();// innerText;
  30. }
  31. /**
  32. * @desc: gets math formula of cell if any
  33. * @type: public
  34. */
  35. this.getMathValue = function() {
  36. if (this.cell._val)
  37. return this.cell._val;// innerText;
  38. else
  39. return this.getValue();
  40. }
  41. /**
  42. * @desc: determ. font style if it was set
  43. * @returns: font name only if it was set for the cell
  44. * @type: public
  45. */
  46. this.getFont = function() {
  47. arOut = new Array(3);
  48. if (this.cell.style.fontFamily)
  49. arOut[0] = this.cell.style.fontFamily
  50. if (this.cell.style.fontWeight == 'bold'
  51. || this.cell.parentNode.style.fontWeight == 'bold')
  52. arOut[1] = 'bold';
  53. if (this.cell.style.fontStyle == 'italic'
  54. || this.cell.parentNode.style.fontWeight == 'italic')
  55. arOut[1] += 'italic';
  56. if (this.cell.style.fontSize)
  57. arOut[2] = this.cell.style.fontSize
  58. else
  59. arOut[2] = "";
  60. return arOut.join("-")
  61. }
  62. /**
  63. * @desc: determ. cell's text color
  64. * @returns: cell's text color
  65. * @type: public
  66. */
  67. this.getTextColor = function() {
  68. if (this.cell.style.color)
  69. return this.cell.style.color
  70. else
  71. return "#000000";
  72. }
  73. /**
  74. * @desc: determ. cell's background color
  75. * @returns: cell's background color
  76. * @type: public
  77. */
  78. this.getBgColor = function() {
  79. if (this.cell.bgColor)
  80. return this.cell.bgColor
  81. else
  82. return "#FFFFFF";
  83. }
  84. /**
  85. * @desc: determines horisontal align od the cell
  86. * @returns: horisontal align of cell content
  87. * @type: public
  88. */
  89. this.getHorAlign = function() {
  90. if (this.cell.style.textAlign)
  91. return this.cell.style.textAlign;
  92. else if (this.cell.align)
  93. return this.cell.align
  94. else
  95. return "left";
  96. }
  97. /**
  98. * @desc: gets width of the cell in pixel
  99. * @returns: width of the cell in pixels
  100. * @type: public
  101. */
  102. this.getWidth = function() {
  103. return this.cell.scrollWidth;
  104. }
  105. /**
  106. * @desc: sets font family to the cell
  107. * @param: val - string in format:
  108. * Arial-bold(italic,bolditalic,underline)-12px
  109. * @type: public
  110. */
  111. this.setFont = function(val) {
  112. fntAr = val.split("-");
  113. this.cell.style.fontFamily = fntAr[0];
  114. this.cell.style.fontSize = fntAr[fntAr.length - 1]
  115. if (fntAr.length == 3) {
  116. if (/bold/.test(fntAr[1]))
  117. this.cell.style.fontWeight = "bold";
  118. if (/italic/.test(fntAr[1]))
  119. this.cell.style.fontStyle = "italic";
  120. if (/underline/.test(fntAr[1]))
  121. this.cell.style.textDecoration = "underline";
  122. }
  123. }
  124. /**
  125. * @desc: sets text color to the cell
  126. * @param: val - color value (name or hex)
  127. * @type: public
  128. */
  129. this.setTextColor = function(val) {
  130. this.cell.style.color = val;
  131. }
  132. /**
  133. * @desc: sets background color to the cell
  134. * @param: val - color value (name or hex)
  135. * @type: public
  136. */
  137. this.setBgColor = function(val) {
  138. if (val == "")
  139. val = null;
  140. this.cell.bgColor = val;
  141. }
  142. /**
  143. * @desc: sets horisontal align to the cell
  144. * @param: val - value in single-letter or full format(exmp: r or right)
  145. * @type: public
  146. */
  147. this.setHorAlign = function(val) {
  148. if (val.length == 1) {
  149. if (val == 'c')
  150. this.cell.style.textAlign = 'center'
  151. else if (val == 'l')
  152. this.cell.style.textAlign = 'left';
  153. else
  154. this.cell.style.textAlign = 'right';
  155. } else
  156. this.cell.style.textAlign = val
  157. }
  158. /**
  159. * @desc: determines whether cell value was changed
  160. * @returns: true if cell value was changed, otherwise - false
  161. * @type: public
  162. */
  163. this.wasChanged = function() {
  164. if (this.cell.wasChanged)
  165. return true;
  166. else
  167. return false;
  168. }
  169. /**
  170. * @desc: determines whether first child of the cell is checkbox or radio
  171. * @returns: true if first child of the cell is input element of type radio
  172. * or checkbox
  173. * @type: public
  174. */
  175. this.isCheckbox = function() {
  176. var ch = this.cell.firstChild;
  177. if (ch && ch.tagName == 'INPUT') {
  178. type = ch.type;
  179. if (type == 'radio' || type == 'checkbox')
  180. return true;
  181. else
  182. return false;
  183. } else
  184. return false;
  185. }
  186. /**
  187. * @desc: determines whether radio or checkbox inside is checked
  188. * @returns: true if first child of the cell is checked
  189. * @type: public
  190. */
  191. this.isChecked = function() {
  192. if (this.isCheckbox()) {
  193. return this.cell.firstChild.checked;
  194. }
  195. }
  196. /**
  197. * @desc: determines whether cell content (radio,checkbox) is disabled
  198. * @returns: true if first child of the cell is disabled
  199. * @type: public
  200. */
  201. this.isDisabled = function() {
  202. if (this.isCheckbox()) {
  203. return this.cell.firstChild.disabled;
  204. }
  205. }
  206. /**
  207. * @desc: checks checkbox or radion
  208. * @param: fl - true or false
  209. * @type: public
  210. */
  211. this.setChecked = function(fl) {
  212. if (this.isCheckbox()) {
  213. if (fl != 'true' && fl != 1)
  214. fl = false;
  215. this.cell.firstChild.checked = fl;
  216. }
  217. }
  218. /**
  219. * @desc: disables radio or checkbox
  220. * @param: fl - true or false
  221. * @type: public
  222. */
  223. this.setDisabled = function(fl) {
  224. if (this.isCheckbox()) {
  225. if (fl != 'true' && fl != 1)
  226. fl = false;
  227. this.cell.firstChild.disabled = fl;
  228. if (this.disabledF)
  229. this.disabledF(fl);
  230. }
  231. }
  232. }
  233. /**
  234. * @desc: sets value to the cell
  235. * @param: val - new value
  236. * @type: public
  237. */
  238. dhtmlXGridCellObject.prototype.setValue = function(val) {
  239. if (!val || val.toString()._dhx_trim() == "") {
  240. val = " "
  241. this.cell._clearCell = true;
  242. }
  243. this.cell.innerHTML = val;
  244. }
  245. /**
  246. * @desc: geth math code of ExCell
  247. * @param: val - new value
  248. * @type: public
  249. */
  250. dhtmlXGridCellObject.prototype.getMath = function(val) {
  251. if (this._val)
  252. return this.val;
  253. else
  254. return this.getValue();
  255. }
  256. /**
  257. * @desc: dhtmlxGrid cell editor constructor (base for all eXcells). Shouldn't
  258. * be accessed directly
  259. * @returns: dhtmlxGrid cell editor object
  260. * @type: public
  261. */
  262. function eXcell() {
  263. this.obj = null;// editor
  264. // this.cell = null//cell to get value from
  265. this.val = null;// current value (before edit)
  266. /**
  267. * @desc: occures on space for example
  268. * @type: private
  269. */
  270. this.changeState = function() {
  271. return false
  272. }
  273. /**
  274. * @desc: opens editor
  275. * @type: private
  276. */
  277. this.edit = function() {
  278. this.val = this.getValue()
  279. }//
  280. /**
  281. * @desc: return value to cell, closes editor
  282. * @returns: if cell's value was changed (true) or not
  283. * @type: private
  284. */
  285. this.detach = function() {
  286. return false
  287. }//
  288. /**
  289. * @desc: gets position (left-right) of element
  290. * @param: oNode - element to get position of
  291. * @type: private
  292. * @topic: 8
  293. */
  294. this.getPosition = function(oNode) {
  295. var oCurrentNode = oNode;
  296. var iLeft = 0;
  297. var iTop = 0;
  298. while (oCurrentNode.tagName != "BODY") {
  299. iLeft += oCurrentNode.offsetLeft;
  300. iTop += oCurrentNode.offsetTop;
  301. oCurrentNode = oCurrentNode.offsetParent;
  302. }
  303. return new Array(iLeft, iTop);
  304. }
  305. }
  306. eXcell.prototype = new dhtmlXGridCellObject;
  307. // simple text editor
  308. function eXcell_ed(cell) {
  309. try {
  310. this.cell = cell;
  311. this.grid = this.cell.parentNode.grid;
  312. } catch (er) {
  313. }
  314. this.edit = function() {
  315. this.val = this.getValue();
  316. this.obj = document.createElement(_isKHTML ? "INPUT" : "TEXTAREA");
  317. this.obj.style.height = (this.cell.offsetHeight - (this.grid.multiLine
  318. ? 5
  319. : 4))
  320. + "px";
  321. this.obj.className = "dhx_combo_edit";
  322. this.obj.wrap = "soft";
  323. this.obj.style.textAlign = this.cell.align;
  324. this.obj.onclick = function(e) {
  325. (e || event).cancelBubble = true
  326. }
  327. this.obj.value = this.val
  328. this.cell.innerHTML = "";
  329. this.cell.appendChild(this.obj);
  330. this.obj.onselectstart = function(e) {
  331. if (!e)
  332. e = event;
  333. e.cancelBubble = true;
  334. return true;
  335. };
  336. this.obj.focus()
  337. this.obj.focus()
  338. }
  339. this.getValue = function() {
  340. // this.grid.editStop();
  341. return this.cell.innerHTML.toString()._dhx_trim()
  342. }
  343. this.detach = function() {
  344. this.setValue(this.obj.value);
  345. return this.val != this.getValue();
  346. }
  347. }
  348. eXcell_ed.prototype = new eXcell;
  349. // numeric text editor
  350. function eXcell_edn(cell) {
  351. try {
  352. this.cell = cell;
  353. this.grid = this.cell.parentNode.grid;
  354. } catch (er) {
  355. }
  356. this.edit = function() {
  357. this.val = this.getValue();
  358. this.obj = document.createElement(_isKHTML ? "INPUT" : "TEXTAREA");
  359. this.obj.className = "dhx_combo_edit";
  360. this.obj.style.height = (this.cell.offsetHeight - 4) + "px";
  361. this.obj.wrap = "soft";
  362. this.obj.style.textAlign = this.cell.align;
  363. this.obj.onclick = function(e) {
  364. (e || event).cancelBubble = true
  365. }
  366. this.obj.value = this.val;
  367. this.cell.innerHTML = "";
  368. this.cell.appendChild(this.obj);
  369. this.obj.onselectstart = function(e) {
  370. if (!e)
  371. e = event;
  372. e.cancelBubble = true;
  373. return true;
  374. };
  375. this.obj.focus()
  376. this.obj.focus()
  377. }
  378. this.getValue = function() {
  379. // this.grid.editStop();
  380. return this.grid._aplNFb(this.cell.innerHTML.toString()._dhx_trim(),
  381. this.cell._cellIndex);
  382. }
  383. this.detach = function() {
  384. var tv = this.obj.value;
  385. this.setValue(tv);
  386. return this.val != this.getValue();
  387. }
  388. }
  389. eXcell_edn.prototype = new eXcell;
  390. eXcell_edn.prototype.setValue = function(val) {
  391. if (!val || val.toString()._dhx_trim() == "")
  392. val = "0"
  393. this.cell.innerHTML = this.grid._aplNF(val, this.cell._cellIndex);
  394. }
  395. // Checkbox
  396. function eXcell_ch(cell) {
  397. try {
  398. this.cell = cell;
  399. this.grid = this.cell.parentNode.grid;
  400. this.cell.obj = this;
  401. } catch (er) {
  402. }
  403. this.disabledF = function(fl) {
  404. if ((fl == true) || (fl == 1))
  405. this.cell.innerHTML = this.cell.innerHTML.replace("item_chk0.",
  406. "item_chk0_dis.").replace("item_chk1.", "item_chk1_dis.");
  407. else
  408. this.cell.innerHTML = this.cell.innerHTML.replace("item_chk0_dis.",
  409. "item_chk0.").replace("item_chk1_dis.", "item_chk1.");
  410. }
  411. this.changeState = function() {
  412. // nb:
  413. if (!this.grid.isEditable)
  414. return;
  415. if (typeof(this.grid.onEditCell) == "string") {
  416. if (eval(this.grid.onEditCell + "(0,'" + this.cell.parentNode.idd
  417. + "'," + this.cell._cellIndex + ");") != false) {
  418. this.val = this.getValue()
  419. if (this.val == "1")
  420. this.setValue("<checkbox state='false'>")
  421. else
  422. this.setValue("<checkbox state='true'>")
  423. // nb:
  424. eval(this.grid.onEditCell + "(1,'" + this.cell.parentNode.idd
  425. + "'," + this.cell._cellIndex + ");")
  426. if (this.grid.onCheckbox)
  427. this.grid.onCheckbox(this.cell.parentNode.idd,
  428. (this.val != '1'), this.cell._cellIndex);
  429. } else {// preserve editing (not tested thoroughly for this editor)
  430. this.grid.editor = null;//
  431. }
  432. } else {
  433. if (this.grid.onEditCell(0, this.cell.parentNode.idd,
  434. this.cell._cellIndex) != false) {
  435. this.val = this.getValue()
  436. if (this.val == "1")
  437. this.setValue("<checkbox state='false'>")
  438. else
  439. this.setValue("<checkbox state='true'>")
  440. // nb:
  441. this.grid.onEditCell(1, this.cell.parentNode.idd,
  442. this.cell._cellIndex)
  443. if (typeof(this.grid.onCheckbox) == 'function')
  444. this.grid.onCheckbox(this.cell.parentNode.idd,
  445. this.cell._cellIndex, (this.val != '1'))
  446. } else {// preserve editing (not tested thoroughly for this editor)
  447. this.editor = null;
  448. }
  449. }
  450. //
  451. /*
  452. * if(eval(this.grid.onEditCell+"(0,'"+this.cell.parentNode.idd+"',"+this.cell._cellIndex+");")!=false){
  453. * this.val = this.getValue() if(this.val=="1") this.setValue("<checkbox
  454. * state='false'>") else this.setValue("<checkbox state='true'>") //nb:
  455. * eval(this.grid.onEditCell+"(1,'"+this.cell.parentNode.idd+"',"+this.cell._cellIndex+");")
  456. * eval(this.grid.onCheckbox+"('"+this.cell.parentNode.idd+"',"+(this.val!='1')+","+this.cell._cellIndex+");") }
  457. */
  458. //
  459. }
  460. this.getValue = function() {
  461. try {
  462. return this.cell.chstate.toString();
  463. } catch (er) {
  464. return null;
  465. }
  466. }
  467. this.isCheckbox = function() {
  468. return true;
  469. }
  470. this.isChecked = function() {
  471. if (this.getValue() == "1")
  472. return true;
  473. else
  474. return false;
  475. }
  476. this.setChecked = function(fl) {
  477. this.setValue(fl.toString())
  478. }
  479. this.detach = function() {
  480. return this.val != this.getValue();
  481. }
  482. }
  483. eXcell_ch.prototype = new eXcell;
  484. eXcell_ch.prototype.setValue = function(val) {
  485. // val can be int
  486. val = (val || "").toString();
  487. if (val.indexOf("1") != -1 || val.indexOf("true") != -1) {
  488. val = "1";
  489. this.cell.chstate = "1";
  490. } else {
  491. val = "0";
  492. this.cell.chstate = "0"
  493. }
  494. var obj = this;
  495. this.cell.innerHTML = "<img src='" + this.grid.imgURL + "item_chk" + val
  496. + ".gif' onclick='this.parentNode.obj.changeState()'>";
  497. }
  498. // Radiobutton
  499. function eXcell_ra(cell) {
  500. this.base = eXcell_ch;
  501. this.base(cell)
  502. this.grid = cell.parentNode.grid;
  503. this.disabledF = function(fl) {
  504. if ((fl == true) || (fl == 1))
  505. this.cell.innerHTML = this.cell.innerHTML.replace("radio_chk0.",
  506. "radio_chk0_dis.")
  507. .replace("radio_chk1.", "radio_chk1_dis.");
  508. else
  509. this.cell.innerHTML = this.cell.innerHTML.replace(
  510. "radio_chk0_dis.", "radio_chk0.").replace(
  511. "radio_chk1_dis.", "radio_chk1.");
  512. }
  513. this.changeState = function() {
  514. if (!this.grid.isEditable)
  515. return;
  516. // nb:
  517. /*
  518. * if(eval(this.grid.onEditCell+"(0,'"+this.cell.parentNode.idd+"',"+this.cell._cellIndex+");")!=false){
  519. * this.val = this.getValue() if(this.val=="0"){ this.setValue("<checkbox
  520. * state='true'>") //nb:
  521. * eval(this.grid.onEditCell+"(1,'"+this.cell.parentNode.idd+"',"+this.cell._cellIndex+");")
  522. * eval(this.grid.onCheckbox+"('"+this.cell.parentNode.idd+"',"+(this.val!='1')+","+this.cell._cellIndex+");")
  523. * for(var i=0;i<this.grid.getRowsNum();i++){
  524. * if(this.grid.cells2(i,this.cell._cellIndex).isChecked() &&
  525. * this.grid.cells2(i,this.cell._cellIndex).cell!=this.cell)
  526. * this.grid.cells2(i,this.cell._cellIndex).setValue("<checkbox
  527. * state='false'>") } } }
  528. */
  529. if (typeof(this.grid.onEditCell) == "string") {
  530. if (eval(this.grid.onEditCell + "(0,'" + this.cell.parentNode.idd
  531. + "'," + this.cell._cellIndex + ");") != false) {
  532. this.val = this.getValue()
  533. if (this.val == "1")
  534. this.setValue("<checkbox state='false'>")
  535. else
  536. this.setValue("<checkbox state='true'>")
  537. // nb:
  538. eval(this.grid.onEditCell + "(1,'" + this.cell.parentNode.idd
  539. + "'," + this.cell._cellIndex + ");")
  540. if (this.grid.onCheckbox)
  541. this.grid.onCheckbox(this.cell.parentNode.idd,
  542. (this.val != '1'), this.cell._cellIndex);
  543. for (var i = 0; i < this.grid.getRowsNum(); i++) {
  544. if (this.grid.cells2(i, this.cell._cellIndex).isChecked()
  545. && this.grid.cells2(i, this.cell._cellIndex).cell != this.cell)
  546. this.grid.cells2(i, this.cell._cellIndex)
  547. .setValue("<checkbox state='false'>")
  548. }
  549. } else {// preserve editing (not tested thoroughly for this editor)
  550. this.grid.editor = null;//
  551. }
  552. } else {
  553. if (this.grid.onEditCell(0, this.cell.parentNode.idd,
  554. this.cell._cellIndex) != false) {
  555. this.val = this.getValue()
  556. if (this.val == "1")
  557. this.setValue("<checkbox state='false'>")
  558. else
  559. this.setValue("<checkbox state='true'>")
  560. // nb:
  561. this.grid.onEditCell(1, this.cell.parentNode.idd,
  562. this.cell._cellIndex)
  563. if (typeof(this.grid.onCheckbox) == 'function')
  564. this.grid.onCheckbox(this.cell.parentNode.idd,
  565. this.cell._cellIndex, (this.val != '1'))
  566. for (var i = 0; i < this.grid.getRowsNum(); i++) {
  567. if (this.grid.cells2(i, this.cell._cellIndex).isChecked()
  568. && this.grid.cells2(i, this.cell._cellIndex).cell != this.cell) {
  569. this.grid.cells2(i, this.cell._cellIndex)
  570. .setValue("<checkbox state='false'>")
  571. this.grid.onEditCell(1, this.grid.rowsCol[i].idd,
  572. this.cell._cellIndex);
  573. }
  574. }
  575. } else {// preserve editing (not tested thoroughly for this editor)
  576. this.editor = null;
  577. }
  578. }
  579. }
  580. }
  581. eXcell_ra.prototype = new eXcell_ch;
  582. eXcell_ra.prototype.setValue = function(val) {
  583. if ((val || "").indexOf("1") != -1 || (val || "").indexOf("true") != -1) {
  584. val = "1";
  585. this.cell.chstate = "1";
  586. } else {
  587. val = "0";
  588. this.cell.chstate = "0"
  589. }
  590. var obj = this;
  591. this.cell.innerHTML = "<img src='" + this.grid.imgURL + "radio_chk" + val
  592. + ".gif' onclick='this.parentNode.obj.changeState()'>";
  593. }
  594. // Multiline popup text editor
  595. function eXcell_txt(cell) {
  596. try {
  597. this.cell = cell;
  598. this.grid = this.cell.parentNode.grid;
  599. } catch (er) {
  600. }
  601. this.edit = function() {
  602. this.val = this.getValue()
  603. this.obj = document.createElement("TEXTAREA");
  604. this.obj.className = "dhx_textarea";
  605. this.obj.onclick = function(e) {
  606. (e || event).cancelBubble = true
  607. }
  608. var arPos = this.grid.getPosition(this.cell);// ,this.grid.objBox
  609. if (!this.cell._clearCell)
  610. this.obj.value = this.cell.innerHTML;
  611. // this.grid.entBox.appendChild(this.obj);
  612. // this.grid.objBox.appendChild(this.obj);
  613. document.body.appendChild(this.obj);// nb:
  614. this.obj.style.left = arPos[0] - this.grid.objBox.scrollLeft + "px";
  615. this.obj.style.top = arPos[1] + this.cell.offsetHeight
  616. - this.grid.objBox.scrollTop + "px";
  617. if (this.cell.scrollWidth < 200)
  618. this.obj.style.width = "200px";
  619. else
  620. this.obj.style.width = this.cell.scrollWidth + "px";
  621. this.obj.style.display = "";
  622. this.obj.style.textAlign = this.cell.align;
  623. this.obj.focus();
  624. this.obj.focus()
  625. }
  626. this.detach = function() {
  627. if (this.obj.value == "") {
  628. this.cell._clearCell = true;
  629. } else
  630. this.cell._clearCell = false;
  631. this.setValue(this.obj.value);
  632. // isIE()?this.obj.removeNode(true):this.grid.objBox.removeChild(this.obj);
  633. document.body.removeChild(this.obj);
  634. return this.val != this.getValue();
  635. }
  636. }
  637. eXcell_txt.prototype = new eXcell;
  638. // Combobox
  639. function eXcell_co(cell) {
  640. try {
  641. this.cell = cell;
  642. this.grid = this.cell.parentNode.grid;
  643. this.combo = this.grid.getCombo(this.cell._cellIndex);
  644. this.editable = true
  645. } catch (er) {
  646. }
  647. this.shiftNext = function() {
  648. var z = this.list.options[this.list.selectedIndex + 1];
  649. if (z)
  650. z.selected = true;
  651. this.obj.value = this.list.value;
  652. return true;
  653. }
  654. this.shiftPrev = function() {
  655. var z = this.list.options[this.list.selectedIndex - 1];
  656. if (z)
  657. z.selected = true;
  658. this.obj.value = this.list.value;
  659. return true;
  660. }
  661. this.edit = function() {
  662. this.val = this.getValue();
  663. this.text = this.cell.innerHTML._dhx_trim();
  664. var arPos = this.grid.getPosition(this.cell)// ,this.grid.objBox)
  665. this.obj = document.createElement("TEXTAREA");
  666. this.obj.className = "dhx_combo_edit";
  667. this.obj.style.height = (this.cell.offsetHeight - 4) + "px";
  668. this.obj.wrap = "soft";
  669. this.obj.style.textAlign = this.cell.align;
  670. this.obj.onclick = function(e) {
  671. (e || event).cancelBubble = true
  672. }
  673. this.obj.value = this.text
  674. this.list = document.createElement("SELECT");
  675. this.list.editor_obj = this;
  676. this.list.className = 'dhx_combo_select';
  677. this.list.style.width = this.cell.offsetWidth + "px";
  678. this.list.style.left = arPos[0] - this.grid.objBox.scrollLeft + "px";// arPos[0]
  679. this.list.style.top = arPos[1] + this.cell.offsetHeight
  680. - this.grid.objBox.scrollTop + "px";// arPos[1]+this.cell.offsetHeight;
  681. this.list.size = "6";
  682. this.list.onclick = function(e) {
  683. var ev = e || window.event;
  684. var cell = ev.target || ev.srcElement
  685. // tbl.editor_obj.val=cell.combo_val;
  686. if (cell.tagName == "OPTION")
  687. cell = cell.parentNode;
  688. cell.editor_obj.setValue(cell.value);
  689. cell.editor_obj.editable = false;
  690. cell.editor_obj.detach();
  691. }
  692. var comboKeys = this.combo.getKeys();
  693. var fl = false
  694. var selOptId = 0;
  695. for (var i = 0; i < comboKeys.length; i++) {
  696. var val = this.combo.get(comboKeys[i])
  697. this.list.options[this.list.options.length] = new Option(val,
  698. comboKeys[i]);
  699. if (comboKeys[i] == this.val) {
  700. selOptId = this.list.options.length - 1;
  701. fl = true;
  702. }
  703. }
  704. if (fl == false) {// if no such value in combo list
  705. this.list.options[this.list.options.length] = new Option(this.text,
  706. this.val === null ? "" : this.val);
  707. selOptId = this.list.options.length - 1;
  708. }
  709. document.body.appendChild(this.list)// nb:this.grid.objBox.appendChild(this.listBox);
  710. this.cstate = 1;
  711. if (this.editable) {
  712. this.cell.innerHTML = "";
  713. } else {
  714. this.obj.style.width = "1px";
  715. this.obj.style.height = "1px";
  716. }
  717. this.cell.appendChild(this.obj);
  718. this.list.options[selOptId].selected = true;
  719. this.obj.focus();
  720. this.obj.focus();
  721. if (!this.editable)
  722. this.obj.style.visibility = "hidden";
  723. }
  724. this.getValue = function() {
  725. return this.cell.combo_value;
  726. }
  727. this.getText = function() {
  728. return this.cell.innerHTML;
  729. }
  730. this.detach = function() {
  731. if (this.val != this.getValue()) {
  732. this.cell.wasChanged = true;
  733. }
  734. if (this.list.parentNode != null) {
  735. if (this.editable)
  736. if (this.obj.value._dhx_trim() != this.text) {
  737. this.setValue(this.obj.value)
  738. } else {
  739. this.setValue(this.val)
  740. }
  741. else
  742. this.setValue(this.list.value)
  743. }
  744. // nb:
  745. if (typeof(this.grid.onEditCell) == "string")
  746. eval(this.grid.onEditCell + "(2,'" + this.cell.parentNode.idd
  747. + "'," + this.cell._cellIndex + ");")
  748. else if (typeof(this.grid.onEditCell) == 'function') {
  749. this.grid.onEditCell(2, this.cell.parentNode.idd,
  750. this.cell._cellIndex)
  751. }
  752. // this.obj.removeNode(true)
  753. if (this.list.parentNode)
  754. this.list.parentNode.removeChild(this.list);
  755. if (this.obj.parentNode)
  756. this.obj.parentNode.removeChild(this.obj);
  757. return this.val != this.getValue();
  758. }
  759. }
  760. eXcell_co.prototype = new eXcell;
  761. eXcell_co.prototype.setValue = function(val) {
  762. if ((val || "").toString()._dhx_trim() == "")
  763. val = null
  764. if (val !== null)
  765. this.cell.innerHTML = this.grid.getCombo(this.cell._cellIndex).get(val)
  766. || val;
  767. else
  768. this.cell.innerHTML = "&nbsp;";
  769. this.cell.combo_value = val;
  770. }
  771. // Selectbox
  772. function eXcell_coro(cell) {
  773. this.base = eXcell_co;
  774. this.base(cell)
  775. this.editable = false;
  776. }
  777. eXcell_coro.prototype = new eXcell_co;
  778. // color picker
  779. function eXcell_cp(cell) {
  780. try {
  781. this.cell = cell;
  782. this.grid = this.cell.parentNode.grid;
  783. } catch (er) {
  784. }
  785. this.edit = function() {
  786. this.val = this.getValue()
  787. this.obj = document.createElement("SPAN");
  788. this.obj.style.border = "1px solid black";
  789. this.obj.style.position = "absolute";
  790. var arPos = this.grid.getPosition(this.cell);// ,this.grid.objBox
  791. this.colorPanel(4, this.obj)
  792. document.body.appendChild(this.obj);// this.grid.objBox.appendChild(this.obj);
  793. this.obj.style.left = arPos[0] - this.grid.objBox.scrollLeft;
  794. this.obj.style.top = arPos[1] + this.cell.offsetHeight
  795. - this.grid.objBox.scrollTop;
  796. }
  797. this.toolDNum = function(value) {
  798. if (value.length == 1)
  799. value = '0' + value;
  800. return value;
  801. }
  802. this.colorPanel = function(index, parent) {
  803. var tbl = document.createElement("TABLE");
  804. parent.appendChild(tbl)
  805. tbl.cellSpacing = 0;
  806. tbl.editor_obj = this;
  807. tbl.style.cursor = "default";
  808. tbl.style.cursor = "table-layout:fixed";
  809. tbl.onclick = function(e) {
  810. var ev = e || window.event
  811. var cell = ev.target || ev.srcElement;
  812. var ed = cell.parentNode.parentNode.parentNode.editor_obj
  813. ed.setValue(cell.style.backgroundColor)
  814. ed.detach()
  815. }
  816. var cnt = 256 / index;
  817. for (var j = 0; j <= (256 / cnt); j++) {
  818. var r = tbl.insertRow(j);
  819. for (var i = 0; i <= (256 / cnt); i++) {
  820. for (var n = 0; n <= (256 / cnt); n++) {
  821. R = new Number(cnt * j) - (j == 0 ? 0 : 1)
  822. G = new Number(cnt * i) - (i == 0 ? 0 : 1)
  823. B = new Number(cnt * n) - (n == 0 ? 0 : 1)
  824. var rgb = this.toolDNum(R.toString(16)) + ""
  825. + this.toolDNum(G.toString(16)) + ""
  826. + this.toolDNum(B.toString(16));
  827. var c = r.insertCell(i);
  828. c.width = "10px";
  829. c.innerHTML = "&nbsp;";// R+":"+G+":"+B;//
  830. c.title = rgb.toUpperCase()
  831. c.style.backgroundColor = rgb
  832. if (this.val != null
  833. && "#" + rgb.toUpperCase() == this.val
  834. .toUpperCase()) {
  835. c.style.border = "2px solid white"
  836. }
  837. }
  838. }
  839. }
  840. }
  841. this.getValue = function() {
  842. return this.cell.firstChild.style.backgroundColor;// this.getBgColor()
  843. }
  844. this.getRed = function() {
  845. return Number(parseInt(this.getValue().substr(1, 2), 16))
  846. }
  847. this.getGreen = function() {
  848. return Number(parseInt(this.getValue().substr(3, 2), 16))
  849. }
  850. this.getBlue = function() {
  851. return Number(parseInt(this.getValue().substr(5, 2), 16))
  852. }
  853. this.detach = function() {
  854. // nb:
  855. if (typeof(this.grid.onEditCell) == "string")
  856. eval(this.grid.onEditCell + "(2,'" + this.cell.parentNode.idd
  857. + "'," + this.cell._cellIndex + ");")
  858. else {
  859. this.grid.onEditCell(2, this.cell.parentNode.idd,
  860. this.cell._cellIndex)
  861. }
  862. if (this.obj.offsetParent != null)
  863. document.body.removeChild(this.obj);
  864. // this.obj.removeNode(true)
  865. return this.val != this.getValue();
  866. }
  867. }
  868. eXcell_cp.prototype = new eXcell;
  869. eXcell_cp.prototype.setValue = function(val) {
  870. this.cell.innerHTML = "<div style='width:100%;height:"
  871. + (this.cell.offsetHeight - 2) + ";background-color:" + (val || "")
  872. + ";border:0px;'>&nbsp;</div>";// this.setBgColor(val)
  873. }
  874. // image
  875. /*
  876. * The corresponding cell value in XML should be a "^" delimited list of
  877. * following values: 1st - image src 2nd - image alt text (optional) 3rd - link
  878. * (optional) 4rd - target (optional, default is _self)
  879. */
  880. function eXcell_img(cell) {
  881. try {
  882. this.cell = cell;
  883. this.grid = this.cell.parentNode.grid;
  884. } catch (er) {
  885. }
  886. this.getValue = function() {
  887. if (this.cell.firstChild.tagName == "IMG")
  888. return this.cell.firstChild.src
  889. + (this.cell.titFl != null ? "^" + this.cell.tit : "");
  890. else if (this.cell.firstChild.tagName == "A") {
  891. var out = this.cell.firstChild.firstChild.src
  892. + (this.cell.titFl != null ? "^" + this.cell.tit : "");
  893. out += "^" + this.cell.lnk;
  894. if (this.cell.trg)
  895. out += "^" + this.cell.trg
  896. return out;
  897. }
  898. }
  899. this.getTitle = function() {
  900. return this.cell.tit
  901. }
  902. }
  903. eXcell_img.prototype = new eXcell;
  904. eXcell_img.prototype.setValue = function(val) {
  905. var title = val;
  906. if (val.indexOf("^") != -1) {
  907. var ar = val.split("^");
  908. val = ar[0]
  909. title = ar[1];
  910. // link
  911. if (ar.length > 2) {
  912. this.cell.lnk = ar[2]
  913. if (ar[3])
  914. this.cell.trg = ar[3]
  915. }
  916. this.cell.titFl = "1";
  917. }
  918. this.cell.innerHTML = "<img src='" + (val || "")._dhx_trim()
  919. + "' border='0'>";
  920. if (this.cell.lnk) {
  921. this.cell.innerHTML = "<a href='" + this.cell.lnk + "' target='"
  922. + this.cell.trg + "'>" + this.cell.innerHTML + "</a>"
  923. }
  924. this.cell.tit = title;
  925. }
  926. // extended simple editor (money oriented)
  927. function eXcell_price(cell) {
  928. this.base = eXcell_ed;
  929. this.base(cell)
  930. this.getValue = function() {
  931. if (this.cell.childNodes.length > 1)
  932. return this.cell.childNodes[1].innerHTML.toString()._dhx_trim()
  933. else
  934. return "0";
  935. }
  936. }
  937. eXcell_price.prototype = new eXcell_ed;
  938. eXcell_price.prototype.setValue = function(val) {
  939. if (isNaN(Number(val))) {
  940. if (!(val || "") || (val || "")._dhx_trim() != "")
  941. val = 0;// alert("Value must be an integer")
  942. val = this.val || 0;
  943. }
  944. if (val > 0) {
  945. var color = "green";
  946. this.cell.innerHTML = "<span>$</span><span style='padding-right:2px;color:"
  947. + color + ";'>" + val + "</span>";
  948. } else {
  949. this.cell.innerHTML = "<div align='center' style='color:red;'>&nbsp;</div>";
  950. }
  951. }
  952. // extended simple editor (dynamic of sales)
  953. function eXcell_dyn(cell) {
  954. this.base = eXcell_ed;
  955. this.base(cell)
  956. this.getValue = function() {
  957. return this.cell.firstChild.childNodes[1].innerHTML.toString()
  958. ._dhx_trim()
  959. }
  960. }
  961. eXcell_dyn.prototype = new eXcell_ed;
  962. eXcell_dyn.prototype.setValue = function(val) {
  963. if (!val || isNaN(Number(val))) {
  964. val = 0;
  965. }
  966. if (val > 0) {
  967. var color = "green";
  968. var img = "dyn_up.gif";
  969. } else if (val == 0) {
  970. var color = "black";
  971. var img = "dyn_.gif";
  972. } else {
  973. var color = "red";
  974. var img = "dyn_down.gif";
  975. }
  976. this.cell.innerHTML = "<div style='position:relative;padding-right:2px; width:100%;'><img src='"
  977. + this.grid.imgURL
  978. + ""
  979. + img
  980. + "' height='15' style='position:absolute;top:0px;left:0px;'><span style='width:100%;color:"
  981. + color + ";'>" + val + "</span></div>";
  982. }
  983. // readonly
  984. function eXcell_ro(cell) {
  985. this.cell = cell;
  986. this.grid = this.cell.parentNode.grid;
  987. this.edit = function() {
  988. }
  989. }
  990. eXcell_ro.prototype = new eXcell;
  991. /**
  992. * @desc: combobox object constructor (shouldn't be accessed directly - instead
  993. * please use getCombo(...) method of the grid)
  994. * @type: public
  995. * @returns: combobox for dhtmlxGrid
  996. */
  997. function dhtmlXGridComboObject() {
  998. this.keys = new Array();
  999. this.values = new Array();
  1000. /**
  1001. * @desc: puts new combination of key and value into combobox
  1002. * @type: public
  1003. * @param: key - object to use as a key (should be a string in the case of
  1004. * combobox)
  1005. * @param: value - object value of combobox line
  1006. */
  1007. this.put = function(key, value) {
  1008. for (var i = 0; i < this.keys.length; i++) {
  1009. if (this.keys[i] == key) {
  1010. this.values[i] = value;
  1011. return true;
  1012. }
  1013. }
  1014. this.values[this.values.length] = value;
  1015. this.keys[this.keys.length] = key;
  1016. }
  1017. /**
  1018. * @desc: gets value corresponding to the given key
  1019. * @type: public
  1020. * @param: key - object to use as a key (should be a string in the case of
  1021. * combobox)
  1022. * @returns: value correspond. to given key or null if no such key
  1023. */
  1024. this.get = function(key) {
  1025. for (var i = 0; i < this.keys.length; i++) {
  1026. if (this.keys[i] == key) {
  1027. return this.values[i];
  1028. }
  1029. }
  1030. return null;
  1031. }
  1032. /**
  1033. * @desc: clears combobox
  1034. * @type: public
  1035. */
  1036. this.clear = function() {
  1037. /*
  1038. * for(var i=0;i<this.keys.length;i++){ this.keys._dhx_removeAt(i);
  1039. * this.values._dhx_removeAt(i); }
  1040. */
  1041. this.keys = new Array();
  1042. this.values = new Array();
  1043. }
  1044. /**
  1045. * @desc: remove pair of key-value from combobox with given key
  1046. * @type: public
  1047. * @param: key - object to use as a key
  1048. */
  1049. this.remove = function(key) {
  1050. for (var i = 0; i < this.keys.length; i++) {
  1051. if (this.keys[i] == key) {
  1052. this.keys._dhx_removeAt(i);
  1053. this.values._dhx_removeAt(i);
  1054. return true;
  1055. }
  1056. }
  1057. }
  1058. /**
  1059. * @desc: gets the size of combobox
  1060. * @type: public
  1061. * @returns: current size of combobox
  1062. */
  1063. this.size = function() {
  1064. var j = 0;
  1065. for (var i = 0; i < this.keys.length; i++) {
  1066. if (this.keys[i] != null)
  1067. j++;
  1068. }
  1069. return j;
  1070. }
  1071. /**
  1072. * @desc: gets array of all available keys present in combobox
  1073. * @type: public
  1074. * @returns: array of all available keys
  1075. */
  1076. this.getKeys = function() {
  1077. var keyAr = new Array(0);
  1078. for (var i = 0; i < this.keys.length; i++) {
  1079. if (this.keys[i] != null)
  1080. keyAr[keyAr.length] = this.keys[i];
  1081. }
  1082. return keyAr;
  1083. }
  1084. /**
  1085. * @desc: save curent state
  1086. * @type: public
  1087. */
  1088. this.save = function() {
  1089. this._save = new Array();
  1090. for (var i = 0; i < this.keys.length; i++)
  1091. this._save[i] = [this.keys[i], this.values[i]];
  1092. }
  1093. /**
  1094. * @desc: restore saved state
  1095. * @type: public
  1096. */
  1097. this.restore = function() {
  1098. if (this._save) {
  1099. this.keys[i] = new Array();
  1100. this.values[i] = new Array();
  1101. for (var i = 0; i < this._save.length; i++) {
  1102. this.keys[i] = this._save[i][0];
  1103. this.values[i] = this._save[i][1];
  1104. }
  1105. }
  1106. }
  1107. return this;
  1108. }
  1109. function Hashtable() {
  1110. this.keys = new Array();
  1111. this.values = new Array();
  1112. return this;
  1113. }
  1114. Hashtable.prototype = new dhtmlXGridComboObject;