MyAppealExplorer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  3. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  4. MWF.xApplication.Attendance.MyAppealExplorer = 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/$MyAppealExplorer/";
  11. this.cssPath = "/x_component_Attendance/$MyAppealExplorer/"+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. var month = (new Date().getMonth()+1).toString();
  23. if( month.length == 1 )month = "0"+month;
  24. var filterData = {
  25. "status" : "999",
  26. "yearString" : new Date().getFullYear().toString(),
  27. "monthString" : month
  28. }
  29. this.loadView( filterData );
  30. this.setNodeScroll();
  31. },
  32. loadFilter : function(){
  33. this.fileterNode = new Element("div.fileterNode", {
  34. "styles" : this.css.fileterNode
  35. }).inject(this.node)
  36. var table = new Element("table", {
  37. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.filterTable, "class" : "filterTable"
  38. }).inject( this.fileterNode );
  39. var tr = new Element("tr").inject(table);
  40. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : (new Date).format(this.app.lp.dateFormatMonth) }).inject(tr);
  41. this.createStatusSelectTd(tr);
  42. this.createAppealReasonTd(tr);
  43. //this.createDepartmentTd(tr);
  44. //this.createPersonTd( tr );
  45. //this.createYearSelectTd( tr );
  46. //this.createMonthSelectTd( tr );
  47. this.createActionTd( tr );
  48. },
  49. createStatusSelectTd : function( tr ){
  50. var _self = this;
  51. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "审批状态" }).inject(tr);
  52. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  53. this.status = new MDomItem( td, {
  54. "name" : "status",
  55. "type" : "select",
  56. "value" : "999",
  57. "selectText" :["所有状态","待处理","审批通过","审批未通过"],
  58. "selectValue" :["999","0","1","-1"]
  59. }, true, this.app );
  60. this.status.load();
  61. },
  62. createAppealReasonTd : function( tr ){
  63. var _self = this;
  64. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "申诉原因" }).inject(tr);
  65. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  66. this.appealReason = new MDomItem( td, {
  67. "name" : "appealReason",
  68. "type" : "select",
  69. "selectText" :["","临时请假","出差","因公外出","其他"]
  70. }, true, this.app );
  71. this.appealReason.load();
  72. },
  73. createDepartmentTd : function(tr){
  74. var _self = this;
  75. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "部门" }).inject(tr);
  76. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  77. this.departmentName = new MDomItem( td, {
  78. "name" : "departmentName",
  79. "style" : {"width":"60px"},
  80. "defaultValue" : this.app.manageDepartments.length > 0 ? this.app.manageDepartments[0] : "",
  81. "event" : {
  82. "click" : function(mdi){ _self.selecePerson( mdi, "department" ); }
  83. }
  84. }, true, this.app );
  85. this.departmentName.load();
  86. },
  87. createPersonTd : function(tr){
  88. var _self = this;
  89. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "人员" }).inject(tr);
  90. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  91. this.empName = new MDomItem( td, {
  92. "name" : "empName",
  93. "style" : {"width":"60px"},
  94. "event" : {
  95. "click" : function(mdi){ _self.selecePerson( mdi, "person" ); }
  96. }
  97. }, true, this.app );
  98. this.empName.load();
  99. },
  100. createYearSelectTd : function( tr ){
  101. var _self = this;
  102. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "年度" }).inject(tr);
  103. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  104. this.yearString = new MDomItem( td, {
  105. "name" : "yearString",
  106. "type" : "select",
  107. "selectValue" : function(){
  108. var years = [];
  109. var year = new Date().getFullYear();
  110. for(var i=0; i<6; i++ ){
  111. years.push( year-- );
  112. }
  113. return years;
  114. }
  115. }, true, this.app );
  116. this.yearString.load();
  117. },
  118. createMonthSelectTd : function( tr ){
  119. var _self = this;
  120. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "月份" }).inject(tr);
  121. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  122. this.monthString = new MDomItem( td, {
  123. "name" : "monthString",
  124. "type" : "select",
  125. "selectValue" :["","01","02","03","04","05","06","07","08","09","10","11","12"]
  126. }, true, this.app );
  127. this.monthString.load();
  128. },
  129. createActionTd : function( tr ){
  130. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  131. var input = new Element("button",{
  132. "text" : "查询",
  133. "styles" : this.css.filterButton
  134. }).inject(td);
  135. input.addEvent("click", function(){
  136. var filterData = {
  137. status : this.status.getValue(),
  138. appealReason : this.appealReason.getValue(),
  139. //departmentName : this.departmentName.getValue(),
  140. //empName : this.empName.getValue(),
  141. //yearString : this.yearString.getValue(),
  142. //monthString : this.monthString.getValue()
  143. }
  144. this.loadView( filterData );
  145. }.bind(this))
  146. },
  147. selecePerson: function( el, type ){
  148. var text = "选择人员"
  149. if( type=="company") {
  150. text = "选择公司"
  151. }else if( type=="department"){
  152. text = "选择部门"
  153. }
  154. var options = {
  155. "type": type, //company department person,
  156. "title": text,
  157. "count" : "1",
  158. "names": [ el.get("value") ] || [],
  159. "onComplete": function(items){
  160. var arr = [];
  161. items.each(function(item){
  162. arr.push(item.data.name);
  163. }.bind(this));
  164. el.set("value",arr.join(","));
  165. }.bind(this)
  166. };
  167. var selector = new MWF.OrgSelector(this.app.content, options);
  168. },
  169. setContentSize: function(){
  170. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : {"x":0,"y":0};
  171. var titlebarSize = this.app.titleBar ? this.app.titleBar.getSize() : {"x":0,"y":0};
  172. var filterSize = this.fileterNode ? this.fileterNode.getSize() : {"x":0,"y":0};
  173. var nodeSize = this.node.getSize();
  174. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  175. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  176. //var filterSize = this.filterNode.getSize();
  177. var filterConditionSize = this.filterConditionNode ? this.filterConditionNode.getSize() : {"x":0,"y":0};
  178. var height = nodeSize.y-toolbarSize.y-pt-pb-filterConditionSize.y-titlebarSize.y-filterSize.y;
  179. this.elementContentNode.setStyle("height", ""+height+"px");
  180. this.pageCount = (height/30).toInt()+5;
  181. if (this.view && this.view.items.length<this.pageCount){
  182. this.view.loadElementList(this.pageCount-this.view.items.length);
  183. }
  184. },
  185. loadView : function( filterData ){
  186. this.elementContentNode.empty();
  187. this.view = new MWF.xApplication.Attendance.MyAppealExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  188. this.view.filterData = filterData;
  189. this.view.load();
  190. this.setContentSize();
  191. },
  192. createDocument: function(){
  193. if(this.view)this.view._createDocument();
  194. }
  195. });
  196. MWF.xApplication.Attendance.MyAppealExplorer.View = new Class({
  197. Extends: MWF.xApplication.Attendance.Explorer.View,
  198. _createItem: function(data){
  199. return new MWF.xApplication.Attendance.MyAppealExplorer.Document(this.table, data, this.explorer, this);
  200. },
  201. _getCurrentPageData: function(callback, count){
  202. if(!count )count=20;
  203. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  204. var filter = this.filterData || {};
  205. var month = (new Date().getMonth()+1).toString();
  206. if( month.length == 1 )month = "0"+month;
  207. filter.yearString = new Date().getFullYear().toString();
  208. filter.monthString = month;
  209. filter.empName = layout.desktop.session.user.name;
  210. this.actions.listAppealFilterNext(id, count, filter, function(json){
  211. var data = json.data;
  212. data.sort( function( a, b ){
  213. return parseInt( b.appealDateString.replace(/-/g,"") ) - parseInt( a.appealDateString.replace(/-/g,"") );
  214. })
  215. json.data = data;
  216. if (callback) callback(json);
  217. });
  218. },
  219. _removeDocument: function(documentData, all){
  220. },
  221. _createDocument: function(){
  222. },
  223. _openDocument: function( documentData ){
  224. var appeal = new MWF.xApplication.Attendance.MyAppealExplorer.Appeal(this.explorer, documentData );
  225. appeal.open();
  226. }
  227. })
  228. MWF.xApplication.Attendance.MyAppealExplorer.Document = new Class({
  229. Extends: MWF.xApplication.Attendance.Explorer.Document,
  230. agree : function(){
  231. },
  232. deny : function(){
  233. }
  234. })
  235. MWF.xApplication.Attendance.MyAppealExplorer.Appeal = new Class({
  236. Extends: MWF.widget.Common,
  237. initialize: function( explorer, data ){
  238. this.explorer = explorer;
  239. this.app = explorer.app;
  240. this.data = data || {};
  241. //this.app.restActions.getAppeal(this.data.detailId, function(json){
  242. // this.data = json.data
  243. //}.bind(this),null,false)
  244. //alert(JSON.stringify(this.data))
  245. this.css = this.explorer.css;
  246. this.load();
  247. },
  248. load: function(){
  249. this.app.restActions.getDetail(this.data.detailId, function(json){
  250. this.data.onDutyTime = json.data.onDutyTime;
  251. this.data.offDutyTime = json.data.offDutyTime;
  252. }.bind(this),null,false)
  253. },
  254. open: function(e){
  255. this.isNew = false;
  256. this.isEdited = false;
  257. this._open();
  258. },
  259. create: function(){
  260. this.isNew = true;
  261. this._open();
  262. },
  263. edit: function(){
  264. this.isEdited = true;
  265. this._open();
  266. },
  267. _open : function(){
  268. this.createMarkNode = new Element("div", {
  269. "styles": this.css.createMarkNode,
  270. "events": {
  271. "mouseover": function(e){e.stopPropagation();},
  272. "mouseout": function(e){e.stopPropagation();}
  273. }
  274. }).inject(this.app.content, "after");
  275. this.createAreaNode = new Element("div", {
  276. "styles": this.css.createAreaNode
  277. });
  278. this.createNode();
  279. this.createAreaNode.inject(this.createMarkNode, "after");
  280. this.createAreaNode.fade("in");
  281. this.setCreateNodeSize();
  282. this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  283. this.addEvent("resize", this.setCreateNodeSizeFun);
  284. },
  285. createNode: function(){
  286. var _self = this;
  287. this.createNode = new Element("div", {
  288. "styles": this.css.createNode
  289. }).inject(this.createAreaNode);
  290. //
  291. //this.createIconNode = new Element("div", {
  292. // "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  293. //}).inject(this.createNode);
  294. this.createContainerNode = new Element("div", {
  295. "styles": this.css.createContainerNode
  296. }).inject(this.createNode);
  297. this.setScrollBar( this.createContainerNode );
  298. this.createFormNode = new Element("div", {
  299. "styles": this.css.createFormNode
  300. }).inject(this.createContainerNode);
  301. this.createTableContainer = new Element("div", {
  302. "styles": this.css.createTableContainer
  303. }).inject(this.createFormNode);
  304. this.createTableArea = new Element("div", {
  305. "styles": this.css.createTableArea
  306. }).inject(this.createTableContainer);
  307. var d = this.data;
  308. var appealStatus = "发起";
  309. if (d.status == 0 ) {
  310. appealStatus = "待处理"
  311. } else if (d.status == 1) {
  312. appealStatus = "审批通过"
  313. } else if (d.status == -1) {
  314. appealStatus = "申诉不通过"
  315. }
  316. this.data.appealStatusShow = appealStatus;
  317. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  318. "<tr><td colspan='4' styles='formTableHead'>申诉申请单</td></tr>" +
  319. "<tr><td styles='formTableTitle' lable='empName'></td>"+
  320. " <td styles='formTableValue' item='empName'></td>" +
  321. " <td styles='formTableTitle' lable='recordDateString'></td>"+
  322. " <td styles='formTableValue' item='recordDateString'></td></tr>" +
  323. "<tr><td styles='formTableTitle' lable='onDutyTime'></td>"+
  324. " <td styles='formTableValue' item='onDutyTime'></td>" +
  325. " <td styles='formTableTitle' lable='offDutyTime'></td>"+
  326. " <td styles='formTableValue' item='offDutyTime'></td></tr>" +
  327. "<tr><td styles='formTableTitle' lable='appealStatusShow'></td>"+
  328. " <td styles='formTableValue' item='appealStatusShow' colspan='3'></td></tr>" +
  329. "<tr><td styles='formTableTitle' lable='appealReason'></td>"+
  330. " <td styles='formTableValue' item='appealReason' colspan='3'></td></tr>" +
  331. "<tr contain='selfHolidayType'><td styles='formTableTitle' lable='selfHolidayType'></td>"+
  332. " <td styles='formTableValue' item='selfHolidayType' colspan='3'></td></tr>" +
  333. "<tr contain='address'><td styles='formTableTitle' lable='address'></td>"+
  334. " <td styles='formTableValue' item='address' colspan='3'></td></tr>" +
  335. "<tr contain='startTime'><td styles='formTableTitle' lable='startTime'></td>"+
  336. " <td styles='formTableValue' item='startTime' colspan='3'></td></tr>" +
  337. "<tr contain='endTime'><td styles='formTableTitle' lable='endTime'></td>"+
  338. " <td styles='formTableValue' item='endTime' colspan='3'></td></tr>" +
  339. "<tr contain='appealDescription'><td styles='formTableTitle' lable='appealDescription'></td>"+
  340. " <td styles='formTableValue' item='appealDescription' colspan='3'></td></tr>" +
  341. "<tr contain='opinion1'><td styles='formTableTitle' lable='opinion1'></td>"+
  342. " <td styles='formTableValue' item='opinion1' colspan='3'></td></tr>" +
  343. "</table>"
  344. this.createTableArea.set("html",html);
  345. this.document = new MForm( this.createTableArea, this.data, {
  346. style : "popup",
  347. isEdited : this.isEdited || this.isNew,
  348. itemTemplate : {
  349. empName : { text:"员工姓名", type : "innertext" },
  350. recordDateString : { text:"考勤日期", type : "innertext"},
  351. onDutyTime : { text:"上班打卡时间", type : "innertext"},
  352. offDutyTime : { text:"下班打卡时间", type : "innertext"},
  353. statusShow : { text:"考勤状态", type : "innertext" },
  354. appealStatusShow : { text:"审批状态",type : "innertext"},
  355. appealReason : {
  356. notEmpty : true,
  357. text:"申述原因",
  358. type : "select",
  359. selectValue : ["","临时请假","出差","因公外出","其他"],
  360. event : { change : function(mdi){
  361. _self.switchFieldByAppealReason(mdi.getValue());
  362. }}
  363. },
  364. address : { text:"地点" },
  365. selfHolidayType : {
  366. text:"请假类型",
  367. type : "select",
  368. selectValue : ["","带薪年休假","带薪病假","带薪福利假","扣薪事假","其他"]
  369. },
  370. startTime : { text:"开始日期", tType : "datetime" },
  371. endTime : { text:"结束日期", tType : "datetime" },
  372. appealDescription : { text:"事由" },
  373. opinion1 : { text :"审批意见" }
  374. }
  375. }, this.app,this.css);
  376. this.document.load();
  377. _self.switchFieldByAppealReason(this.data.appealReason);
  378. //createFormNode.set("html", html);
  379. //this.setScrollBar(this.createTableContainer)
  380. this.cancelActionNode = new Element("div", {
  381. "styles": this.css.createCancelActionNode,
  382. "text": "关闭"
  383. }).inject(this.createFormNode);
  384. this.cancelActionNode.addEvent("click", function(e){
  385. this.cancelCreate(e);
  386. }.bind(this));
  387. if( this.isNew || this.isEdited){
  388. this.denyActionNode = new Element("div", {
  389. "styles": this.css.createDenyActionNode,
  390. "text": "不同意"
  391. }).inject(this.createFormNode);
  392. this.createOkActionNode = new Element("div", {
  393. "styles": this.css.createOkActionNode,
  394. "text": "同意"
  395. }).inject(this.createFormNode);
  396. this.denyActionNode.addEvent("click", function(e){
  397. this.deny(e);
  398. }.bind(this));
  399. this.createOkActionNode.addEvent("click", function(e){
  400. this.okCreate(e);
  401. }.bind(this));
  402. }
  403. },
  404. switchFieldByAppealReason : function( ar ){
  405. var tempField = ["selfHolidayType","startTime","endTime","address","appealDescription"];
  406. var showField = [];
  407. if( ar == "临时请假" ){
  408. showField = ["selfHolidayType","startTime","endTime"];
  409. }else if( ar == "出差" ){
  410. showField = ["address","startTime","endTime"];
  411. }else if( ar == "因公外出" ){
  412. showField = ["address","startTime","endTime","appealDescription"];
  413. }else if( ar == "其他" ){
  414. showField = ["appealDescription"];
  415. }
  416. tempField.each( function( f ){
  417. this.createTableArea.getElement("[contain='"+f+"']").setStyle("display", showField.contains(f) ? "" : "none" );
  418. if( this.isNew || this.isEdited )this.document.items[f].options.notEmpty = (showField.contains(f) ? true : false )
  419. }.bind(this))
  420. },
  421. setCreateNodeSize: function(){
  422. var size = this.app.node.getSize();
  423. var allSize = this.app.content.getSize();
  424. var height = "560";
  425. var width = "800";
  426. this.createAreaNode.setStyles({
  427. "width": ""+size.x+"px",
  428. "height": ""+size.y+"px"
  429. });
  430. var hY = height;
  431. var mY = (size.y-height)/2;
  432. this.createNode.setStyles({
  433. "height": ""+hY+"px",
  434. "margin-top": ""+mY+"px",
  435. "width" : ""+width+"px"
  436. });
  437. this.createContainerNode.setStyles({
  438. "height": ""+hY+"px"
  439. });
  440. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x:0,y:0};
  441. var formMargin = hY-iconSize.y-60;
  442. this.createFormNode.setStyles({
  443. "height": ""+formMargin+"px",
  444. "margin-top": ""+60+"px"
  445. });
  446. },
  447. cancelCreate: function(e){
  448. this.createMarkNode.destroy();
  449. this.createAreaNode.destroy();
  450. delete this;
  451. },
  452. deny : function(e){
  453. var data = { 'status':'-1', 'opinion1': this.opinion1.getValue() }
  454. if (data.opinion1 ){
  455. this.process( data );
  456. }else{
  457. this.app.notice( "请填写意见", "error");
  458. }
  459. },
  460. okCreate: function(e){
  461. var data = { 'status':'1', 'opinion1': this.opinion1.getValue() }
  462. this.process( data );
  463. },
  464. process: function( data ){
  465. this.app.restActions.processAppeal( this.data.id, data, function(json){
  466. if( json.type == "ERROR" ){
  467. this.app.notice( json.message , "error");
  468. }else{
  469. this.createMarkNode.destroy();
  470. this.createAreaNode.destroy();
  471. if(this.explorer.view)this.explorer.view.reload();
  472. this.app.notice( "处理成功" , "success");
  473. }
  474. // this.app.processConfig();
  475. }.bind(this));
  476. }
  477. })