DayView.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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. "border": "0",
  416. "cellPadding": "0",
  417. "cellSpacing": "0"
  418. }).inject(this.container);
  419. this.dataTable_wholeDay.setStyles({
  420. "display" : "none",
  421. "position":"absolute",
  422. "top" : "51px",
  423. "left" : "0px",
  424. "margin": "0px auto 0px 12px"
  425. });
  426. var tr = new Element("tr").inject(this.dataTable_wholeDay);
  427. new Element( "td" , {
  428. "styles" : {"height":"0px" ,"position":"relative"}
  429. }).inject( tr );
  430. this.dataTd_wholeDay = new Element( "td" , {
  431. "valign" : "top",
  432. "styles" : {"height":"0px","position":"relative"}
  433. }).inject( tr );
  434. },
  435. loadwholeDay : function( json ){
  436. this.wholeDay = new MWFCalendarDayView.Calendar.wholeDay( this, json, this.date);
  437. },
  438. loadDataTable: function( json ){
  439. this.bodyNode.setStyle("position","relative");
  440. this.dataTable = new Element("table.dataTable", {
  441. "styles": this.css.calendarTable,
  442. "height": "100%",
  443. "border": "0",
  444. "cellPadding": "0",
  445. "cellSpacing": "0"
  446. }).inject(this.bodyNode);
  447. this.dataTable.setStyles({
  448. "position":"absolute",
  449. "top" : "0px",
  450. "left" : "0px"
  451. });
  452. var tr = new Element("tr").inject(this.dataTable);
  453. new Element( "td" , {
  454. "styles" : {"height":"0px","position":"relative"}
  455. }).inject( tr );
  456. this.dataTd = new Element( "td" , {
  457. "styles" : {"height":"0px","position":"relative"}
  458. }).inject( tr );
  459. },
  460. loadDataDay : function(data){
  461. if( data.length > 0 ){
  462. this.loadDay( data[0].inOneDayEvents );
  463. }
  464. //var dataArray = [];
  465. //json.each( function( d ){
  466. // var date2 = Date.parse(d.startTime );
  467. // if( this.isSameday( this.date, date2 ) ){
  468. // dataArray.push( d );
  469. // }
  470. //}.bind(this));
  471. //if( dataArray.length ){
  472. // this.loadDay( dataArray );
  473. //}
  474. },
  475. loadDay: function( dataArray ){
  476. this.day = new MWFCalendarDayView.Calendar.Day( this.dataTd, this.date, this, dataArray);
  477. },
  478. resetBodySize: function(){
  479. //if( this.app.inContainer )return;
  480. var size = this.container.getSize();
  481. var titleSize = this.titleNode.getSize();
  482. var titleTableSize = this.titleTable.getSize();
  483. var y = size.y-titleSize.y-titleTableSize.y;
  484. //this.bodyNode.setStyle("height", ""+y+"px");
  485. if (this.contentWarpNode){
  486. this.contentWarpNode.setStyles({
  487. "width": (size.x - 40) +"px"
  488. });
  489. }
  490. this.scrollNode.setStyle("height", ""+y+"px");
  491. var hourTdX = 60;
  492. var tdX = MWFCalendarDayView.DayWidth = size.x - 40 - hourTdX;
  493. if(this.calendarTable){
  494. this.calendarTable.setStyles({
  495. "width": (size.x - 40) +"px"
  496. });
  497. var tr =this.calendarTable.getElement("tr:nth-child(1)");
  498. tr.getElements("td").each( function( td, i ){
  499. td.setStyle("width", (i==0 ? hourTdX : tdX )+"px");
  500. })
  501. }
  502. if(this.titleTable){
  503. this.titleTable.setStyles({
  504. "width": (size.x - 40) +"px"
  505. });
  506. var tr =this.titleTable.getElement("tr:nth-child(1)");
  507. tr.getElements("td").each( function( td, i ){
  508. td.setStyle("width", (i==0 ? hourTdX : tdX )+"px");
  509. })
  510. }
  511. if( this.dataTable ){
  512. this.dataTable.setStyles({
  513. "width": (size.x - 40) +"px"
  514. });
  515. var tr =this.dataTable.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.day ){
  521. this.day.resize();
  522. }
  523. if( this.dataTable_wholeDay ){
  524. this.dataTable_wholeDay.setStyles({
  525. "width": (size.x - 40) +"px"
  526. });
  527. var tr =this.dataTable_wholeDay.getElement("tr:nth-child(1)");
  528. tr.getElements("td").each( function( td, i ){
  529. td.setStyle("width", (i==0 ? hourTdX : tdX )+"px");
  530. })
  531. }
  532. if(this.wholeDay){
  533. this.wholeDay.resize();
  534. }
  535. if(this.nowTimeNode){
  536. this.nowTimeNode.setStyle("width",tdX);
  537. if(this.nowTd)this.nowTimeNode.setStyle("left", this.nowTd.getPosition(this.bodyNode).x );
  538. }
  539. //for( var key in this.dayMap_wholeDay ){
  540. // this.dayMap_wholeDay[key].resize();
  541. //}
  542. },
  543. reload : function(){
  544. this.view.reload();
  545. },
  546. destroy: function(){
  547. if( this.day ){
  548. this.day.destroy();
  549. }
  550. if( this.wholeDay ){
  551. this.wholeDay.destroy();
  552. }
  553. this.container.empty();
  554. },
  555. getIndexByPage: function( page ){
  556. var pos = this.calendarTable.getPosition();
  557. this.pageOffsetHeight = page.y - pos.y;
  558. var row = ( page.y - pos.y ) / MWFCalendarDayView.HourHeight;
  559. if( row < 0 || row > 24 )return null;
  560. return Math.floor(row);
  561. },
  562. getIndexListByRange : function( index1, index2 ){
  563. var minIndex = Math.min( index1, index2 );
  564. var maxIndex = Math.max( index1, index2 );
  565. var result = [];
  566. for( var i = minIndex; i<=maxIndex; i++ ){
  567. result.push( i );
  568. }
  569. return result;
  570. },
  571. cellDragStart: function(td, e){
  572. td.store("index", this.getIndexByPage(e.page ) );
  573. this.scrollNodeHeight = this.scrollNode.getSize().y;
  574. },
  575. cellDrag: function(td, e){
  576. var orgIndex = td.retrieve( "index" );
  577. var curIndex = this.getIndexByPage( e.page );
  578. if( !curIndex )return;
  579. var indexs = this.getIndexListByRange( orgIndex, curIndex );
  580. var flag = this.isToday( this.date );
  581. if( this.selectedIndexRange ){
  582. var oldIndex = this.selectedIndexRange;
  583. this.selectedIndexRange.each( function( index ){
  584. if( !indexs.contains(index) ){
  585. this.hourTdMap[index].setStyle("background-color", flag ? "#F8FBFF" : "#fff");
  586. }
  587. }.bind(this));
  588. indexs.each( function( index ){
  589. if( !this.selectedIndexRange.contains(index) ){
  590. this.hourTdMap[index].setStyle("background-color", "#fffdf2")
  591. }
  592. }.bind(this))
  593. }else{
  594. for( var i=0; i<indexs.length; i++ ){
  595. this.hourTdMap[indexs[i]].setStyle("background-color", "#fffdf2")
  596. }
  597. }
  598. this.selectedIndexRange = indexs;
  599. var scrollNodeTop = this.scrollNode.getScroll().y;
  600. if(( this.pageOffsetHeight + MWFCalendarDayView.HourHeight * 1.5) > ( this.scrollNodeHeight + scrollNodeTop )){
  601. window.setTimeout( function(){
  602. this.scrollNode.scrollTo(0, scrollNodeTop + MWFCalendarDayView.HourHeight )
  603. }.bind(this), 200)
  604. }else if( this.pageOffsetHeight - MWFCalendarDayView.HourHeight * 1.5 < scrollNodeTop ){
  605. window.setTimeout( function(){
  606. this.scrollNode.scrollTo(0, scrollNodeTop - MWFCalendarDayView.HourHeight )
  607. }.bind(this), 200)
  608. }
  609. },
  610. completeDrag: function(td, e){
  611. var flag = this.isToday( this.date );
  612. if( this.selectedIndexRange && this.selectedIndexRange.length ){
  613. this.selectedIndexRange.each( function( index ){
  614. this.hourTdMap[index ].setStyle("background-color", flag ? "#F8FBFF" : "#fff");
  615. }.bind(this));
  616. var beginIndex = this.selectedIndexRange[0];
  617. var endIndex = this.selectedIndexRange.getLast();
  618. var beginTime = this.date.format("%Y-%m-%d") + " " + beginIndex+":00";
  619. var endTime = this.date.format("%Y-%m-%d") + " " + endIndex+":59";
  620. var form = new MWF.xApplication.Calendar.EventForm(this,{}, {
  621. startTime : beginTime ,
  622. endTime : endTime
  623. }, {app:this.app});
  624. form.view = this;
  625. form.create();
  626. this.selectedIndexRange = null;
  627. }
  628. }
  629. });
  630. MWFCalendarDayView.Calendar.wholeDay = new Class({
  631. Implements: [Events],
  632. initialize: function( calendar, data, date){
  633. this.calendar = calendar;
  634. this.view = this.calendar.view;
  635. this.css = this.calendar.css;
  636. this.app = this.calendar.app;
  637. this.date = date.clone();
  638. this.data = data;
  639. this.load();
  640. },
  641. load: function(){
  642. //this.startTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 0, 0, 0 );
  643. //this.endTime = new Date( this.date.get("year"), this.date.get("month"), this.date.get("date"), 23, 59, 59 );
  644. this.startTime = this.calendar.startTime;
  645. this.endTime = this.calendar.endTime;
  646. this.rangeList = [];
  647. this.rangeObject = {};
  648. this.data.each( function(d , i){
  649. var range = this.getTimeRange( d.startTime, d.endTime );
  650. if( !range )return null;
  651. d.range = range;
  652. d.range.id = d.id;
  653. d.range.data = d;
  654. this.rangeList.push( range );
  655. this.rangeObject[d.id] = range;
  656. }.bind(this));
  657. this.sortRange();
  658. this.calendar.titleTable.getElement("td:nth-child(1)").setStyle("height", 24*this.rangeList.length + 3) ;
  659. this.documentList = [];
  660. this.rangeList.each( function(r , i){
  661. var d = r.data;
  662. if( !d )return null;
  663. this.documentList.push( new MWFCalendarDayView.Calendar.wholeDayDocument( this, d, r ) );
  664. }.bind(this))
  665. },
  666. sortRange : function(){
  667. this.rangeList.sort( function( range1, range2 ){
  668. return range2.diff - range1.diff;
  669. }.bind(this));
  670. },
  671. getTimeRange : function( startTime, endTime ){
  672. var start = Date.parse(startTime );
  673. var end = Date.parse(endTime );
  674. if( end < this.startTime )return null;
  675. if( this.endTime < start )return null;
  676. if( start < this.startTime )start = this.startTime.clone();
  677. if( this.endTime < end )end = this.endTime.clone();
  678. var end = new Date( end.get("year"), end.get("month"), end.get("date"), 23, 59, 59 );
  679. start = Date.parse(startTime );
  680. end = Date.parse(endTime );
  681. return {
  682. start : start,
  683. end : end,
  684. diff : end - start
  685. }
  686. },
  687. resize: function(){
  688. if(!this.documentList)return;
  689. this.documentList.each( function(d){
  690. d.resize();
  691. }.bind(this))
  692. },
  693. destroy : function(){
  694. if(!this.documentList)return;
  695. while( this.documentList.length ){
  696. this.documentList.pop().destroy()
  697. }
  698. this.calendar.dataTd_wholeDay.empty();
  699. }
  700. });
  701. MWFCalendarDayView.Calendar.wholeDayDocument = new Class({
  702. initialize: function(day, data, range ){
  703. this.day = day;
  704. this.calendar = day.calendar;
  705. this.view = this.calendar.view;
  706. this.css = this.calendar.css;
  707. this.app = this.calendar.app;
  708. this.date = day.date.clone();
  709. this.data = data;
  710. this.range = range;
  711. this.load();
  712. },
  713. load: function(){
  714. this.container = this.calendar.dataTd_wholeDay;
  715. var items = this.items = [];
  716. this.data.dateStart = Date.parse( this.data.startTime );
  717. this.data.dateEnd = Date.parse( this.data.endTime );
  718. this.yIndex = this.getUsefulTdYIndex();
  719. this.createNode();
  720. //this.range.days.each( function( d, i ){
  721. // items.push( new MWFCalendarDayView.Calendar.wholeDayItem( this, d, i ) )
  722. //}.bind(this))
  723. },
  724. getUsefulTdYIndex : function(){
  725. if( typeOf( this.day.yIndex )=="null" ){
  726. this.day.yIndex = 0
  727. }else{
  728. this.day.yIndex ++
  729. }
  730. return this.day.yIndex;
  731. },
  732. createNode : function(){
  733. var lightColor = this.lightColor = MWFCalendar.ColorOptions.getLightColor( this.data.color );
  734. var node = this.node = new Element("div",{
  735. styles : {
  736. position : "absolute",
  737. "overflow" : "hidden",
  738. "height" : "20px",
  739. "line-height" : "20px",
  740. "border-top" : "1px solid " + lightColor,
  741. "border-bottom" : "1px solid " + lightColor,
  742. "background-color": lightColor
  743. },
  744. events : {
  745. click : function(){
  746. var form = new MWF.xApplication.Calendar.EventForm(this, this.data, {
  747. isFull : true
  748. }, {app:this.app});
  749. form.view = this.view;
  750. form.edit();
  751. }.bind(this),
  752. "mouseover" : function () {
  753. this.node.setStyle("border-color", this.data.color );
  754. }.bind(this),
  755. "mouseout" : function () {
  756. this.node.setStyle("border-color", this.lightColor );
  757. }.bind(this)
  758. }
  759. }).inject( this.container );
  760. node.setStyles(this.getCoordinate());
  761. if( !this.beginDateOutRange ){
  762. node.setStyles({
  763. "border-left" : "1px solid " + lightColor,
  764. "border-top-left-radius" : "10px",
  765. "border-bottom-left-radius" : "10px"
  766. })
  767. }
  768. if( !this.endDateOutRange ){
  769. node.setStyles({
  770. "border-right" : "1px solid " + lightColor,
  771. "border-top-right-radius" : "10px",
  772. "border-bottom-right-radius" : "10px"
  773. })
  774. }
  775. //if( this.isFirst ){
  776. var timeNode = new Element("div",{
  777. styles : {
  778. "font-size" : "10px",
  779. "padding-left" : "2px",
  780. "float" : "left"
  781. },
  782. text : this.data.dateStart.format("%m-%d %H:%M") + "至" + this.data.dateEnd.format("%m-%d %H:%M")
  783. }).inject( node );
  784. var titleNode = new Element("div",{
  785. styles : {
  786. "padding-left" : "5px",
  787. "font-size" : "12px",
  788. "float" : "left"
  789. },
  790. text : this.data.title
  791. }).inject( node );
  792. //}
  793. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  794. axis : "y", "delay" : 350
  795. });
  796. },
  797. getCoordinate : function(){
  798. var data = this.data;
  799. var range = this.range;
  800. var top = this.yIndex * 24;
  801. var dateStart = this.day.startTime;
  802. var dateEnd = this.day.endTime;
  803. if( this.data.dateStart < dateStart ){
  804. this.beginDateOutRange = true;
  805. }else{
  806. this.beginDateOutRange = false;
  807. dateStart = this.data.dateStart;
  808. }
  809. if( this.data.dateEnd > dateEnd ){
  810. this.endDateOutRange = true;
  811. }else{
  812. this.endDateOutRange = false;
  813. dateEnd = this.data.dateEnd;
  814. }
  815. var diff = dateEnd - dateStart;
  816. var width = ( diff / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayWidth - 2;
  817. var left = ( ( dateStart - this.day.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayWidth + 3;
  818. //var marginRight = ( ( this.weekDateEnd - dateEnd ) / MWFCalendarDayView.DayMsec) * MWFCalendarDayView.DayWidth;
  819. return {
  820. top : top + 2,
  821. left : left,
  822. width : width // + ( !this.isLast ? 2 : -2 ) //,
  823. //"margin-left" : marginLeft,
  824. //"margin-right" : marginRight
  825. }
  826. },
  827. resize : function(){
  828. this.node.setStyles(this.getCoordinate());
  829. },
  830. reload: function(){
  831. if( this.tooltip )this.tooltip.destroy();
  832. this.view.reload();
  833. },
  834. destroy : function(){
  835. if( this.tooltip )this.tooltip.destroy();
  836. this.node.destroy();
  837. }
  838. });
  839. MWFCalendarDayView.Calendar.Day = new Class({
  840. Implements: [Events],
  841. initialize: function(container, date, calendar, data){
  842. this.container = container;
  843. this.calendar = calendar;
  844. this.view = this.calendar.view;
  845. this.css = this.calendar.css;
  846. this.app = this.calendar.app;
  847. this.date = date.clone();
  848. this.data = data;
  849. this.calendars = [];
  850. this.load();
  851. },
  852. load: function(){
  853. this.day = this.date.getDate();
  854. this.month = this.date.getMonth();
  855. this.year = this.date.getFullYear();
  856. //this.startTime = new Date( this.year, this.month, this.day, 0, 0, 0 );
  857. //this.endTime = new Date( this.year, this.month, this.day, 23, 59, 59 );
  858. this.startTime = this.calendar.startTime;
  859. this.endTime = this.calendar.endTime;
  860. this.rangeList = [];
  861. this.rangeObject = {};
  862. this.data.each( function(d , i){
  863. var range = this.getTimeRange( d.startTime, d.endTime );
  864. if( !range )return null;
  865. d.range = range;
  866. d.range.data = d;
  867. d.range.id = d.id;
  868. this.rangeList.push( range );
  869. this.rangeObject[d.id] = range;
  870. }.bind(this));
  871. this.sortRange();
  872. var length = this.data.length;
  873. this.documentList = [];
  874. this.rangeList.each( function(r , i){
  875. r.index = this.rangeList.indexOf( r );
  876. var d = r.data;
  877. //var coordinate = this.getCoordinate( d, range );
  878. this.documentList.push( new MWFCalendarDayView.Calendar.Document(this.container, this, d, r ) );
  879. }.bind(this))
  880. },
  881. sortRange : function(){
  882. this.rangeList.sort( function(range1, range2){
  883. return range1.startTime - range2.startTime;
  884. });
  885. },
  886. getTimeRange: function( bDate1, eDate1 ){
  887. var bDate = typeOf(bDate1) == "string" ? Date.parse(bDate1) : bDate1;
  888. var eDate = typeOf(eDate1) == "string" ? Date.parse(eDate1) : eDate1;
  889. if( eDate <= this.startTime ){ //比当天天12点更晚
  890. return null;
  891. }
  892. if( this.endTime <= bDate ){
  893. return null;
  894. }
  895. var range = {
  896. start: ( bDate <= this.startTime ) ? [0, 0, 0] : [bDate.get("hr"), bDate.get("min"), bDate.get("sec")],
  897. end: ( this.endTime <= eDate ) ? [23, 59, 59] : [eDate.get("hr"), eDate.get("min"), eDate.get("sec")]
  898. };
  899. range.startTime = new Date( this.year, this.month, this.day, range.start[0], range.start[1], range.start[2] );
  900. range.endTime = new Date( this.year, this.month, this.day, range.end[0], range.end[1], range.end[2] );
  901. range.diff = range.endTime - range.startTime;
  902. return range;
  903. },
  904. resize : function(){
  905. if(!this.documentList)return;
  906. this.documentList.each( function( doc ){
  907. doc.resize();
  908. }.bind(this))
  909. },
  910. reload: function(){
  911. this.view.reload();
  912. },
  913. destroy : function(){
  914. while( this.documentList.length > 0 ){
  915. this.documentList.pop().destroy();
  916. }
  917. this.container.empty();
  918. }
  919. });
  920. MWFCalendarDayView.Calendar.Document = new Class({
  921. initialize: function(container, day, data, range ){
  922. this.container = container;
  923. this.day = day;
  924. this.calendar = day.calendar;
  925. this.view = this.calendar.view;
  926. this.css = this.calendar.css;
  927. this.app = this.calendar.app;
  928. this.date = day.date.clone();
  929. this.data = data;
  930. this.range = range;
  931. this.load();
  932. },
  933. load: function(){
  934. var lightColor = this.lightColor = MWFCalendar.ColorOptions.getLightColor( this.data.color );
  935. var node = this.node = new Element("div",{
  936. styles : {
  937. position : "absolute",
  938. border : "1px solid "+lightColor,
  939. "background-color" : lightColor,
  940. "overflow" : "hidden",
  941. "border-radius" : "5px",
  942. "max-width" : "150px"
  943. },
  944. events : {
  945. click : function(){
  946. var form = new MWF.xApplication.Calendar.EventForm(this, this.data, {
  947. isFull : true
  948. }, {app:this.app});
  949. form.view = this.view;
  950. form.edit();
  951. }.bind(this),
  952. "mouseover" : function () {
  953. this.node.setStyle("border-color", this.data.color );
  954. }.bind(this),
  955. "mouseout" : function () {
  956. this.node.setStyle("border-color", this.lightColor );
  957. }.bind(this)
  958. }
  959. }).inject( this.container );
  960. node.setStyles(this.getCoordinate());
  961. var timeNode = new Element("div",{
  962. styles : {
  963. "font-size" : "10px",
  964. "padding-top" : "2px",
  965. "padding-left" : "2px"
  966. },
  967. text : this.range.startTime.format("%H:%M") + "-" + this.range.endTime.format("%H:%M")
  968. }).inject( node );
  969. var titleNode = new Element("div",{
  970. styles : {
  971. "padding-top" : "10px",
  972. "padding-left" : "5px",
  973. "font-size" : "12px"
  974. },
  975. text : this.data.title
  976. }).inject( node );
  977. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  978. axis : "x", "delay" : 350
  979. });
  980. },
  981. resize : function(){
  982. this.node.setStyles(this.getCoordinate());
  983. },
  984. getCoordinate : function(){
  985. var data = this.data;
  986. var range = this.range;
  987. var height = Math.floor( ( ( range.endTime - range.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayHeight)-4;
  988. var top = Math.floor( ( ( range.startTime - this.day.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayHeight)+2;
  989. //var width = Math.floor( MWFCalendarDayView.DayWidth / length )-2;
  990. //var left = ( width + 2)* index + 1;
  991. //var width = Math.floor( MWFCalendarDayView.DayWidth / range.path.length )-5;
  992. //var left = ( width + 5)* range.path.indexOf( data.id ) + 3;
  993. var width = Math.floor( MWFCalendarDayView.DayWidth / this.day.rangeList.length )-5;
  994. if( width > 150 ){
  995. width = 150;
  996. }
  997. var left = ( width + 5)* this.range.index + 3;
  998. return {
  999. top : top,
  1000. left : left,
  1001. width : width,
  1002. height : height
  1003. }
  1004. },
  1005. reload: function(){
  1006. if( this.tooltip )this.tooltip.destroy();
  1007. this.view.reload();
  1008. },
  1009. destroy: function(){
  1010. if( this.tooltip )this.tooltip.destroy();
  1011. this.node.destroy()
  1012. }
  1013. });