HolidayExplorer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  3. MWF.xApplication.Attendance.HolidayExplorer = new Class({
  4. Extends: MWF.xApplication.Attendance.Explorer,
  5. Implements: [Options, Events],
  6. initialize: function(node, app, actions, options){
  7. this.setOptions(options);
  8. this.app = app;
  9. this.path = "../x_component_Attendance/$HolidayExplorer/";
  10. this.cssPath = "../x_component_Attendance/$HolidayExplorer/"+this.options.style+"/css.wcss";
  11. this._loadCss();
  12. this.actions = actions;
  13. this.node = $(node);
  14. this.initData();
  15. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  16. },
  17. loadView : function(){
  18. this.view = new MWF.xApplication.Attendance.HolidayExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  19. this.view.load();
  20. this.setContentSize();
  21. },
  22. createDocument: function(){
  23. if(this.view)this.view._createDocument();
  24. }
  25. });
  26. MWF.xApplication.Attendance.HolidayExplorer.View = new Class({
  27. Extends: MWF.xApplication.Attendance.Explorer.View,
  28. _createItem: function(data){
  29. return new MWF.xApplication.Attendance.HolidayExplorer.Document(this.table, data, this.explorer, this);
  30. },
  31. _getCurrentPageData: function(callback, count){
  32. this.actions.listHolidayAll(function(json){
  33. if (callback) callback(json);
  34. });
  35. },
  36. _removeDocument: function(document, isNotice, callback){
  37. this.actions.listHolidayByYearAndName(document.configYear,document.configName, function( json ){
  38. json.data.each(function(d){
  39. this.actions.deleteHoliday(d.id, function(json){
  40. }.bind(this), null, false);
  41. }.bind(this));
  42. if(!isNotice)this.app.notice(this.app.lp.deleteDocumentOK, "success");
  43. if(callback)callback();
  44. this.explorer.reload();
  45. }.bind(this))
  46. },
  47. _createDocument: function(){
  48. var holiday = new MWF.xApplication.Attendance.HolidayExplorer.Holiday(this.explorer);
  49. holiday.create();
  50. },
  51. _openDocument: function( documentData ){
  52. this.actions.getHoliday( documentData.id, function( json ) {
  53. var data = json.data;
  54. var holidy = {
  55. "configYear" : data.configYear,
  56. "configName" : data.configName,
  57. "makeUpClassDay" : []
  58. };
  59. this.actions.listHolidayByYearAndName(data.configYear,data.configName, function( json ){
  60. var startDate, endDate;
  61. json.data.each(function( d ){
  62. if( d.configType == "Workday" ){
  63. holidy.makeUpClassDay.push( d.configDate )
  64. }else{
  65. if( !startDate ){
  66. startDate = d.configDate;
  67. }else if( new Date(startDate) > new Date(d.configDate) ){
  68. startDate = d.configDate;
  69. }
  70. if( !endDate ){
  71. endDate = d.configDate;
  72. }else if( new Date(endDate) < new Date(d.configDate) ){
  73. endDate = d.configDate;
  74. }
  75. }
  76. }.bind(this));
  77. // holidy.makeUpClassDay = holidy.makeUpClassDay.join(",");
  78. holidy.startDate = startDate;
  79. holidy.endDate = endDate;
  80. var h = new MWF.xApplication.Attendance.HolidayExplorer.Holiday(this.explorer,holidy);
  81. h.edit();
  82. }.bind(this))
  83. }.bind(this))
  84. }
  85. });
  86. MWF.xApplication.Attendance.HolidayExplorer.Document = new Class({
  87. Extends: MWF.xApplication.Attendance.Explorer.Document
  88. });
  89. MWF.xApplication.Attendance.HolidayExplorer.Holiday = new Class({
  90. Extends: MWF.widget.Common,
  91. options: {
  92. "width": "500",
  93. "height": "600"
  94. },
  95. initialize: function( explorer, data ){
  96. this.explorer = explorer;
  97. this.app = explorer.app;
  98. this.data = data || {};
  99. this.css = this.explorer.css;
  100. this.load();
  101. },
  102. load : function(){
  103. },
  104. open: function(e){
  105. this.isNew = false;
  106. this.isEdited = false;
  107. this._open();
  108. },
  109. create: function(){
  110. this.isNew = true;
  111. this._open();
  112. },
  113. edit: function(){
  114. this.isEdited = true;
  115. this._open();
  116. },
  117. _open : function(){
  118. this.createMarkNode = new Element("div", {
  119. "styles": this.css.createMarkNode,
  120. "events": {
  121. "mouseover": function(e){e.stopPropagation();},
  122. "mouseout": function(e){e.stopPropagation();}
  123. }
  124. }).inject(this.app.content, "after");
  125. this.createAreaNode = new Element("div", {
  126. "styles": this.css.createAreaNode
  127. });
  128. this.createNode();
  129. this.createAreaNode.inject(this.createMarkNode, "after");
  130. this.createAreaNode.fade("in");
  131. this.setCreateNodeSize();
  132. this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  133. this.addEvent("resize", this.setCreateNodeSizeFun);
  134. },
  135. createNode: function(){
  136. var _self = this;
  137. this.createNode = new Element("div", {
  138. "styles": this.css.createNode
  139. }).inject(this.createAreaNode);
  140. this.createNode.setStyle("overflow-y","auto");
  141. this.createIconNode = new Element("div", {
  142. "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  143. }).inject(this.createNode);
  144. this.createFormNode = new Element("div", {
  145. "styles": this.css.createFormNode
  146. }).inject(this.createNode);
  147. var lp = this.app.lp.holiday;
  148. var inputStyle = "width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;";
  149. var inputTimeStyle = "width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC;height: 26px;"+
  150. "background : url(../x_component_Attendance/$HolidayExplorer/default/icon/calendar.png) 98% center no-repeat";
  151. var makeupClassArea = "";
  152. if( this.data && this.data.makeUpClassDay ){
  153. this.data.makeUpClassDay.each( function ( d, idx ) {
  154. makeupClassArea += "<input type='text' class='makeUpClassDay' " +
  155. "style='" + inputTimeStyle +"'" +
  156. " value='" + ( d || "" ) + "'/>";
  157. if( idx > 0 )makeupClassArea += "<div class='removeMakeUpClassDay' style='color: #354f67;padding-bottom: 5px;cursor: pointer;'>删除</div>";
  158. }.bind(this))
  159. }else{
  160. makeupClassArea += "<input type='text' class='makeUpClassDay' " +
  161. "style='" + inputTimeStyle +"'" +
  162. " value='" + ( "" ) + "'/>";
  163. }
  164. var html = "<table width='100%' height='200' border='0' cellPadding='3' cellSpacing='0'>" +
  165. "<tr>"+
  166. "<td colspan='2' style='height: 50px; line-height: 50px; text-align: center; min-width: 80px; font-size:18px;font-weight: bold;'>" + lp.setHoliday + "</td>" +
  167. "</tr>" +
  168. "<tr>"+
  169. "<td style='height: 30px; line-height: 30px; text-align: left; min-width: 80px; width:25%'>" + lp.year + ":</td>" +
  170. "<td style='; text-align: left;' id='yearArea'>"+
  171. //(!this.isNew && !this.isEdited ? "" :
  172. // ("<input type='text' id='configYear' " + "style='" + inputStyle +"'" + " value='" + ( this.data && this.data.configYear ? this.data.configYear : "") + "'/>")) +
  173. "</td>"+
  174. "</tr>" +
  175. "<tr>"+
  176. "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.name+":</td>" +
  177. "<td style='; text-align: right;'>"+
  178. (!this.isNew && !this.isEdited ? "" :
  179. ("<input type='text' id='configName' " + "style='" + inputStyle +"'" + " value='" + ( this.data && this.data.configName ? this.data.configName : "") + "'/>")) +
  180. "</td>" +
  181. "</tr>" +
  182. "<tr>" +
  183. "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.startDate+":</td>" +
  184. "<td style='; text-align: right;'>" +
  185. (!this.isNew && !this.isEdited ? "" :
  186. ("<input type='text' id='startDate' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.startDate ? this.data.startDate : "") + "'/>")) +
  187. "</td>" +
  188. "</tr>" +
  189. "<tr>" +
  190. "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.endDate+":</td>" +
  191. "<td style='; text-align: right;'>" +
  192. (!this.isNew && !this.isEdited ? "" :
  193. ("<input type='text' id='endDate' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.endDate ? this.data.endDate : "") + "'/>")) +
  194. "</td>" +
  195. "</tr>" +
  196. "<tr>" +
  197. "<td valign='top' style='height: 30px; line-height: 30px; text-align: left'>"+lp.makeUpClassDay+":</td>" +
  198. "<td style='; text-align: right;' id='makeUpClassDayTd'>" +
  199. (!this.isNew && !this.isEdited ? "" :makeupClassArea )+
  200. (!this.isNew && !this.isEdited ? "" : "<div id='addMakeupClass' style='color: #354f67;cursor: pointer;'>增加补班日期</div>" )+
  201. "</td>" +
  202. "</tr>" +
  203. "</table>";
  204. this.createFormNode.set("html", html);
  205. //this.configYear = this.createFormNode.getElement("#configYear");
  206. this.yearArea = this.createFormNode.getElement("#yearArea");
  207. this.configYear = new MDomItem( this.yearArea, {
  208. "name" : "configYear",
  209. "type" : "select",
  210. "value" : this.data.configYear || new Date().getFullYear(),
  211. "selectValue" : function(){
  212. var years = [];
  213. var year = new Date().getFullYear()+5;
  214. for(var i=0; i<11; i++ ){
  215. years.push( year-- );
  216. }
  217. return years;
  218. }
  219. }, true, this.app );
  220. this.configYear.load();
  221. this.configName = this.createFormNode.getElement("#configName");
  222. this.startDate = this.createFormNode.getElement("#startDate");
  223. this.endDate = this.createFormNode.getElement("#endDate");
  224. this.makeUpClassDay = this.createFormNode.getElements(".makeUpClassDay");
  225. this.removeMakeUpClassDay = this.createFormNode.getElements(".removeMakeUpClassDay");
  226. this.addMakeupClass = this.createFormNode.getElement("#addMakeupClass");
  227. this.makeUpClassDayTd = this.createFormNode.getElement("#makeUpClassDayTd");
  228. this.startDate.addEvent("click",function(){
  229. _self.selectCalendar(this);
  230. });
  231. this.endDate.addEvent("click",function(){
  232. _self.selectCalendar(this);
  233. });
  234. this.makeUpClassDay.addEvent("click",function(){
  235. _self.selectCalendar(this);
  236. });
  237. this.removeMakeUpClassDay.addEvent("click", function () {
  238. var input = this.getPrevious();
  239. if(input && input.get('tag') === "input")input.destroy();
  240. this.destroy();
  241. });
  242. this.addMakeupClass.addEvent("click",function(){
  243. var input = new Element("input",{
  244. class : "makeUpClassDay",
  245. style : inputTimeStyle,
  246. value : "",
  247. events : {
  248. click : function () {
  249. _self.selectCalendar(this);
  250. }
  251. }
  252. }).inject(this, "before");
  253. var div = new Element("div",{
  254. "class" : "removeMakeUpClassDay",
  255. style : "color: #354f67;padding-bottom: 5px;cursor: pointer;",
  256. text : "删除",
  257. events : {
  258. click : function () {
  259. var input = this.getPrevious();
  260. if(input && input.get('tag') === "input")input.destroy();
  261. this.destroy();
  262. }
  263. }
  264. }).inject(this, "before")
  265. });
  266. this.cancelActionNode = new Element("div", {
  267. "styles": this.css.createCancelActionNode,
  268. "text": this.app.lp.cancel
  269. }).inject(this.createFormNode);
  270. this.createOkActionNode = new Element("div", {
  271. "styles": this.css.createOkActionNode,
  272. "text": this.app.lp.ok
  273. }).inject(this.createFormNode);
  274. this.cancelActionNode.addEvent("click", function(e){
  275. this.cancelCreate(e);
  276. }.bind(this));
  277. this.createOkActionNode.addEvent("click", function(e){
  278. this.okCreate(e);
  279. }.bind(this));
  280. },
  281. setCreateNodeSize: function (width, height, top, left) {
  282. if (!width)width = this.options && this.options.width ? this.options.width : "50%";
  283. if (!height)height = this.options && this.options.height ? this.options.height : "50%";
  284. if (!top) top = this.options && this.options.top ? this.options.top : 0;
  285. if (!left) left = this.options && this.options.left ? this.options.left : 0;
  286. var allSize = this.app.content.getSize();
  287. var limitWidth = allSize.x; //window.screen.width
  288. var limitHeight = allSize.y; //window.screen.height
  289. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  290. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  291. 300 > width && (width = 300);
  292. 220 > height && (height = 220);
  293. top = top || parseInt((limitHeight - height) / 2, 10);
  294. left = left || parseInt((limitWidth - width) / 2, 10);
  295. this.createAreaNode.setStyles({
  296. "width": "" + width + "px",
  297. "height": "" + height + "px",
  298. "top": "" + top + "px",
  299. "left": "" + left + "px"
  300. });
  301. this.createNode.setStyles({
  302. "width": "" + width + "px",
  303. "height": "" + height + "px"
  304. });
  305. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x: 0, y: 0};
  306. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  307. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  308. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  309. //var formMargin = formHeight -iconSize.y;
  310. this.createFormNode.setStyles({
  311. "height": "" + contentHeight + "px"
  312. });
  313. },
  314. //setCreateNodeSize: function(){
  315. // var size = this.app.node.getSize();
  316. // var allSize = this.app.content.getSize();
  317. //
  318. // this.createAreaNode.setStyles({
  319. // "width": ""+size.x+"px",
  320. // "height": ""+size.y+"px"
  321. // });
  322. // var hY = size.y*0.8;
  323. // var mY = size.y*0.2/2;
  324. // this.createNode.setStyles({
  325. // "height": ""+hY+"px",
  326. // "margin-top": ""+mY+"px"
  327. // });
  328. //
  329. // var iconSize = this.createIconNode.getSize();
  330. // var formHeight = hY*0.7;
  331. // if (formHeight>250) formHeight = 250;
  332. // var formMargin = hY*0.3/2-iconSize.y;
  333. // this.createFormNode.setStyles({
  334. // "height": ""+formHeight+"px",
  335. // "margin-top": ""+formMargin+"px"
  336. // });
  337. //},
  338. cancelCreate: function(e){
  339. var _self = this;
  340. if ( this.isNew && this.configName.get("value") ){
  341. this.app.confirm("warn", e,
  342. this.app.lp.create_cancel_title,
  343. this.app.lp.create_cancel, "320px", "100px",
  344. function(){
  345. _self.createMarkNode.destroy();
  346. _self.createAreaNode.destroy();
  347. this.close();
  348. },function(){
  349. this.close();
  350. }
  351. );
  352. }else{
  353. this.createMarkNode.destroy();
  354. this.createAreaNode.destroy();
  355. delete _self;
  356. }
  357. },
  358. okCreate: function(e){
  359. var data = {
  360. "id" : (this.data && this.data.id) ? this.data.id : this.app.restActions.getUUID(),
  361. "configYear": this.configYear.get("value"),
  362. "configName": this.configName.get("value"),
  363. "startDate": this.startDate.get("value"),
  364. "endDate": this.endDate.get("value")
  365. // "makeUpClassDay": this.makeUpClassDay.get("value")
  366. };
  367. if (data.configYear && data.configName && data.startDate && data.endDate ){
  368. var endDate = new Date( data.endDate );
  369. var startDate = new Date( data.startDate );
  370. if( startDate > endDate ){
  371. this.app.notice("开始日期不能大于结束日期","error");
  372. return;
  373. }
  374. var flag = true;
  375. var save = function(){
  376. var error = "";
  377. this.getDateByRange(startDate,endDate).each(function( date ){
  378. this.app.restActions.saveHoliday({
  379. "configName" : data.configName,
  380. "configYear" : data.configYear,
  381. "configDate": date,
  382. "configType": "Holiday"
  383. }, function(json){
  384. if( json.type == "ERROR" ){error=json.message}
  385. }.bind(this),
  386. function(json){
  387. flag = false;
  388. }.bind(this),false);
  389. }.bind(this));
  390. // if(data.makeUpClassDay!=""){
  391. // data.makeUpClassDay.split(",").each(function( date ){
  392. // this.app.restActions.saveHoliday({
  393. // "configName" : data.configName,
  394. // "configYear" : data.configYear,
  395. // "configDate": this.dateFormat( new Date(date),"yyyy-MM-dd"),
  396. // "configType": "Workday"
  397. // }, function(json){
  398. // if( json.type == "ERROR" ){error=json.message}
  399. // },function(json){
  400. // flag = false;
  401. // }.bind(this),false);
  402. // }.bind(this))
  403. // }
  404. this.createFormNode.getElements(".makeUpClassDay").each( function(el){
  405. if(el.get("value")){
  406. this.app.restActions.saveHoliday({
  407. "configName" : data.configName,
  408. "configYear" : data.configYear,
  409. "configDate": this.dateFormat( new Date(el.get("value")),"yyyy-MM-dd"),
  410. "configType": "Workday"
  411. }, function(json){
  412. if( json.type == "ERROR" ){error=json.message}
  413. },function(json){
  414. flag = false;
  415. }.bind(this),false);
  416. }
  417. }.bind(this))
  418. if(error==""){
  419. this.createMarkNode.destroy();
  420. this.createAreaNode.destroy();
  421. if(this.explorer.view)this.explorer.view.reload();
  422. this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  423. }else{
  424. this.app.notice( error , "error");
  425. }
  426. }.bind(this);
  427. if(!this.isNew){
  428. this.explorer.view._removeDocument(data, false, save )
  429. }else{
  430. save();
  431. }
  432. }else{
  433. this.configName.setStyle("border-color", "red");
  434. this.configName.focus();
  435. this.app.notice( this.app.lp.holiday.inputValid, "error");
  436. }
  437. },
  438. selectCalendar : function( calendarNode ){
  439. MWF.require("MWF.widget.Calendar", function(){
  440. var calendar = new MWF.widget.Calendar( calendarNode, {
  441. "style": "xform",
  442. "isTime": false,
  443. "target": this.app.content
  444. });
  445. calendar.show();
  446. }.bind(this));
  447. },
  448. getDateByRange : function(startDate, endDate){
  449. var days = [];
  450. while (startDate <= endDate) {
  451. days.push( this.dateFormat(startDate,"yyyy-MM-dd") );
  452. startDate.setDate(startDate.getDate() + 1);
  453. }
  454. return days;
  455. },
  456. dateFormat : function(date, fmt){
  457. var o = {
  458. "M+" : date.getMonth()+1, //月份
  459. "d+" : date.getDate(), //日
  460. "h+" : date.getHours(), //小时
  461. "m+" : date.getMinutes(), //分
  462. "s+" : date.getSeconds(), //秒
  463. "q+" : Math.floor((date.getMonth()+3)/3), //季度
  464. "S" : date.getMilliseconds() //毫秒
  465. };
  466. if(/(y+)/.test(fmt))
  467. fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
  468. for(var k in o)
  469. if(new RegExp("("+ k +")").test(fmt))
  470. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  471. return fmt;
  472. }
  473. });