dhtmlXGrid_excell_calendar.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright Scand LLC http://www.scbr.com To use this component please contact
  3. * info@scbr.com to obtain license
  4. */
  5. document.write("<script src='" + _js_prefix + "calendar/YAHOO.js'></script>");
  6. document.write("<script src='" + _js_prefix + "calendar/event.js'></script>");
  7. document
  8. .write("<script src='" + _js_prefix + "calendar/calendar.js'></script>");
  9. document.write("<script src='" + _js_prefix
  10. + "calendar/calendar_init.js'></script>");
  11. document.write("<link rel='stylesheet' type='text/css' href='" + _js_prefix
  12. + "calendar/calendar.css'></link>");
  13. // simple text editor
  14. function eXcell_calendar(cell) {
  15. try {
  16. this.cell = cell;
  17. this.grid = this.cell.parentNode.grid;
  18. } catch (er) {
  19. }
  20. this.edit = function() {
  21. if (!window._grid_calendar)
  22. _grid_calendar_init();
  23. var arPos = this.grid.getPosition(this.cell);
  24. var pval = this._date2str2(this.cell.val || allGetServerTime());
  25. window._grid_calendar.render(arPos[0] - this.grid.objBox.scrollLeft,
  26. arPos[1] + this.cell.offsetHeight - this.grid.objBox.scrollTop,
  27. this, pval);
  28. this.cell._cediton = true;
  29. this.val = this.cell.val;
  30. }
  31. this.getValue = function() {
  32. // this.grid.editStop();
  33. if (this.cell.val)
  34. return this._date2str2(this.cell.val);
  35. return this.cell.innerHTML.toString()._dhx_trim()
  36. }
  37. this.detach = function() {
  38. if (this.cell._cediton)
  39. this.cell._cediton = false;
  40. else
  41. return;
  42. var z = window._grid_calendar.getSelectedDates()[0];
  43. window._grid_calendar.hide();
  44. if (!z.getFullYear())
  45. return;
  46. this.cell.val = new Date(z.valueOf());
  47. this.cell.innerHTML = this._date2str(z);
  48. return this.val.valueOf() != z.valueOf();
  49. }
  50. this._2dg = function(val) {
  51. if (val.toString().length == 1)
  52. return ("0" + val.toString());
  53. return val;
  54. }
  55. this._date2str2 = function(z) {
  56. return ("m/d/y").replace("m", this._2dg((z.getMonth() * 1 + 1)))
  57. .replace("d", this._2dg(z.getDate())).replace("y",
  58. this._2dg((z.getFullYear() * 1)));
  59. }
  60. this._date2str = function(z) {
  61. return (this.grid._dtmask || "m/d/y").replace("m",
  62. this._2dg((z.getMonth() * 1 + 1))).replace("d",
  63. this._2dg(z.getDate())).replace("y",
  64. this._2dg((z.getFullYear() * 1)));
  65. }
  66. }
  67. eXcell_calendar.prototype = new eXcell;
  68. eXcell_calendar.prototype.setValue = function(val) {
  69. if (!val || val.toString()._dhx_trim() == "")
  70. val = "";
  71. this.cell.val = new Date(val.toString());
  72. if (this.cell.val == "NaN") {
  73. this.cell.val = "";
  74. this.cell.innerHTML = "&nbsp;";
  75. } else
  76. this.cell.innerHTML = this._date2str(this.cell.val);
  77. }