DayView.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  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. this.tooltip.view = this.view;
  798. },
  799. getCoordinate : function(){
  800. var data = this.data;
  801. var range = this.range;
  802. var top = this.yIndex * 24;
  803. var dateStart = this.day.startTime;
  804. var dateEnd = this.day.endTime;
  805. if( this.data.dateStart < dateStart ){
  806. this.beginDateOutRange = true;
  807. }else{
  808. this.beginDateOutRange = false;
  809. dateStart = this.data.dateStart;
  810. }
  811. if( this.data.dateEnd > dateEnd ){
  812. this.endDateOutRange = true;
  813. }else{
  814. this.endDateOutRange = false;
  815. dateEnd = this.data.dateEnd;
  816. }
  817. var diff = dateEnd - dateStart;
  818. var width = ( diff / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayWidth - 2;
  819. var left = ( ( dateStart - this.day.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayWidth + 3;
  820. //var marginRight = ( ( this.weekDateEnd - dateEnd ) / MWFCalendarDayView.DayMsec) * MWFCalendarDayView.DayWidth;
  821. return {
  822. top : top + 2,
  823. left : left,
  824. width : width // + ( !this.isLast ? 2 : -2 ) //,
  825. //"margin-left" : marginLeft,
  826. //"margin-right" : marginRight
  827. }
  828. },
  829. resize : function(){
  830. this.node.setStyles(this.getCoordinate());
  831. },
  832. reload: function(){
  833. if( this.tooltip )this.tooltip.destroy();
  834. this.view.reload();
  835. },
  836. destroy : function(){
  837. if( this.tooltip )this.tooltip.destroy();
  838. this.node.destroy();
  839. }
  840. });
  841. MWFCalendarDayView.Calendar.Day = new Class({
  842. Implements: [Events],
  843. initialize: function(container, date, calendar, data){
  844. this.container = container;
  845. this.calendar = calendar;
  846. this.view = this.calendar.view;
  847. this.css = this.calendar.css;
  848. this.app = this.calendar.app;
  849. this.date = date.clone();
  850. this.data = data;
  851. this.calendars = [];
  852. this.load();
  853. },
  854. load: function(){
  855. this.day = this.date.getDate();
  856. this.month = this.date.getMonth();
  857. this.year = this.date.getFullYear();
  858. //this.startTime = new Date( this.year, this.month, this.day, 0, 0, 0 );
  859. //this.endTime = new Date( this.year, this.month, this.day, 23, 59, 59 );
  860. this.startTime = this.calendar.startTime;
  861. this.endTime = this.calendar.endTime;
  862. this.rangeList = [];
  863. this.rangeObject = {};
  864. this.data.each( function(d , i){
  865. var range = this.getTimeRange( d.startTime, d.endTime );
  866. if( !range )return null;
  867. d.range = range;
  868. d.range.data = d;
  869. d.range.id = d.id;
  870. this.rangeList.push( range );
  871. this.rangeObject[d.id] = range;
  872. }.bind(this));
  873. this.sortRange();
  874. var length = this.data.length;
  875. this.documentList = [];
  876. this.rangeList.each( function(r , i){
  877. r.index = this.rangeList.indexOf( r );
  878. var d = r.data;
  879. //var coordinate = this.getCoordinate( d, range );
  880. this.documentList.push( new MWFCalendarDayView.Calendar.Document(this.container, this, d, r ) );
  881. }.bind(this))
  882. },
  883. sortRange : function(){
  884. this.rangeList.sort( function(range1, range2){
  885. return range1.startTime - range2.startTime;
  886. });
  887. },
  888. getTimeRange: function( bDate1, eDate1 ){
  889. var bDate = typeOf(bDate1) == "string" ? Date.parse(bDate1) : bDate1;
  890. var eDate = typeOf(eDate1) == "string" ? Date.parse(eDate1) : eDate1;
  891. if( eDate <= this.startTime ){ //比当天天12点更晚
  892. return null;
  893. }
  894. if( this.endTime <= bDate ){
  895. return null;
  896. }
  897. var range = {
  898. start: ( bDate <= this.startTime ) ? [0, 0, 0] : [bDate.get("hr"), bDate.get("min"), bDate.get("sec")],
  899. end: ( this.endTime <= eDate ) ? [23, 59, 59] : [eDate.get("hr"), eDate.get("min"), eDate.get("sec")]
  900. };
  901. range.startTime = new Date( this.year, this.month, this.day, range.start[0], range.start[1], range.start[2] );
  902. range.endTime = new Date( this.year, this.month, this.day, range.end[0], range.end[1], range.end[2] );
  903. range.diff = range.endTime - range.startTime;
  904. return range;
  905. },
  906. resize : function(){
  907. if(!this.documentList)return;
  908. this.documentList.each( function( doc ){
  909. doc.resize();
  910. }.bind(this))
  911. },
  912. reload: function(){
  913. this.view.reload();
  914. },
  915. destroy : function(){
  916. while( this.documentList.length > 0 ){
  917. this.documentList.pop().destroy();
  918. }
  919. this.container.empty();
  920. }
  921. });
  922. MWFCalendarDayView.Calendar.Document = new Class({
  923. initialize: function(container, day, data, range ){
  924. this.container = container;
  925. this.day = day;
  926. this.calendar = day.calendar;
  927. this.view = this.calendar.view;
  928. this.css = this.calendar.css;
  929. this.app = this.calendar.app;
  930. this.date = day.date.clone();
  931. this.data = data;
  932. this.range = range;
  933. this.load();
  934. },
  935. load: function(){
  936. var lightColor = this.lightColor = MWFCalendar.ColorOptions.getLightColor( this.data.color );
  937. var node = this.node = new Element("div",{
  938. styles : {
  939. position : "absolute",
  940. border : "1px solid "+lightColor,
  941. "background-color" : lightColor,
  942. "overflow" : "hidden",
  943. "border-radius" : "5px",
  944. "max-width" : "150px"
  945. },
  946. events : {
  947. click : function(){
  948. var form = new MWF.xApplication.Calendar.EventForm(this, this.data, {
  949. isFull : true
  950. }, {app:this.app});
  951. form.view = this.view;
  952. form.edit();
  953. }.bind(this),
  954. "mouseover" : function () {
  955. this.node.setStyle("border-color", this.data.color );
  956. }.bind(this),
  957. "mouseout" : function () {
  958. this.node.setStyle("border-color", this.lightColor );
  959. }.bind(this)
  960. }
  961. }).inject( this.container );
  962. node.setStyles(this.getCoordinate());
  963. var timeNode = new Element("div",{
  964. styles : {
  965. "font-size" : "10px",
  966. "padding-top" : "2px",
  967. "padding-left" : "2px"
  968. },
  969. text : this.range.startTime.format("%H:%M") + "-" + this.range.endTime.format("%H:%M")
  970. }).inject( node );
  971. var titleNode = new Element("div",{
  972. styles : {
  973. "padding-top" : "10px",
  974. "padding-left" : "5px",
  975. "font-size" : "12px"
  976. },
  977. text : this.data.title
  978. }).inject( node );
  979. this.tooltip = new MWF.xApplication.Calendar.EventTooltip(this.app.content, this.node, this.app, this.data, {
  980. axis : "x", "delay" : 350
  981. });
  982. this.tooltip.view = this.view;
  983. },
  984. resize : function(){
  985. this.node.setStyles(this.getCoordinate());
  986. },
  987. getCoordinate : function(){
  988. var data = this.data;
  989. var range = this.range;
  990. var width_div = 8;
  991. var top_div = 0;
  992. if(Browser.name === "ie" ){
  993. width_div = 4;
  994. top_div = -2
  995. }
  996. var height = Math.floor( ( ( range.endTime - range.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayHeight)-width_div;
  997. if(height < 16) height = 16;
  998. var top = Math.floor( ( ( range.startTime - this.day.startTime ) / MWFCalendarDayView.DayMsec ) * MWFCalendarDayView.DayHeight)-top_div;
  999. //var width = Math.floor( MWFCalendarDayView.DayWidth / length )-2;
  1000. //var left = ( width + 2)* index + 1;
  1001. //var width = Math.floor( MWFCalendarDayView.DayWidth / range.path.length )-5;
  1002. //var left = ( width + 5)* range.path.indexOf( data.id ) + 3;
  1003. var width = Math.floor( MWFCalendarDayView.DayWidth / this.day.rangeList.length )-5;
  1004. if( width > 150 ){
  1005. width = 150;
  1006. }
  1007. var left = ( width + 5)* this.range.index + 3;
  1008. return {
  1009. top : top,
  1010. left : left,
  1011. width : width,
  1012. height : height
  1013. }
  1014. },
  1015. reload: function(){
  1016. if( this.tooltip )this.tooltip.destroy();
  1017. this.view.reload();
  1018. },
  1019. destroy: function(){
  1020. if( this.tooltip )this.tooltip.destroy();
  1021. this.node.destroy()
  1022. }
  1023. });