StatisticsCycleExplorer.js 17 KB

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