DepartmentDetail.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  3. MWF.xApplication.Attendance.DepartmentDetail = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(node, app, actions, options){
  10. this.setOptions(options);
  11. this.app = app;
  12. this.path = "/x_component_Attendance/$DepartmentDetail/";
  13. this.cssPath = "/x_component_Attendance/$DepartmentDetail/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.actions = actions;
  16. this.node = $(node);
  17. },
  18. load: function(){
  19. this.loadTab();
  20. },
  21. loadTab : function(){
  22. this.tabNode = new Element("div",{"styles" : this.css.tabNode }).inject(this.node)
  23. this.detailArea = new Element("div",{"styles" : this.css.tabPageContainer }).inject(this.tabNode)
  24. //this.selfHolidayArea = new Element("div",{"styles" : this.css.tabPageContainer }).inject(this.tabNode)
  25. this.detailStaticArea = new Element("div",{"styles" : this.css.tabPageContainer }).inject(this.tabNode)
  26. //this.selfHolidayStaticArea = new Element("div",{"styles" : this.css.tabPageContainer }).inject(this.tabNode)
  27. MWF.require("MWF.widget.Tab", function(){
  28. this.tabs = new MWF.widget.Tab(this.tabNode, {"style": "attendance"});
  29. this.tabs.load();
  30. this.detailPage = this.tabs.addTab(this.detailArea, "部门出勤明细", false);
  31. this.detailPage.contentNodeArea.set("class","detailPage");
  32. this.detailPage.addEvent("show",function(){
  33. if( !this.detailExplorer ){
  34. this.detailExplorer = new MWF.xApplication.Attendance.DepartmentDetail.Explorer( this.detailArea, this );
  35. this.detailExplorer.load();
  36. }
  37. }.bind(this))
  38. this.detailStaticPage = this.tabs.addTab(this.detailStaticArea, "部门出勤率统计", false);
  39. this.detailStaticPage.contentNodeArea.set("class","detailStaticPage");
  40. this.detailStaticPage.addEvent("show",function(){
  41. if( !this.detailStaticExplorer ){
  42. this.detailStaticExplorer = new MWF.xApplication.Attendance.DepartmentDetail.DetailStaticExplorer( this.detailStaticArea, this );
  43. this.detailStaticExplorer.load();
  44. }
  45. }.bind(this))
  46. this.tabs.pages[0].showTab();
  47. }.bind(this));
  48. }
  49. })
  50. MWF.xApplication.Attendance.DepartmentDetail.Explorer = new Class({
  51. Extends: MWF.xApplication.Attendance.Explorer,
  52. Implements: [Options, Events],
  53. initialize: function(node, parent, options){
  54. this.setOptions(options);
  55. this.parent = parent;
  56. this.app = parent.app;
  57. this.lp = this.app.lp;
  58. this.css = parent.css;
  59. this.path = parent.path;
  60. this.actions = parent.actions;
  61. this.node = $(node);
  62. this.initData();
  63. if (!this.peopleActions) this.peopleActions = new MWF.xAction.org.express.RestActions();
  64. },
  65. initData: function(){
  66. this.toolItemNodes = [];
  67. },
  68. reload: function(){
  69. this.node.empty();
  70. this.load();
  71. },
  72. load: function(){
  73. this.loadFilter();
  74. this.loadContentNode();
  75. this.setNodeScroll();
  76. },
  77. loadFilter : function(){
  78. this.fileterNode = new Element("div.fileterNode", {
  79. "styles" : this.css.fileterNode
  80. }).inject(this.node)
  81. var table = new Element("table", {
  82. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.filterTable, "class" : "filterTable"
  83. }).inject( this.fileterNode );
  84. var tr = new Element("tr").inject(table);
  85. this.createDepartmentTd( tr )
  86. this.createYearSelectTd( tr )
  87. this.createMonthSelectTd( tr )
  88. this.createDateSelectTd( tr )
  89. this.createIsAbsent(tr)
  90. this.createIsLate( tr )
  91. //this.createIsLeaveEarlier( tr )
  92. this.createLackOfTimeCount(tr)
  93. this.createActionTd( tr )
  94. },
  95. createTypeId : function(tr){
  96. var _self = this;
  97. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : this.lp.type }).inject(tr);
  98. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  99. this.q_type = new MDomItem( td, {
  100. "name" : "q_type",
  101. "type" : "select",
  102. "selectValue": ["day","month"],
  103. "selectText": [this.lp.staticByDay,this.lp.staticByMonth],
  104. }, true, this.app );
  105. this.q_type.load();
  106. },
  107. createDepartmentTd : function(tr){
  108. var _self = this;
  109. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "部门" }).inject(tr);
  110. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  111. if( this.app.isAdmin() ){
  112. this.q_departmentName = new MDomItem( td, {
  113. "name" : "q_departmentName",
  114. "defaultValue" : this.app.manageDepartments.length > 0 ? this.app.manageDepartments[0] : "",
  115. "event" : {
  116. "click" : function(el){ _self.selecePerson(); }
  117. }
  118. }, true, this.app );
  119. this.q_departmentName.load();
  120. }else{
  121. this.q_departmentName = new MDomItem( td, {
  122. "name" : "q_departmentName",
  123. "type" : "select",
  124. "selectValue": this.app.manageDepartments
  125. }, true, this.app );
  126. this.q_departmentName.load();
  127. }
  128. },
  129. createYearSelectTd : function( tr ){
  130. var _self = this;
  131. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "年度" }).inject(tr);
  132. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  133. this.cycleYear = new MDomItem( td, {
  134. "name" : "cycleYear",
  135. "type" : "select",
  136. "selectValue" : function(){
  137. var years = [];
  138. var year = new Date().getFullYear();
  139. for(var i=0; i<6; i++ ){
  140. years.push( year-- );
  141. }
  142. return years;
  143. },
  144. "event" : {
  145. "change" : function(){ if(_self.dateSelecterTd)_self.createDateSelectTd() }
  146. }
  147. }, true, this.app );
  148. this.cycleYear.load();
  149. },
  150. createMonthSelectTd : function( tr ){
  151. var _self = this;
  152. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "月份" }).inject(tr);
  153. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  154. this.cycleMonth = new MDomItem( td, {
  155. "name" : "cycleMonth",
  156. "type" : "select",
  157. "defaultValue" : function(){
  158. var month = (new Date().getMonth() + 1 ).toString();
  159. return month.length == 1 ? "0"+month : month;
  160. },
  161. "selectValue" :["","01","02","03","04","05","06","07","08","09","10","11","12"],
  162. "event" : {
  163. "change" : function(){ if(_self.dateSelecterTd)_self.createDateSelectTd() }
  164. }
  165. }, true, this.app );
  166. this.cycleMonth.load();
  167. },
  168. createDateSelectTd : function( tr ){
  169. var _self = this;
  170. if( tr ){
  171. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "日期" }).inject(tr);
  172. this.dateSelecterTd = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  173. }
  174. if( this.q_date ){
  175. this.dateSelecterTd.empty();
  176. }
  177. this.q_date = new MDomItem( this.dateSelecterTd, {
  178. "name" : "q_date",
  179. "type" : "select",
  180. "selectValue" : function(){
  181. var year = parseInt(_self.cycleYear.getValue());
  182. var month = parseInt(_self.cycleMonth.getValue())-1;
  183. var date = new Date(year, month, 1);
  184. var days = [];
  185. days.push("");
  186. while (date.getMonth() === month) {
  187. var d = date.getDate().toString();
  188. if( d.length == 1 )d = "0"+d
  189. days.push( d );
  190. date.setDate(date.getDate() + 1);
  191. }
  192. return days;
  193. }
  194. }, true, this.app );
  195. this.q_date.load();
  196. },
  197. createIsAbsent: function(tr){
  198. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "缺勤" }).inject(tr);
  199. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  200. this.isAbsent = new MDomItem( td, {
  201. "name" : "isAbsent",
  202. "type" : "select",
  203. "selectValue" : ["","true","false"],
  204. "selectText" : ["","缺勤","未缺勤"],
  205. }, true, this.app );
  206. this.isAbsent.load();
  207. },
  208. //createIsLeaveEarlier: function(tr){
  209. // var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "早退" }).inject(tr);
  210. // var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  211. // this.isLeaveEarlier = new MDomItem( td, {
  212. // "name" : "isLeaveEarlier",
  213. // "type" : "select",
  214. // "selectValue" : ["-1","true","false"],
  215. // "selectText" : ["","早退","未早退"],
  216. // }, true, this.app );
  217. // this.isLeaveEarlier.load();
  218. //},
  219. createLackOfTimeCount: function(tr){
  220. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "工时不足" }).inject(tr);
  221. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  222. this.isLackOfTime = new MDomItem( td, {
  223. "name" : "isLackOfTime",
  224. "type" : "select",
  225. "selectValue" : ["","true","false"],
  226. "selectText" : ["","是","否"],
  227. }, true, this.app );
  228. this.isLackOfTime.load();
  229. },
  230. createIsLate: function(tr){
  231. var td = new Element("td", { "styles" : this.css.filterTableTitle, "text" : "迟到" }).inject(tr);
  232. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  233. this.isLate = new MDomItem( td, {
  234. "name" : "isLate",
  235. "type" : "select",
  236. "selectValue" : ["","true","false"],
  237. "selectText" : ["","迟到","未迟到"],
  238. }, true, this.app );
  239. this.isLate.load();
  240. },
  241. createActionTd : function( tr ){
  242. var td = new Element("td", { "styles" : this.css.filterTableValue }).inject(tr);
  243. var input = new Element("button",{
  244. "text" : "查询",
  245. "styles" : this.css.filterButton
  246. }).inject(td);
  247. input.addEvent("click", function(){
  248. if( this.q_departmentName.getValue().trim() == "" ){
  249. this.app.notice( "请先选择部门", "error" );
  250. return;
  251. }
  252. var filterData = {
  253. q_departmentName : this.q_departmentName.getValue(),
  254. cycleYear : this.cycleYear.getValue(),
  255. cycleMonth : this.cycleMonth.getValue()
  256. }
  257. if( this.q_type ){
  258. filterData.q_type = this.q_type.getValue();
  259. }
  260. if( this.isAbsent && this.isAbsent.getValue()!="" ){
  261. filterData.isAbsent = this.getBoolean(this.isAbsent.getValue());
  262. }
  263. if( this.isLeaveEarlier && this.isLeaveEarlier.getValue()!="" ){
  264. filterData.isLeaveEarlier = this.getBoolean(this.isLeaveEarlier.getValue());
  265. }
  266. if( this.isLate && this.isLate.getValue()!="" ){
  267. filterData.isLate = this.getBoolean(this.isLate.getValue());
  268. }
  269. if( this.isLackOfTime && this.isLackOfTime.getValue()!="" ){
  270. filterData.isLackOfTime = this.getBoolean( this.isLackOfTime.getValue() );
  271. }
  272. if( this.q_date && this.q_date.getValue()!="" ){
  273. filterData.q_day = this.q_date.getValue();
  274. filterData.q_date = this.cycleYear.getValue() + "-" + this.cycleMonth.getValue() + "-" + this.q_date.getValue();
  275. }
  276. this.loadView( filterData );
  277. }.bind(this))
  278. },
  279. getBoolean : function( value ){
  280. if( value === "true" )return true;
  281. if( value === "false" )return false;
  282. return value;
  283. },
  284. selecePerson: function(){
  285. var options = {
  286. "type": "department",
  287. "title": "选择部门",
  288. "count" : "1",
  289. "onComplete": function(items){
  290. var names = [];
  291. items.each(function(item){
  292. names.push(item.data.name);
  293. }.bind(this));
  294. this.q_departmentName.setValue( names.join(",") )
  295. }.bind(this)
  296. };
  297. //if( !this.app.isAdmin() && this.app.isDepartmentManager() ){
  298. // options.departments = this.app.manageDepartments;
  299. //}
  300. var selector = new MWF.OrgSelector(this.app.content, options);
  301. },
  302. loadContentNode: function(){
  303. this.elementContentNode = new Element("div", {
  304. "styles": this.css.elementContentNode
  305. }).inject(this.node);
  306. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  307. },
  308. loadView : function( filterData ){
  309. this.elementContentNode.empty();
  310. if( this.view )delete this.view;
  311. this.view = new MWF.xApplication.Attendance.DepartmentDetail.View(this.elementContentNode, this.app,this );
  312. this.view.filterData = filterData
  313. this.view.load();
  314. this.setContentSize();
  315. },
  316. setContentSize: function(){
  317. var tabNodeSize = this.parent.tabs ? this.parent.tabs.tabNodeContainer.getSize() : {"x":0,"y":0};
  318. var fileterNodeSize = this.fileterNode ? this.fileterNode.getSize() : {"x":0,"y":0};
  319. var nodeSize = this.parent.node.getSize();
  320. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  321. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  322. //var filterSize = this.filterNode.getSize();
  323. var height = nodeSize.y-tabNodeSize.y-pt-pb-fileterNodeSize.y-20;
  324. this.elementContentNode.setStyle("height", ""+height+"px");
  325. this.pageCount = (height/40).toInt()+5;
  326. if (this.view && this.view.items.length<this.pageCount){
  327. this.view.loadElementList(this.pageCount-this.view.items.length);
  328. }
  329. }
  330. });
  331. MWF.xApplication.Attendance.DepartmentDetail.DetailStaticExplorer = new Class({
  332. Extends: MWF.xApplication.Attendance.DepartmentDetail.Explorer,
  333. loadFilter : function(){
  334. this.fileterNode = new Element("div.fileterNode", {
  335. "styles" : this.css.fileterNode
  336. }).inject(this.node)
  337. var table = new Element("table", {
  338. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.filterTable, "class" : "filterTable"
  339. }).inject( this.fileterNode );
  340. table.setStyle("width","700px");
  341. var tr = new Element("tr").inject(table);
  342. //this.createTypeId(tr);
  343. this.createDepartmentTd( tr )
  344. this.createYearSelectTd( tr )
  345. this.createMonthSelectTd( tr )
  346. //this.createDateSelectTd( tr )
  347. this.createActionTd( tr )
  348. },
  349. createActionTd : function( tr ) {
  350. var td = new Element("td", {"styles": this.css.filterTableValue}).inject(tr);
  351. var input = new Element("button", {
  352. "text": "查询",
  353. "styles": this.css.filterButton
  354. }).inject(td);
  355. input.addEvent("click", function () {
  356. if (this.q_departmentName.getValue().trim() == "") {
  357. this.app.notice("请先选择部门", "error");
  358. return;
  359. }if (this.cycleMonth.getValue().trim() == "") {
  360. this.app.notice("请先选择月份", "error");
  361. return;
  362. }
  363. var filterData = {
  364. q_departmentName: this.q_departmentName.getValue(),
  365. cycleYear: this.cycleYear.getValue(),
  366. cycleMonth: this.cycleMonth.getValue()
  367. }
  368. if (this.q_type) {
  369. filterData.q_type = this.q_type.getValue();
  370. }
  371. if (this.isAbsent && this.isAbsent.getValue()!="" ) {
  372. filterData.isAbsent = this.isAbsent.getValue();
  373. }
  374. if (this.isLeaveEarlier && this.isLeaveEarlier.getValue()!="" ) {
  375. filterData.isLeaveEarlier = this.isLeaveEarlier.getValue();
  376. }
  377. if (this.isLate && this.isLate.getValue()!="" ) {
  378. filterData.isLate = this.isLate.getValue();
  379. }
  380. if (this.q_date && this.q_date.getValue() != "") {
  381. filterData.q_day = this.q_date.getValue();
  382. filterData.q_date = this.cycleYear.getValue() + "-" + this.cycleMonth.getValue() + "-" + this.q_date.getValue();
  383. }
  384. this.loadView(filterData);
  385. }.bind(this))
  386. },
  387. loadView : function( filterData ){
  388. this.elementContentNode.empty();
  389. if( this.view )delete this.view;
  390. this.view = new MWF.xApplication.Attendance.DepartmentDetail.DetailStaticView(this.elementContentNode, this.app,this );
  391. this.view.filterData = filterData;
  392. this.view.listItemUrl = this.path+"listItem_detailStatic.json";
  393. this.view.load();
  394. this.setContentSize();
  395. }
  396. })
  397. MWF.xApplication.Attendance.DepartmentDetail.View = new Class({
  398. Extends: MWF.xApplication.Attendance.Explorer.View,
  399. _createItem: function(data){
  400. return new MWF.xApplication.Attendance.DepartmentDetail.Document(this.table, data, this.explorer, this);
  401. },
  402. _getCurrentPageData: function(callback, count){
  403. if(!count)count=20;
  404. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  405. var filter = this.filterData || {};
  406. //filter.key = this.sortField || this.sortFieldDefault || "";
  407. //filter.order = this.sortType || this.sortTypeDefault || "";
  408. this.actions.listDetailFilterNext( id, count, filter, function(json){
  409. if( callback )callback(json);
  410. }.bind(this))
  411. //var filter = this.filterData || {};
  412. //this.actions.listDepartmentDetailFilter( filter, function(json){
  413. // if( callback )callback(json);
  414. //}.bind(this))
  415. },
  416. _removeDocument: function(documentData, all){
  417. },
  418. _createDocument: function(){
  419. },
  420. _openDocument: function( documentData ){
  421. }
  422. })
  423. MWF.xApplication.Attendance.DepartmentDetail.DetailStaticView = new Class({
  424. Extends: MWF.xApplication.Attendance.Explorer.View,
  425. _createItem: function(data){
  426. return new MWF.xApplication.Attendance.DepartmentDetail.DetailStaticDocument(this.table, data, this.explorer, this);
  427. },
  428. _getCurrentPageData: function(callback, count){
  429. var filter = this.filterData || {};
  430. //if( !filter.cycleMonth || filter.cycleMonth == "" )filter.cycleMonth = "(0)";
  431. this.actions.listPersonMonthStaticByDepartment( filter.q_departmentName, filter.cycleYear, filter.cycleMonth, function(json){
  432. //var data = json.data;
  433. //data.sort( function( a, b ){
  434. // return parseInt( b.statisticYear + b.statisticMonth ) - parseInt( a.statisticYear + a.statisticMonth )
  435. //})
  436. //json.data = data;
  437. if( callback )callback(json);
  438. }.bind(this))
  439. //if( filter.q_type == "day" ) {
  440. // if( filter.q_date && filter.q_date != "" ){
  441. // this.actions.listStaticDateDepartment( filter.q_departmentName, filter.q_date , function(json){
  442. // if( callback )callback(json);
  443. // }.bind(this))
  444. // }else{
  445. // this.actions.listStaticDayDepartment( filter.q_departmentName, filter.cycleYear, filter.cycleMonth, function(json){
  446. // //var data = json.data;
  447. // //data.sort( function( a, b ){
  448. // // return parseInt( b.statisticDate.replace(/-/g,"") ) - parseInt( a.statisticDate.replace(/-/g,"") );
  449. // //})
  450. // //json.data = data;
  451. // if( callback )callback(json);
  452. // }.bind(this))
  453. // }
  454. //}else{
  455. // if( !filter.cycleMonth || filter.cycleMonth == "" )filter.cycleMonth = "(0)";
  456. // this.actions.listStaticMonthDepartment( filter.q_departmentName, filter.cycleYear, filter.cycleMonth, function(json){
  457. // //var data = json.data;
  458. // //data.sort( function( a, b ){
  459. // // return parseInt( b.statisticYear + b.statisticMonth ) - parseInt( a.statisticYear + a.statisticMonth )
  460. // //})
  461. // //json.data = data;
  462. // if( callback )callback(json);
  463. // }.bind(this))
  464. //}
  465. },
  466. _removeDocument: function(documentData, all){
  467. },
  468. _createDocument: function(){
  469. },
  470. _openDocument: function( documentData ){
  471. }
  472. })
  473. MWF.xApplication.Attendance.DepartmentDetail.Document = new Class({
  474. Extends: MWF.xApplication.Attendance.Explorer.Document
  475. })
  476. MWF.xApplication.Attendance.DepartmentDetail.DetailStaticDocument = new Class({
  477. Extends: MWF.xApplication.Attendance.Explorer.Document
  478. })