SelfHolidayExplorer.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  3. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  4. MWF.xApplication.Attendance.SelfHolidayExplorer = 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/$SelfHolidayExplorer/";
  11. this.cssPath = "/x_component_Attendance/$SelfHolidayExplorer/"+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. load: function(){
  19. this.loadToolbar();
  20. this.loadFilter();
  21. this.loadContentNode();
  22. this.loadView();
  23. this.setNodeScroll();
  24. },
  25. loadFilter : function(){
  26. this.fileterNode = new Element("div.fileterNode", {
  27. "styles" : this.css.fileterNode
  28. }).inject(this.node)
  29. this._loadFilterContent();
  30. },
  31. exportExcel : function(){
  32. var exportForm = new MWF.xApplication.Attendance.SelfHolidayExplorer.ExportExcelForm( this );
  33. exportForm.edit();
  34. },
  35. _loadFilterContent : function(){
  36. var _self = this;
  37. var html = "<table bordr='0' cellpadding='5' cellspacing='0' styles='formTable' width='950'>"+
  38. "<tr>" +
  39. " <td styles='formTableTitle' lable='q_companyName'></td>"+
  40. " <td styles='formTableValue' item='q_companyName'></td>"+
  41. " <td styles='formTableTitle' lable='q_departmentName'></td>"+
  42. " <td styles='formTableValue' item='q_departmentName'></td>"+
  43. " <td styles='formTableTitle' lable='q_empName'></td>"+
  44. " <td styles='formTableValue' item='q_empName'></td>"+
  45. " <td styles='formTableValue' item='action'></td>"+
  46. "</tr>" +
  47. "</table>"
  48. this.fileterNode.set("html",html);
  49. MWF.xDesktop.requireApp("Template", "MForm", function(){
  50. this.filter = new MForm( this.fileterNode, {}, {
  51. style : "filter",
  52. isEdited : true,
  53. itemTemplate : {
  54. q_companyName : { "text" : "选择公司", "tType" : "company" },
  55. q_departmentName : { "text" : "选择部门", "tType" : "department" },
  56. q_empName : { "text" : "选择人员", "tType" : "person" },
  57. action : {
  58. "type" : "button",
  59. "value" : "查询",
  60. "event" : { "click" : function(){
  61. var filterData = _self.filter.getResult( true,",",true,true,true);
  62. this.loadView( filterData );
  63. }.bind(this)}
  64. }
  65. }
  66. }, this.app, this.css);
  67. this.filter.load();
  68. }.bind(this), true);
  69. },
  70. loadView : function( filterData ){
  71. this.elementContentNode.empty();
  72. this.view = new MWF.xApplication.Attendance.SelfHolidayExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  73. this.view.filterData = filterData;
  74. this.view.load();
  75. this.setContentSize();
  76. },
  77. createDocument: function(){
  78. if(this.view)this.view._createDocument();
  79. }
  80. });
  81. MWF.xApplication.Attendance.SelfHolidayExplorer.View = new Class({
  82. Extends: MWF.xApplication.Attendance.Explorer.View,
  83. _createItem: function(data){
  84. return new MWF.xApplication.Attendance.SelfHolidayExplorer.Document(this.table, data, this.explorer, this);
  85. },
  86. _getCurrentPageData: function(callback, count){
  87. //this.actions.listSelfHoliday(function(json){
  88. // if (callback) callback(json);
  89. //});
  90. if(!count )count=20;
  91. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  92. var filter = this.filterData || {};
  93. this.actions.listSelfHolidayFilterNext(id, count, filter, function(json){
  94. if (callback) callback(json);
  95. });
  96. },
  97. _removeDocument: function(documentData, all){
  98. this.actions.deleteSelfHoliday(documentData.id, function(json){
  99. this.explorer.view.reload();
  100. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  101. }.bind(this));
  102. },
  103. _createDocument: function(){
  104. var selfHoliday = new MWF.xApplication.Attendance.SelfHolidayExplorer.SelfHoliday(this.explorer);
  105. selfHoliday.create();
  106. },
  107. _openDocument: function( documentData ){
  108. var selfHoliday = new MWF.xApplication.Attendance.SelfHolidayExplorer.SelfHoliday(this.explorer, documentData );
  109. selfHoliday.open();
  110. }
  111. })
  112. MWF.xApplication.Attendance.SelfHolidayExplorer.Document = new Class({
  113. Extends: MWF.xApplication.Attendance.Explorer.Document
  114. })
  115. MWF.xApplication.Attendance.SelfHolidayExplorer.ExportExcelForm = new Class({
  116. Extends: MWF.xApplication.Attendance.Explorer.PopupForm,
  117. _createTableContent: function(){
  118. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  119. "<tr><td colspan='2' styles='formTableHead'>导出员工休假记录</td></tr>" +
  120. "<tr>" +
  121. " <td styles='formTableTitle' lable='startDate'></td>"+
  122. " <td styles='formTableValue' item='startDate'></td>"+
  123. "</tr>" +
  124. "<tr>" +
  125. " <td styles='formTableTitle' lable='endDate'></td>"+
  126. " <td styles='formTableValue' item='endDate'></td>"+
  127. //" <td styles='formTableValue' item='action'></td>"+
  128. "</tr>" +
  129. "</table>"
  130. this.formTableArea.set("html",html);
  131. MWF.xDesktop.requireApp("Template", "MForm", function(){
  132. this.form = new MForm( this.formTableArea, {q_empName : layout.desktop.session.user.name }, {
  133. isEdited : true,
  134. itemTemplate : {
  135. startDate : { "text" : "开始日期", "tType" : "date" },
  136. endDate : { "text" : "结束日期", "tType" : "date" }
  137. }
  138. }, this.app );
  139. this.form.load();
  140. }.bind(this), true);
  141. },
  142. _ok: function( data, callback ){
  143. this.app.restActions.exportSelfHoliday( data.startDate, data.endDate, function(json){
  144. if( callback )callback(json);
  145. }.bind(this) );
  146. this.close();
  147. }
  148. })
  149. MWF.xApplication.Attendance.SelfHolidayExplorer.SelfHoliday = new Class({
  150. Extends: MWF.widget.Common,
  151. Implements: [Options, Events],
  152. options: {
  153. "width": "500",
  154. "height": "400"
  155. },
  156. initialize: function( explorer, data ){
  157. this.explorer = explorer;
  158. this.app = explorer.app;
  159. this.data = data || {};
  160. this.css = this.explorer.css;
  161. this.load();
  162. },
  163. load: function(){
  164. },
  165. open: function(){
  166. this.isNew = false;
  167. this.isEdited = false;
  168. this._open();
  169. },
  170. create: function(){
  171. this.isNew = true;
  172. this._open();
  173. },
  174. edit: function(){
  175. this.isEdited = true;
  176. this._open();
  177. },
  178. _open : function(){
  179. this.createMarkNode = new Element("div", {
  180. "styles": this.css.createMarkNode,
  181. "events": {
  182. "mouseover": function(e){e.stopPropagation();},
  183. "mouseout": function(e){e.stopPropagation();}
  184. }
  185. }).inject(this.app.content, "after");
  186. this.createAreaNode = new Element("div", {
  187. "styles": this.css.createAreaNode
  188. });
  189. this.createNode();
  190. this.createAreaNode.inject(this.createMarkNode, "after");
  191. this.createAreaNode.fade("in");
  192. this.setCreateNodeSize();
  193. this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  194. this.addEvent("resize", this.setCreateNodeSizeFun);
  195. },
  196. createNode: function(){
  197. var _self = this;
  198. var d = this.data;
  199. this.createNode = new Element("div", {
  200. "styles": this.css.createNode
  201. }).inject(this.createAreaNode);
  202. this.createIconNode = new Element("div", {
  203. "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  204. }).inject(this.createNode);
  205. this.createFormNode = new Element("div", {
  206. "styles": this.css.createFormNode
  207. }).inject(this.createNode);
  208. var table = new Element("table", {
  209. "width" : "100%", "border" : "0", "cellpadding" : "0", "cellspacing" : "0"
  210. }).inject( this.createFormNode );
  211. var tr = new Element("tr").inject(table);
  212. var td = new Element("td", { "colspan":'2', "styles" : this.css.editTableHead, "text" : "员工休假记录" }).inject(tr);
  213. var tr = new Element("tr").inject(table);
  214. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "部门:" }).inject(tr);
  215. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  216. if( !this.isNew && !this.isEdited ){
  217. td.set("text", d.organizationName )
  218. }else{
  219. this.organizationName = new MDomItem( td, {
  220. "name" : "organizationName",
  221. "value" : d.organizationName,
  222. "style" : this.css.inputPersonStyle,
  223. "event" : {
  224. "click" : function( mdi){ _self.selectPeople(this, "department", mdi.get("value").split(",") ) }
  225. }
  226. }, true, this.app );
  227. this.organizationName.load();
  228. }
  229. var tr = new Element("tr").inject(table);
  230. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "员工姓名:" }).inject(tr);
  231. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  232. if( !this.isNew && !this.isEdited ){
  233. td.set("text", d.employeeName )
  234. }else{
  235. this.employeeName = new MDomItem( td, {
  236. "name" : "employeeName",
  237. "value" : d.employeeName,
  238. "style" : this.css.inputPersonStyle,
  239. "event" : {
  240. "click" : function( mdi){ _self.selectPeople(this, "person", mdi.get("value").split(",") ) }
  241. }
  242. }, true, this.app );
  243. this.employeeName.load();
  244. }
  245. var tr = new Element("tr").inject(table);
  246. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "休假类型:" }).inject(tr);
  247. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  248. if( !this.isNew && !this.isEdited ){
  249. td.set("text", d.leaveType )
  250. }else{
  251. this.leaveType = new MDomItem( td, {
  252. "name" : "leaveType",
  253. "type" : "select",
  254. "value" : d.leaveType,
  255. "selectValue" : "带薪年休假,带薪病假,带薪福利假,扣薪事假,其他".split(",")
  256. }, true, this.app );
  257. this.leaveType.load();
  258. }
  259. var tr = new Element("tr").inject(table);
  260. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "开始时间:" }).inject(tr);
  261. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  262. if( !this.isNew && !this.isEdited ){
  263. td.set("text", d.startTime )
  264. }else{
  265. this.startTime = new MDomItem( td, {
  266. "name" : "startTime",
  267. "value" : d.startTime,
  268. "style" : this.css.inputTimeStyle,
  269. "event" : {
  270. "click" : function( mdi){ _self.selectDateTime(this, false, true ) }
  271. }
  272. }, true, this.app );
  273. this.startTime.load();
  274. }
  275. var tr = new Element("tr").inject(table);
  276. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "结束时间:" }).inject(tr);
  277. var td = new Element("td", { "styles" : this.css.editTableValue} ).inject(tr);
  278. if( !this.isNew && !this.isEdited ){
  279. td.set("text", d.endTime )
  280. }else{
  281. this.endTime = new MDomItem( td, {
  282. "name" : "endTime",
  283. "value" : d.endTime,
  284. "style" : this.css.inputTimeStyle,
  285. "event" : {
  286. "click" : function( mdi){ _self.selectDateTime(this, false, true ) }
  287. }
  288. }, true, this.app );
  289. this.endTime.load();
  290. }
  291. var tr = new Element("tr").inject(table);
  292. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "休假天数:" }).inject(tr);
  293. var td = new Element("td", { "styles" : this.css.editTableValue}).inject(tr);
  294. if( !this.isNew && !this.isEdited ){
  295. td.set("text", d.leaveDayNumber )
  296. }else{
  297. this.leaveDayNumber = new MDomItem( td, {
  298. "name" : "leaveDayNumber",
  299. "value" : d.leaveDayNumber,
  300. "style" : this.css.inputStyle,
  301. "event" : {
  302. "keyup" : function(){ this.value=this.value.replace(/[^\d.]/g,'') }
  303. }
  304. }, true, this.app );
  305. this.leaveDayNumber.load();
  306. }
  307. if( this.isNew || this.isEdited ){
  308. this.createOkActionNode = new Element("div", {
  309. "styles": this.css.createOkActionNode,
  310. "text": this.app.lp.ok
  311. }).inject(this.createFormNode);
  312. this.createOkActionNode.addEvent("click", function(e){
  313. this.okCreate(e);
  314. }.bind(this));
  315. }
  316. this.cancelActionNode = new Element("div", {
  317. "styles": this.css.createCancelActionNode,
  318. "text": this.app.lp.cancel
  319. }).inject(this.createFormNode);
  320. this.cancelActionNode.addEvent("click", function(e){
  321. this.cancelCreate(e);
  322. }.bind(this));
  323. },
  324. setCreateNodeSize: function (width, height, top, left) {
  325. if (!width)width = this.options && this.options.width ? this.options.width : "50%"
  326. if (!height)height = this.options && this.options.height ? this.options.height : "50%"
  327. if (!top) top = this.options && this.options.top ? this.options.top : 0;
  328. if (!left) left = this.options && this.options.left ? this.options.left : 0;
  329. var allSize = this.app.content.getSize();
  330. var limitWidth = allSize.x; //window.screen.width
  331. var limitHeight = allSize.y; //window.screen.height
  332. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  333. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  334. 300 > width && (width = 300);
  335. 220 > height && (height = 220);
  336. top = top || parseInt((limitHeight - height) / 2, 10);
  337. left = left || parseInt((limitWidth - width) / 2, 10);
  338. this.createAreaNode.setStyles({
  339. "width": "" + width + "px",
  340. "height": "" + height + "px",
  341. "top": "" + top + "px",
  342. "left": "" + left + "px"
  343. });
  344. this.createNode.setStyles({
  345. "width": "" + width + "px",
  346. "height": "" + height + "px"
  347. });
  348. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x: 0, y: 0};
  349. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  350. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  351. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  352. //var formMargin = formHeight -iconSize.y;
  353. this.createFormNode.setStyles({
  354. "height": "" + contentHeight + "px"
  355. });
  356. },
  357. //setCreateNodeSize: function(){
  358. // var size = this.app.node.getSize();
  359. // var allSize = this.app.content.getSize();
  360. //
  361. // this.createAreaNode.setStyles({
  362. // "width": ""+size.x+"px",
  363. // "height": ""+size.y+"px"
  364. // });
  365. // var hY = size.y*0.8;
  366. // var mY = size.y*0.2/2;
  367. // this.createNode.setStyles({
  368. // "height": ""+hY+"px",
  369. // "margin-top": ""+mY+"px"
  370. // });
  371. //
  372. // var iconSize = this.createIconNode.getSize();
  373. // var formHeight = hY*0.9;
  374. // if (formHeight>250) formHeight = 250;
  375. // var formMargin = hY*0.3/2-iconSize.y;
  376. // this.createFormNode.setStyles({
  377. // "height": ""+formHeight+"px",
  378. // "margin-top": ""+formMargin+"px"
  379. // });
  380. //},
  381. cancelCreate: function(e){
  382. var _self = this;
  383. if( this.organizationName )var organizationName = this.organizationName.get("value");
  384. if ( this.isNew && organizationName!="" && organizationName!="default" ){
  385. this.app.confirm("warn", e,
  386. this.app.lp.create_cancel_title,
  387. this.app.lp.create_cancel, "320px", "100px",
  388. function(){
  389. _self.createMarkNode.destroy();
  390. _self.createAreaNode.destroy();
  391. this.close();
  392. },function(){
  393. this.close();
  394. }
  395. );
  396. }else{
  397. this.createMarkNode.destroy();
  398. this.createAreaNode.destroy();
  399. delete _self;
  400. }
  401. },
  402. okCreate: function(e){
  403. var data = {
  404. "id" : (this.data && this.data.id) ? this.data.id : null,
  405. "organizationName": this.organizationName.get("value"),
  406. "employeeName": this.employeeName.get("value"),
  407. "leaveType": this.leaveType.get("value"),
  408. "startTime": this.startTime.get("value"),
  409. "endTime": this.endTime.get("value"),
  410. "leaveDayNumber": this.leaveDayNumber.get("value")
  411. };
  412. //alert(JSON.stringify(data))
  413. if (data.organizationName && data.employeeName && data.leaveType && data.startTime && data.endTime && data.leaveDayNumber){
  414. this.app.restActions.saveSelfHoliday(data, function(json){
  415. if( json.type == "ERROR" ){
  416. this.app.notice( json.message , "error");
  417. }else{
  418. this.createMarkNode.destroy();
  419. this.createAreaNode.destroy();
  420. if(this.explorer.view)this.explorer.view.reload();
  421. this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  422. }
  423. // this.app.processConfig();
  424. }.bind(this));
  425. }else{
  426. this.app.notice( this.app.lp.selfHoliday.inputVaild, "error");
  427. }
  428. },
  429. selectDateTime : function( el, timeOnly, isTme ){
  430. MWF.require("MWF.widget.Calendar", function(){
  431. var calendar = new MWF.widget.Calendar( el, {
  432. "style": "xform",
  433. "timeOnly": timeOnly,
  434. "isTime": isTme,
  435. "target": this.app.content
  436. });
  437. calendar.show();
  438. }.bind(this));
  439. },
  440. selectPeople: function(el, type, value ){
  441. var title
  442. if( type == "department" ){
  443. title = "选择部门"
  444. }else if( type == "company" ){
  445. title = "选择公司"
  446. }else{
  447. title = "选择个人"
  448. }
  449. var options = {
  450. "type": type,
  451. "title": title,
  452. "count" : "1",
  453. "names": value || [],
  454. "onComplete": function(items){
  455. var vs = [];
  456. items.each(function(item){
  457. vs.push(item.data.name);
  458. }.bind(this));
  459. el.set("value",vs.join( "," ));
  460. }.bind(this)
  461. };
  462. var selector = new MWF.OrgSelector(this.app.content, options);
  463. }
  464. });