ScheduleExplorer.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Selector", "package", null, false);
  4. MWF.xApplication.Attendance.ScheduleExplorer = new Class({
  5. Extends: MWF.xApplication.Attendance.Explorer,
  6. Implements: [Options, Events],
  7. initialize: function(node, app, actions, options){
  8. this.setOptions(options);
  9. this.app = app;
  10. this.path = "/x_component_Attendance/$ScheduleExplorer/";
  11. this.cssPath = "/x_component_Attendance/$ScheduleExplorer/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.actions = actions;
  14. this.node = $(node);
  15. this.initData();
  16. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  17. },
  18. loadView : function(){
  19. this.view = new MWF.xApplication.Attendance.ScheduleExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  20. this.view.load();
  21. this.setContentSize();
  22. },
  23. createDocument: function(){
  24. if(this.view)this.view._createDocument();
  25. }
  26. });
  27. MWF.xApplication.Attendance.ScheduleExplorer.View = new Class({
  28. Extends: MWF.xApplication.Attendance.Explorer.View,
  29. _createItem: function(data){
  30. return new MWF.xApplication.Attendance.ScheduleExplorer.Document(this.table, data, this.explorer, this);
  31. },
  32. _getCurrentPageData: function(callback, count){
  33. this.actions.listSchedule(function(json){
  34. if (callback) callback(json);
  35. });
  36. },
  37. _removeDocument: function(documentData, all){
  38. this.actions.deleteSchedule(documentData.id, function(json){
  39. this.explorer.view.reload();
  40. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  41. }.bind(this));
  42. },
  43. _createDocument: function(){
  44. var schedule = new MWF.xApplication.Attendance.ScheduleExplorer.Schedule(this.explorer);
  45. schedule.create();
  46. },
  47. _openDocument: function( documentData ){
  48. var schedule = new MWF.xApplication.Attendance.ScheduleExplorer.Schedule(this.explorer, documentData );
  49. schedule.edit();
  50. }
  51. });
  52. MWF.xApplication.Attendance.ScheduleExplorer.Document = new Class({
  53. Extends: MWF.xApplication.Attendance.Explorer.Document
  54. });
  55. MWF.xApplication.Attendance.ScheduleExplorer.Schedule = new Class({
  56. Extends: MWF.xApplication.Attendance.Explorer.PopupForm,
  57. options : {
  58. "width": 600,
  59. "height": 450,
  60. "hasTop" : true,
  61. "hasBottom" : true,
  62. "title" : "",
  63. "draggable" : true,
  64. "closeAction" : true
  65. },
  66. _createTableContent: function(){
  67. var lp = this.app.lp.schedule;
  68. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  69. "<tr><td colspan='2' styles='formTableHead'>"+lp.setSchedule+"</td></tr>" +
  70. "<tr><td styles='formTabelTitle' lable='unitName'></td>"+
  71. " <td styles='formTableValue' item='unitName'></td></tr>" +
  72. "<tr><td styles='formTabelTitle' lable='onDutyTime'></td>"+
  73. " <td styles='formTableValue' item='onDutyTime'></td></tr>" +
  74. "<tr><td styles='formTabelTitle' lable='offDutyTime'></td>"+
  75. " <td styles='formTableValue' item='offDutyTime'></td></tr>" +
  76. "<tr><td styles='formTabelTitle' lable='lateStartTime'></td>"+
  77. " <td styles='formTableValue' item='lateStartTime'></td></tr>" +
  78. "<tr><td styles='formTabelTitle' lable='leaveEarlyStartTime'></td>"+
  79. " <td styles='formTableValue' item='leaveEarlyStartTime'></td></tr>" +
  80. "<tr><td styles='formTabelTitle' lable='absenceStartTime'></td>"+
  81. " <td styles='formTableValue' item='absenceStartTime'></td></tr>" +
  82. "</table>";
  83. this.formTableArea.set("html",html);
  84. MWF.xDesktop.requireApp("Template", "MForm", function(){
  85. this.form = new MForm( this.formTableArea, this.data, {
  86. isEdited : this.isEdited || this.isNew,
  87. itemTemplate : {
  88. unitName : { text: lp.unit, type : "org", orgType : "unit" },
  89. onDutyTime : { text: lp.workTime, tType : "time",notEmpty:true },
  90. offDutyTime : { text: lp.offTime, tType : "time",notEmpty:true },
  91. lateStartTime : { text: lp.lateTime, tType : "time",notEmpty:true},
  92. leaveEarlyTime : { text:lp.leaveEarlyTime, tType : "time" },
  93. absenceStartTime : { text:lp.absenteeismTime, tType : "time" }
  94. }
  95. }, this.app);
  96. this.form.load();
  97. }.bind(this), true);
  98. },
  99. _ok: function( data, callback ){
  100. this.app.restActions.saveSchedule(data, function(json){
  101. if( callback )callback(json);
  102. }.bind(this));
  103. }
  104. });
  105. //
  106. //
  107. //MWF.xApplication.Attendance.ScheduleExplorer.Schedule2 = new Class({
  108. // Extends: MWF.widget.Common,
  109. // options: {
  110. // "width": "600",
  111. // "height": "450"
  112. // },
  113. // initialize: function( explorer, data ){
  114. // this.explorer = explorer;
  115. // this.app = explorer.app;
  116. // this.data = data || {};
  117. // this.css = this.explorer.css;
  118. //
  119. // this.load();
  120. // },
  121. // load: function(){
  122. // this.data.workTime = this.data.onDutyTime;
  123. // this.data.offTime = this.data.offDutyTime;
  124. // this.data.unit = this.data.unitName;
  125. // this.data.lateTime = this.data.lateStartTime;
  126. // this.data.leaveEarlyTime =this.data.leaveEarlyStartTime;
  127. // this.data.absenteeismTime =this.data.absenceStartTime;
  128. // },
  129. //
  130. // open: function(e){
  131. // this.isNew = false;
  132. // this.isEdited = false;
  133. // },
  134. // create: function(){
  135. // this.isNew = true;
  136. // this._open();
  137. // },
  138. // edit: function(){
  139. // this.isEdited = true;
  140. // this._open();
  141. // },
  142. // _open : function(){
  143. // this.createMarkNode = new Element("div", {
  144. // "styles": this.css.createMarkNode,
  145. // "events": {
  146. // "mouseover": function(e){e.stopPropagation();},
  147. // "mouseout": function(e){e.stopPropagation();}
  148. // }
  149. // }).inject(this.app.content, "after");
  150. //
  151. // this.createAreaNode = new Element("div", {
  152. // "styles": this.css.createAreaNode
  153. // });
  154. //
  155. // this.createNode();
  156. //
  157. // this.createAreaNode.inject(this.createMarkNode, "after");
  158. // this.createAreaNode.fade("in");
  159. //
  160. // this.unit.focus();
  161. //
  162. // this.setCreateNodeSize();
  163. // this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  164. // this.addEvent("resize", this.setCreateNodeSizeFun);
  165. // },
  166. // createNode: function(){
  167. // var _self = this;
  168. // this.createNode = new Element("div", {
  169. // "styles": this.css.createNode
  170. // }).inject(this.createAreaNode);
  171. //
  172. //
  173. // this.createIconNode = new Element("div", {
  174. // "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  175. // }).inject(this.createNode);
  176. //
  177. //
  178. // this.createFormNode = new Element("div", {
  179. // "styles": this.css.createFormNode
  180. // }).inject(this.createNode);
  181. //
  182. // var lp = this.app.lp.schedule;
  183. //
  184. // var inputStyle = "width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;";
  185. // var inputTimeStyle = "width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;"+
  186. // "background : url(/x_component_Attendance/$ScheduleExplorer/default/icon/calendar.png) 98% center no-repeat";
  187. // var inputPersonStyle = "width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;"+
  188. // "background : url(/x_component_Attendance/$PermissionExplorer/default/icon/selectperson.png) 98% center no-repeat";
  189. //
  190. // var html = "<table width='100%' height='270' border='0' cellPadding='0' cellSpacing='0'>" +
  191. // "<tr>"+
  192. // "<td colspan='2' style='height: 50px; line-height: 50px; text-align: center; min-width: 80px; font-size:18px;font-weight: bold;'>" + lp.setSchedule + "</td>" +
  193. // "</tr>" +
  194. // "<tr>"+
  195. // "<td style='height: 60px; line-height: 60px; text-align: left; min-width: 80px; width:25%' rowspan='2'>" + lp.unit + ":</td>" +
  196. // "<td style='; text-align: right;'>"+
  197. // (!this.isNew && !this.isEdited ? "" :
  198. // ("<input type='text' id='unit' " + "style='" + inputPersonStyle +"'" + " value='" + ( this.data && this.data.unit ? this.data.unit : "") + "'/>")) +
  199. // "</td>"+
  200. // "</tr>" +
  201. // "<tr>"+
  202. // "<td style='; text-align: left;font-size:14px;padding-bottom: 5px'>"+
  203. // (!this.isNew && !this.isEdited ? "" :("<input type='button' id='selTopUnit' " +"style='margin-right:5px'"+ " value='选择公司'/>")) +
  204. // (!this.isNew && !this.isEdited ? "" :("<input type='button' id='selUnit' " + " value='选择部门'/>")) +
  205. // //"注:不选择" + lp.unit + "则为默认排班"+
  206. // "</td>"+
  207. // "</tr>" +
  208. // "<tr>" +
  209. // "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.workTime+":</td>" +
  210. // "<td style='; text-align: right;'>" +
  211. // (!this.isNew && !this.isEdited ? "" :
  212. // ("<input type='text' id='workTime' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.workTime ? this.data.workTime : "") + "'/>")) +
  213. // "</td>" +
  214. // "</tr>" +
  215. // "<tr>" +
  216. // "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.offTime+":</td>" +
  217. // "<td style='; text-align: right;'>" +
  218. // (!this.isNew && !this.isEdited ? "" :
  219. // ("<input type='text' id='offTime' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.offTime ? this.data.offTime : "") + "'/>")) +
  220. // "</td>" +
  221. // "</tr>" +
  222. // "<tr>" +
  223. // "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.lateTime+":</td>" +
  224. // "<td style='; text-align: right;'>" +
  225. // (!this.isNew && !this.isEdited ? "" :
  226. // ("<input type='text' id='lateTime' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.lateTime ? this.data.lateTime : "") + "'/>")) +
  227. // "</td>" +
  228. // "</tr>" +
  229. // "<tr>" +
  230. // "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.leaveEarlyTime+":</td>" +
  231. // "<td style='; text-align: right;'>" +
  232. // (!this.isNew && !this.isEdited ? "" :
  233. // ("<input type='text' id='leaveEarlyTime' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.leaveEarlyTime ? this.data.leaveEarlyTime : "") + "'/>")) +
  234. // "</td>" +
  235. // "</tr>" +
  236. // "<tr>" +
  237. // "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.absenteeismTime+":</td>" +
  238. // "<td style='; text-align: right;'>" +
  239. // (!this.isNew && !this.isEdited ? "" :
  240. // ("<input type='text' id='absenteeismTime' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.absenteeismTime ? this.data.absenteeismTime : "") + "'/>")) +
  241. // "</td>" +
  242. // "</tr>" +
  243. // "</table>";
  244. // this.createFormNode.set("html", html);
  245. //
  246. // this.unit = this.createFormNode.getElement("#unit");
  247. // this.workTime = this.createFormNode.getElement("#workTime");
  248. // this.offTime = this.createFormNode.getElement("#offTime");
  249. // this.lateTime = this.createFormNode.getElement("#lateTime");
  250. // this.leaveEarlyTime = this.createFormNode.getElement("#leaveEarlyTime");
  251. // this.absenteeismTime = this.createFormNode.getElement("#absenteeismTime");
  252. //
  253. // this.createFormNode.getElement("#selUnit").addEvent("click",function(){
  254. // _self.selectUnit(this,"d");
  255. // })
  256. // this.createFormNode.getElement("#selTopUnit").addEvent("click",function(){
  257. // _self.selectUnit(this,"c");
  258. // })
  259. //
  260. // this.workTime.addEvent("click",function(){
  261. // _self.selectCalendar(this);
  262. // })
  263. // this.offTime.addEvent("click",function(){
  264. // _self.selectCalendar(this);
  265. // })
  266. // this.lateTime.addEvent("click",function(){
  267. // _self.selectCalendar(this);
  268. // })
  269. // this.leaveEarlyTime.addEvent("click",function(){
  270. // _self.selectCalendar(this);
  271. // })
  272. // this.absenteeismTime.addEvent("click",function(){
  273. // _self.selectCalendar(this);
  274. // })
  275. //
  276. // this.cancelActionNode = new Element("div", {
  277. // "styles": this.css.createCancelActionNode,
  278. // "text": this.app.lp.cancel
  279. // }).inject(this.createFormNode);
  280. // this.createOkActionNode = new Element("div", {
  281. // "styles": this.css.createOkActionNode,
  282. // "text": this.app.lp.ok
  283. // }).inject(this.createFormNode);
  284. //
  285. // this.cancelActionNode.addEvent("click", function(e){
  286. // this.cancelCreate(e);
  287. // }.bind(this));
  288. // this.createOkActionNode.addEvent("click", function(e){
  289. // this.okCreate(e);
  290. // }.bind(this));
  291. // },
  292. //
  293. // setCreateNodeSize: function (width, height, top, left) {
  294. // if (!width)width = this.options && this.options.width ? this.options.width : "50%"
  295. // if (!height)height = this.options && this.options.height ? this.options.height : "50%"
  296. // if (!top) top = this.options && this.options.top ? this.options.top : 0;
  297. // if (!left) left = this.options && this.options.left ? this.options.left : 0;
  298. //
  299. // var allSize = this.app.content.getSize();
  300. // var limitWidth = allSize.x; //window.screen.width
  301. // var limitHeight = allSize.y; //window.screen.height
  302. //
  303. // "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  304. // "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  305. // 300 > width && (width = 300);
  306. // 220 > height && (height = 220);
  307. // top = top || parseInt((limitHeight - height) / 2, 10);
  308. // left = left || parseInt((limitWidth - width) / 2, 10);
  309. //
  310. // this.createAreaNode.setStyles({
  311. // "width": "" + width + "px",
  312. // "height": "" + height + "px",
  313. // "top": "" + top + "px",
  314. // "left": "" + left + "px"
  315. // });
  316. //
  317. // this.createNode.setStyles({
  318. // "width": "" + width + "px",
  319. // "height": "" + height + "px"
  320. // });
  321. //
  322. // var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x: 0, y: 0};
  323. // var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  324. // var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  325. //
  326. // var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  327. // //var formMargin = formHeight -iconSize.y;
  328. // this.createFormNode.setStyles({
  329. // "height": "" + contentHeight + "px"
  330. // });
  331. // },
  332. // cancelCreate: function(e){
  333. // var _self = this;
  334. // var unit = this.unit.get("value");
  335. // if ( this.isNew && unit!="" && unit!="default" ){
  336. // this.app.confirm("warn", e,
  337. // this.app.lp.create_cancel_title,
  338. // this.app.lp.create_cancel, "320px", "100px",
  339. // function(){
  340. // _self.createMarkNode.destroy();
  341. // _self.createAreaNode.destroy();
  342. // this.close();
  343. // },function(){
  344. // this.close();
  345. // }
  346. // );
  347. // }else{
  348. // this.createMarkNode.destroy();
  349. // this.createAreaNode.destroy();
  350. // delete _self;
  351. // }
  352. // },
  353. // okCreate: function(e){
  354. // var data = {
  355. // "id" : (this.data && this.data.id) ? this.data.id : null,
  356. // "unitName": this.unit.get("value"),
  357. // "onDutyTime": this.workTime.get("value"),
  358. // "offDutyTime": this.offTime.get("value"),
  359. // "lateStartTime": this.lateTime.get("value"),
  360. // "leaveEarlyStartTime": this.leaveEarlyTime.get("value"),
  361. // "absenceStartTime": this.absenteeismTime.get("value")
  362. // };
  363. //
  364. // if (data.onDutyTime && data.offDutyTime && data.lateStartTime ){
  365. // this.app.restActions.saveSchedule(data, function(json){
  366. // if( json.type == "ERROR" ){
  367. // this.app.notice( json.message , "error");
  368. // }else{
  369. // this.createMarkNode.destroy();
  370. // this.createAreaNode.destroy();
  371. // if(this.explorer.view)this.explorer.view.reload();
  372. // this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  373. // }
  374. // // this.app.processConfig();
  375. // }.bind(this));
  376. // }else{
  377. // this.app.notice( "请选择上班打卡时间、下班打卡时间和迟到起算时间", "error");
  378. // }
  379. // },
  380. // selectCalendar : function( calendarNode ){
  381. // MWF.require("MWF.widget.Calendar", function(){
  382. // var calendar = new MWF.widget.Calendar( calendarNode, {
  383. // "style": "xform",
  384. // "timeOnly": true,
  385. // "isTime": true,
  386. // "target": this.app.content
  387. // });
  388. // calendar.show();
  389. // }.bind(this));
  390. // },
  391. // selectUnit: function(el, type ){
  392. // var options = {
  393. // "type": type == "d" ? "unit" : "topUnit",
  394. // "title": type == "d" ? "选择部门" : "选择公司",
  395. // "values": this.data.unit || [],
  396. // "count" : "1",
  397. // "onComplete": function(items){
  398. // this.data.unit = [];
  399. // items.each(function(item){
  400. // this.data.unit.push(item.data.name);
  401. // }.bind(this));
  402. // this.unit.set("value",this.data.unit);
  403. // }.bind(this)
  404. // };
  405. // var selector = new MWF.O2Selector(this.app.content, options);
  406. // }
  407. //});