StatisticsCycle.js 20 KB

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