ScheduleExplorer.js 16 KB

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