dhtmlXGrid_excell_clist.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright Scand LLC http://www.scbr.com To use this component please contact
  3. * info@scbr.com to obtain license
  4. */
  5. // simple text editor
  6. function eXcell_clist(cell) {
  7. try {
  8. this.cell = cell;
  9. this.grid = this.cell.parentNode.grid;
  10. } catch (er) {
  11. }
  12. this.edit = function() {
  13. this.val = this.getValue();
  14. var a = this.grid.clists[this.cell._cellIndex];
  15. if (!a) {
  16. return;
  17. }
  18. this.obj = document.createElement("DIV");
  19. var b = this.val.split(",");
  20. var text = "";
  21. for (var i = 0; i < a.length; i++) {
  22. var fl = false;
  23. for (var j = 0; j < b.length; j++) {
  24. if (a[i] == b[j]) {
  25. fl = true;
  26. }
  27. }
  28. if (fl) {
  29. text += "<div><input type='checkbox' checked='true' /><label>"
  30. + a[i] + "</label></div>";
  31. } else {
  32. text += "<div><input type='checkbox' id='ch_lst_" + i
  33. + "'/><label>" + a[i] + "</label></div>";
  34. }
  35. }
  36. text += "<div><input type='button' value='Apply' style='width:100px; font-size:8pt;' onclick='this.parentNode.parentNode.editor.detach();'/></div>";
  37. this.obj.editor = this;
  38. this.obj.innerHTML = text;
  39. document.body.appendChild(this.obj);
  40. this.obj.style.position = "absolute";
  41. this.obj.style.zIndex = 19;
  42. this.obj.style.backgroundColor = "white";
  43. this.obj.style.border = "1px solid black";
  44. this.obj.style.padding = "2px 2px 2px 2px";
  45. var arPos = this.grid.getPosition(this.cell);
  46. this.obj.style.left = arPos[0] - this.grid.objBox.scrollLeft + "px";
  47. this.obj.style.top = arPos[1] + this.cell.offsetHeight
  48. - this.grid.objBox.scrollTop + "px";
  49. this.obj.getValue = function() {
  50. var text = "";
  51. for (var i = 0; i < this.childNodes.length - 1; i++) {
  52. if (this.childNodes[i].childNodes[0].checked) {
  53. if (text) {
  54. text += ",";
  55. }
  56. text += this.childNodes[i].childNodes[1].innerHTML;
  57. }
  58. }
  59. return text;
  60. };
  61. };
  62. this.getValue = function() {
  63. // this.grid.editStop();
  64. return this.cell.innerHTML.toString()._dhx_trim();
  65. };
  66. /**
  67. * @desc: return value to cell, closes editor
  68. * @returns: if cell's value was changed (true) or not
  69. * @type: private
  70. */
  71. this.detach = function(val) {
  72. if (this.obj) {
  73. this.setValue(this.obj.getValue());
  74. this.obj.editor = null;
  75. this.obj.parentNode.removeChild(this.obj);
  76. this.obj = null;
  77. }
  78. return this.val != this.getValue();
  79. };
  80. }
  81. eXcell_clist.prototype = new eXcell;
  82. /**
  83. * @desc: register list of values for CList cell
  84. * @param: col - index of CList collumn
  85. * @param: list - array of list data
  86. * @type: public
  87. * @edition: Professional
  88. */
  89. dhtmlXGridObject.prototype.registerCList = function(col, list) {
  90. if (!this.clists) {
  91. this.clists = new Array();
  92. }
  93. this.clists[col] = list;
  94. };