DayView.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. MWF.require("MWF.widget.Calendar", null, false);
  2. var MWFCalendarDayView = MWF.xApplication.Calendar.DayView = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "date" : ""
  8. },
  9. initialize: function(node, app, options){
  10. this.setOptions(options);
  11. this.path = "../x_component_Calendar/$DayView/";
  12. this.cssPath = "../x_component_Calendar/$DayView/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.app = app;
  15. this.container = $(node);
  16. this.weekBegin = this.app.calendarConfig.weekBegin || "0";
  17. this.load();
  18. },
  19. load: function(){
  20. this.node = new Element("div.node", {"styles": this.css.node}).inject(this.container);
  21. this.node.setStyle("position","relative");
  22. //this.loadSideBar();
  23. this.resetNodeSize();
  24. //this.app.addEvent("resize", this.resetNodeSize.bind(this));
  25. this.loadCalendar();
  26. },
  27. resetNodeSize: function(){
  28. //if( this.app.inContainer )return;
  29. var size = this.container.getSize();
  30. var y = size.y-50;
  31. this.node.setStyle("height", ""+y+"px");
  32. //this.node.setStyle("margin-top", "60px");
  33. if( this.calendar ){
  34. this.calendar.resetBodySize()
  35. }
  36. },
  37. loadCalendar: function(){
  38. var date = "";
  39. if( this.options.date ){
  40. date = Date.parse( this.options.date )
  41. }else{
  42. date = new Date();
  43. }
  44. this.calendar = new MWFCalendarDayView.Calendar(this, date );
  45. },
  46. hide: function(){
  47. var fx = new Fx.Morph(this.node, {
  48. "duration": "300",
  49. "transition": Fx.Transitions.Expo.easeOut
  50. });
  51. fx.start({
  52. "opacity": 0
  53. }).chain(function(){
  54. this.node.setStyle("display", "none");
  55. }.bind(this));
  56. },
  57. show: function(){
  58. this.node.setStyles(this.css.node);
  59. var fx = new Fx.Morph(this.node, {
  60. "duration": "800",
  61. "transition": Fx.Transitions.Expo.easeOut
  62. });
  63. //this.app.fireAppEvent("resize");
  64. fx.start({
  65. "opacity": 1
  66. //"left": MWFCalendar.LeftNaviWidth+"px"
  67. }).chain(function(){
  68. //this.node.setStyles({
  69. // "position": "static",
  70. // "width": "auto"
  71. //});
  72. if( this.calendar.dataTable_wholeDay ){
  73. this.calendar.dataTable_wholeDay.setStyle("display","");
  74. }
  75. }.bind(this));
  76. },
  77. reload: function(){
  78. if (this.calendar) this.calendar.reLoadCalendar();
  79. },
  80. recordStatus : function(){
  81. return {
  82. date : (this.calendar && this.calendar.date) ? this.calendar.date.format( "db" ) : ""
  83. };
  84. },
  85. destroy: function(){
  86. if (this.calendar){
  87. this.calendar.destroy();
  88. }
  89. this.node.destroy();
  90. //MWF.release( this );
  91. }
  92. });
  93. MWFCalendarDayView.DayWidth;
  94. MWFCalendarDayView.HourHeight = 48;
  95. MWFCalendarDayView.DayHeight = MWFCalendarDayView.HourHeight*24;
  96. MWFCalendarDayView.DayMsec = 3600 * 24 * 1000;
  97. MWFCalendarDayView.Calendar = new Class({
  98. Implements: [Events],
  99. initialize: function(view, date){
  100. this.view = view;
  101. this.css = this.view.css;
  102. this.container = this.view.node;
  103. this.app = this.view.app;
  104. this.lp = this.app.lp;
  105. this.date = date || new Date();
  106. this.today = new Date();
  107. this.load();
  108. },
  109. load: function(){
  110. this.startTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 0, 0, 0 );
  111. this.startTimeStr = this.startTime.format( "db" );
  112. this.endTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 23, 59, 59 );
  113. this.endTimeStr = this.endTime.format( "db" );
  114. this.titleNode = new Element("div", {"styles": this.css.calendarTitleNode}).inject(this.container);
  115. this.titleTable = new Element("table", {
  116. "styles": this.css.titleTable,
  117. "border": "0",
  118. "cellPadding": "0",
  119. "cellSpacing": "0"
  120. }).inject(this.container);
  121. this.scrollNode = new Element("div.scrollNode", {
  122. "styles": this.css.scrollNode //this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode
  123. }).inject(this.container);
  124. this.contentWarpNode = new Element("div.contentWarpNode", {
  125. "styles": this.css.contentWarpNode
  126. }).inject(this.scrollNode);
  127. this.contentContainerNode = new Element("div.contentContainerNode",{
  128. "styles" : this.css.contentContainerNode
  129. }).inject(this.contentWarpNode);
  130. this.bodyNode = new Element("div.bodyNode", {
  131. "styles": this.css.contentNode
  132. }).inject(this.contentContainerNode);
  133. //this.bodyNode = new Element("div", {"styles": this.css.calendarBodyNode}).inject(this.container);
  134. this.setTitleNode();
  135. this.loadTitleTable();
  136. this.loadBodyTable();
  137. //this.resetBodySize();
  138. this.loadDataTable_wholeDay();
  139. this.loadDataTable();
  140. this.loadCalendar();
  141. },
  142. setTitleNode: function(){
  143. this.prevDayNode = new Element("div.o2icon-triangle_left", {"styles": this.css.calendarPrevDayNode}).inject(this.titleNode);
  144. var text = this.date.format(this.lp.dateFormatDay) + "," + this.lp.weeks.arr[ this.date.getDay() ];
  145. this.titleTextNode = new Element("div", {"styles": this.css.calendarTitleTextNode, "text": text}).inject(this.titleNode);
  146. this.nextDayNode = new Element("div.o2icon-triangle_right", {"styles": this.css.calendarNextDayNode}).inject(this.titleNode);
  147. this.prevDayNode.addEvents({
  148. "mouseover": function(){
  149. this.prevDayNode.setStyles(this.css.calendarPrevDayNode_over);
  150. this.prevDayNode.addClass("mainColor_color");
  151. }.bind(this),
  152. "mouseout": function(){
  153. this.prevDayNode.setStyles(this.css.calendarPrevDayNode);
  154. this.prevDayNode.removeClass("mainColor_color");
  155. }.bind(this),
  156. "mousedown": function(){this.prevDayNode.setStyles(this.css.calendarPrevDayNode_down);}.bind(this),
  157. "mouseup": function(){this.prevDayNode.setStyles(this.css.calendarPrevDayNode_over);}.bind(this),
  158. "click": function(){this.changeDayPrev();}.bind(this)
  159. });
  160. this.nextDayNode.addEvents({
  161. "mouseover": function(){
  162. this.nextDayNode.setStyles(this.css.calendarNextDayNode_over);
  163. this.nextDayNode.addClass("mainColor_color");
  164. }.bind(this),
  165. "mouseout": function(){
  166. this.nextDayNode.setStyles(this.css.calendarNextDayNode);
  167. this.nextDayNode.removeClass("mainColor_color");
  168. }.bind(this),
  169. "mousedown": function(){this.nextDayNode.setStyles(this.css.calendarNextDayNode_down);}.bind(this),
  170. "mouseup": function(){this.nextDayNode.setStyles(this.css.calendarNextDayNode_over);}.bind(this),
  171. "click": function(){this.changeDayNext();}.bind(this)
  172. });
  173. this.titleTextNode.addEvents({
  174. "mouseover": function(){
  175. this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);
  176. this.titleTextNode.addClass("mainColor_color");
  177. }.bind(this),
  178. "mouseout": function(){
  179. this.titleTextNode.setStyles(this.css.calendarTitleTextNode);
  180. this.titleTextNode.removeClass("mainColor_color");
  181. }.bind(this),
  182. "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  183. "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this)
  184. //"click": function(){this.changeDaySelect();}.bind(this)
  185. });
  186. this.createDaySelector();
  187. },
  188. changeDayPrev: function(){
  189. this.date.decrement("day", 1);
  190. var text = this.date.format(this.lp.dateFormatDay) + "," + this.lp.weeks.arr[ this.date.getDay() ];
  191. this.titleTextNode.set("text", text);
  192. this.reLoadCalendar();
  193. },
  194. changeDayNext: function(){
  195. this.date.increment("day", 1);
  196. var text = this.date.format(this.lp.dateFormatDay) + "," + this.lp.weeks.arr[ this.date.getDay() ];
  197. this.titleTextNode.set("text", text);
  198. this.reLoadCalendar();
  199. },
  200. changeDaySelect: function(){
  201. if (!this.monthSelector) this.createDaySelector();
  202. //this.monthSelector.show();
  203. },
  204. createDaySelector: function(){
  205. MWF.require("MWF.widget.Calendar", function(){
  206. this.calendar = new MWF.widget.Calendar(this.titleTextNode, {
  207. "style":"meeting_blue",
  208. "target": this.node,
  209. "baseDate" : this.date,
  210. "todayClass": "mainColor_bg",
  211. "onQueryComplate": function(e, dv, date){
  212. var selectedDate = new Date.parse(dv);
  213. this.changeDayTo(selectedDate);
  214. }.bind(this)
  215. });
  216. }.bind(this));
  217. },
  218. changeDayTo: function(d){
  219. this.date = d;
  220. var text = this.date.format(this.lp.dateFormatDay) + "," + this.lp.weeks.arr[ this.date.getDay() ];
  221. this.titleTextNode.set("text", text);
  222. this.reLoadCalendar();
  223. },
  224. isToday : function( d ){
  225. var today = new Date();
  226. if( today.get("year") != d.get("year") )return false;
  227. if( today.get("month") != d.get("month") )return false;
  228. if( today.get("date") != d.get("date") )return false;
  229. return true;
  230. },
  231. isSameday : function( d1, d2 ){
  232. if( d1.get("year") != d2.get("year") )return false;
  233. if( d1.get("month") != d2.get("month") )return false;
  234. if( d1.get("date") != d2.get("date") )return false;
  235. return true;
  236. },
  237. loadTitleTable: function(){
  238. if( !this.wholeDayTd ){
  239. var tr = new Element( "tr").inject( this.titleTable );
  240. var td = new Element( "td.calendarTableCell", {
  241. "tdType" : "hour",
  242. styles : this.css.calendarTableCell_hour
  243. } ).inject( tr );
  244. td.setStyle("min-height","80px");
  245. var node = new Element("div",{
  246. text : this.lp.allDay
  247. }).inject( td );
  248. this.wholeDayTd = new Element( "td" , {
  249. "tdType" : "calendar",
  250. "styles" : this.css.calendarTableCell
  251. }).inject( tr );
  252. this.wholeDayTd.addEvent("click", function(ev){
  253. this.setCurrentTd( this.wholeDayTd );
  254. }.bind(this));
  255. this.wholeDayTd.addEvent("dblclick", function(ev){
  256. this.cancelCurrentTd();
  257. var dateStr = this.date.format("%Y-%m-%d");
  258. var form = new MWF.xApplication.Calendar.EventForm(this,{}, {
  259. startTime : Date.parse( ev.target.retrieve("dateStr")) ,
  260. endTime : Date.parse( ev.target.retrieve("dateStr")),
  261. isWholeday : true
  262. }, {app:this.app});
  263. form.view = this;
  264. form.create();
  265. }.bind(this));
  266. }
  267. },
  268. loadBodyTable: function(){
  269. this.calendarTable = new Element("table", {
  270. "styles": this.css.calendarTable,
  271. "height": "100%",
  272. "border": "0",
  273. "cellPadding": "0",
  274. "cellSpacing": "0"
  275. }).inject(this.bodyNode);
  276. this.hourTdMap = {};
  277. for( var i=0; i<24; i++ ){
  278. var tr = new Element( "tr").inject( this.calendarTable );
  279. var td = new Element( "td.calendarTableCell", {
  280. "tdType" : "hour",
  281. styles : this.css.calendarTableCell_hour,
  282. valign : "top"
  283. } ).inject( tr );
  284. var node = new Element("div",{
  285. text : i + ":00"
  286. }).inject( td );
  287. td.store("hour",i );
  288. td = this.hourTdMap[i] = new Element( "td" , {
  289. "tdType" : "calendar",
  290. "styles" : this.css.calendarTableCell
  291. }).inject( tr );
  292. td.store("hour",i );
  293. td.addEvent("click", function(ev){
  294. this.setCurrentTd( ev.target );
  295. }.bind(this));
  296. td.addEvent("dblclick", function(ev){
  297. this.cancelCurrentTd();
  298. var hour = ev.target.retrieve("hour");
  299. var dateStr = this.date.format( "%Y-%m-%d" );
  300. var form = new MWF.xApplication.Calendar.EventForm(this,{}, {
  301. startTime : Date.parse( dateStr + " " +hour+":00") ,
  302. endTime : Date.parse( dateStr + " " + (hour+1)+":00" )
  303. }, {app:this.app});
  304. form.view = this;
  305. form.create();
  306. }.bind(this));
  307. new Drag(td, {
  308. "onStart": function(dragged, e){
  309. this.cancelCurrentTd();
  310. this.cellDragStart(dragged, e);
  311. }.bind(this),
  312. "onDrag": function(dragged, e){
  313. this.cellDrag(dragged, e);
  314. }.bind(this),
  315. "onComplete": function(dragged, e){
  316. this.completeDrag(dragged, e);
  317. }.bind(this)
  318. });
  319. }
  320. },
  321. setCurrentTd : function(td){
  322. td.setStyle("background-color","#fffdf2");
  323. if( this.currentSelectedTd ){
  324. var flag = this.isToday( this.date );
  325. this.currentSelectedTd.setStyle("background-color",flag?"#F8FBFF":"#fff");
  326. }
  327. this.currentSelectedTd = td;
  328. },
  329. cancelCurrentTd : function(){
  330. if( this.currentSelectedTd ){
  331. var flag = this.isToday( this.date );
  332. this.currentSelectedTd.setStyle("background-color",flag?"#F8FBFF":"#fff");
  333. }
  334. this.currentSelectedTd = null;
  335. },
  336. reLoadCalendar: function(){
  337. this.startTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 0, 0, 0 );
  338. this.startTimeStr = this.startTime.format( "db" );
  339. this.endTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 23, 59, 59 );
  340. this.endTimeStr = this.endTime.format( "db" );
  341. if( this.day ){
  342. this.day.destroy();
  343. }
  344. this.day = null;
  345. if( this.wholeDay ){
  346. this.wholeDay.destroy();
  347. }
  348. this.wholeDay = null;
  349. //this.calendarTable.getElements("td[tdType='calendar']").each( function(td){
  350. // td.empty();
  351. //}.bind(this));
  352. this.loadTitleTable();
  353. this.loadCalendar();
  354. },
  355. loadCalendar : function(){
  356. this.app.currentDate = this.date.clone();
  357. this.dateIndexMap = null;
  358. this.titleTable.getElement("td:nth-child(1)").setStyle("height", "auto") ;
  359. this.loadData( function( json ){
  360. this.loadwholeDay(this.wholeDayData);
  361. this.loadDataDay( this.inOneDayEvents );
  362. this.resetBodySize();
  363. this.setTodayTds();
  364. this.cancelCurrentTd();
  365. }.bind(this));
  366. },
  367. setTodayTds : function(){
  368. if( this.isToday( this.date ) ){
  369. this.wholeDayTd.setStyle("background-color","#f8fbff");
  370. Object.each( this.hourTdMap, function( td ){
  371. td.setStyle("background-color","#f8fbff");
  372. });
  373. var now = new Date();
  374. var nowTd = this.nowTd = this.hourTdMap[ now.get("hours") ];
  375. var mintues = now.get("minutes");
  376. mintues = mintues < 2 ? 2 : mintues;
  377. var nowTdPosition = nowTd.getPosition(this.bodyNode);
  378. this.nowTimeNode = new Element("div",{
  379. styles : {
  380. "position" : "absolute",
  381. "left" : nowTdPosition.x,
  382. "top" : nowTdPosition.y + ( (mintues - 2) / 60 ) * MWFCalendarDayView.HourHeight,
  383. "height" : "2px",
  384. "width" : MWFCalendarDayView.DayWidth,
  385. "background-color" : "#ff3333"
  386. }
  387. }).inject(this.bodyNode);
  388. this.isSetToday = true;
  389. }else if( this.isSetToday ){
  390. this.wholeDayTd.setStyle("background-color","#fff");
  391. Object.each( this.hourTdMap, function( td ){
  392. td.setStyle("background-color","#fff");
  393. });
  394. if(this.nowTimeNode)this.nowTimeNode.destroy();
  395. if(this.nowTd)this.nowTd = null;
  396. this.isSetToday = false;
  397. }
  398. },
  399. loadData : function( callback ){
  400. this.app.actions.listEventWithFilter( {
  401. calendarIds : this.app.getSelectedCalendarId(),
  402. startTime : this.startTimeStr,
  403. endTime : this.endTimeStr //,
  404. //createPerson : this.app.userName
  405. }, function(json){
  406. this.wholeDayData = ( json.data && json.data.wholeDayEvents ) ? json.data.wholeDayEvents : [];
  407. this.inOneDayEvents = [];
  408. (( json.data && json.data.inOneDayEvents) ? json.data.inOneDayEvents : []).each( function( d ){
  409. if(d.inOneDayEvents.length > 0 ){
  410. this.inOneDayEvents.push( d );
  411. }
  412. }.bind(this));
  413. //json.data.each( function(d){
  414. // var flag = false;
  415. // if( d.isAllDayEvent ){
  416. // flag = true;
  417. // }else if( d.startTime.split(" ")[0] != d.endTime.split(" ")[0] ){
  418. // flag = true;
  419. // }
  420. // if( flag ){
  421. // this.wholeDayData.push( d )
  422. // }else{
  423. // this.dayData.push(d)
  424. // }
  425. //}.bind(this));
  426. if(callback)callback();
  427. }.bind(this));
  428. },
  429. loadDataTable_wholeDay: function( json ){
  430. this.dataTable_wholeDay = new Element("table.dataTable", {
  431. "styles": this.css.calendarTable,
  432. "height" : "0",
  433. "border": "0",
  434. "cellPadding": "0",
  435. "cellSpacing": "0"
  436. }).inject(this.container);
  437. this.dataTable_wholeDay.setStyles({
  438. "display" : "none",
  439. "position":"absolute",
  440. "top" : "51px",
  441. "left" : "0px",
  442. "margin": "0px auto 0px 12px"
  443. });
  444. var tr = new Element("tr").inject(this.dataTable_wholeDay);
  445. new Element( "td" , {
  446. "styles" : {"height":"0px" ,"position":"relative"}
  447. }).inject( tr );
  448. this.dataTd_wholeDay = new Element( "td" , {
  449. "valign" : "top",
  450. "styles" : {"height":"0px","position":"relative"}
  451. }).inject( tr );
  452. },
  453. loadwholeDay : function( json ){
  454. this.wholeDay = new MWFCalendarDayView.Calendar.wholeDay( this, json, this.date);
  455. },
  456. loadDataTable: function( json ){
  457. this.bodyNode.setStyle("position","relative");
  458. this.dataTable = new Element("table.dataTable", {
  459. "styles": this.css.calendarTable,
  460. "height": "0",
  461. "border": "0",
  462. "cellPadding": "0",
  463. "cellSpacing": "0"
  464. }).inject(this.bodyNode);
  465. this.dataTable.setStyles({
  466. "position":"absolute",
  467. "top" : "0px",
  468. "left" : "0px"
  469. });
  470. var tr = new Element("tr").inject(this.dataTable);
  471. new Element( "td" , {
  472. "styles" : {"height":"0px","position":"relative"}
  473. }).inject( tr );
  474. this.dataTd = new Element( "td" , {
  475. "styles" : {"height":"0px","position":"relative"}
  476. }).inject( tr );
  477. },
  478. loadDataDay : function(data){
  479. if( data.length > 0 ){
  480. this.loadDay( data[0].inOneDayEvents );
  481. }
  482. //var dataArray = [];
  483. //json.each( function( d ){
  484. // var date2 = Date.parse(d.startTime );
  485. // if( this.isSameday( this.date, date2 ) ){
  486. // dataArray.push( d );
  487. // }
  488. //}.bind(this));
  489. //if( dataArray.length ){
  490. // this.loadDay( dataArray );
  491. //}
  492. },
  493. loadDay: function( dataArray ){
  494. this.day = new MWFCalendarDayView.Calendar.Day( this.dataTd, this.date, this, dataArray);
  495. },
  496. resetBodySize: function(){
  497. //if( this.app.inContainer )return;
  498. var size = this.container.getSize();
  499. var titleSize = this.titleNode.getSize();
  500. var titleTableSize = this.titleTable.getSize();
  501. var y = size.y-titleSize.y-titleTableSize.y;
  502. //this.bodyNode.setStyle("height", ""+y+"px");
  503. if (this.contentWarpNode){
  504. this.contentWarpNode.setStyles({
  505. "width": (size.x - 40) +"px"
  506. });
  507. }
  508. this.scrollNode.setStyle("height", ""+y+"px");
  509. var hourTdX = 60;
  510. var tdX = MWFCalendarDayView.DayWidth = size.x - 40 - hourTdX;
  511. if(this.calendarTable){
  512. this.calendarTable.setStyles({
  513. "width": (size.x - 40) +"px"
  514. });
  515. var tr =this.calendarTable.getElement("tr:nth-child(1)");
  516. tr.getElements("td").each( function( td, i ){
  517. td.setStyle("width", (i==0 ? hourTdX : tdX )+"px");
  518. })
  519. }
  520. if(this.titleTable){
  521. this.titleTable.setStyles({
  522. "width": (size.x - 40) +"px"
  523. });
  524. var tr =this.titleTable.getElement("tr:nth-child(1)");
  525. tr.getElements("td").each( function( td, i ){
  526. td.setStyle("width", (i==0 ? hourTdX : tdX )+"px");
  527. })
  528. }
  529. if( this.dataTable ){
  530. this.dataTable.setStyles({
  531. "width": (size.x - 40) +"px"
  532. });
  533. var tr =this.dataTable.getElement("tr:nth-child(1)");
  534. tr.getElements("td").each( function( td, i ){
  535. td.setStyle("width", (i==0 ? hourTdX : tdX )+"px");
  536. })
  537. }
  538. if( this.day ){
  539. this.day.resize();
  540. }
  541. if( this.dataTable_wholeDay ){
  542. this.dataTable_wholeDay.setStyles({
  543. "width": (size.x - 40) +"px"
  544. });
  545. var tr =this.dataTable_wholeDay.getElement("tr:nth-child(1)");
  546. tr.getElements("td").each( function( td, i ){
  547. td.setStyle("width", (i==0 ? hourTdX : tdX )+"px");
  548. })
  549. }
  550. if(this.wholeDay){
  551. this.wholeDay.resize();
  552. }
  553. if(this.nowTimeNode){
  554. this.nowTimeNode.setStyle("width",tdX);
  555. if(this.nowTd)this.nowTimeNode.setStyle("left", this.nowTd.getPosition(this.bodyNode).x );
  556. }
  557. //for( var key in this.dayMap_wholeDay ){
  558. // this.dayMap_wholeDay[key].resize();
  559. //}
  560. },
  561. reload : function(){
  562. this.view.reload();
  563. },
  564. destroy: function(){
  565. if( this.day ){
  566. this.day.destroy();
  567. }
  568. if( this.wholeDay ){
  569. this.wholeDay.destroy();
  570. }
  571. this.container.empty();
  572. },
  573. getIndexByPage: function( page ){
  574. var pos = this.calendarTable.getPosition();
  575. this.pageOffsetHeight = page.y - pos.y;
  576. var row = ( page.y - pos.y ) / MWFCalendarDayView.HourHeight;
  577. if( row < 0 || row > 24 )return null;
  578. return Math.floor(row);
  579. },
  580. getIndexListByRange : function( index1, index2 ){
  581. var minIndex = Math.min( index1, index2 );
  582. var maxIndex = Math.max( index1, index2 );
  583. var result = [];
  584. for( var i = minIndex; i<=maxIndex; i++ ){
  585. result.push( i );
  586. }
  587. return result;
  588. },
  589. cellDragStart: function(td, e){
  590. td.store("index", this.getIndexByPage(e.page ) );
  591. this.scrollNodeHeight = this.scrollNode.getSize().y;
  592. },
  593. cellDrag: function(td, e){
  594. var orgIndex = td.retrieve( "index" );
  595. var curIndex = this.getIndexByPage( e.page );
  596. if( !curIndex )return;
  597. var indexs = this.getIndexListByRange( orgIndex, curIndex );
  598. var flag = this.isToday( this.date );
  599. if( this.selectedIndexRange ){
  600. var oldIndex = this.selectedIndexRange;
  601. this.selectedIndexRange.each( function( index ){
  602. if( !indexs.contains(index) ){
  603. this.hourTdMap[index].setStyle("background-color", flag ? "#F8FBFF" : "#fff");
  604. }
  605. }.bind(this));
  606. indexs.each( function( index ){
  607. if( !this.selectedIndexRange.contains(index) ){
  608. this.hourTdMap[index].setStyle("background-color", "#fffdf2")
  609. }
  610. }.bind(this))
  611. }else{
  612. for( var i=0; i<indexs.length; i++ ){
  613. this.hourTdMap[indexs[i]].setStyle("background-color", "#fffdf2")
  614. }
  615. }
  616. this.selectedIndexRange = indexs;
  617. var scrollNodeTop = this.scrollNode.getScroll().y;
  618. if(( this.pageOffsetHeight + MWFCalendarDayView.HourHeight * 1.5) > ( this.scrollNodeHeight + scrollNodeTop )){
  619. window.setTimeout( function(){
  620. this.scrollNode.scrollTo(0, scrollNodeTop + MWFCalendarDayView.HourHeight )
  621. }.bind(this), 200)
  622. }else if( this.pageOffsetHeight - MWFCalendarDayView.HourHeight * 1.5 < scrollNodeTop ){
  623. window.setTimeout( function(){
  624. this.scrollNode.scrollTo(0, scrollNodeTop - MWFCalendarDayView.HourHeight )
  625. }.bind(this), 200)
  626. }
  627. },
  628. completeDrag: function(td, e){
  629. var flag = this.isToday( this.date );
  630. if( this.selectedIndexRange && this.selectedIndexRange.length ){
  631. this.selectedIndexRange.each( function( index ){
  632. this.hourTdMap[index ].setStyle("background-color", flag ? "#F8FBFF" : "#fff");
  633. }.bind(this));
  634. var beginIndex = this.selectedIndexRange[0];
  635. var endIndex = this.selectedIndexRange.getLast();
  636. var beginTime = this.date.format("%Y-%m-%d") + " " + beginIndex+":00";
  637. var endTime = this.date.format("%Y-%m-%d") + " " + endIndex+":59";
  638. var form = new MWF.xApplication.Calendar.EventForm(this,{}, {
  639. startTime : beginTime ,
  640. endTime : endTime
  641. }, {app:this.app});
  642. form.view = this;
  643. form.create();
  644. this.selectedIndexRange = null;
  645. }
  646. }
  647. });
  648. MWFCalendarDayView.Calendar.wholeDay = new Class({
  649. Implements: [Events],
  650. initialize: function( calendar, data, date){
  651. this.calendar = calendar;
  652. this.view = this.calendar.view;
  653. this.css = this.calendar.css;
  654. this.app = this.calendar.app;
  655. this.date = date.clone();
  656. this.data = data;
  657. this.load();
  658. },
  659. load: function(){
  660. //this.startTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 0, 0, 0 );
  661. //this.endTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 23, 59, 59 );
  662. this.startTime = this.calendar.startTime;
  663. this.endTime = this.calendar.endTime;
  664. this.rangeList = [];
  665. this.rangeObject = {};
  666. this.data.each( function(d , i){
  667. var range = this.getTimeRange( d.startTime, d.endTime );
  668. if( !range )return null;
  669. d.range = range;
  670. d.range.id = d.id;
  671. d.range.data = d;
  672. this.rangeList.push( range );
  673. this.rangeObject[d.id] = range;
  674. }.bind(this));
  675. this.sortRange();
  676. this.calendar.titleTable.getElement("td:nth-child(1)").setStyle("height", 24*this.rangeList.length + 3) ;
  677. this.documentList = [];
  678. this.rangeList.each( function(r , i){
  679. var d = r.data;
  680. if( !d )return null;
  681. this.documentList.push( new MWFCalendarDayView.Calendar.wholeDayDocument( this, d, r ) );
  682. }.bind(this))
  683. },
  684. sortRange : function(){
  685. this.rangeList.sort( function( range1, range2 ){
  686. return range2.diff - range1.diff;
  687. }.bind(this));
  688. },
  689. getTimeRange : function( startTime, endTime ){
  690. var start = Date.parse(startTime );
  691. var end = Date.parse(endTime );
  692. if( end < this.startTime )return null;
  693. if( this.endTime < start )return null;
  694. if( start < this.startTime )start = this.startTime.clone();
  695. if( this.endTime < end )end = this.endTime.clone();
  696. var end = new Date( end.get("year"), end.get("month"), end.get("date"), 23, 59, 59 );
  697. start = Date.parse(startTime );
  698. end = Date.parse(endTime );
  699. return {
  700. start : start,
  701. end : end,
  702. diff : end - start
  703. }
  704. },
  705. resize: function(){
  706. if(!this.documentList)return;
  707. this.documentList.each( function(d){
  708. d.resize();
  709. }.bind(this))
  710. },
  711. destroy : function(){
  712. if(!this.documentList)return;
  713. while( this.documentList.length ){
  714. this.documentList.pop().destroy()
  715. }
  716. this.calendar.dataTd_wholeDay.empty();
  717. }
  718. });
  719. MWFCalendarDayView.Calendar.wholeDayDocument = new Class({
  720. initialize: function(day, data, range ){
  721. this.day = day;
  722. this.calendar = day.calendar;
  723. this.view = this.calendar.view;
  724. this.css = this.calendar.css;
  725. this.app = this.calendar.app;
  726. this.date = day.date.clone();
  727. this.data = data;
  728. this.range = range;
  729. this.load();
  730. },
  731. load: function(){
  732. this.container = this.calendar.dataTd_wholeDay;
  733. var items = this.items = [];
  734. this.data.dateStart = Date.parse( this.data.startTime );
  735. this.data.dateEnd = Date.parse( this.data.endTime );
  736. this.yIndex = this.getUsefulTdYIndex();
  737. this.createNode();
  738. //this.range.days.each( function( d, i ){
  739. // items.push( new MWFCalendarDayView.Calendar.wholeDayItem( this, d, i ) )
  740. //}.bind(this))
  741. },
  742. getUsefulTdYIndex : function(){
  743. if( typeOf( this.day.yIndex )=="null" ){
  744. this.day.yIndex = 0
  745. }else{
  746. this.day.yIndex ++
  747. }
  748. return this.day.yIndex;
  749. },
  750. createNode : function(){
  751. var lightColor = this.lightColor = MWFCalendar.ColorOptions.getLightColor( this.data.color );
  752. var node = this.node = new Element("div",{
  753. styles : {
  754. position : "absolute",
  755. "overflow" : "hidden",
  756. "height" : "20px",
  757. "line-height" : "20px",
  758. "border-top" : "1px solid " + lightColor,
  759. "border-bottom" : "1px solid " + lightColor,
  760. "background-color": lightColor
  761. },
  762. events : {
  763. click : function(){
  764. var form = new MWF.xApplication.Calendar.EventForm(this, this.data, {
  765. isFull : true
  766. }, {app:this.app});
  767. form.view = this.view;
  768. this.calendar.app.isEventEditable(this.data) ? form.edit() : form.open();
  769. }.bind(this),
  770. "mouseover" : function () {
  771. this.node.setStyle("border-color", this.data.color );
  772. }.bind(this),
  773. "mouseout" : function () {
  774. this.node.setStyle("border-color", this.lightColor );
  775. }.bind(this)
  776. }
  777. }).inject( this.container );
  778. node.setStyles(this.getCoordinate());
  779. if( !this.beginDateOutRange ){
  780. node.setStyles({
  781. "border-left" : "1px solid " + lightColor,
  782. "border-top-left-radius" : "10px",
  783. "border-bottom-left-radius" : "10px"
  784. })
  785. }
  786. if( !this.endDateOutRange ){
  787. node.setStyles({
  788. "border-right" : "1px solid " + lightColor,
  789. "border-top-right-radius" : "10px",
  790. "border-bottom-right-radius" : "10px"
  791. })
  792. }
  793. //if( this.isFirst ){
  794. var timeNode = new Element("div",{
  795. styles : {
  796. "font-size" : "10px",
  797. "padding-left" : "2px",
  798. "float" : "left"
  799. },
  800. text : this.data.dateStart.format("%m-%d %H:%M") + this.app.lp.to + this.data.dateEnd.format("%m-%d %H:%M")
  801. }).inject( node );
  802. var titleNode = new Element("div",{
  803. styles : {
  804. "padding-left" : "5px",
  805. "font-size" : "12px",
  806. "float" : "left"
  807. },
  808. text : this.data.title
  809. }).inject( node );
  810. //}
  811. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  812. axis : "y", "delay" : 350
  813. });
  814. this.tooltip.view = this.view;
  815. },
  816. getCoordinate : function(){
  817. var data = this.data;
  818. var range = this.range;
  819. var top = this.yIndex * 24;
  820. var dateStart = this.day.startTime;
  821. var dateEnd = this.day.endTime;
  822. if( this.data.dateStart < dateStart ){
  823. this.beginDateOutRange = true;
  824. }else{
  825. this.beginDateOutRange = false;
  826. dateStart = this.data.dateStart;
  827. }
  828. if( this.data.dateEnd > dateEnd ){
  829. this.endDateOutRange = true;
  830. }else{
  831. this.endDateOutRange = false;
  832. dateEnd = this.data.dateEnd;
  833. }
  834. var diff = dateEnd - dateStart;
  835. var width = ( diff / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayWidth - 2;
  836. var left = ( ( dateStart - this.day.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayWidth + 3;
  837. //var marginRight = ( ( this.weekDateEnd - dateEnd ) / MWFCalendarDayView.DayMsec) * MWFCalendarDayView.DayWidth;
  838. return {
  839. top : top + 2,
  840. left : left,
  841. width : width // + ( !this.isLast ? 2 : -2 ) //,
  842. //"margin-left" : marginLeft,
  843. //"margin-right" : marginRight
  844. }
  845. },
  846. resize : function(){
  847. this.node.setStyles(this.getCoordinate());
  848. },
  849. reload: function(){
  850. if( this.tooltip )this.tooltip.destroy();
  851. this.view.reload();
  852. },
  853. destroy : function(){
  854. if( this.tooltip )this.tooltip.destroy();
  855. this.node.destroy();
  856. }
  857. });
  858. MWFCalendarDayView.Calendar.Day = new Class({
  859. Implements: [Events],
  860. initialize: function(container, date, calendar, data){
  861. this.container = container;
  862. this.calendar = calendar;
  863. this.view = this.calendar.view;
  864. this.css = this.calendar.css;
  865. this.app = this.calendar.app;
  866. this.date = date.clone();
  867. this.data = data;
  868. this.calendars = [];
  869. this.load();
  870. },
  871. load: function(){
  872. this.day = this.date.getDate();
  873. this.month = this.date.getMonth();
  874. this.year = this.date.getFullYear();
  875. //this.startTime = new Date( this.year, this.month, this.day, 0, 0, 0 );
  876. //this.endTime = new Date( this.year, this.month, this.day, 23, 59, 59 );
  877. this.startTime = this.calendar.startTime;
  878. this.endTime = this.calendar.endTime;
  879. this.rangeList = [];
  880. this.rangeObject = {};
  881. this.data.each( function(d , i){
  882. var range = this.getTimeRange( d.startTime, d.endTime );
  883. if( !range )return null;
  884. d.range = range;
  885. d.range.data = d;
  886. d.range.id = d.id;
  887. this.rangeList.push( range );
  888. this.rangeObject[d.id] = range;
  889. }.bind(this));
  890. this.sortRange();
  891. var length = this.data.length;
  892. this.documentList = [];
  893. this.rangeList.each( function(r , i){
  894. r.index = this.rangeList.indexOf( r );
  895. var d = r.data;
  896. //var coordinate = this.getCoordinate( d, range );
  897. this.documentList.push( new MWFCalendarDayView.Calendar.Document(this.container, this, d, r ) );
  898. }.bind(this))
  899. },
  900. sortRange : function(){
  901. this.rangeList.sort( function(range1, range2){
  902. return range1.startTime - range2.startTime;
  903. });
  904. },
  905. getTimeRange: function( bDate1, eDate1 ){
  906. var bDate = typeOf(bDate1) == "string" ? Date.parse(bDate1) : bDate1;
  907. var eDate = typeOf(eDate1) == "string" ? Date.parse(eDate1) : eDate1;
  908. if( eDate <= this.startTime ){ //比当天天12点更晚
  909. return null;
  910. }
  911. if( this.endTime <= bDate ){
  912. return null;
  913. }
  914. var range = {
  915. start: ( bDate <= this.startTime ) ? [0, 0, 0] : [bDate.get("hr"), bDate.get("min"), bDate.get("sec")],
  916. end: ( this.endTime <= eDate ) ? [23, 59, 59] : [eDate.get("hr"), eDate.get("min"), eDate.get("sec")]
  917. };
  918. range.startTime = new Date( this.year, this.month, this.day, range.start[0], range.start[1], range.start[2] );
  919. range.endTime = new Date( this.year, this.month, this.day, range.end[0], range.end[1], range.end[2] );
  920. range.diff = range.endTime - range.startTime;
  921. return range;
  922. },
  923. resize : function(){
  924. if(!this.documentList)return;
  925. this.documentList.each( function( doc ){
  926. doc.resize();
  927. }.bind(this))
  928. },
  929. reload: function(){
  930. this.view.reload();
  931. },
  932. destroy : function(){
  933. while( this.documentList.length > 0 ){
  934. this.documentList.pop().destroy();
  935. }
  936. this.container.empty();
  937. }
  938. });
  939. MWFCalendarDayView.Calendar.Document = new Class({
  940. initialize: function(container, day, data, range ){
  941. this.container = container;
  942. this.day = day;
  943. this.calendar = day.calendar;
  944. this.view = this.calendar.view;
  945. this.css = this.calendar.css;
  946. this.app = this.calendar.app;
  947. this.date = day.date.clone();
  948. this.data = data;
  949. this.range = range;
  950. this.load();
  951. },
  952. load: function(){
  953. var lightColor = this.lightColor = MWFCalendar.ColorOptions.getLightColor( this.data.color );
  954. var node = this.node = new Element("div",{
  955. styles : {
  956. position : "absolute",
  957. border : "1px solid "+lightColor,
  958. "background-color" : lightColor,
  959. "overflow" : "hidden",
  960. "border-radius" : "5px",
  961. "max-width" : "150px"
  962. },
  963. events : {
  964. click : function(){
  965. var form = new MWF.xApplication.Calendar.EventForm(this, this.data, {
  966. isFull : true
  967. }, {app:this.app});
  968. form.view = this.view;
  969. this.calendar.app.isEventEditable(this.data) ? form.edit() : form.open();
  970. }.bind(this),
  971. "mouseover" : function () {
  972. this.node.setStyle("border-color", this.data.color );
  973. }.bind(this),
  974. "mouseout" : function () {
  975. this.node.setStyle("border-color", this.lightColor );
  976. }.bind(this)
  977. }
  978. }).inject( this.container );
  979. node.setStyles(this.getCoordinate());
  980. var timeNode = new Element("div",{
  981. styles : {
  982. "font-size" : "10px",
  983. "padding-top" : "2px",
  984. "padding-left" : "2px"
  985. },
  986. text : this.range.startTime.format("%H:%M") + "-" + this.range.endTime.format("%H:%M")
  987. }).inject( node );
  988. var titleNode = new Element("div",{
  989. styles : {
  990. "padding-top" : "7px",
  991. "padding-left" : "5px",
  992. "font-size" : "12px"
  993. },
  994. text : this.data.title
  995. }).inject( node );
  996. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  997. axis : "x", "delay" : 350
  998. });
  999. this.tooltip.view = this.view;
  1000. },
  1001. resize : function(){
  1002. this.node.setStyles(this.getCoordinate());
  1003. },
  1004. getCoordinate : function(){
  1005. var data = this.data;
  1006. var range = this.range;
  1007. var width_div = 4;
  1008. var top_div = 0;
  1009. if(Browser.name === "ie" ){
  1010. width_div = 4;
  1011. top_div = -2
  1012. }
  1013. var height = Math.floor( ( ( range.endTime - range.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayHeight)-width_div;
  1014. if(height < 16) height = 16;
  1015. var top = Math.floor( ( ( range.startTime - this.day.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayHeight)-top_div;
  1016. //var width = Math.floor( MWFCalendarDayView.DayWidth / length )-2;
  1017. //var left = ( width + 2)* index + 1;
  1018. //var width = Math.floor( MWFCalendarDayView.DayWidth / range.path.length )-5;
  1019. //var left = ( width + 5)* range.path.indexOf( data.id ) + 3;
  1020. var width = Math.floor( MWFCalendarDayView.DayWidth / this.day.rangeList.length )-5;
  1021. if( width > 150 ){
  1022. width = 150;
  1023. }
  1024. var left = ( width + 5)* this.range.index + 3;
  1025. return {
  1026. top : top,
  1027. left : left,
  1028. width : width,
  1029. height : height
  1030. }
  1031. },
  1032. reload: function(){
  1033. if( this.tooltip )this.tooltip.destroy();
  1034. this.view.reload();
  1035. },
  1036. destroy: function(){
  1037. if( this.tooltip )this.tooltip.destroy();
  1038. this.node.destroy()
  1039. }
  1040. });