StatisticsCycle.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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" : MWF.xApplication.Attendance.LP.statisticsPeriodSetting,
  63. "draggable" : true,
  64. "closeAction" : true
  65. },
  66. _createTableContent: function(){
  67. var lp = MWF.xApplication.Attendance.LP;
  68. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  69. "<tr><td styles='formTabelTitle' lable='topUnitName'></td>"+
  70. " <td styles='formTableValue'>" +
  71. " <div item='topUnitName'></div>"+
  72. " <div style='font-size: 12px;color: #999;'>"+lp.selectCompanyNotice+"</div>"+
  73. " </td></tr>" +
  74. "<tr><td styles='formTabelTitle' lable='unitName'></td>"+
  75. " <td styles='formTableValue'>" +
  76. " <div item='unitName'></div>"+
  77. " <div style='font-size: 12px;color: #999;'>"+lp.selectDepartmentNotice+"</div>"+
  78. " </td></tr>" +
  79. "<tr><td styles='formTabelTitle' lable='cycleYear'></td>"+
  80. " <td styles='formTableValue' item='cycleYear'></td></tr>" +
  81. "<tr><td styles='formTabelTitle' lable='cycleMonth'></td>"+
  82. " <td styles='formTableValue' item='cycleMonth'></td></tr>" +
  83. "<tr><td styles='formTabelTitle' lable='cycleStartDateString'></td>"+
  84. " <td styles='formTableValue' item='cycleStartDateString'></td></tr>" +
  85. "<tr><td styles='formTabelTitle' lable='cycleEndDateString'></td>"+
  86. " <td styles='formTableValue' item='cycleEndDateString'></td></tr>" +
  87. "<tr><td styles='formTabelTitle' lable='description'></td>"+
  88. " <td styles='formTableValue' item='description'></td></tr>" +
  89. "</table>";
  90. this.formTableArea.set("html",html);
  91. MWF.xDesktop.requireApp("Template", "MForm", function(){
  92. this.form = new MForm( this.formTableArea, this.data, {
  93. style: "attendance",
  94. isEdited : this.isEdited || this.isNew,
  95. itemTemplate : {
  96. topUnitName : { text:lp.statisticsCompany, type : "org", orgType : "unit" },
  97. unitName : { text: lp.statisticsUnit, type : "org", orgType : "unit" },
  98. cycleYear : { text: lp.cycleYear, 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: lp.cycleMonth, type : "select",notEmpty:true, selectValue : ["01","02","03","04","05","06","07","08","09","10","11","12"] },
  107. cycleStartDateString : { text: lp.startDate, tType : "date"},
  108. cycleEndDateString : { text:lp.endData, tType : "date" },
  109. description : { text:lp.description, 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. var lp = MWF.xApplication.Attendance.LP;
  169. this.createNode = new Element("div", {
  170. "styles": this.css.createNode
  171. }).inject(this.createAreaNode);
  172. this.createIconNode = new Element("div", {
  173. "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  174. }).inject(this.createNode);
  175. this.createFormNode = new Element("div", {
  176. "styles": this.css.createFormNode
  177. }).inject(this.createNode);
  178. this.createTableContainer = new Element("div", {
  179. "styles": this.css.createTableContainer
  180. }).inject(this.createFormNode);
  181. this.createTableArea = new Element("div", {
  182. "styles": this.css.createTableArea
  183. }).inject(this.createTableContainer);
  184. var table = new Element("table", {
  185. "width" : "100%", "height" : "250", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.editTable, "class" : "editTable"
  186. }).inject( this.createTableArea );
  187. var d = this.data;
  188. var tr = new Element("tr").inject(table);
  189. var td = new Element("td", { "styles" : this.css.editTableHead, "colspan": "4", "text" : lp.statisticsPeriodSetting }).inject(tr);
  190. var tr = new Element("tr").inject(table);
  191. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : lp.topUnitName + ":" }).inject(tr);
  192. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  193. if( !this.isNew && !this.isEdited ){
  194. td.set("text", d.topUnitName )
  195. }else{
  196. this.topUnitName = new MDomItem( td, {
  197. "name" : "topUnitName",
  198. "value" : d.topUnitName,
  199. "style" : this.css.inputPersonStyle,
  200. "event" : {
  201. "dblclick" : function( mdi){ _self.selectPeople(this, "topUnit", mdi.get("value").split(",") ) }
  202. }
  203. }, true, this.app );
  204. this.topUnitName.load();
  205. new Element("div", { "text" : lp.selectCompanyNotice , "styles" : {"color":"#ccc"}}).inject(td)
  206. }
  207. var tr = new Element("tr").inject(table);
  208. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : lp.unitName+":" }).inject(tr);
  209. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  210. if( !this.isNew && !this.isEdited ){
  211. td.set("text", d.unitName )
  212. }else{
  213. this.unitName = new MDomItem( td, {
  214. "name" : "unitName",
  215. "value" : d.unitName,
  216. "style" : this.css.inputPersonStyle,
  217. "event" : {
  218. "dblclick" : function( mdi){ _self.selectPeople(this, "unit", mdi.get("value").split(",") ) }
  219. }
  220. }, true, this.app );
  221. this.unitName.load();
  222. new Element("div", { "text" : lp.selectDepartmentNotice , "styles" : {"color":"#ccc"} }).inject(td)
  223. }
  224. var tr = new Element("tr").inject(table);
  225. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : lp.cycleYear+":" }).inject(tr);
  226. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  227. if( !this.isNew && !this.isEdited ){
  228. td.set( "text", d.cycleYear || "")
  229. }else {
  230. this.cycleYear = new MDomItem(td, {
  231. "name": "cycleYear",
  232. "type": "select",
  233. "value": d.cycleYear || new Date().getFullYear(),
  234. "selectValue": function () {
  235. var years = [];
  236. var year = new Date().getFullYear() + 5;
  237. for (var i = 0; i < 10; i++) {
  238. years.push(year--);
  239. }
  240. return years;
  241. }
  242. }, true, this.app);
  243. this.cycleYear.load();
  244. }
  245. var tr = new Element("tr").inject(table);
  246. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : lp.cycleMonth+":" }).inject(tr);
  247. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  248. if( !this.isNew && !this.isEdited ){
  249. td.set( "text", d.cycleMonth || "")
  250. }else{
  251. this.cycleMonth = new MDomItem( td, {
  252. "name" : "cycleMonth",
  253. "type" : "select",
  254. "value" : d.cycleMonth,
  255. "selectValue" :["01","02","03","04","05","06","07","08","09","10","11","12"]
  256. }, true, this.app );
  257. this.cycleMonth.load();
  258. }
  259. var tr = new Element("tr").inject(table);
  260. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : lp.startDate+":" }).inject(tr);
  261. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  262. this.cycleStartDateString = new MDomItem( td, {
  263. "name" : "cycleStartDateString",
  264. "value" : d.cycleStartDateString,
  265. "style" : this.css.inputTimeStyle,
  266. "event" : {
  267. "click" : function( mdi){
  268. var da = new Date(_self.cycleYear.getValue() + "-" + _self.cycleMonth.getValue() + "-" + "01");
  269. _self.selectDateTime(this, false, false, da.decrement("month", 1) );
  270. }
  271. }
  272. }, true, this.app );
  273. this.cycleStartDateString.load();
  274. var tr = new Element("tr").inject(table);
  275. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : lp.endData+":" }).inject(tr);
  276. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  277. this.cycleEndDateString = new MDomItem( td, {
  278. "name" : "cycleEndDateString",
  279. "value" : d.cycleEndDateString,
  280. "style" : this.css.inputTimeStyle,
  281. "event" : {
  282. "click" : function( mdi){
  283. var da = new Date(_self.cycleYear.getValue() + "-" + _self.cycleMonth.getValue() + "-" + "01");
  284. _self.selectDateTime(this, false, false, da );
  285. }
  286. }
  287. }, true, this.app );
  288. this.cycleEndDateString.load();
  289. var tr = new Element("tr").inject(table);
  290. var td = new Element("td", { "styles" : this.css.editTableTitle, "text" : lp.description+":" }).inject(tr);
  291. var td = new Element("td", { "styles" : this.css.editTableValue }).inject(tr);
  292. this.description = new MDomItem( td, {
  293. "type" : "textarea",
  294. "name" : "description",
  295. "value" : d.description,
  296. "style" : this.css.inputTextAreaStyle
  297. }, true, this.app );
  298. this.description.load();
  299. this.cancelActionNode = new Element("div", {
  300. "styles": this.css.createCancelActionNode,
  301. "text": lp.cancel
  302. }).inject(this.createFormNode);
  303. this.cancelActionNode.addEvent("click", function(e){
  304. this.cancelCreate(e);
  305. }.bind(this));
  306. if( this.isNew || this.isEdited){
  307. this.createOkActionNode = new Element("div", {
  308. "styles": this.css.createOkActionNode,
  309. "text": lp.ok
  310. }).inject(this.createFormNode);
  311. this.createOkActionNode.addEvent("click", function(e){
  312. this.okCreate(e);
  313. }.bind(this));
  314. }
  315. },
  316. setCreateNodeSize: function (width, height, top, left) {
  317. if (!width)width = this.options && this.options.width ? this.options.width : "50%";
  318. if (!height)height = this.options && this.options.height ? this.options.height : "50%";
  319. if (!top) top = this.options && this.options.top ? this.options.top : 0;
  320. if (!left) left = this.options && this.options.left ? this.options.left : 0;
  321. var allSize = this.app.content.getSize();
  322. var limitWidth = allSize.x; //window.screen.width
  323. var limitHeight = allSize.y; //window.screen.height
  324. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  325. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  326. 300 > width && (width = 300);
  327. 220 > height && (height = 220);
  328. top = top || parseInt((limitHeight - height) / 2, 10);
  329. left = left || parseInt((limitWidth - width) / 2, 10);
  330. this.createAreaNode.setStyles({
  331. "width": "" + width + "px",
  332. "height": "" + height + "px",
  333. "top": "" + top + "px",
  334. "left": "" + left + "px"
  335. });
  336. this.createNode.setStyles({
  337. "width": "" + width + "px",
  338. "height": "" + height + "px"
  339. });
  340. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x: 0, y: 0};
  341. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  342. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  343. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  344. //var formMargin = formHeight -iconSize.y;
  345. this.createFormNode.setStyles({
  346. "height": "" + contentHeight + "px"
  347. });
  348. },
  349. //setCreateNodeSize: function(){
  350. // var size = this.app.node.getSize();
  351. // var allSize = this.app.content.getSize();
  352. //
  353. // this.createAreaNode.setStyles({
  354. // "width": ""+size.x+"px",
  355. // "height": ""+size.y+"px"
  356. // });
  357. // var hY = size.y*0.9;
  358. // var mY = size.y*0.2/2;
  359. // this.createNode.setStyles({
  360. // "height": ""+hY+"px",
  361. // "margin-top": ""+mY+"px"
  362. // });
  363. //
  364. // var iconSize = this.createIconNode.getSize();
  365. // var formHeight = hY*0.7;
  366. // if (formHeight>250) formHeight = 250;
  367. // var formMargin = hY*0.3/2-iconSize.y;
  368. // this.createFormNode.setStyles({
  369. // "height": ""+formHeight+"px",
  370. // "margin-top": ""+formMargin+"px"
  371. // });
  372. //},
  373. cancelCreate: function(e){
  374. var _self = this;
  375. this.createMarkNode.destroy();
  376. this.createAreaNode.destroy();
  377. delete _self;
  378. },
  379. okCreate: function(e){
  380. var data = {
  381. "topUnitName": this.topUnitName.get("value")=="" ? "*" : this.topUnitName.get("value"),
  382. "unitName" : this.unitName.get("value")=="" ? "*" : this.unitName.get("value"),
  383. "cycleYear": this.cycleYear.get("value"),
  384. "cycleMonth": this.cycleMonth.get("value"),
  385. "cycleStartDateString": this.cycleStartDateString.get("value"),
  386. "cycleEndDateString": this.cycleEndDateString.get("value"),
  387. "description": this.description.get("value")
  388. };
  389. if( this.data.id ) data.id = this.data.id;
  390. if (data.cycleStartDateString && data.cycleEndDateString ){
  391. this.app.restActions.saveCycle(data, function(json){
  392. if( json.type == "ERROR" ){
  393. this.app.notice( json.message , "error");
  394. }else{
  395. this.createMarkNode.destroy();
  396. this.createAreaNode.destroy();
  397. if(this.explorer.view)this.explorer.view.reload();
  398. this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  399. }
  400. // this.app.processConfig();
  401. }.bind(this));
  402. }else{
  403. // this.adminName.setStyle("border-color", "red");
  404. //this.adminName.focus();
  405. this.app.notice( this.app.lp.selectStartEndEndDataNotice, "error");
  406. }
  407. },
  408. selectDateTime : function( el, timeOnly, isTme, baseDate ){
  409. var opt = {
  410. "style": "xform",
  411. "timeOnly": timeOnly,
  412. "isTime": isTme,
  413. "target": this.app.content
  414. };
  415. if( baseDate )opt.baseDate = baseDate;
  416. MWF.require("MWF.widget.Calendar", function(){
  417. var calendar = new MWF.widget.Calendar( el, opt );
  418. calendar.show();
  419. }.bind(this));
  420. },
  421. selectPeople: function(el, type, value ){
  422. var lp = MWF.xApplication.Attendance.LP;
  423. var title;
  424. if( type == "unit" ){
  425. title = lp.selectDepartment
  426. }else if( type == "topUnit" ){
  427. title = lp.selectCompany
  428. }else{
  429. title = lp.selectPerson
  430. }
  431. var options = {
  432. "type": type,
  433. "title": title,
  434. "count" : "1",
  435. "values": value || [],
  436. "onComplete": function(items){
  437. var vs = [];
  438. items.each(function(item){
  439. vs.push(item.data.name);
  440. }.bind(this));
  441. el.set("value",vs.join( "," ));
  442. }.bind(this)
  443. };
  444. var selector = new MWF.O2Selector(this.app.content, options);
  445. }
  446. });