StatisticsCycle.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  3. MWF.xDesktop.requireApp("Selector", "package", null, false);
  4. MWF.xApplication.Attendance.StatisticsCycle = 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/$StatisticsCycle/";
  11. this.cssPath = "../x_component_Attendance/$StatisticsCycle/"+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. loadView : function(){
  19. this.view = new MWF.xApplication.Attendance.StatisticsCycle.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  20. this.view.load();
  21. this.setContentSize();
  22. },
  23. createDocument: function(){
  24. if(this.view)this.view._createDocument();
  25. }
  26. });
  27. MWF.xApplication.Attendance.StatisticsCycle.View = new Class({
  28. Extends: MWF.xApplication.Attendance.Explorer.View,
  29. _createItem: function(data){
  30. return new MWF.xApplication.Attendance.StatisticsCycle.Document(this.table, data, this.explorer, this);
  31. },
  32. _getCurrentPageData: function(callback, count){
  33. this.actions.listCycle(function(json){
  34. if (callback) callback(json);
  35. });
  36. },
  37. _removeDocument: function(document, all){
  38. this.actions.deleteCycle(document.id, function(json){
  39. this.explorer.view.reload();
  40. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  41. }.bind(this));
  42. },
  43. _createDocument: function(){
  44. var sc = new MWF.xApplication.Attendance.StatisticsCycle.Form(this.explorer);
  45. sc.create();
  46. },
  47. _openDocument: function( documentData ){
  48. var sc = new MWF.xApplication.Attendance.StatisticsCycle.Form(this.explorer, documentData );
  49. sc.edit();
  50. }
  51. });
  52. MWF.xApplication.Attendance.StatisticsCycle.Document = new Class({
  53. Extends: MWF.xApplication.Attendance.Explorer.Document
  54. });
  55. MWF.xApplication.Attendance.StatisticsCycle.Form = new Class({
  56. Extends: MWF.xApplication.Attendance.Explorer.PopupForm,
  57. options : {
  58. "width": 600,
  59. "height": 600,
  60. "hasTop" : true,
  61. "hasBottom" : true,
  62. "title" : "",
  63. "draggable" : true,
  64. "closeAction" : true
  65. },
  66. _createTableContent: function(){
  67. var lp = this.app.lp.schedule;
  68. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  69. "<tr><td colspan='2' styles='formTableHead'>统计周期设置</td></tr>" +
  70. "<tr><td styles='formTabelTitle' lable='topUnitName'></td>"+
  71. " <td styles='formTableValue'>" +
  72. " <div item='topUnitName'></div>"+
  73. " <div style='font-size: 12px;color: #999;'>双击选择,填写'*'匹配所有公司</div>"+
  74. " </td></tr>" +
  75. "<tr><td styles='formTabelTitle' lable='unitName'></td>"+
  76. " <td styles='formTableValue'>" +
  77. " <div item='unitName'></div>"+
  78. " <div style='font-size: 12px;color: #999;'>双击选择,填写'*'匹配所有部门</div>"+
  79. " </td></tr>" +
  80. "<tr><td styles='formTabelTitle' lable='cycleYear'></td>"+
  81. " <td styles='formTableValue' item='cycleYear'></td></tr>" +
  82. "<tr><td styles='formTabelTitle' lable='cycleMonth'></td>"+
  83. " <td styles='formTableValue' item='cycleMonth'></td></tr>" +
  84. "<tr><td styles='formTabelTitle' lable='cycleStartDateString'></td>"+
  85. " <td styles='formTableValue' item='cycleStartDateString'></td></tr>" +
  86. "<tr><td styles='formTabelTitle' lable='cycleEndDateString'></td>"+
  87. " <td styles='formTableValue' item='cycleEndDateString'></td></tr>" +
  88. "<tr><td styles='formTabelTitle' lable='description'></td>"+
  89. " <td styles='formTableValue' item='description'></td></tr>" +
  90. "</table>";
  91. this.formTableArea.set("html",html);
  92. MWF.xDesktop.requireApp("Template", "MForm", function(){
  93. this.form = new MForm( this.formTableArea, this.data, {
  94. isEdited : this.isEdited || this.isNew,
  95. itemTemplate : {
  96. topUnitName : { text:"统计公司", type : "org", orgType : "unit" },
  97. unitName : { text: "统计部门", type : "org", orgType : "unit" },
  98. cycleYear : { text: "统计周期年份", type : "select", notEmpty:true, defaultValue : new Date().getFullYear(), selectValue : function(){
  99. var years = [];
  100. var year = new Date().getFullYear() + 5;
  101. for (var i = 0; i < 10; i++) {
  102. years.push(year--);
  103. }
  104. return years;
  105. }},
  106. cycleMonth : { text: "统计周期月份", type : "select",notEmpty:true, selectValue : ["01","02","03","04","05","06","07","08","09","10","11","12"] },
  107. cycleStartDateString : { text: "开始日期", tType : "date"},
  108. cycleEndDateString : { text:"结束日期", tType : "date" },
  109. description : { text:"说明备注", type : "textarea" }
  110. }
  111. }, this.app);
  112. this.form.load();
  113. }.bind(this), true);
  114. },
  115. _ok: function( data, callback ){
  116. this.app.restActions.saveCycle(data, function(json){
  117. if( callback )callback(json);
  118. }.bind(this));
  119. }
  120. });
  121. MWF.xApplication.Attendance.StatisticsCycle.StatisticsCycle2 = new Class({
  122. Extends: MWF.widget.Common,
  123. options: {
  124. "width": "600",
  125. "height": "600"
  126. },
  127. initialize: function( explorer, data ){
  128. this.explorer = explorer;
  129. this.app = explorer.app;
  130. this.data = data || {};
  131. this.css = this.explorer.css;
  132. this.load();
  133. },
  134. load: function(){
  135. },
  136. open: function(e){
  137. this.isNew = false;
  138. this.isEdited = false;
  139. },
  140. create: function(){
  141. this.isNew = true;
  142. this._open();
  143. },
  144. edit: function(){
  145. this.isEdited = true;
  146. this._open();
  147. },
  148. _open : function(){
  149. this.createMarkNode = new Element("div", {
  150. "styles": this.css.createMarkNode,
  151. "events": {
  152. "mouseover": function(e){e.stopPropagation();},
  153. "mouseout": function(e){e.stopPropagation();}
  154. }
  155. }).inject(this.app.content, "after");
  156. this.createAreaNode = new Element("div", {
  157. "styles": this.css.createAreaNode
  158. });
  159. this.createNode();
  160. this.createAreaNode.inject(this.createMarkNode, "after");
  161. this.createAreaNode.fade("in");
  162. this.setCreateNodeSize();
  163. this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  164. this.addEvent("resize", this.setCreateNodeSizeFun);
  165. },
  166. createNode: function(){
  167. var _self = this;
  168. this.createNode = new Element("div", {
  169. "styles": this.css.createNode
  170. }).inject(this.createAreaNode);
  171. this.createIconNode = new Element("div", {
  172. "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  173. }).inject(this.createNode);
  174. this.createFormNode = new Element("div", {
  175. "styles": this.css.createFormNode
  176. }).inject(this.createNode);
  177. this.createTableContainer = new Element("div", {
  178. "styles": this.css.createTableContainer
  179. }).inject(this.createFormNode);
  180. this.createTableArea = new Element("div", {
  181. "styles": this.css.createTableArea
  182. }).inject(this.createTableContainer);
  183. var table = new Element("table", {
  184. "width" : "100%", "height" : "250", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.editTable, "class" : "editTable"
  185. }).inject( this.createTableArea );
  186. var d = this.data;
  187. var tr = new Element("tr").inject(table);
  188. var td = new Element("td", { "styles" : this.css.editTableHead, "colspan": "4", "text" : "统计周期设置" }).inject(tr);
  189. var tr = new Element("tr").inject(table);
  190. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "公司名称:" }).inject(tr);
  191. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  192. if( !this.isNew && !this.isEdited ){
  193. td.set("text", d.topUnitName )
  194. }else{
  195. this.topUnitName = new MDomItem( td, {
  196. "name" : "topUnitName",
  197. "value" : d.topUnitName,
  198. "style" : this.css.inputPersonStyle,
  199. "event" : {
  200. "dblclick" : function( mdi){ _self.selectPeople(this, "topUnit", mdi.get("value").split(",") ) }
  201. }
  202. }, true, this.app );
  203. this.topUnitName.load();
  204. new Element("div", { "text" : "双击选择,填写'*'匹配所有公司" , "styles" : {"color":"#ccc"}}).inject(td)
  205. }
  206. var tr = new Element("tr").inject(table);
  207. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "部门名称:" }).inject(tr);
  208. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  209. if( !this.isNew && !this.isEdited ){
  210. td.set("text", d.unitName )
  211. }else{
  212. this.unitName = new MDomItem( td, {
  213. "name" : "unitName",
  214. "value" : d.unitName,
  215. "style" : this.css.inputPersonStyle,
  216. "event" : {
  217. "dblclick" : function( mdi){ _self.selectPeople(this, "unit", mdi.get("value").split(",") ) }
  218. }
  219. }, true, this.app );
  220. this.unitName.load();
  221. new Element("div", { "text" : "双击选择,填写'*'匹配所有部门" , "styles" : {"color":"#ccc"} }).inject(td)
  222. }
  223. var tr = new Element("tr").inject(table);
  224. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "统计周期年份:" }).inject(tr);
  225. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  226. if( !this.isNew && !this.isEdited ){
  227. td.set( "text", d.cycleYear || "")
  228. }else {
  229. this.cycleYear = new MDomItem(td, {
  230. "name": "cycleYear",
  231. "type": "select",
  232. "value": d.cycleYear || new Date().getFullYear(),
  233. "selectValue": function () {
  234. var years = [];
  235. var year = new Date().getFullYear() + 5;
  236. for (var i = 0; i < 10; i++) {
  237. years.push(year--);
  238. }
  239. return years;
  240. }
  241. }, true, this.app);
  242. this.cycleYear.load();
  243. }
  244. var tr = new Element("tr").inject(table);
  245. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "统计周期月份:" }).inject(tr);
  246. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  247. if( !this.isNew && !this.isEdited ){
  248. td.set( "text", d.cycleMonth || "")
  249. }else{
  250. this.cycleMonth = new MDomItem( td, {
  251. "name" : "cycleMonth",
  252. "type" : "select",
  253. "value" : d.cycleMonth,
  254. "selectValue" :["01","02","03","04","05","06","07","08","09","10","11","12"]
  255. }, true, this.app );
  256. this.cycleMonth.load();
  257. }
  258. var tr = new Element("tr").inject(table);
  259. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "开始日期:" }).inject(tr);
  260. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  261. this.cycleStartDateString = new MDomItem( td, {
  262. "name" : "cycleStartDateString",
  263. "value" : d.cycleStartDateString,
  264. "style" : this.css.inputTimeStyle,
  265. "event" : {
  266. "click" : function( mdi){
  267. var da = new Date(_self.cycleYear.getValue() + "-" + _self.cycleMonth.getValue() + "-" + "01");
  268. _self.selectDateTime(this, false, false, da.decrement("month", 1) );
  269. }
  270. }
  271. }, true, this.app );
  272. this.cycleStartDateString.load();
  273. var tr = new Element("tr").inject(table);
  274. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "结束日期:" }).inject(tr);
  275. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  276. this.cycleEndDateString = new MDomItem( td, {
  277. "name" : "cycleEndDateString",
  278. "value" : d.cycleEndDateString,
  279. "style" : this.css.inputTimeStyle,
  280. "event" : {
  281. "click" : function( mdi){
  282. var da = new Date(_self.cycleYear.getValue() + "-" + _self.cycleMonth.getValue() + "-" + "01");
  283. _self.selectDateTime(this, false, false, da );
  284. }
  285. }
  286. }, true, this.app );
  287. this.cycleEndDateString.load();
  288. var tr = new Element("tr").inject(table);
  289. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : "说明备注:" }).inject(tr);
  290. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  291. this.description = new MDomItem( td, {
  292. "type" : "textarea",
  293. "name" : "description",
  294. "value" : d.description,
  295. "style" : this.css.inputTextAreaStyle
  296. }, true, this.app );
  297. this.description.load();
  298. this.cancelActionNode = new Element("div", {
  299. "styles": this.css.createCancelActionNode,
  300. "text": "取消"
  301. }).inject(this.createFormNode);
  302. this.cancelActionNode.addEvent("click", function(e){
  303. this.cancelCreate(e);
  304. }.bind(this));
  305. if( this.isNew || this.isEdited){
  306. this.createOkActionNode = new Element("div", {
  307. "styles": this.css.createOkActionNode,
  308. "text": "确定"
  309. }).inject(this.createFormNode);
  310. this.createOkActionNode.addEvent("click", function(e){
  311. this.okCreate(e);
  312. }.bind(this));
  313. }
  314. },
  315. setCreateNodeSize: function (width, height, top, left) {
  316. if (!width)width = this.options && this.options.width ? this.options.width : "50%";
  317. if (!height)height = this.options && this.options.height ? this.options.height : "50%";
  318. if (!top) top = this.options && this.options.top ? this.options.top : 0;
  319. if (!left) left = this.options && this.options.left ? this.options.left : 0;
  320. var allSize = this.app.content.getSize();
  321. var limitWidth = allSize.x; //window.screen.width
  322. var limitHeight = allSize.y; //window.screen.height
  323. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  324. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  325. 300 > width && (width = 300);
  326. 220 > height && (height = 220);
  327. top = top || parseInt((limitHeight - height) / 2, 10);
  328. left = left || parseInt((limitWidth - width) / 2, 10);
  329. this.createAreaNode.setStyles({
  330. "width": "" + width + "px",
  331. "height": "" + height + "px",
  332. "top": "" + top + "px",
  333. "left": "" + left + "px"
  334. });
  335. this.createNode.setStyles({
  336. "width": "" + width + "px",
  337. "height": "" + height + "px"
  338. });
  339. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x: 0, y: 0};
  340. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  341. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  342. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  343. //var formMargin = formHeight -iconSize.y;
  344. this.createFormNode.setStyles({
  345. "height": "" + contentHeight + "px"
  346. });
  347. },
  348. //setCreateNodeSize: function(){
  349. // var size = this.app.node.getSize();
  350. // var allSize = this.app.content.getSize();
  351. //
  352. // this.createAreaNode.setStyles({
  353. // "width": ""+size.x+"px",
  354. // "height": ""+size.y+"px"
  355. // });
  356. // var hY = size.y*0.9;
  357. // var mY = size.y*0.2/2;
  358. // this.createNode.setStyles({
  359. // "height": ""+hY+"px",
  360. // "margin-top": ""+mY+"px"
  361. // });
  362. //
  363. // var iconSize = this.createIconNode.getSize();
  364. // var formHeight = hY*0.7;
  365. // if (formHeight>250) formHeight = 250;
  366. // var formMargin = hY*0.3/2-iconSize.y;
  367. // this.createFormNode.setStyles({
  368. // "height": ""+formHeight+"px",
  369. // "margin-top": ""+formMargin+"px"
  370. // });
  371. //},
  372. cancelCreate: function(e){
  373. var _self = this;
  374. this.createMarkNode.destroy();
  375. this.createAreaNode.destroy();
  376. delete _self;
  377. },
  378. okCreate: function(e){
  379. var data = {
  380. "topUnitName": this.topUnitName.get("value")=="" ? "*" : this.topUnitName.get("value"),
  381. "unitName" : this.unitName.get("value")=="" ? "*" : this.unitName.get("value"),
  382. "cycleYear": this.cycleYear.get("value"),
  383. "cycleMonth": this.cycleMonth.get("value"),
  384. "cycleStartDateString": this.cycleStartDateString.get("value"),
  385. "cycleEndDateString": this.cycleEndDateString.get("value"),
  386. "description": this.description.get("value")
  387. };
  388. if( this.data.id ) data.id = this.data.id;
  389. if (data.cycleStartDateString && data.cycleEndDateString ){
  390. this.app.restActions.saveCycle(data, function(json){
  391. if( json.type == "ERROR" ){
  392. this.app.notice( json.message , "error");
  393. }else{
  394. this.createMarkNode.destroy();
  395. this.createAreaNode.destroy();
  396. if(this.explorer.view)this.explorer.view.reload();
  397. this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  398. }
  399. // this.app.processConfig();
  400. }.bind(this));
  401. }else{
  402. // this.adminName.setStyle("border-color", "red");
  403. //this.adminName.focus();
  404. this.app.notice( "请选择开始日期和结束日期", "error");
  405. }
  406. },
  407. selectDateTime : function( el, timeOnly, isTme, baseDate ){
  408. var opt = {
  409. "style": "xform",
  410. "timeOnly": timeOnly,
  411. "isTime": isTme,
  412. "target": this.app.content
  413. };
  414. if( baseDate )opt.baseDate = baseDate;
  415. MWF.require("MWF.widget.Calendar", function(){
  416. var calendar = new MWF.widget.Calendar( el, opt );
  417. calendar.show();
  418. }.bind(this));
  419. },
  420. selectPeople: function(el, type, value ){
  421. var title;
  422. if( type == "unit" ){
  423. title = "选择部门"
  424. }else if( type == "topUnit" ){
  425. title = "选择公司"
  426. }else{
  427. title = "选择个人"
  428. }
  429. var options = {
  430. "type": type,
  431. "title": title,
  432. "count" : "1",
  433. "values": value || [],
  434. "onComplete": function(items){
  435. var vs = [];
  436. items.each(function(item){
  437. vs.push(item.data.name);
  438. }.bind(this));
  439. el.set("value",vs.join( "," ));
  440. }.bind(this)
  441. };
  442. var selector = new MWF.O2Selector(this.app.content, options);
  443. }
  444. });