Calendar.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
  2. MWF.xApplication.process.Xform.Calendar = MWF.APPCalendar = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APP$Input,
  5. iconStyle: "calendarIcon",
  6. options: {
  7. "moduleEvents": ["queryLoad","postLoad","load","complete", "clear", "change"]
  8. },
  9. _loadNode: function(){
  10. if (this.readonly || this.json.isReadonly){
  11. this._loadNodeRead();
  12. }else{
  13. this._loadNodeEdit();
  14. }
  15. },
  16. setDescriptionEvent: function(){
  17. if (this.descriptionNode){
  18. this.descriptionNode.addEvents({
  19. "mousedown": function(){
  20. this.descriptionNode.setStyle("display", "none");
  21. this.clickSelect();
  22. }.bind(this)
  23. });
  24. }
  25. },
  26. getValue: function(isDate){
  27. var value = this._getBusinessData();
  28. if (!value) value = this._computeValue();
  29. var d = (!!value) ? Date.parse(value) : "";
  30. if (isDate){
  31. return d || null;
  32. }else{
  33. //if (d) value = Date.parse(value).format(this.json.format);
  34. return (d) ? d.format(this.json.format) : "";
  35. }
  36. },
  37. clickSelect: function(){
  38. if (!this.calendar){
  39. MWF.require("MWF.widget.Calendar", function(){
  40. var options = {
  41. "style": "xform",
  42. "secondEnable" : this.json.isSelectSecond,
  43. "isTime": (this.json.selectType==="datetime" || this.json.selectType==="time"),
  44. "timeOnly": (this.json.selectType === "time"),
  45. //"target": this.form.node,
  46. "target": this.form.app.content,
  47. "format": this.json.format,
  48. "onComplate": function(){
  49. this.validationMode();
  50. if(this.validation())this._setBusinessData(this.getInputData("change"));
  51. this.fireEvent("complete");
  52. }.bind(this),
  53. "onChange": function(){
  54. this.fireEvent("change");
  55. }.bind(this),
  56. "onClear": function(){
  57. this.validationMode();
  58. if(this.validation())this._setBusinessData(this.getInputData("change"));
  59. this.fireEvent("clear");
  60. if (!this.node.getFirst().get("value")) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  61. }.bind(this),
  62. "onShow": function(){
  63. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  64. }.bind(this),
  65. "onHide": function(){
  66. if (!this.node.getFirst().get("value")) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  67. }.bind(this)
  68. };
  69. var value = this.getValue(true);
  70. if( value ){
  71. options.baseDate = value;
  72. }
  73. this.calendar = new MWF.widget.Calendar(this.node.getFirst(), options);
  74. this.calendar.show();
  75. }.bind(this));
  76. }else{
  77. var options = {};
  78. var value = this.getValue(true);
  79. if( value ){
  80. options.baseDate = value;
  81. }
  82. this.calendar.setOptions(options);
  83. //this.calendar.show();
  84. this.node.getFirst().focus();
  85. }
  86. }
  87. });