CompanyDetail.js 20 KB

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