MonthView.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  1. var MWFCalendarMonthView = MWF.xApplication.Calendar.MonthView = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "date" : ""
  7. },
  8. initialize: function(node, app, options){
  9. this.setOptions(options);
  10. this.path = "../x_component_Calendar/$MonthView/";
  11. this.cssPath = "../x_component_Calendar/$MonthView/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.app = app;
  14. //this.titleContainer = $(titleNode);
  15. this.container = $(node);
  16. this.load();
  17. },
  18. load: function(){
  19. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  20. //this.loadSideBar();
  21. //this.app.addEvent("resize", this.resetNodeSize.bind(this));
  22. this.loadCalendar();
  23. this.resetNodeSize();
  24. },
  25. resetNodeSize: function(){
  26. var size = this.container.getSize();
  27. var y = size.y-50;
  28. this.node.setStyle("height", ""+y+"px");
  29. //this.node.setStyle("margin-top", "60px");
  30. var sideBarSize = this.app.sideBar ? this.app.sideBar.getSize() : { x : 0, y:0 };
  31. this.node.setStyle("width", ""+(size.x - sideBarSize.x)+"px");
  32. this.node.setStyle("margin-right", ""+sideBarSize.x+"px");
  33. if( this.calendar ){
  34. this.calendar.resetBodySize()
  35. }
  36. //var size = this.container.getSize();
  37. //
  38. //this.scrollNode.setStyle("height", ""+(size.y-60)+"px");
  39. //this.scrollNode.setStyle("margin-top", "60px");
  40. //
  41. //if (this.contentWarpNode){
  42. // this.contentWarpNode.setStyles({
  43. // "width": (size.x - 50) +"px"
  44. // });
  45. //}
  46. },
  47. loadCalendar: function(){
  48. var date = "";
  49. if( this.options.date ){
  50. date = Date.parse( this.options.date )
  51. }
  52. this.calendar = new MWFCalendarMonthView.Calendar(this, date );
  53. },
  54. hide: function(){
  55. var fx = new Fx.Morph(this.node, {
  56. "duration": "300",
  57. "transition": Fx.Transitions.Expo.easeOut
  58. });
  59. fx.start({
  60. "opacity": 0
  61. }).chain(function(){
  62. this.node.setStyle("display", "none");
  63. }.bind(this));
  64. },
  65. show: function(){
  66. this.node.setStyles(this.css.node);
  67. var fx = new Fx.Morph(this.node, {
  68. "duration": "800",
  69. "transition": Fx.Transitions.Expo.easeOut
  70. });
  71. //this.app.fireAppEvent("resize");
  72. fx.start({
  73. "opacity": 1
  74. //"left": MWFCalendar.LeftNaviWidth+"px"
  75. }).chain(function(){
  76. //this.node.setStyles({
  77. // "position": "static",
  78. // "width": "auto"
  79. //});
  80. }.bind(this));
  81. },
  82. reload: function(){
  83. if (this.calendar) this.calendar.reLoadCalendar();
  84. },
  85. recordStatus : function(){
  86. return {
  87. date : (this.calendar && this.calendar.date) ? this.calendar.date.format( "db" ) : ""
  88. };
  89. },
  90. destroy: function(){
  91. if (this.calendar){
  92. this.calendar.destroy();
  93. }
  94. this.node.destroy();
  95. //MWF.release( this );
  96. }
  97. });
  98. MWFCalendarMonthView.Calendar = new Class({
  99. Implements: [Events],
  100. initialize: function(view, date){
  101. this.view = view;
  102. this.css = this.view.css;
  103. this.container = this.view.node;
  104. this.app = this.view.app;
  105. this.date = date || new Date();
  106. this.today = new Date();
  107. this.days = {};
  108. this.weekBegin = this.app.calendarConfig.weekBegin || 0;
  109. this.load();
  110. },
  111. load: function(){
  112. this.titleNode = new Element("div", {"styles": this.css.calendarTitleNode}).inject(this.container);
  113. this.titleTableContainer = new Element("div", {"styles": this.css.calendarTitleTableContainer}).inject(this.container);
  114. this.scrollNode = new Element("div", {
  115. "styles": this.css.scrollNode
  116. }).inject(this.container);
  117. this.contentWarpNode = new Element("div", {
  118. "styles": this.css.contentWarpNode
  119. }).inject(this.scrollNode);
  120. this.contentContainerNode = new Element("div",{
  121. "styles" : this.css.contentContainerNode
  122. }).inject(this.contentWarpNode);
  123. this.bodyNode = new Element("div", {
  124. "styles": this.css.contentNode
  125. }).inject(this.contentContainerNode);
  126. this.bodyNode.setStyle("position","relative");
  127. //this.bodyNode = new Element("div", {"styles": this.css.calendarBodyNode}).inject(this.container);
  128. this.setTitleNode();
  129. this.setTitleTableNode();
  130. this.setBodyNode();
  131. //this.app.addEvent("resize", this.resetBodySize.bind(this));
  132. },
  133. resetBodySize: function(){
  134. var size = this.container.getSize();
  135. var titleSize = this.titleNode.getSize();
  136. var titleTableSize = this.titleTable.getSize();
  137. var y = size.y-titleSize.y-titleTableSize.y;
  138. //this.bodyNode.setStyle("height", ""+y+"px");
  139. //var size = this.container.getSize();
  140. this.scrollNode.setStyle("height", ""+y+"px");
  141. //this.scrollNode.setStyle("margin-top", "60px");
  142. this.titleTableContainer.setStyles({
  143. "width": (size.x - 40) +"px"
  144. });
  145. if (this.contentWarpNode){
  146. this.contentWarpNode.setStyles({
  147. "width": (size.x - 40) +"px"
  148. });
  149. }
  150. var tableSize = this.calendarTable.getSize();
  151. MWFCalendarMonthView.WeekWidth = tableSize.x;
  152. MWFCalendarMonthView.DayWidth = tableSize.x / 7;
  153. this.dataTdList.each( function( td ){
  154. td.setStyle("width", MWFCalendarMonthView.WeekWidth)
  155. });
  156. if( this.wholeDayDocumentList && this.wholeDayDocumentList.length ){
  157. this.wholeDayDocumentList.each( function( doc ){
  158. doc.resize();
  159. }.bind(this))
  160. }
  161. if( this.oneDayDocumentList && this.oneDayDocumentList.length ){
  162. this.oneDayDocumentList.each( function( doc ){
  163. doc.resize();
  164. }.bind(this))
  165. }
  166. var top = 30; //MWFCalendarMonthView.THHeight + 30;
  167. var trs = this.calendarTable.getElements("tr");
  168. this.calendarTrHeight = [];
  169. for( var key in this.usedYIndex ){
  170. var idx = this.usedYIndex[key];
  171. var maxLength = Math.max( idx[0].length, idx[1].length, idx[2].length, idx[3].length, idx[4].length, idx[5].length, idx[6].length );
  172. if( maxLength > 4 ){
  173. this.dataTableList[key].setStyle("top", top );
  174. var height = 30 + maxLength * (22 + 2);
  175. top = top + height;
  176. trs[ parseInt(key) ].getElements("td").each( function(td){
  177. td.setStyle("height", height )
  178. });
  179. this.calendarTrHeight.push( height );
  180. }else{
  181. this.dataTableList[key].setStyle("top", top );
  182. top = top + MWFCalendarMonthView.WeekHeight + 1;
  183. trs[ parseInt(key) ].getElements("td").each( function(td){
  184. td.setStyle("height", MWFCalendarMonthView.WeekHeight )
  185. });
  186. this.calendarTrHeight.push( MWFCalendarMonthView.WeekHeight );
  187. }
  188. }
  189. //var tdy = (y-30)/6;
  190. //tdy = tdy-34;
  191. //var tds = this.calendarTable.getElements("td");
  192. //tds.each(function(td){
  193. // var yy = tdy;
  194. // var node = td.getLast("div");
  195. // if (node.childNodes.length>=4){
  196. // if (yy<92) yy = 69;
  197. // }
  198. // node.setStyle("height", ""+yy+"px");
  199. //}.bind(this));
  200. },
  201. setTitleNode: function(){
  202. //this.view.titleContainer.getElements("div:only-child").setStyle("display","none");
  203. //if( this.titleNode ){
  204. // this.titleNode.setStyle("display","")
  205. //}
  206. //this.titleNode = new Element("div").inject(this.view.titleContainer);
  207. this.prevMonthNode = new Element("div.o2icon-triangle_left", {"styles": this.css.calendarPrevMonthNode}).inject(this.titleNode);
  208. var text = this.date.format(this.app.lp.dateFormatMonth);
  209. this.titleTextNode = new Element("div", {"styles": this.css.calendarTitleTextNode, "text": text}).inject(this.titleNode);
  210. this.nextMonthNode = new Element("div.o2icon-triangle_right", {"styles": this.css.calendarNextMonthNode}).inject(this.titleNode);
  211. this.prevMonthNode.addEvents({
  212. "mouseover": function(){
  213. this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);
  214. this.prevMonthNode.addClass("mainColor_color");
  215. }.bind(this),
  216. "mouseout": function(){
  217. this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode);
  218. this.prevMonthNode.removeClass("mainColor_color");
  219. }.bind(this),
  220. "mousedown": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_down);}.bind(this),
  221. "mouseup": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  222. "click": function(){this.changeMonthPrev();}.bind(this)
  223. });
  224. this.nextMonthNode.addEvents({
  225. "mouseover": function(){
  226. this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);
  227. this.nextMonthNode.addClass("mainColor_color");
  228. }.bind(this),
  229. "mouseout": function(){
  230. this.nextMonthNode.setStyles(this.css.calendarNextMonthNode);
  231. this.nextMonthNode.removeClass("mainColor_color");
  232. }.bind(this),
  233. "mousedown": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_down);}.bind(this),
  234. "mouseup": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  235. "click": function(){this.changeMonthNext();}.bind(this)
  236. });
  237. this.titleTextNode.addEvents({
  238. "mouseover": function(){
  239. this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);
  240. this.titleTextNode.addClass("mainColor_color");
  241. }.bind(this),
  242. "mouseout": function(){
  243. this.titleTextNode.setStyles(this.css.calendarTitleTextNode);
  244. this.titleTextNode.removeClass("mainColor_color");
  245. }.bind(this),
  246. "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  247. "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  248. "click": function(){this.changeMonthSelect();}.bind(this)
  249. });
  250. },
  251. changeMonthPrev: function(){
  252. this.date.decrement("month", 1);
  253. var text = this.date.format(this.app.lp.dateFormatMonth);
  254. this.titleTextNode.set("text", text);
  255. this.reLoadCalendar();
  256. },
  257. changeMonthNext: function(){
  258. this.date.increment("month", 1);
  259. var text = this.date.format(this.app.lp.dateFormatMonth);
  260. this.titleTextNode.set("text", text);
  261. this.reLoadCalendar();
  262. },
  263. changeMonthSelect: function(){
  264. if (!this.monthSelector) this.createMonthSelector();
  265. this.monthSelector.show();
  266. },
  267. createMonthSelector: function(){
  268. this.monthSelector = new MWFCalendarMonthView.MonthSelector(this.date, this);
  269. },
  270. changeMonthTo: function(d){
  271. this.date = d;
  272. var text = this.date.format(this.app.lp.dateFormatMonth);
  273. this.titleTextNode.set("text", text);
  274. this.reLoadCalendar();
  275. },
  276. setTitleTableNode : function(){
  277. if( this.weekBegin == "1" ){
  278. var html = "<tr><th>"+this.app.lp.weeks.Mon+"</th><th>"+this.app.lp.weeks.Tues+"</th><th>"+this.app.lp.weeks.Wed+"</th>" +
  279. "<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>";
  280. }else{
  281. 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>" +
  282. "<th>"+this.app.lp.weeks.Thur+"</th><th>"+this.app.lp.weeks.Fri+"</th><th>"+this.app.lp.weeks.Sat+"</th></tr>";
  283. }
  284. this.titleTable = new Element("table", {
  285. "styles": this.css.calendarTable,
  286. "height": "100%",
  287. "border": "0",
  288. "cellPadding": "0",
  289. "cellSpacing": "0",
  290. "html": html
  291. }).inject(this.titleTableContainer);
  292. this.calendarTableTitleTr = this.titleTable.getElement("tr");
  293. this.calendarTableTitleTr.setStyles(this.css.calendarTableTitleTr);
  294. var ths = this.calendarTableTitleTr.getElements("th");
  295. ths.setStyles(this.css.calendarTableTh);
  296. },
  297. setBodyNode: function(){
  298. var html = "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  299. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  300. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  301. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  302. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  303. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  304. this.calendarTable = new Element("table", {
  305. "styles": this.css.calendarTable,
  306. "height": "100%",
  307. "border": "0",
  308. "cellPadding": "0",
  309. "cellSpacing": "0",
  310. "html": html
  311. }).inject(this.bodyNode);
  312. this.loadBackgroundCalendar( true );
  313. this.loadDataContainer();
  314. //var tds = this.calendarTable.getElements("td");
  315. //tds.setStyles(this.css.calendarTableCell);
  316. this.loadCalendar();
  317. },
  318. reLoadCalendar: function(){
  319. if( this.wholeDayDocumentList && this.wholeDayDocumentList.length ){
  320. this.wholeDayDocumentList.each( function( doc ){
  321. doc.destroy();
  322. }.bind(this))
  323. }
  324. this.wholeDayDocumentList = [];
  325. if( this.oneDayDocumentList && this.oneDayDocumentList.length ){
  326. this.oneDayDocumentList.each( function( doc ){
  327. doc.destroy();
  328. }.bind(this))
  329. }
  330. this.oneDayDocumentList = [];
  331. this.loadBackgroundCalendar( false );
  332. this.loadCalendar();
  333. },
  334. loadDataContainer : function(){
  335. this.dataTableList = [];
  336. this.dataTdList = [];
  337. [0,1,2,3,4,5,6].each( function( i){
  338. var dataTable = new Element("table.dataTable", {
  339. "styles": this.css.calendarTable,
  340. "border": "0",
  341. "cellPadding": "0",
  342. "cellSpacing": "0",
  343. "index" : i
  344. }).inject(this.bodyNode);
  345. dataTable.setStyles({
  346. //"display" : "none",
  347. "position":"absolute",
  348. "top" : (MWFCalendarMonthView.WeekHeight + 1) * i + MWFCalendarMonthView.THHeight + 30,
  349. "left" : "0px",
  350. "margin": "0px auto 0px 0px"
  351. });
  352. var tr = new Element("tr").inject(dataTable);
  353. var dataTd = new Element( "td" , {
  354. "valign" : "top",
  355. "styles" : {"height":"0px","position":"relative"}
  356. }).inject( tr );
  357. this.dataTableList.push( dataTable );
  358. this.dataTdList.push( dataTd );
  359. }.bind(this))
  360. },
  361. calculateMonthRange : function(){
  362. var date = this.date.clone();
  363. var start = new Date( date.get("year"), date.get("month"), 1, 0, 0, 0 );
  364. var week = start.getDay();
  365. if( this.weekBegin == "1" ){
  366. var decrementDay = ((week-1)<0) ? 6 : week-1;
  367. }else{
  368. var decrementDay = week;
  369. }
  370. start.decrement("day", decrementDay);
  371. this.monthStart = start;
  372. this.monthStartStr = this.monthStart.format("db");
  373. var end = start.clone();
  374. end.increment("day", 41);
  375. this.monthEnd = new Date( end.get("year"), end.get("month"), end.get("date"), 23, 59, 59 );
  376. this.monthEndStr = this.monthEnd.format("db");
  377. this.calculateWeekRange();
  378. },
  379. calculateWeekRange: function(){
  380. this.weekRangeList = [];
  381. var start = this.monthStart.clone();
  382. var end;
  383. for( var i=0; i<6; i++ ){
  384. end = start.clone().increment("day", 6);
  385. end = new Date( end.get("year"), end.get("month"), end.get("date"), 23, 59, 59 );
  386. this.weekRangeList.push( {
  387. start : start,
  388. end : end
  389. });
  390. start = end.clone().increment("second",1);
  391. }
  392. this.weekDaysList = [];
  393. start = this.monthStart.clone();
  394. for( var i=0; i<this.weekRangeList.length; i++ ){
  395. var j =0;
  396. var days = [];
  397. while( j<7 ){
  398. days.push( start.format("%Y-%m-%d") );
  399. start.increment("day",1);
  400. j++;
  401. }
  402. this.weekDaysList.push(days);
  403. }
  404. this.usedYIndex = {};
  405. for( var i=0; i<this.weekRangeList.length; i++ ){
  406. this.usedYIndex[i] = {};
  407. var j =0;
  408. while( j<7 ){
  409. this.usedYIndex[i][j] = [];
  410. j++;
  411. }
  412. }
  413. },
  414. getUserfulYIndex : function( weekIndex, dayNumbersOfWeek ){ //获取指定周的y轴上的占用情况
  415. var yIndex = 0;
  416. var flag = true;
  417. var weekUsed = this.usedYIndex[weekIndex];
  418. while( flag ){
  419. var isContains = false;
  420. for( var j = 0; j<dayNumbersOfWeek.length; j++ ){
  421. if( weekUsed[ dayNumbersOfWeek[j]].contains( yIndex ) ){
  422. isContains = true;
  423. break;
  424. }
  425. }
  426. if( !isContains ){
  427. flag = false;
  428. }else{
  429. yIndex ++;
  430. }
  431. }
  432. for( var j = 0; j<dayNumbersOfWeek.length; j++ ){
  433. weekUsed[ dayNumbersOfWeek[j]].push( yIndex );
  434. }
  435. return yIndex;
  436. },
  437. getDateIndex : function( date ) {
  438. var dateStr = date.format("%Y-%m-%d");
  439. for (var i = 0; i < this.weekDaysList.length; i++) {
  440. var index = this.weekDaysList[i].indexOf(dateStr);
  441. if( index > -1 ){
  442. return {
  443. weekIndex: i,
  444. dayIndex: index
  445. }
  446. }
  447. }
  448. return null;
  449. },
  450. getDateIndexOfWeek : function( weekIndex, days ){
  451. var weekDays = this.weekDaysList[weekIndex];
  452. var indexs = [];
  453. for( var i=0; i<days.length;i++ ){
  454. indexs.push( weekDays.indexOf( days[i] ) );
  455. }
  456. return indexs;
  457. },
  458. inCurrentMonth : function( time ){
  459. return time > this.monthStart && time < this.monthEnd;
  460. },
  461. getTimeRange : function( bDate, eDate ){
  462. if( bDate > this.monthEnd || eDate < this.monthStart )return null;
  463. var range = {
  464. startTime : bDate,
  465. endTime : eDate,
  466. start: ( bDate <= this.monthStart ) ? this.monthStart.clone() : bDate.clone(),
  467. end: ( this.monthEnd <= eDate ) ? this.monthEnd.clone() : eDate.clone()
  468. };
  469. range.firstDay = range.start.clone().clearTime();
  470. range.diff = range.start - range.end;
  471. range.weekInforList = this.getWeekInfor(bDate, eDate);
  472. return range;
  473. },
  474. getWeekInfor : function( startTime, endTime ){
  475. if( startTime > this.monthEnd || endTime < this.monthStart )return null;
  476. var rangeWeekInfor = {};
  477. for( var i=0 ; i<this.weekRangeList.length; i++ ){
  478. var range = this.weekRangeList[i];
  479. if(startTime > range.end || endTime < range.start )continue;
  480. var isStart = startTime >= range.start;
  481. var isEnd = range.end >= endTime;
  482. var start = isStart ? startTime : range.start;
  483. var end = isEnd ? endTime : range.end;
  484. var diff = end - start;
  485. var left = start - range.start;
  486. var days = this.getDaysByRange(start, end);
  487. var daysIndex = this.getDateIndexOfWeek( i, days );
  488. rangeWeekInfor[i] = {
  489. index : i,
  490. isEventStart : isStart,
  491. isEventEnd : isEnd,
  492. start : start,
  493. end : end,
  494. diff : diff,
  495. days : days,
  496. left : left,
  497. daysIndex : daysIndex
  498. };
  499. if( isEnd )break;
  500. }
  501. return rangeWeekInfor;
  502. },
  503. getDaysByRange : function( startTime, endTime ){
  504. var start = startTime.clone();
  505. var end = endTime;
  506. var days = [];
  507. while( start < end ){
  508. days.push( start.clone().format("%Y-%m-%d") );
  509. start.increment()
  510. }
  511. return days;
  512. },
  513. loadCalendar: function(){
  514. this.app.currentDate = this.date.clone();
  515. this.calculateMonthRange();
  516. this.cancelCurrentTd();
  517. this.loadData( function(){
  518. this.loadWholeDay( this.wholeDayData );
  519. this.loadOneDay( this.inOneDayEvents );
  520. this.resetBodySize();
  521. }.bind(this));
  522. },
  523. loadBackgroundCalendar: function( isCreate ){
  524. var date = this.date.clone();
  525. date.set("date", 1);
  526. var week = date.getDay();
  527. if( this.weekBegin == "1" ){
  528. var decrementDay = ((week-1)<0) ? 6 : week-1;
  529. }else{
  530. var decrementDay = week;
  531. }
  532. date.decrement("day", decrementDay);
  533. var tds = this.calendarTable.getElements("td");
  534. tds.each(function(td){
  535. this.loadDay(td, date, isCreate);
  536. date.increment();
  537. }.bind(this));
  538. },
  539. loadData : function( callback ){
  540. this.app.actions.listEventWithFilter( {
  541. calendarIds : this.app.getSelectedCalendarId(),
  542. startTime : this.monthStartStr,
  543. endTime : this.monthEndStr //,
  544. //createPerson : this.app.userName
  545. }, function(json){
  546. this.wholeDayData = ( json.data && json.data.wholeDayEvents ) ? json.data.wholeDayEvents : [];
  547. this.inOneDayEvents = [];
  548. (( json.data && json.data.inOneDayEvents) ? json.data.inOneDayEvents : []).each( function( d ){
  549. if(d.inOneDayEvents.length > 0 ){
  550. this.inOneDayEvents.push( d );
  551. }
  552. }.bind(this));
  553. if(callback)callback();
  554. }.bind(this));
  555. },
  556. loadOneDay: function( data ){
  557. this.oneDayDocumentList = [];
  558. data.each( function( d, i ){
  559. d.inOneDayEvents.each( function( event, i ){
  560. this.oneDayDocumentList.push( new MWFCalendarMonthView.Calendar.InOnDayDocument( this, event, d.eventDate ) );
  561. }.bind(this))
  562. }.bind(this))
  563. },
  564. loadWholeDay: function( data ){
  565. this.wholeDayRange = [];
  566. data.each( function( d , i){
  567. var range = this.getTimeRange( Date.parse(d.startTime), Date.parse(d.endTime ) );
  568. if( !range )return;
  569. range.data = d;
  570. this.wholeDayRange.push( range );
  571. }.bind(this));
  572. this.wholeDayRange.sort( function( range1, range2 ){
  573. if( range1.firstDay > range2.firstDay )return 1;
  574. if( range1.firstDay < range2.firstDay )return -1;
  575. return range1.diff - range2.diff;
  576. }.bind(this));
  577. this.wholeDayDocumentList = [];
  578. this.wholeDayRange.each( function( r ){
  579. this.wholeDayDocumentList.push( new MWFCalendarMonthView.Calendar.WholeDayDocument( this, r ) );
  580. }.bind(this))
  581. },
  582. loadDay: function(td, date, isCreate){
  583. var _self = this;
  584. td.empty();
  585. var type = "thisMonth";
  586. var m = date.get("month");
  587. var y = date.get("year");
  588. var d = date.get("date");
  589. var mm = this.date.get("month");
  590. var yy = this.date.get("year");
  591. var mmm = this.today.get("month");
  592. var yyy = this.today.get("year");
  593. var ddd = this.today.get("date");
  594. if ((m==mmm) && (y==yyy) && (d==ddd)){
  595. type = "today";
  596. }else if ((m==mm) && (y==yy)){
  597. type = "thisMonth";
  598. }else{
  599. type = "otherMonth";
  600. }
  601. //var node = new Element("div", {
  602. // "styles" : this.css["calendarTableCell_"+type]
  603. //}).inject( td );
  604. td.set( "valign","top");
  605. td.setStyles( this.css["calendarTableCell_"+type] );
  606. td.store("dateStr",date.format("%Y-%m-%d"));
  607. td.store("type", type );
  608. if( isCreate ){
  609. td.addEvent("click", function(ev){
  610. this.setCurrentTd( td );
  611. }.bind(this));
  612. td.addEvent("dblclick", function(ev){
  613. _self.cancelCurrentTd();
  614. var form = new MWF.xApplication.Calendar.EventForm(_self,{}, {
  615. startTime : Date.parse( this.retrieve("dateStr") + " 08:00") ,
  616. endTime : Date.parse( this.retrieve("dateStr") + " 09:00")
  617. }, {app:_self.app});
  618. form.view = _self;
  619. form.create();
  620. }.bind(td));
  621. new Drag(td, {
  622. "onStart": function(dragged, e){
  623. this.cancelCurrentTd();
  624. this.cellDragStart(dragged, e);
  625. }.bind(this),
  626. "onDrag": function(dragged, e){
  627. this.cellDrag(dragged, e);
  628. }.bind(this),
  629. "onComplete": function(dragged, e){
  630. this.completeDrag(dragged, e);
  631. }.bind(this)
  632. });
  633. }
  634. var titleNode = new Element("div", {"styles": this.css["dayTitle_"+ type]}).inject(td);
  635. var titleDayNode = new Element("div", {"styles": this.css["dayTitleDay_"+ type], "text": d }).inject(titleNode);
  636. titleDayNode.addEvent("click", function(){
  637. _self.app.toDay( this.date );
  638. }.bind({ date : date.format("%Y-%m-%d") }));
  639. if( type === "today" ){
  640. titleDayNode.addClass("mainColor_bg");
  641. }
  642. //var contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(node);
  643. },
  644. setCurrentTd : function(td){
  645. td.setStyle("background-color","#fffdf2");
  646. if( this.currentSelectedTd ){
  647. this.currentSelectedTd.setStyle("background-color",this.currentSelectedTd.retrieve("type")=="today"?"#F8FBFF":"#fff");
  648. }
  649. this.currentSelectedTd = td;
  650. },
  651. cancelCurrentTd : function(){
  652. if( this.currentSelectedTd ){
  653. this.currentSelectedTd.setStyle("background-color",this.currentSelectedTd.retrieve("type")=="today"?"#F8FBFF":"#fff");
  654. }
  655. this.currentSelectedTd = null;
  656. },
  657. //loadDay: function(td, date){
  658. // td.empty();
  659. // var type = "thisMonth";
  660. // var m = date.get("month");
  661. // var y = date.get("year");
  662. // var d = date.get("date");
  663. // var mm = this.date.get("month");
  664. // var yy = this.date.get("year");
  665. // var mmm = this.today.get("month");
  666. // var yyy = this.today.get("year");
  667. // var ddd = this.today.get("date");
  668. //
  669. // if ((m==mmm) && (y==yyy) && (d==ddd)){
  670. // type = "today";
  671. // }else if ((m==mm) && (y==yy)){
  672. // type = "thisMonth";
  673. // }else{
  674. // type = "otherMonth";
  675. // }
  676. //
  677. // var node = new Element("div", {
  678. // "styles" : this.css["calendarTableCell_"+type]
  679. // }).inject( td );
  680. // node.store("dateStr",date.format("%Y-%m-%d"));
  681. //
  682. // node.addEvent("dblclick", function(ev){
  683. // var form = new MWF.xApplication.Calendar.EventForm(this,{}, {
  684. // startTime : Date.parse( ev.target.retrieve("dateStr") + " 08:00") ,
  685. // endTime : Date.parse( ev.target.retrieve("dateStr") + " 09:00")
  686. // }, {app:this.app});
  687. // form.view = this;
  688. // form.create();
  689. // }.bind(this));
  690. //
  691. // new Drag(node, {
  692. // "onStart": function(dragged, e){
  693. // this.cellDragStart(dragged, e);
  694. // }.bind(this),
  695. // "onDrag": function(dragged, e){
  696. // this.cellDrag(dragged, e);
  697. // }.bind(this),
  698. // "onComplete": function(dragged, e){
  699. // this.completeDrag(dragged, e);
  700. // }.bind(this)
  701. // });
  702. //
  703. // var titleNode = new Element("div", {"styles": this.css["dayTitle_"+ type]}).inject(node);
  704. // var titleDayNode = new Element("div", {"styles": this.css["dayTitleDay_"+ type], "text": d }).inject(titleNode);
  705. //
  706. // var contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(node);
  707. //
  708. //},
  709. reload : function(){
  710. this.view.reload();
  711. },
  712. destroy: function(){
  713. Object.each(this.days, function(day){
  714. day.destroy();
  715. }.bind(this));
  716. this.container.empty();
  717. },
  718. getIndexByPage: function( page ){
  719. var pos = this.calendarTable.getPosition();
  720. var col = (page.x - pos.x ) / MWFCalendarMonthView.DayWidth;
  721. if( col < 0 || col > 7 )return null;
  722. this.pageOffsetHeight = page.y - pos.y;
  723. var y = page.y - pos.y - MWFCalendarMonthView.THHeight;
  724. if( y < 0 )return null;
  725. var row = null;
  726. for( var i = 0; i< this.calendarTrHeight.length; i++ ){
  727. if( y < this.calendarTrHeight[i] ){
  728. row = i;
  729. break;
  730. }else{
  731. y = y - this.calendarTrHeight[i];
  732. }
  733. }
  734. if( row != null ){
  735. return {
  736. row : row,
  737. col : Math.floor(col)
  738. }
  739. }else{
  740. return null;
  741. }
  742. },
  743. getTdsByIndexRange : function( index1, index2 ){
  744. if( this.calendarTableTds ){
  745. var tds = this.calendarTableTds;
  746. }else{
  747. var tds = this.calendarTableTds = this.calendarTable.getElements("td");
  748. }
  749. var minIndex, maxIndex;
  750. if( index1.row == index2.row ){
  751. if( index1.col <= index2.col ){
  752. minIndex = index1;
  753. maxIndex = index2;
  754. }else{
  755. minIndex = index2;
  756. maxIndex = index1;
  757. }
  758. }else if( index1.row < index2.row ){
  759. minIndex = index1;
  760. maxIndex = index2;
  761. }else{
  762. minIndex = index2;
  763. maxIndex = index1;
  764. }
  765. var startIndex = minIndex.row * 7 + minIndex.col;
  766. var endIndex = maxIndex.row * 7 + maxIndex.col;
  767. var result = [];
  768. for( var i=startIndex; i<=endIndex; i++ ){
  769. result.push( tds[i] );
  770. }
  771. return result;
  772. },
  773. cellDragStart: function(td, e){
  774. td.store("index", this.getIndexByPage(e.page ) );
  775. this.scrollNodeHeight = this.scrollNode.getSize().y;
  776. },
  777. cellDrag: function(td, e){
  778. var orgIndex = td.retrieve( "index" );
  779. var curIndex = this.getIndexByPage( e.page );
  780. if( !curIndex )return;
  781. var tds = this.getTdsByIndexRange( orgIndex, curIndex );
  782. if( this.selectedTds ){
  783. this.selectedTds.each( function( td ){
  784. var type = td.retrieve("type");
  785. if( !tds.contains(td) )td.setStyle("background-color", type == "today" ? "#F8FBFF" : "#fff");
  786. }.bind(this));
  787. tds.each( function( td ){
  788. if( !this.selectedTds.contains(td) )td.setStyle("background-color", "#fffdf2");
  789. }.bind(this))
  790. }else{
  791. tds.each( function(td){
  792. td.setStyle("background-color", "#fffdf2");
  793. }.bind(this))
  794. }
  795. var scrollNodeTop = this.scrollNode.getScroll().y;
  796. if(( this.pageOffsetHeight + MWFCalendarMonthView.WeekHeight * 1.5) > ( this.scrollNodeHeight + scrollNodeTop )){
  797. window.setTimeout( function(){
  798. this.scrollNode.scrollTo(0, scrollNodeTop + MWFCalendarMonthView.WeekHeight )
  799. }.bind(this), 200)
  800. }else if( this.pageOffsetHeight - MWFCalendarMonthView.WeekHeight * 1.5 < scrollNodeTop ){
  801. window.setTimeout( function(){
  802. this.scrollNode.scrollTo(0, scrollNodeTop - MWFCalendarMonthView.WeekHeight )
  803. }.bind(this), 200)
  804. }
  805. this.selectedTds = tds
  806. },
  807. completeDrag: function(td, e){
  808. if( this.selectedTds && this.selectedTds.length ){
  809. this.selectedTds.each( function( td ){
  810. var type = td.retrieve("type");
  811. td.setStyle("background-color", type == "today" ? "#F8FBFF" : "#fff");
  812. }.bind(this));
  813. var startTime = this.selectedTds[0].retrieve("dateStr");
  814. var endTime = this.selectedTds.getLast().retrieve("dateStr");
  815. var form = new MWF.xApplication.Calendar.EventForm(this,{}, {
  816. startTime : startTime ,
  817. endTime : endTime,
  818. isWholeday : true
  819. }, {app:this.app});
  820. form.view = this;
  821. form.create();
  822. this.selectedTds = null;
  823. }
  824. }
  825. });
  826. MWFCalendarMonthView.THHeight = 50;
  827. MWFCalendarMonthView.WeekHeight = 140;
  828. MWFCalendarMonthView.WeekWidth;
  829. MWFCalendarMonthView.DayWidth;
  830. MWFCalendarMonthView.Calendar.WholeDayDocument = new Class({
  831. Implements: [Events],
  832. initialize: function(calendar, range){
  833. this.calendar = calendar;
  834. this.view = this.calendar.view;
  835. this.css = this.calendar.css;
  836. this.app = this.calendar.app;
  837. this.range = range;
  838. this.load();
  839. },
  840. load: function(){
  841. this.weekList = [];
  842. Object.each( this.range.weekInforList, function( weekInfor ){
  843. this.weekList.push( new MWFCalendarMonthView.Calendar.WholeDayWeek(this, weekInfor, this.range.data ) )
  844. }.bind(this))
  845. },
  846. setMouseOver : function(){
  847. this.weekList.each( function( week ){
  848. week.mouseover();
  849. }.bind(this))
  850. },
  851. setMouseOut : function(){
  852. this.weekList.each( function( week ){
  853. week.mouseout();
  854. }.bind(this))
  855. },
  856. resize : function(){
  857. this.weekList.each( function( week ){
  858. week.resize();
  859. }.bind(this))
  860. },
  861. destroy : function(){
  862. this.weekList.each( function( week ){
  863. week.destroy();
  864. }.bind(this))
  865. }
  866. });
  867. MWFCalendarMonthView.Calendar.WholeDayWeek = new Class({
  868. Implements: [Events],
  869. initialize: function(document, weekInfor, data){
  870. this.document = document;
  871. this.calendar = document.calendar;
  872. this.view = this.calendar.view;
  873. this.css = this.calendar.css;
  874. this.app = this.calendar.app;
  875. this.weekInfor = weekInfor;
  876. this.data = data;
  877. this.load();
  878. },
  879. load: function(){
  880. this.timeStart = Date.parse( this.data.startTime );
  881. this.timeEnd = Date.parse( this.data.endTime );
  882. this.yIndex = this.calendar.getUserfulYIndex( this.weekInfor.index, this.weekInfor.daysIndex );
  883. this.container = this.getContainer();
  884. this.createNode();
  885. },
  886. createNode : function(){
  887. var lightColor = this.lightColor = MWFCalendar.ColorOptions.getLightColor( this.data.color );
  888. var node = this.node = new Element("div",{
  889. styles : {
  890. position : "absolute",
  891. "overflow" : "hidden",
  892. "height" : "20px",
  893. "line-height" : "20px",
  894. "border-top" : "1px solid " + lightColor,
  895. "border-bottom" : "1px solid " + lightColor,
  896. "background-color": lightColor
  897. },
  898. events : {
  899. click : function(){
  900. var form = new MWF.xApplication.Calendar.EventForm(this, this.data, {
  901. isFull : true
  902. }, {app:this.app});
  903. form.view = this.view;
  904. this.calendar.app.isEventEditable(this.data) ? form.edit() : form.open();
  905. }.bind(this),
  906. mouseover : function(){
  907. this.document.setMouseOver();
  908. }.bind(this),
  909. mouseout : function(){
  910. this.document.setMouseOut();
  911. }.bind(this)
  912. }
  913. }).inject( this.container );
  914. var coordinate = this.getCoordinate();
  915. node.setStyles(coordinate);
  916. if( this.weekInfor.isEventStart ){
  917. node.setStyles({
  918. "border-left" : "1px solid " + lightColor,
  919. "border-top-left-radius" : "10px",
  920. "border-bottom-left-radius" : "10px"
  921. })
  922. }
  923. if( this.weekInfor.isEventEnd ){
  924. node.setStyles({
  925. "border-right" : "1px solid " + lightColor,
  926. "border-top-right-radius" : "10px",
  927. "border-bottom-right-radius" : "10px"
  928. })
  929. }
  930. if( this.weekInfor.isEventStart ){
  931. this.timeNode = new Element("div",{
  932. styles : {
  933. "font-size" : "10px",
  934. "padding-left" : "2px",
  935. "float" : "left"
  936. },
  937. text : this.timeStart.format("%m-%d %H:%M") + MWF.xApplication.Calendar.LP.to + this.timeEnd.format("%m-%d %H:%M")
  938. }).inject( node );
  939. }
  940. this.titleNode = new Element("div",{
  941. styles : {
  942. "padding-left" : "5px",
  943. "font-size" : "12px",
  944. "float" : "left",
  945. "overflow" : "hidden",
  946. "text-overflow" : "ellipsis",
  947. "white-space" : "nowrap"
  948. },
  949. text : this.data.title
  950. }).inject( node );
  951. this.titleNode.setStyle("width", coordinate.width - ( this.timeNode ? this.timeNode.getSize().x : 0 ) -6 );
  952. //}
  953. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  954. axis : "y", "delay" : 350
  955. });
  956. this.tooltip.view = this.view;
  957. },
  958. getContainer : function(){
  959. return this.calendar.dataTdList[ this.weekInfor.index ]
  960. },
  961. getCoordinate : function(){
  962. var data = this.data;
  963. var infor = this.weekInfor;
  964. var top = this.yIndex * 24;
  965. var width = ( infor.daysIndex.length / 7 ) * MWFCalendarMonthView.WeekWidth - 3;
  966. var left = ( infor.daysIndex[0] / 7 ) * MWFCalendarMonthView.WeekWidth;
  967. //var width = ( infor.diff / MWFCalendarMonthView.WeekMsec ) * MWFCalendarMonthView.WeekWidth - 2;
  968. //var left = ( infor.left / MWFCalendarMonthView.WeekMsec ) * MWFCalendarMonthView.WeekWidth + 3;
  969. return {
  970. top : top + 2,
  971. left : left,
  972. width : width
  973. }
  974. },
  975. mouseover : function(){
  976. this.node.setStyle("border-color", this.data.color );
  977. },
  978. mouseout : function(){
  979. this.node.setStyle("border-color", this.lightColor );
  980. },
  981. resize : function(){
  982. // this.node.setStyles(this.getCoordinate());
  983. var coordinate = this.getCoordinate();
  984. this.node.setStyles( coordinate );
  985. this.titleNode.setStyle("width", coordinate.width - ( this.timeNode ? this.timeNode.getSize().x : 0 ) - 6 );
  986. },
  987. reload: function(){
  988. if( this.tooltip )this.tooltip.destroy();
  989. this.view.reload();
  990. },
  991. destroy : function(){
  992. if( this.tooltip )this.tooltip.destroy();
  993. this.node.destroy();
  994. }
  995. });
  996. MWFCalendarMonthView.Calendar.InOnDayDocument = new Class({
  997. Implements: [Events],
  998. initialize: function(calendar, data, dateStr){
  999. this.calendar = calendar;
  1000. this.view = this.calendar.view;
  1001. this.css = this.calendar.css;
  1002. this.app = this.calendar.app;
  1003. this.data = data;
  1004. this.dateStr = dateStr;
  1005. this.date = Date.parse( dateStr );
  1006. this.load();
  1007. },
  1008. load: function(){
  1009. this.timeStart = Date.parse( this.data.startTime );
  1010. this.timeEnd = Date.parse( this.data.endTime );
  1011. this.index = this.calendar.getDateIndex( this.date );
  1012. this.yIndex = this.calendar.getUserfulYIndex( this.index.weekIndex, [this.index.dayIndex] );
  1013. this.container = this.getContainer();
  1014. this.createNode();
  1015. },
  1016. createNode : function(){
  1017. var lightColor = this.lightColor = MWFCalendar.ColorOptions.getLightColor( this.data.color );
  1018. var node = this.node = new Element("div",{
  1019. styles : {
  1020. position : "absolute",
  1021. border : "1px solid "+lightColor,
  1022. "background-color" : lightColor,
  1023. "overflow" : "hidden",
  1024. "height" : "20px",
  1025. "line-height" : "20px",
  1026. "border-radius" : "10px"
  1027. },
  1028. events : {
  1029. click : function(){
  1030. var form = new MWF.xApplication.Calendar.EventForm(this, this.data, {
  1031. isFull : true
  1032. }, {app:this.app});
  1033. form.view = this.view;
  1034. this.app.isEventEditable(this.data) ? form.edit() : form.open();
  1035. }.bind(this),
  1036. "mouseover" : function () {
  1037. this.node.setStyle("border-color", this.data.color );
  1038. }.bind(this),
  1039. "mouseout" : function () {
  1040. this.node.setStyle("border-color", this.lightColor );
  1041. }.bind(this)
  1042. }
  1043. }).inject( this.container );
  1044. var coordinate = this.getCoordinate();
  1045. node.setStyles(coordinate);
  1046. //if( this.isFirst ){
  1047. this.timeNode = new Element("div",{
  1048. styles : {
  1049. "font-size" : "10px",
  1050. "padding-left" : "2px",
  1051. "float" : "left"
  1052. },
  1053. text : this.timeStart.format("%H:%M") + MWF.xApplication.Calendar.LP.to + this.timeEnd.format("%H:%M")
  1054. }).inject( node );
  1055. this.titleNode = new Element("div",{
  1056. styles : {
  1057. "padding-left" : "5px",
  1058. "font-size" : "12px",
  1059. "float" : "left",
  1060. "overflow" : "hidden",
  1061. "text-overflow" : "ellipsis",
  1062. "white-space" : "nowrap"
  1063. },
  1064. text : this.data.title
  1065. }).inject( node );
  1066. this.titleNode.setStyle("width", coordinate.width - this.timeNode.getSize().x - 6 );
  1067. //}
  1068. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  1069. axis : "y", "delay" : 350
  1070. });
  1071. this.tooltip.view = this.view;
  1072. },
  1073. getContainer : function(){
  1074. return this.calendar.dataTdList[ this.index.weekIndex ]
  1075. },
  1076. getCoordinate : function(){
  1077. var data = this.data;
  1078. var top = this.yIndex * 24;
  1079. var width = MWFCalendarMonthView.DayWidth - 3;
  1080. var left = this.index.dayIndex * MWFCalendarMonthView.DayWidth;
  1081. //var width = ( infor.diff / MWFCalendarMonthView.WeekMsec ) * MWFCalendarMonthView.WeekWidth - 2;
  1082. //var left = ( infor.left / MWFCalendarMonthView.WeekMsec ) * MWFCalendarMonthView.WeekWidth + 3;
  1083. return {
  1084. top : top + 2,
  1085. left : left,
  1086. width : width
  1087. }
  1088. },
  1089. resize : function(){
  1090. var coordinate = this.getCoordinate();
  1091. this.node.setStyles( coordinate );
  1092. this.titleNode.setStyle("width", coordinate.width - this.timeNode.getSize().x - 6 );
  1093. },
  1094. reload: function(){
  1095. if( this.tooltip )this.tooltip.destroy();
  1096. this.view.reload();
  1097. },
  1098. destroy : function(){
  1099. if( this.tooltip )this.tooltip.destroy();
  1100. this.node.destroy();
  1101. }
  1102. });
  1103. MWFCalendarMonthView.Document = new Class({
  1104. initialize: function(day, data, index){
  1105. this.day = day;
  1106. this.css = this.day.css;
  1107. this.view = this.day.view;
  1108. this.app = this.day.app;
  1109. this.container = this.day.contentNode;
  1110. this.data = data;
  1111. this.index = index;
  1112. this.load();
  1113. },
  1114. load: function(){
  1115. this.nodeStyles = (this.day.type == "today") ? this.css.calendarNode_today : this.css.calendarNode;
  1116. this.node = new Element("div", {
  1117. "styles": this.nodeStyles
  1118. }).inject(this.container);
  1119. this.iconNode = new Element("div", {"styles": this.css.calendarIconNode}).inject(this.node);
  1120. this.timeNode = new Element("div", {"styles": this.css.calendarTimeNode}).inject(this.node);
  1121. this.textNode = new Element("div", {"styles": this.css.calendarTextNode}).inject(this.node);
  1122. var timeStr = Date.parse(this.data.startTime).format("%H:%M");
  1123. this.timeNode.set("text", timeStr);
  1124. this.textNode.set("text", this.data.subject);
  1125. //this.node.set("title", this.data.subject);
  1126. //
  1127. //if (this.data.myWaitAccept){
  1128. // this.iconNode.setStyle("background", "url(../x_component_Calendar/$MonthView/"+this.app.options.style+"/icon/invite.png) no-repeat center center");
  1129. //}
  1130. this.node.addEvents({
  1131. mouseenter : function(){
  1132. this.day.collapseReady = false;
  1133. this.node.setStyles( this.css.calendarNode_over );
  1134. //this.showTooltip();
  1135. }.bind(this),
  1136. mouseleave : function(){
  1137. this.node.setStyles( this.nodeStyles );
  1138. }.bind(this),
  1139. "click": function(){this.openCalendar();}.bind(this)
  1140. });
  1141. this.loadTooltip();
  1142. },
  1143. loadTooltip : function(){
  1144. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  1145. axis : "x",
  1146. hiddenDelay : 300,
  1147. displayDelay : 300,
  1148. onShow : function(){
  1149. this.day.collapseDisable = true;
  1150. }.bind(this),
  1151. onQueryCreate : function(){
  1152. this.day.collapseDisable = true;
  1153. }.bind(this),
  1154. onHide : function(){
  1155. this.day.collapseDisable = false;
  1156. this.day.collapse();
  1157. }.bind(this)
  1158. });
  1159. this.tooltip.view = this.view;
  1160. },
  1161. showTooltip: function( ){
  1162. //if( this.index > 3 && this.day.isCollapse ){
  1163. //}else{
  1164. if( this.tooltip ){
  1165. this.tooltip.load();
  1166. }else{
  1167. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  1168. axis : "x", "delay" : 150
  1169. //onShow : function(){
  1170. // this.day.collapseDisable = true;
  1171. //}.bind(this),
  1172. //onQueryCreate : function(){
  1173. // this.day.collapseDisable = true;
  1174. //}.bind(this),
  1175. //onHide : function(){
  1176. // this.day.collapseDisable = false;
  1177. //}.bind(this)
  1178. });
  1179. this.tooltip.view = this.view;
  1180. this.tooltip.load();
  1181. }
  1182. //}
  1183. },
  1184. openCalendar: function(){
  1185. this.form = new MWF.xApplication.Calendar.CalendarForm(this,this.data, {}, {app:this.app});
  1186. this.form.view = this;
  1187. this.form.open();
  1188. },
  1189. destroy: function(){
  1190. if(this.tooltip)this.tooltip.destroy();
  1191. this.node.destroy();
  1192. MWF.release(this);
  1193. },
  1194. reload: function(){
  1195. this.view.reload();
  1196. }
  1197. });
  1198. MWFCalendarMonthView.MonthSelector = new Class({
  1199. Implements: [Events],
  1200. initialize: function(date, calendar){
  1201. this.calendar = calendar;
  1202. this.css = this.calendar.css;
  1203. this.app = this.calendar.app;
  1204. this.date = date;
  1205. this.year = this.date.get("year");
  1206. this.load();
  1207. },
  1208. load: function(){
  1209. this.monthSelectNode = new Element("div", {"styles": this.css.calendarMonthSelectNode}).inject(this.calendar.container);
  1210. this.monthSelectNode.position({
  1211. relativeTo: this.calendar.titleTextNode,
  1212. position: 'bottomCenter',
  1213. edge: 'upperCenter'
  1214. });
  1215. this.monthSelectNode.addEvent("mousedown", function(e){e.stopPropagation();});
  1216. this.monthSelectTitleNode = new Element("div", {"styles": this.css.calendarMonthSelectTitleNode}).inject(this.monthSelectNode);
  1217. // this.monthSelectTitleNode.addClass("overColor_bg");
  1218. this.monthSelectPrevYearNode = new Element("div.o2icon-triangle_left", {"styles": this.css.calendarMonthSelectTitlePrevYearNode}).inject(this.monthSelectTitleNode);
  1219. this.monthSelectNextYearNode = new Element("div.o2icon-triangle_right", {"styles": this.css.calendarMonthSelectTitleNextYearNode}).inject(this.monthSelectTitleNode);
  1220. this.monthSelectTextNode = new Element("div.MWF_calendar_current", {"styles": this.css.calendarMonthSelectTitleTextNode}).inject(this.monthSelectTitleNode);
  1221. this.monthSelectTextNode.set("text", this.year);
  1222. var html = "<tr><td></td><td></td><td></td></tr>";
  1223. html += "<tr><td></td><td></td><td></td></tr>";
  1224. html += "<tr><td></td><td></td><td></td></tr>";
  1225. html += "<tr><td></td><td></td><td></td></tr>";
  1226. this.monthSelectTable = new Element("table", {
  1227. "styles": {"margin-top": "10px"},
  1228. "height": "200px",
  1229. "width": "90%",
  1230. "align": "center",
  1231. "border": "0",
  1232. "cellPadding": "0",
  1233. "cellSpacing": "0", //5
  1234. "html": html
  1235. }).inject(this.monthSelectNode);
  1236. //this.loadMonth();
  1237. this.monthSelectBottomNode = new Element("div", {"styles": this.css.calendarMonthSelectBottomNode, "text": this.app.lp.today}).inject(this.monthSelectNode);
  1238. this.setEvent();
  1239. },
  1240. loadMonth: function(){
  1241. this.monthSelectTextNode.set("text", this.year);
  1242. var d = new Date();
  1243. var todayY = d.get("year");
  1244. var todayM = d.get("month");
  1245. var thisY = this.date.get("year");
  1246. var thisM = this.date.get("month");
  1247. var _self = this;
  1248. var tds = this.monthSelectTable.getElements("td");
  1249. tds.each(function(td, idx){
  1250. td.empty();
  1251. td.removeEvents("mouseover");
  1252. td.removeEvents("mouseout");
  1253. td.removeEvents("mousedown");
  1254. td.removeEvents("mouseup");
  1255. td.removeEvents("click");
  1256. var m = idx+1;
  1257. td.store("month", m);
  1258. td.setStyles(this.css.calendarMonthSelectTdNode);
  1259. td.setStyle("background-color", "#FFF");
  1260. if ((this.year == todayY) && (idx == todayM)){
  1261. new Element("div", {
  1262. class: "mainColor_bg",
  1263. styles : _self.css.calendarMonthSelectTodayNode,
  1264. text : ""+m+ (MWF.language.substr(0,2) === "zh" ? this.app.lp.month : "")
  1265. }).inject( td );
  1266. }else if ((this.year == thisY) && (idx == thisM)){
  1267. //td.setStyle("background-color", "#EEE");
  1268. new Element("div", {
  1269. class: "mainColor_border mainColor_color",
  1270. styles : _self.css.calendarMonthSelectCurrentNode,
  1271. text : ""+m+ (MWF.language.substr(0,2) === "zh" ? this.app.lp.month : "")
  1272. }).inject( td );
  1273. }else{
  1274. td.set("text", ""+m+ (MWF.language.substr(0,2) === "zh" ? this.app.lp.month : ""));
  1275. }
  1276. td.addEvents({
  1277. "mouseover": function(){this.setStyles(_self.css.calendarMonthSelectTdNode_over);},
  1278. "mouseout": function(){this.setStyles(_self.css.calendarMonthSelectTdNode);},
  1279. "mousedown": function(){this.setStyles(_self.css.calendarMonthSelectTdNode_down);},
  1280. "mouseup": function(){this.setStyles(_self.css.calendarMonthSelectTdNode_over);},
  1281. "click": function(){
  1282. _self.selectedMonth(this);
  1283. }
  1284. });
  1285. }.bind(this));
  1286. },
  1287. setEvent: function(){
  1288. this.monthSelectPrevYearNode.addEvent("click", function(){
  1289. this.prevYear();
  1290. }.bind(this));
  1291. this.monthSelectNextYearNode.addEvent("click", function(){
  1292. this.nextYear();
  1293. }.bind(this));
  1294. this.monthSelectBottomNode.addEvents({
  1295. "mouuseover" : function(){ this.monthSelectBottomNode.setStyles( this.css.calendarMonthSelectBottomNode_over ); }.bind(this),
  1296. "mouuseout" : function(){ this.monthSelectBottomNode.setStyles( this.css.calendarMonthSelectBottomNode ); }.bind(this),
  1297. "click" : function(){ this.todayMonth(); }.bind(this)
  1298. });
  1299. },
  1300. prevYear: function(){
  1301. this.year--;
  1302. if (this.year<1900) this.year=1900;
  1303. this.monthSelectTextNode.set("text", this.year);
  1304. this.loadMonth();
  1305. },
  1306. nextYear: function(){
  1307. this.year++;
  1308. //if (this.year<1900) this.year=1900;
  1309. this.monthSelectTextNode.set("text", this.year);
  1310. this.loadMonth();
  1311. },
  1312. todayMonth: function(){
  1313. var d = new Date();
  1314. this.calendar.changeMonthTo(d);
  1315. this.hide();
  1316. },
  1317. selectedMonth: function(td){
  1318. var m = td.retrieve("month");
  1319. var d = Date.parse(this.year+"/"+m+"/1");
  1320. this.calendar.changeMonthTo(d);
  1321. this.hide();
  1322. },
  1323. show: function(){
  1324. this.date = this.calendar.date;
  1325. this.year = this.date.get("year");
  1326. this.loadMonth();
  1327. this.monthSelectNode.setStyle("display", "block");
  1328. this.hideFun = this.hide.bind(this);
  1329. document.body.addEvent("mousedown", this.hideFun);
  1330. },
  1331. hide: function(){
  1332. this.monthSelectNode.setStyle("display", "none");
  1333. document.body.removeEvent("mousedown", this.hideFun);
  1334. },
  1335. destroy: function(){
  1336. //this.titleNode.destroy();
  1337. //this.titleNode = null;
  1338. //this.titleDayNode = null;
  1339. //this.titleInforNode = null;
  1340. //
  1341. //delete this.calendar.days[this.key];
  1342. //
  1343. //this.node.empty();
  1344. //MWF.release(this);
  1345. }
  1346. });