Worktime.js 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. MWF.xDesktop.requireApp("Setting", "servers.DataServers", null, false);
  2. MWF.xApplication.Setting.resource = MWF.xApplication.Setting.resource || {};
  3. MWF.xApplication.Setting.resource.Worktime = new Class({
  4. Extends: MWF.xApplication.Setting.servers.DataServer.Document,
  5. Implements: [Events],
  6. initialize: function(explorer){
  7. this.explorer = explorer;
  8. this.app = this.explorer.app;
  9. this.container = this.explorer.worktimeContent;
  10. this.css = this.explorer.app.css;
  11. this.load();
  12. },
  13. load: function(){
  14. this.app.actions.getResWorktime(function(json){
  15. this.json = json.data;
  16. this.node = new Element("div", {"styles": this.css.centerServerDocumentNode}).inject(this.container);
  17. this.createForm();
  18. }.bind(this));
  19. },
  20. createActions: function(){
  21. this.actionNode = new Element("div", {"styles": this.css.applicationServerDocumentActionNode}).inject(this.node);
  22. this.saveAction = new Element("div", {"styles": this.css.applicationServerDocumentSaveNode}).inject(this.actionNode);
  23. //this.closeAction = new Element("div", {"styles": this.css.applicationServerDocumentCloseNode}).inject(this.actionNode);
  24. this.saveAction.addEvents({
  25. "mouseover": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  26. "mouseout": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode);}.bind(this),
  27. "mousedown": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_down);}.bind(this),
  28. "mouseup": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  29. "click": function(e){this.saveDocument();}.bind(this)
  30. });
  31. },
  32. createBaseInfo: function(){
  33. this.inforAreaNode = new Element("div", {"styles": this.css.applicationServerDocumentInforAreaNode}).inject(this.node);
  34. this.inforNode = new Element("div", {"styles": this.css.dataServerDocumentInforNode}).inject(this.inforAreaNode);
  35. var html = "<table cellSpacing='8px' width='90%' align='center'>" +
  36. "<tr><td width='120px'>amStart</td><td><input value='"+(this.json.amStart || "")+"'/></td></tr>" +
  37. "<tr><td>amEnd</td><td><input value='"+(this.json.amEnd || "")+"'/></td></tr>" +
  38. "<tr><td>pmStart</td><td><input value='"+(this.json.pmStart || "")+"'/></td></tr>" +
  39. "<tr><td>pmEnd</td><td><input value='"+(this.json.pmEnd || "")+"'/></td></tr>" +
  40. "<tr><td>weekends</td><td><textarea>"+this.json.weekends.join(", ")+"</textarea></td></tr>" +
  41. "<tr><td>holidays</td><td><textarea>"+this.json.holidays.join(", ")+"</textarea></td></tr>" +
  42. "<tr><td>workdays</td><td><textarea>"+this.json.workdays.join(", ")+"</textarea></td></tr>" +
  43. "</table>";
  44. this.inforNode.set("html", html);
  45. var tds = this.inforNode.getElements("td");
  46. var inputs = this.inforNode.getElements("input");
  47. var textareas = this.inforNode.getElements("textarea");
  48. tds.setStyles(this.css.applicationServerDocumentTdNode);
  49. inputs.setStyles(this.css.applicationServerDocumentInputNode);
  50. textareas.setStyles(this.css.applicationServerDocumentTextareasNode);
  51. },
  52. saveDocument: function(){
  53. var inputs = this.inforNode.getElements("input");
  54. var textareas = this.inforNode.getElements("textarea");
  55. this.json.amStart = inputs[0].get("value");
  56. this.json.amEnd = inputs[1].get("value");
  57. this.json.pmStart = inputs[2].get("value");
  58. this.json.pmEnd = inputs[3].get("value");
  59. this.json.weekends = textareas[0].get("value").split(/,\s*/g);
  60. this.json.holidays = textareas[1].get("value").split(/,\s*/g);
  61. this.json.workdays = textareas[2].get("value").split(/,\s*/g);
  62. this.app.actions.updateResWorktime(this.json, function(){
  63. this.app.notice(this.app.lp.centerSaveInfor, "success");
  64. }.bind(this));
  65. },
  66. destroy: function(){
  67. if (this.node) this.node.destroy();
  68. MWF.release(this);
  69. },
  70. });