MonthView.js 52 KB

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