ListView.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. MWF.xApplication.Calendar.ListView = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "date": null,
  7. "action" : ""
  8. },
  9. initialize: function(node, app, options){
  10. this.setOptions(options);
  11. this.path = "../x_component_Calendar/$ListView/";
  12. this.cssPath = "../x_component_Calendar/$ListView/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.app = app;
  15. this.container = $(node);
  16. this.date = this.options.date || new Date();
  17. this.load();
  18. },
  19. load: function(){
  20. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  21. this.titleNode = new Element("div", {"styles": this.css.calendarTitleNode}).inject(this.node);
  22. this.contentAreaNode = new Element("div.contentAreaNode", {"styles": this.css.contentAreaNode}).inject(this.node);
  23. this.contentNode = new Element("div.contentNode", {"styles": this.css.contentNode}).inject(this.contentAreaNode);
  24. //this.loadSideBar();
  25. this.resetNodeSizeFun = this.resetNodeSize.bind(this);
  26. //this.app.addEvent("resize", this.resetNodeSizeFun );
  27. this.setTitleNode();
  28. this.loadList();
  29. this.resetNodeSize();
  30. },
  31. resetNodeSize: function(){
  32. //var size = this.container.getSize();
  33. //if (this.app.calendarConfig.hideMenu=="static"){
  34. // var y = size.y-120;
  35. // this.node.setStyle("height", ""+y+"px");
  36. // this.node.setStyle("margin-top", "60px");
  37. //}else{
  38. // var y = size.y-20;
  39. // this.node.setStyle("height", ""+y+"px");
  40. //}
  41. var size = this.container.getSize();
  42. var titleSize = this.titleNode ? this.titleNode.getSize() : {x:0, y:0};
  43. var y = size.y-50;
  44. //this.node.setStyle("margin-top", "60px");
  45. this.node.setStyle("height", ""+y+"px");
  46. var sideBar = this.app.sideBar ? this.app.sideBar.getSize() : { x : 0, y : 0 };
  47. //var x = size.x - sideBar.x;
  48. //this.node.setStyle("width", ""+x+"px");
  49. this.contentAreaNode.setStyle("height",(y-titleSize.y)+"px");
  50. this.contentAreaNode.setStyle("margin-right",sideBar.x+"px");
  51. },
  52. loadList : function(){
  53. this.app.currentDate = this.date.clone();
  54. this.monthStart = new Date( this.date.get("year"), this.date.get("month"), 1, 0, 0, 0 );
  55. this.monthStartStr = this.monthStart.format("db");
  56. var end = this.monthStart.clone().increment("month",1).decrement("day",1);
  57. this.monthEnd = new Date( end.get("year"), end.get("month"), end.get("date"), 23, 59, 59 );
  58. this.monthEndStr = this.monthEnd.format("db");
  59. this.view = new MWF.xApplication.Calendar.ListView.View(this);
  60. },
  61. hide: function(){
  62. var fx = new Fx.Morph(this.node, {
  63. "duration": "300",
  64. "transition": Fx.Transitions.Expo.easeOut
  65. });
  66. fx.start({
  67. "opacity": 0
  68. }).chain(function(){
  69. this.node.setStyle("display", "none");
  70. }.bind(this));
  71. },
  72. show: function(){
  73. this.node.setStyles(this.css.node);
  74. var fx = new Fx.Morph(this.node, {
  75. "duration": "800",
  76. "transition": Fx.Transitions.Expo.easeOut
  77. });
  78. this.app.fireAppEvent("resize");
  79. fx.start({
  80. "opacity": 1
  81. //"left": MWFCalendar.LeftNaviWidth+"px"
  82. }).chain(function(){
  83. //this.node.setStyles({
  84. // "position": "static",
  85. // "width": "auto"
  86. //});
  87. }.bind(this));
  88. },
  89. reload: function(){
  90. //this.app.reload();
  91. this.reLoadView();
  92. },
  93. recordStatus : function(){
  94. //var action = "";
  95. //if( this.currentNavi )action = this.currentNavi.retrieve("action");
  96. //return {
  97. // action : action
  98. //};
  99. },
  100. destroy : function(){
  101. if( this.currentView ){
  102. this.currentView.destroy()
  103. }
  104. this.app.removeEvent("resize", this.resetNodeSizeFun );
  105. this.node.destroy();
  106. },
  107. setTitleNode: function(){
  108. //this.view.titleContainer.getElements("div:only-child").setStyle("display","none");
  109. //if( this.titleNode ){
  110. // this.titleNode.setStyle("display","")
  111. //}
  112. //this.titleNode = new Element("div").inject(this.view.titleContainer);
  113. this.prevMonthNode = new Element("div.o2icon-triangle_left", {"styles": this.css.calendarPrevMonthNode}).inject(this.titleNode);
  114. var text = this.date.format(this.app.lp.dateFormatMonth);
  115. this.titleTextNode = new Element("div", {"styles": this.css.calendarTitleTextNode, "text": text}).inject(this.titleNode);
  116. this.nextMonthNode = new Element("div.o2icon-triangle_right", {"styles": this.css.calendarNextMonthNode}).inject(this.titleNode);
  117. this.prevMonthNode.addEvents({
  118. "mouseover": function(){
  119. this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);
  120. this.prevMonthNode.addClass("mainColor_color");
  121. }.bind(this),
  122. "mouseout": function(){
  123. this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode);
  124. this.prevMonthNode.removeClass("mainColor_color");
  125. }.bind(this),
  126. "mousedown": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_down);}.bind(this),
  127. "mouseup": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  128. "click": function(){this.changeMonthPrev();}.bind(this)
  129. });
  130. this.nextMonthNode.addEvents({
  131. "mouseover": function(){
  132. this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);
  133. this.nextMonthNode.addClass("mainColor_color");
  134. }.bind(this),
  135. "mouseout": function(){
  136. this.nextMonthNode.setStyles(this.css.calendarNextMonthNode);
  137. this.nextMonthNode.removeClass("mainColor_color");
  138. }.bind(this),
  139. "mousedown": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_down);}.bind(this),
  140. "mouseup": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  141. "click": function(){this.changeMonthNext();}.bind(this)
  142. });
  143. this.titleTextNode.addEvents({
  144. "mouseover": function(){
  145. this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);
  146. this.titleTextNode.addClass("mainColor_color");
  147. }.bind(this),
  148. "mouseout": function(){
  149. this.titleTextNode.setStyles(this.css.calendarTitleTextNode);
  150. this.titleTextNode.removeClass("mainColor_color");
  151. }.bind(this),
  152. "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  153. "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  154. "click": function(){this.changeMonthSelect();}.bind(this)
  155. });
  156. },
  157. changeMonthPrev: function(){
  158. this.date.decrement("month", 1);
  159. var text = this.date.format(this.app.lp.dateFormatMonth);
  160. this.titleTextNode.set("text", text);
  161. this.reLoadView();
  162. },
  163. changeMonthNext: function(){
  164. this.date.increment("month", 1);
  165. var text = this.date.format(this.app.lp.dateFormatMonth);
  166. this.titleTextNode.set("text", text);
  167. this.reLoadView();
  168. },
  169. changeMonthSelect: function(){
  170. if (!this.monthSelector) this.createMonthSelector();
  171. this.monthSelector.show();
  172. },
  173. createMonthSelector: function(){
  174. MWF.xDesktop.requireApp("Calendar","MonthView",null, false);
  175. this.monthSelector = new MWFCalendarMonthView.MonthSelector(this.date, this);
  176. },
  177. changeMonthTo: function(d){
  178. this.date = d;
  179. var text = this.date.format(this.app.lp.dateFormatMonth);
  180. this.titleTextNode.set("text", text);
  181. this.reLoadView();
  182. },
  183. reLoadView : function(){
  184. if(this.view)this.view.destroy();
  185. this.loadList();
  186. },
  187. inCurrentMonth : function( d ){
  188. if( d< this.monthStart ) return false;
  189. if( d > this.monthEnd )return false;
  190. return true;
  191. }
  192. });
  193. MWF.xApplication.Calendar.ListView.View = new Class({
  194. initialize: function(view){
  195. this.view = view;
  196. this.css = this.view.css;
  197. this.container = this.view.contentNode;
  198. this.app = this.view.app;
  199. this.lp = this.app.lp;
  200. this.items = [];
  201. this.load();
  202. },
  203. load: function(){
  204. //this.loadHead();
  205. this.loadList();
  206. },
  207. loadHead: function(){
  208. this.table = new Element("table", {
  209. "styles": this.css.listViewTable,
  210. "border": "0",
  211. "cellPadding": "0",
  212. "cellSpacing": "0"
  213. }).inject(this.container);
  214. },
  215. loadEmptyNode : function(){
  216. this.noEventNode = new Element("div",{
  217. "styles" : this.css.noEventNode,
  218. "text" : this.lp.noEventCurMonth
  219. }).inject( this.container );
  220. },
  221. loadList: function() {
  222. this.app.actions.listEventWithFilter( {
  223. calendarIds : this.app.getSelectedCalendarId(),
  224. startTime : this.view.monthStartStr,
  225. endTime : this.view.monthEndStr //,
  226. //createPerson : this.app.userName
  227. }, function(json){
  228. this.parseDate( json );
  229. if( this.wholeDayData.length == 0 && this.inOneDayEvents.length == 0){
  230. this.loadEmptyNode()
  231. }else{
  232. this.loadHead();
  233. this.loadDays();
  234. }
  235. }.bind(this))
  236. },
  237. parseDate: function( json ){
  238. this.dataMap = {};
  239. this.wholeDayData = ( json.data && json.data.wholeDayEvents ) ? json.data.wholeDayEvents : [];
  240. this.inOneDayEvents = [];
  241. (( json.data && json.data.inOneDayEvents) ? json.data.inOneDayEvents : []).each( function( d ){
  242. if(d.inOneDayEvents.length > 0 ){
  243. this.inOneDayEvents.push( d );
  244. }
  245. }.bind(this));
  246. this.getEveryDayByWholeDayData();
  247. this.inOneDayEvents.each( function( d ){
  248. var map = this.dataMap[d.eventDate];
  249. if( !map )map = this.dataMap[d.eventDate] = {};
  250. if( !map.inoneday )map.inoneday = [];
  251. d.inOneDayEvents.each( function( event ){
  252. map.inoneday.push({
  253. start : Date.parse( event.startTime).format("%H:%M"),
  254. end : Date.parse( event.endTime).format("%H:%M"),
  255. data : event
  256. })
  257. });
  258. }.bind(this));
  259. //this.loadLines(json.data);
  260. },
  261. getEveryDayByWholeDayData : function(){
  262. this.wholeDayData.each( function( event ){
  263. var startTime = Date.parse(event.startTime);
  264. var endTime = Date.parse(event.endTime);
  265. var start, end;
  266. start = startTime < this.view.monthStart ? this.view.monthStart.clone() : startTime.clone();
  267. end = endTime > this.view.monthEnd ? this.view.monthEnd.clone() : endTime.clone();
  268. var startDayTime = start.format("%H:%M");
  269. var endDayTime = end.format("%H:%M");
  270. start.clearTime();
  271. end.clearTime();
  272. var i = 0;
  273. while( start <= end ){
  274. var startStr = start.format("%Y-%m-%d");
  275. var alldayFlag = false;
  276. var map = this.dataMap[startStr];
  277. if( !map )map = this.dataMap[startStr] = {};
  278. if( event.isAllDayEvent ){
  279. alldayFlag = true;
  280. }else{
  281. var startT = i==0 ? startDayTime : "00:00";
  282. var endT = start == end ? endDayTime : "23:59";
  283. if( startT == "00:00" && endT == "23:59")alldayFlag = true;
  284. }
  285. if( alldayFlag ){
  286. if( !map.wholeday )map.wholeday = [];
  287. map.wholeday.push({data : event});
  288. }else{
  289. if( !map.inoneday )map.inoneday = [];
  290. map.inoneday.push({
  291. start : startT,
  292. end : endT,
  293. data : event
  294. });
  295. }
  296. start.increment( "day", 1 );
  297. i++;
  298. }
  299. }.bind(this))
  300. },
  301. loadDays: function(items){
  302. for( var dateStr in this.dataMap ){
  303. this.loadLine( dateStr, this.dataMap[dateStr] );
  304. }
  305. if (this.mask){
  306. this.mask.hide(function(){
  307. //MWF.release(this.mask);
  308. this.mask = null;
  309. }.bind(this));
  310. }
  311. },
  312. loadLine: function(dateStr, item){
  313. this.items.push(new MWF.xApplication.Calendar.ListView.View.DayLine(this, dateStr, item));
  314. },
  315. destroy: function(){
  316. this.items.each(function(item){
  317. item.destroy();
  318. });
  319. this.items = [];
  320. this.view.currentView = null;
  321. if(this.table)this.table.destroy();
  322. if( this.noEventNode )this.noEventNode.destroy();
  323. }
  324. });
  325. MWF.xApplication.Calendar.ListView.View.DayLine = new Class({
  326. initialize: function(table, dateStr, item){
  327. this.table = table;
  328. this.view = this.table.view;
  329. this.css = this.view.css;
  330. this.container = this.table.table;
  331. this.dateStr = dateStr;
  332. this.date = Date.parse(dateStr);
  333. this.app = this.view.app;
  334. this.data = item;
  335. this.load();
  336. },
  337. load: function(){
  338. this.isToday = this.date.clone().clearTime().diff( new Date().clearTime(), "day" ) == 0;
  339. var showDate = this.date.format(this.app.lp.dateFormatMonthDay2) + " " + this.app.lp.weeks.arr[ this.date.getDay() ];
  340. this.node = new Element("tr",{
  341. "html": "<td colspan='4'>"+showDate+"</td>"
  342. }).inject(this.container);
  343. if( this.isToday ){
  344. this.node.getElements("td").setStyles(this.css.listViewTableTd_ToDay);
  345. }else{
  346. this.node.getElements("td").setStyles(this.css.listViewTableTd_Day);
  347. }
  348. var wholeday =this.data.wholeday || [];
  349. wholeday.each( function( d ){
  350. new MWF.xApplication.Calendar.ListView.View.Line( this, d, true );
  351. }.bind(this));
  352. var inoneday = this.data.inoneday || [];
  353. inoneday.each( function( d ){
  354. new MWF.xApplication.Calendar.ListView.View.Line( this, d, false );
  355. }.bind(this))
  356. },
  357. destroy: function(){
  358. if (this.node) this.node.destroy();
  359. //MWF.release(this);
  360. }
  361. });
  362. MWF.xApplication.Calendar.ListView.View.Line = new Class({
  363. initialize: function(day, item, isWholeday ){
  364. this.day = day;
  365. this.table = day.table;
  366. this.view = this.table.view;
  367. this.css = this.view.css;
  368. this.container = this.table.table;
  369. this.app = this.view.app;
  370. this.data = item;
  371. this.isWholeday = isWholeday;
  372. this.load();
  373. },
  374. load: function(){
  375. //var sTime = Date.parse(this.data.startTime);
  376. //
  377. //var bdate = sTime.format(this.app.lp.dateFormatDay);
  378. //
  379. //var btime = sTime.format("%H:%M");
  380. //var etime = Date.parse(this.data.completedTime).format("%H:%M");
  381. if( this.isWholeday ){
  382. this.node = new Element("tr",{
  383. "html": "<td width='30'><div></div></td><td width='100'>"+this.app.lp.allDay+"</td><td>"+o2.common.encodeHtml(this.data.data.title) +"</td><td>"+ (this.data.data.locationName || "") +"</td>"
  384. }).inject(this.container);
  385. }else{
  386. var bdate = this.data.start;
  387. var edate = this.data.end;
  388. this.node = new Element("tr",{
  389. "html": "<td width='30'><div></div></td><td>"+bdate+" - "+edate+"</td><td>"+o2.common.encodeHtml(this.data.data.title) +"</td><td>"+(this.data.data.locationName || "") +"</td>"
  390. }).inject(this.container);
  391. }
  392. if( this.day.isToday ){
  393. this.node.getElements("td").setStyles(this.css.listViewTableTd_today2);
  394. }else{
  395. this.node.getElements("td").setStyles(this.css.listViewTableTd);
  396. }
  397. var colorNode = this.node.getElement("div");
  398. colorNode.setStyles(this.css.colorTdNode);
  399. colorNode.setStyle("background-color", this.data.data.color );
  400. this.node.addEvents({
  401. "mouseover" : function(){
  402. this.node.getElements("td").setStyles( this.css.listViewTableTd_over )
  403. }.bind(this),
  404. "mouseout" : function(){
  405. this.node.getElements("td").setStyles( this.day.isToday ? this.css.listViewTableTd_today2 : this.css.listViewTableTd );
  406. }.bind(this)
  407. });
  408. this.node.addEvent("click", function(e){
  409. this.openCalendar(e);
  410. }.bind(this));
  411. },
  412. openCalendar: function(e){
  413. this.form = new MWF.xApplication.Calendar.EventForm(this,this.data.data, {
  414. isFull : true
  415. }, {app:this.app});
  416. this.form.view = this.view;
  417. this.app.isEventEditable(this.data) ? this.form.edit() : this.form.open();
  418. },
  419. destroy: function(){
  420. if (this.node) this.node.destroy();
  421. //MWF.release(this);
  422. }
  423. });