dhtmlXGrid_excell_acheck.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright Scand LLC http://www.scbr.com To use this component please contact
  3. * info@scbr.com to obtain license
  4. */
  5. // Checkbox
  6. function eXcell_acheck(cell) {
  7. try {
  8. this.cell = cell;
  9. this.grid = this.cell.parentNode.grid;
  10. this.cell.obj = this;
  11. } catch (er) {
  12. }
  13. this.changeState = function() {
  14. // nb:
  15. if (typeof(this.grid.onEditCell) == "string") {
  16. if (eval(this.grid.onEditCell + "(0,'" + this.cell.parentNode.idd
  17. + "'," + this.cell._cellIndex + ");") != false) {
  18. this.val = this.getValue();
  19. if (this.val == "1") {
  20. this.setValue("<checkbox state='false'>");
  21. } else {
  22. this.setValue("<checkbox state='true'>");
  23. }
  24. // nb:
  25. eval(this.grid.onEditCell + "(1,'" + this.cell.parentNode.idd
  26. + "'," + this.cell._cellIndex + ");");
  27. if (this.grid.onCheckbox) {
  28. this.grid.onCheckbox(this.cell.parentNode.idd,
  29. this.cell._cellIndex, (this.val != "1"));
  30. }
  31. } else {// preserve editing (not tested thoroughly for this editor)
  32. this.grid.editor = null;//
  33. }
  34. } else {
  35. if (this.grid.onEditCell(0, this.cell.parentNode.idd,
  36. this.cell._cellIndex) != false) {
  37. this.val = this.getValue();
  38. if (this.val == "1") {
  39. this.setValue("<checkbox state='false'>");
  40. } else {
  41. this.setValue("<checkbox state='true'>");
  42. }
  43. // nb:
  44. this.grid.onEditCell(1, this.cell.parentNode.idd,
  45. this.cell._cellIndex);
  46. if (this.grid.onCheckbox) {
  47. this.grid.onCheckbox(this.cell.parentNode.idd,
  48. this.cell._cellIndex, (this.val != "1"));
  49. }
  50. } else {// preserve editing (not tested thoroughly for this editor)
  51. this.editor = null;
  52. }
  53. }
  54. };
  55. this.getValue = function() {
  56. try {
  57. return this.cell.chstate.toString();
  58. } catch (er) {
  59. return null;
  60. }
  61. };
  62. this.isCheckbox = function() {
  63. return true;
  64. };
  65. this.isChecked = function() {
  66. if (this.getValue() == "1") {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. };
  72. this.setChecked = function(fl) {
  73. this.setValue(fl.toString());
  74. };
  75. this.detach = function() {
  76. return this.val != this.getValue();
  77. };
  78. this.drawCurrentState = function() {
  79. if (this.cell.chstate == 1) {
  80. return "<div onclick='this.parentNode.obj.changeState()' style='cursor:pointer; font-weight:bold; text-align:center; '><img height='13px' src='"
  81. + this.grid.imgURL + "green.gif'>&nbsp;Yes</div>";
  82. } else {
  83. return "<div onclick='this.parentNode.obj.changeState()' style='cursor:pointer; text-align:center; '><img height='13px' src='"
  84. + this.grid.imgURL + "red.gif'>&nbsp;No</div>";
  85. }
  86. };
  87. }
  88. eXcell_acheck.prototype = new eXcell;
  89. eXcell_acheck.prototype.setValue = function(val) {
  90. // val can be int
  91. val = (val || "").toString();
  92. if (val.indexOf("1") != -1 || val.indexOf("true") != -1) {
  93. val = "1";
  94. this.cell.chstate = "1";
  95. } else {
  96. val = "0";
  97. this.cell.chstate = "0";
  98. }
  99. var obj = this;
  100. this.cell.innerHTML = this.drawCurrentState();
  101. };