Calendar.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. MWF.xApplication.Attendance.widget = MWF.xApplication.Attendance.widget || {};
  2. MWF.xApplication.Attendance.widget.Calendar = new Class({
  3. Implements: [Options, Events],
  4. Extends: MWF.widget.Common,
  5. options : {
  6. date : null,
  7. cycleStart : null,
  8. cycleEnd : null
  9. },
  10. initialize: function(container, view, data, options) {
  11. this.setOptions(options);
  12. this.view = view;
  13. this.container = container;
  14. this.data = data;
  15. this.app = this.view.app;
  16. this.date = this.options.date || new Date();
  17. this.today = new Date();
  18. this.days = {};
  19. this.weekBegin = 0; //this.app.meetingConfig.weekBegin ||
  20. this.path = "../x_component_Attendance/widget/$Calendar/";
  21. this.cssPath = "../x_component_Attendance/widget/$Calendar/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.load();
  24. },
  25. load: function(){
  26. // this.titleNode = new Element("div", {"styles": this.css.calendarTitleNode}).inject(this.container);
  27. this.scrollNode = new Element("div", {
  28. "styles": this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode
  29. }).inject(this.container);
  30. this.contentWarpNode = new Element("div", {
  31. "styles": this.css.contentWarpNode
  32. }).inject(this.scrollNode);
  33. this.contentContainerNode = new Element("div",{
  34. "styles" : this.css.contentContainerNode
  35. }).inject(this.contentWarpNode);
  36. this.bodyNode = new Element("div", {
  37. "styles": this.css.contentNode
  38. }).inject(this.contentContainerNode);
  39. //this.bodyNode = new Element("div", {"styles": this.css.calendarBodyNode}).inject(this.container);
  40. this.setTitleNode();
  41. this.setBodyNode();
  42. this.resetBodySize();
  43. this.app.addEvent("resize", this.resetBodySize.bind(this));
  44. },
  45. resetBodySize: function(){
  46. //if( this.app.inContainer )return;
  47. var size = this.container.getSize();
  48. var titleSize = this.titleNode.getSize();
  49. var y = size.y-titleSize.y;
  50. //this.bodyNode.setStyle("height", ""+y+"px");
  51. //var size = this.container.getSize();
  52. this.scrollNode.setStyle("height", ""+y+"px");
  53. //this.scrollNode.setStyle("margin-top", "60px");
  54. if (this.contentWarpNode){
  55. this.contentWarpNode.setStyles({
  56. "width": (size.x - 40) +"px"
  57. });
  58. }
  59. //var tdy = (y-30)/6;
  60. //tdy = tdy-34;
  61. //var tds = this.calendarTable.getElements("td");
  62. //tds.each(function(td){
  63. // var yy = tdy;
  64. // var node = td.getLast("div");
  65. // if (node.childNodes.length>=4){
  66. // if (yy<92) yy = 69;
  67. // }
  68. // node.setStyle("height", ""+yy+"px");
  69. //}.bind(this));
  70. },
  71. // setTitleNode: function(){
  72. // this.prevMonthNode = new Element("div", {"styles": this.css.calendarPrevMonthNode}).inject(this.titleNode);
  73. //
  74. // var text = this.date.format(this.app.lp.dateFormatMonth);
  75. // this.titleTextNode = new Element("div", {"styles": this.css.calendarTitleTextNode, "text": text}).inject(this.titleNode);
  76. //
  77. // this.nextMonthNode = new Element("div", {"styles": this.css.calendarNextMonthNode}).inject(this.titleNode);
  78. //
  79. // this.prevMonthNode.addEvents({
  80. // "mouseover": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  81. // "mouseout": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode);}.bind(this),
  82. // "mousedown": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_down);}.bind(this),
  83. // "mouseup": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  84. // "click": function(){this.changeMonthPrev();}.bind(this)
  85. // });
  86. // this.nextMonthNode.addEvents({
  87. // "mouseover": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  88. // "mouseout": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode);}.bind(this),
  89. // "mousedown": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_down);}.bind(this),
  90. // "mouseup": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  91. // "click": function(){this.changeMonthNext();}.bind(this)
  92. // });
  93. // this.titleTextNode.addEvents({
  94. // "mouseover": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  95. // "mouseout": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode);}.bind(this),
  96. // "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  97. // "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  98. // "click": function(){this.changeMonthSelect();}.bind(this)
  99. // });
  100. // },
  101. // changeMonthPrev: function(){
  102. // this.date.decrement("month", 1);
  103. // var text = this.date.format(this.app.lp.dateFormatMonth);
  104. // this.titleTextNode.set("text", text);
  105. // this.reLoadCalendar();
  106. // },
  107. // changeMonthNext: function(){
  108. // this.date.increment("month", 1);
  109. // var text = this.date.format(this.app.lp.dateFormatMonth);
  110. // this.titleTextNode.set("text", text);
  111. // this.reLoadCalendar();
  112. // },
  113. // changeMonthSelect: function(){
  114. // if (!this.monthSelector) this.createMonthSelector();
  115. // this.monthSelector.show();
  116. // },
  117. // createMonthSelector: function(){
  118. // this.monthSelector = new MWF.xApplication.Meeting.MonthView.Calendar.MonthSelector(this.date, this);
  119. // },
  120. changeMonthTo: function(d){
  121. this.date = d;
  122. var text = this.date.format(this.app.lp.dateFormatMonth);
  123. this.titleTextNode.set("text", text);
  124. this.reLoadCalendar();
  125. },
  126. setBodyNode: function(){
  127. if( this.weekBegin == "1" ){
  128. var html = "<tr><th>"+this.app.lp.weeks.Mon+"</th><th>"+this.app.lp.weeks.Tues+"</th><th>"+this.app.lp.weeks.Wed+"</th>" +
  129. "<th>"+this.app.lp.weeks.Thur+"</th><th>"+this.app.lp.weeks.Fri+"</th><th>"+this.app.lp.weeks.Sat+"</th><th>"+this.app.lp.weeks.Sun+"</th></tr>";
  130. }else{
  131. var html = "<tr><th>"+this.app.lp.weeks.Sun+"</th><th>"+this.app.lp.weeks.Mon+"</th><th>"+this.app.lp.weeks.Tues+"</th><th>"+this.app.lp.weeks.Wed+"</th>" +
  132. "<th>"+this.app.lp.weeks.Thur+"</th><th>"+this.app.lp.weeks.Fri+"</th><th>"+this.app.lp.weeks.Sat+"</th></tr>";
  133. }
  134. html += "<tr><td valign='top'></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  135. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  136. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  137. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  138. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  139. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  140. this.calendarTable = new Element("table", {
  141. "styles": this.css.calendarTable,
  142. "height": "100%",
  143. "border": "0",
  144. "cellPadding": "0",
  145. "cellSpacing": "0",
  146. "html": html
  147. }).inject(this.bodyNode);
  148. this.calendarTableTitleTr = this.calendarTable.getElement("tr");
  149. this.calendarTableTitleTr.setStyles(this.css.calendarTableTitleTr);
  150. var ths = this.calendarTableTitleTr.getElements("th");
  151. ths.setStyles(this.css.calendarTableTh);
  152. //var tds = this.calendarTable.getElements("td");
  153. //tds.setStyles(this.css.calendarTableCell);
  154. this.loadCalendar();
  155. },
  156. reLoadCalendar: function(){
  157. Object.each(this.days, function(day){
  158. day.destroy();
  159. }.bind(this));
  160. this.loadCalendar();
  161. },
  162. loadCalendar: function(){
  163. var date = this.date.clone();
  164. date.set("date", 1);
  165. var week = date.getDay();
  166. if( this.weekBegin == "1" ){
  167. var decrementDay = ((week-1)<0) ? 6 : week-1;
  168. }else{
  169. var decrementDay = week;
  170. }
  171. date.decrement("day", decrementDay);
  172. var tds = this.calendarTable.getElements("td");
  173. tds.each(function(td){
  174. this.loadDay(td, date);
  175. date.increment();
  176. }.bind(this));
  177. },
  178. loadDay: function(td, date){
  179. var type = "thisMonth";
  180. var m = date.get("month");
  181. var y = date.get("year");
  182. var d = date.get("date");
  183. var mm = this.date.get("month");
  184. var yy = this.date.get("year");
  185. var mmm = this.today.get("month");
  186. var yyy = this.today.get("year");
  187. var ddd = this.today.get("date");
  188. if ((m==mmm) && (y==yyy) && (d==ddd)){
  189. type = "today";
  190. }else if ((m==mm) && (y==yy)){
  191. type = "thisMonth";
  192. }else{
  193. type = "otherMonth";
  194. }
  195. var key = date.format(this.app.lp.dateFormat);
  196. this.days[key] = MWF.xApplication.Attendance.widget.Calendar.Day(td, date, this, type);
  197. },
  198. reload : function(){
  199. this.view.reload();
  200. },
  201. destroy: function(){
  202. Object.each(this.days, function(day){
  203. day.destroy();
  204. }.bind(this));
  205. this.container.empty();
  206. }
  207. });
  208. MWF.xApplication.Attendance.widget.Calendar.Day = new Class({
  209. Implements: [Events],
  210. initialize: function(td, date, calendar, type){
  211. this.container = td;
  212. this.calendar = calendar;
  213. this.view = this.calendar.view;
  214. this.css = this.calendar.css;
  215. this.app = this.calendar.app;
  216. this.date = date.clone();
  217. this.key = this.date.format(this.app.lp.dateFormat);
  218. this.type = type; //today, otherMonth, thisMonth
  219. this.meetings = [];
  220. this.load();
  221. },
  222. load: function(){
  223. this.color = "#666";
  224. if( this.type == "thisMonth" ){
  225. }else if( this.type == "otherMonth" ){
  226. this.color = "#ccc";
  227. }
  228. this.day = this.date.getDate();
  229. this.month = this.date.getMonth();
  230. this.year = this.date.getYear();
  231. this.node = new Element("div", {
  232. "styles" : this.css["calendarTableCell_"+this.type]
  233. }).inject( this.container );
  234. this.titleNode = new Element("div", {"styles": this.css["dayTitle_"+this.type]}).inject(this.node);
  235. this.titleDayNode = new Element("div", {"styles": this.css["dayTitleDay_"+this.type], "text": this.day}).inject(this.titleNode);
  236. if ((new Date()).diff(this.date)>=0){
  237. this.titleNode.set("title", this.app.lp.titleNode);
  238. this.titleNode.addEvent("click", function(){
  239. this.app.addMeeting(this.date);
  240. }.bind(this));
  241. }
  242. this.contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(this.node);
  243. // this.loadMeetings();
  244. },
  245. loadMeetings: function(){
  246. this.app.isMeetingViewer( function( isAll ){
  247. this._loadMeetings( isAll );
  248. }.bind(this))
  249. },
  250. _loadMeetings: function( isAll ){
  251. var y = this.date.getFullYear();
  252. var m = this.date.getMonth()+1;
  253. var d = this.date.getDate();
  254. var meetingCount = 0;
  255. var myRejectCount = 0;
  256. this.firstStatus = "";
  257. this.lastStatus = "";
  258. this.app.actions[ isAll ? "listMeetingDayAll" : "listMeetingDay" ](y, m, d, function(json){
  259. var length = json.data.length;
  260. json.data.each(function(meeting, i){
  261. if (!meeting.myReject){
  262. meetingCount++;
  263. if (meetingCount==3){
  264. //this.contentNode.setStyle("height", "100px");
  265. }
  266. if( meetingCount == 1 ){
  267. this.firstStatus = meeting.status;
  268. if( meeting.myWaitAccept )this.firstStatus = "myWaitAccept"
  269. }
  270. if( meetingCount + myRejectCount == length ){
  271. this.lastStatus = meeting.status;
  272. if( meeting.myWaitAccept )this.lastStatus = "myWaitAccept"
  273. }
  274. //if (meetingCount<4)
  275. this.meetings.push(new MWF.xApplication.Meeting.MonthView.Calendar.Day.Meeting(this, meeting, meetingCount));
  276. }else{
  277. myRejectCount++;
  278. }
  279. }.bind(this));
  280. if (meetingCount==0){
  281. var node = new Element("div", {
  282. "styles": {
  283. "line-height": "40px",
  284. "font-size": "14px",
  285. "text-align" : "center",
  286. "color" : this.color,
  287. "padding": "0px 10px"
  288. }
  289. }).inject(this.contentNode);
  290. node.set("text", this.app.lp.noMeeting);
  291. }else{
  292. this.titleInforNode = new Element("div", {"styles": this.css["dayTitleInfor_"+this.type]}).inject(this.titleNode);
  293. if( this.app.isViewAvailable( "toDay" ) ) {
  294. this.titleInforNode.addEvent("click", function (e) {
  295. this.app.toDay(this.date);
  296. e.stopPropagation();
  297. }.bind(this));
  298. }else{
  299. this.titleInforNode.setStyle("cursor","default");
  300. }
  301. this.titleInforNode.set("text", ""+meetingCount+this.app.lp.countMeetings+"");
  302. if (meetingCount>3){
  303. this.node.addEvents( {
  304. "mouseenter" : function(){
  305. this.expend();
  306. }.bind(this),
  307. "mouseleave" : function(){
  308. this.collapseReady = true;
  309. this.collapse();
  310. }.bind(this)
  311. } )
  312. }else{
  313. this.titleInforNode.setStyle("color", this.type == "otherMonth" ? "#ccc" : "#999");
  314. }
  315. }
  316. if(this.firstStatus){
  317. switch (this.firstStatus){
  318. case "wait":
  319. this.titleNode.setStyles({ "border-left": "6px solid #4990E2" });
  320. break;
  321. case "processing":
  322. this.titleNode.setStyles({ "border-left": "6px solid #66CC7F" });
  323. break;
  324. case "completed":
  325. this.titleNode.setStyles({ "border-left": "6px solid #ccc" });
  326. break;
  327. case "myWaitAccept":
  328. this.titleNode.setStyles({ "border-left": "6px solid #F6A623" });
  329. break
  330. }
  331. }
  332. if( this.lastStatus ){
  333. var heigth=0;
  334. if( meetingCount >= 3 ){
  335. heigth = 10;
  336. }else{
  337. heigth = 100 - meetingCount*30;
  338. }
  339. var bottomEmptyNode = new Element("div", {
  340. styles : {
  341. "height" : ""+heigth+"px"
  342. }
  343. }).inject( this.node );
  344. switch (this.lastStatus){
  345. case "wait":
  346. bottomEmptyNode.setStyles({ "border-left": "6px solid #4990E2" });
  347. break;
  348. case "processing":
  349. bottomEmptyNode.setStyles({ "border-left": "6px solid #66CC7F" });
  350. break;
  351. case "completed":
  352. bottomEmptyNode.setStyles({ "border-left": "6px solid #ccc" });
  353. break;
  354. case "myWaitAccept":
  355. bottomEmptyNode.setStyles({ "border-left": "6px solid #F6A623" });
  356. break
  357. }
  358. }
  359. }.bind(this));
  360. },
  361. expend : function(){
  362. this.oSize = this.node.getSize();
  363. this.container.setStyles({
  364. "position" : "relative"
  365. });
  366. this.tempNode = new Element("div",{
  367. styles : {
  368. width : (this.node.getSize().x ) + "px",
  369. height : "1px",
  370. margin : "7px"
  371. }
  372. }).inject(this.container);
  373. this.node.setStyles({
  374. "height" : this.node.getScrollSize().y + "px",
  375. "width" : (this.node.getSize().x ) + "px",
  376. "position" : "absolute",
  377. "top" : "0px",
  378. "left" : "0px",
  379. "box-shadow": "0 0 8px 0 rgba(0,0,0,0.25)"
  380. });
  381. var nodeCoordinate = this.node.getCoordinates();
  382. var contentNode = this.calendar.contentWarpNode;
  383. var contentCoordinate = contentNode.getCoordinates();
  384. if( nodeCoordinate.bottom > contentCoordinate.bottom ){
  385. this.contentHeight = contentCoordinate.height;
  386. contentNode.setStyle("height", ( nodeCoordinate.bottom - contentCoordinate.top )+"px" );
  387. }
  388. this.isCollapse = false;
  389. },
  390. collapse : function(){
  391. if( !this.collapseDisable && this.collapseReady){
  392. this.container.setStyles({
  393. "position" : "static"
  394. });
  395. if( this.tempNode )this.tempNode.destroy();
  396. this.node.setStyles({
  397. "height" : "140px",
  398. "width" : "auto",
  399. "position" : "static",
  400. "box-shadow": "none"
  401. });
  402. if( this.contentHeight ){
  403. var contentNode = this.calendar.contentWarpNode;
  404. contentNode .setStyle("height", ( this.contentHeight )+"px" );
  405. this.contentHeight = null;
  406. }
  407. this.isCollapse = true;
  408. }
  409. },
  410. destroy: function(){
  411. this.meetings.each(function(meeting){
  412. meeting.destroy();
  413. }.bind(this));
  414. this.meetings = [];
  415. this.titleNode.destroy();
  416. this.titleNode = null;
  417. this.titleDayNode = null;
  418. this.titleInforNode = null;
  419. delete this.calendar.days[this.key];
  420. this.container.empty();
  421. MWF.release(this);
  422. },
  423. reload: function(){
  424. this.view.reload();
  425. }
  426. });