DayView.js 40 KB

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