ListView.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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", {"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", {"styles": this.css.calendarNextMonthNode}).inject(this.titleNode);
  117. this.prevMonthNode.addEvents({
  118. "mouseover": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  119. "mouseout": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode);}.bind(this),
  120. "mousedown": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_down);}.bind(this),
  121. "mouseup": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  122. "click": function(){this.changeMonthPrev();}.bind(this)
  123. });
  124. this.nextMonthNode.addEvents({
  125. "mouseover": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  126. "mouseout": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode);}.bind(this),
  127. "mousedown": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_down);}.bind(this),
  128. "mouseup": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  129. "click": function(){this.changeMonthNext();}.bind(this)
  130. });
  131. this.titleTextNode.addEvents({
  132. "mouseover": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  133. "mouseout": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode);}.bind(this),
  134. "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  135. "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  136. "click": function(){this.changeMonthSelect();}.bind(this)
  137. });
  138. },
  139. changeMonthPrev: function(){
  140. this.date.decrement("month", 1);
  141. var text = this.date.format(this.app.lp.dateFormatMonth);
  142. this.titleTextNode.set("text", text);
  143. this.reLoadView();
  144. },
  145. changeMonthNext: function(){
  146. this.date.increment("month", 1);
  147. var text = this.date.format(this.app.lp.dateFormatMonth);
  148. this.titleTextNode.set("text", text);
  149. this.reLoadView();
  150. },
  151. changeMonthSelect: function(){
  152. if (!this.monthSelector) this.createMonthSelector();
  153. this.monthSelector.show();
  154. },
  155. createMonthSelector: function(){
  156. MWF.xDesktop.requireApp("Calendar","MonthView",null, false);
  157. this.monthSelector = new MWFCalendarMonthView.MonthSelector(this.date, this);
  158. },
  159. changeMonthTo: function(d){
  160. this.date = d;
  161. var text = this.date.format(this.app.lp.dateFormatMonth);
  162. this.titleTextNode.set("text", text);
  163. this.reLoadView();
  164. },
  165. reLoadView : function(){
  166. if(this.view)this.view.destroy();
  167. this.loadList();
  168. },
  169. inCurrentMonth : function( d ){
  170. if( d< this.monthStart ) return false;
  171. if( d > this.monthEnd )return false;
  172. return true;
  173. }
  174. });
  175. MWF.xApplication.Calendar.ListView.View = new Class({
  176. initialize: function(view){
  177. this.view = view;
  178. this.css = this.view.css;
  179. this.container = this.view.contentNode;
  180. this.app = this.view.app;
  181. this.items = [];
  182. this.load();
  183. },
  184. load: function(){
  185. //this.loadHead();
  186. this.loadList();
  187. },
  188. loadHead: function(){
  189. this.table = new Element("table", {
  190. "styles": this.css.listViewTable,
  191. "border": "0",
  192. "cellPadding": "0",
  193. "cellSpacing": "0"
  194. }).inject(this.container);
  195. },
  196. loadEmptyNode : function(){
  197. this.noEventNode = new Element("div",{
  198. "styles" : this.css.noEventNode,
  199. "text" : "该月无日程安排"
  200. }).inject( this.container );
  201. },
  202. loadList: function() {
  203. this.app.actions.listEventWithFilter( {
  204. calendarIds : this.app.getSelectedCalendarId(),
  205. startTime : this.view.monthStartStr,
  206. endTime : this.view.monthEndStr //,
  207. //createPerson : this.app.userName
  208. }, function(json){
  209. this.parseDate( json );
  210. if( this.wholeDayData.length == 0 && this.inOneDayEvents.length == 0){
  211. this.loadEmptyNode()
  212. }else{
  213. this.loadHead();
  214. this.loadDays();
  215. }
  216. }.bind(this))
  217. },
  218. parseDate: function( json ){
  219. this.dataMap = {};
  220. this.wholeDayData = ( json.data && json.data.wholeDayEvents ) ? json.data.wholeDayEvents : [];
  221. this.inOneDayEvents = [];
  222. (( json.data && json.data.inOneDayEvents) ? json.data.inOneDayEvents : []).each( function( d ){
  223. if(d.inOneDayEvents.length > 0 ){
  224. this.inOneDayEvents.push( d );
  225. }
  226. }.bind(this));
  227. this.getEveryDayByWholeDayData();
  228. this.inOneDayEvents.each( function( d ){
  229. var map = this.dataMap[d.eventDate];
  230. if( !map )map = this.dataMap[d.eventDate] = {};
  231. if( !map.inoneday )map.inoneday = [];
  232. d.inOneDayEvents.each( function( event ){
  233. map.inoneday.push({
  234. start : Date.parse( event.startTime).format("%H:%M"),
  235. end : Date.parse( event.endTime).format("%H:%M"),
  236. data : event
  237. })
  238. });
  239. }.bind(this));
  240. //this.loadLines(json.data);
  241. },
  242. getEveryDayByWholeDayData : function(){
  243. this.wholeDayData.each( function( event ){
  244. var startTime = Date.parse(event.startTime);
  245. var endTime = Date.parse(event.endTime);
  246. var start, end;
  247. start = startTime < this.view.monthStart ? this.view.monthStart.clone() : startTime.clone();
  248. end = endTime > this.view.monthEnd ? this.view.monthEnd.clone() : endTime.clone();
  249. var startDayTime = start.format("%H:%M");
  250. var endDayTime = end.format("%H:%M");
  251. start.clearTime();
  252. end.clearTime();
  253. var i = 0;
  254. while( start <= end ){
  255. var startStr = start.format("%Y-%m-%d");
  256. var alldayFlag = false;
  257. var map = this.dataMap[startStr];
  258. if( !map )map = this.dataMap[startStr] = {};
  259. if( event.isAllDayEvent ){
  260. alldayFlag = true;
  261. }else{
  262. var startT = i==0 ? startDayTime : "00:00";
  263. var endT = start == end ? endDayTime : "23:59";
  264. if( startT == "00:00" && endT == "23:59")alldayFlag = true;
  265. }
  266. if( alldayFlag ){
  267. if( !map.wholeday )map.wholeday = [];
  268. map.wholeday.push({data : event});
  269. }else{
  270. if( !map.inoneday )map.inoneday = [];
  271. map.inoneday.push({
  272. start : startT,
  273. end : endT,
  274. data : event
  275. });
  276. }
  277. start.increment( "day", 1 );
  278. i++;
  279. }
  280. }.bind(this))
  281. },
  282. loadDays: function(items){
  283. for( var dateStr in this.dataMap ){
  284. this.loadLine( dateStr, this.dataMap[dateStr] );
  285. }
  286. if (this.mask){
  287. this.mask.hide(function(){
  288. //MWF.release(this.mask);
  289. this.mask = null;
  290. }.bind(this));
  291. }
  292. },
  293. loadLine: function(dateStr, item){
  294. this.items.push(new MWF.xApplication.Calendar.ListView.View.DayLine(this, dateStr, item));
  295. },
  296. destroy: function(){
  297. this.items.each(function(item){
  298. item.destroy();
  299. });
  300. this.items = [];
  301. this.view.currentView = null;
  302. if(this.table)this.table.destroy();
  303. if( this.noEventNode )this.noEventNode.destroy();
  304. }
  305. });
  306. MWF.xApplication.Calendar.ListView.View.DayLine = new Class({
  307. initialize: function(table, dateStr, item){
  308. this.table = table;
  309. this.view = this.table.view;
  310. this.css = this.view.css;
  311. this.container = this.table.table;
  312. this.dateStr = dateStr;
  313. this.date = Date.parse(dateStr);
  314. this.app = this.view.app;
  315. this.data = item;
  316. this.load();
  317. },
  318. load: function(){
  319. this.isToday = this.date.clone().clearTime().diff( new Date().clearTime(), "day" ) == 0;
  320. var showDate = this.date.format(this.app.lp.dateFormatMonthDay2) + " " + this.app.lp.weeks.arr[ this.date.getDay() ];
  321. this.node = new Element("tr",{
  322. "html": "<td colspan='4'>"+showDate+"</td>"
  323. }).inject(this.container);
  324. if( this.isToday ){
  325. this.node.getElements("td").setStyles(this.css.listViewTableTd_ToDay);
  326. }else{
  327. this.node.getElements("td").setStyles(this.css.listViewTableTd_Day);
  328. }
  329. var wholeday =this.data.wholeday || [];
  330. wholeday.each( function( d ){
  331. new MWF.xApplication.Calendar.ListView.View.Line( this, d, true );
  332. }.bind(this));
  333. var inoneday = this.data.inoneday || [];
  334. inoneday.each( function( d ){
  335. new MWF.xApplication.Calendar.ListView.View.Line( this, d, false );
  336. }.bind(this))
  337. },
  338. destroy: function(){
  339. if (this.node) this.node.destroy();
  340. //MWF.release(this);
  341. }
  342. });
  343. MWF.xApplication.Calendar.ListView.View.Line = new Class({
  344. initialize: function(day, item, isWholeday ){
  345. this.day = day;
  346. this.table = day.table;
  347. this.view = this.table.view;
  348. this.css = this.view.css;
  349. this.container = this.table.table;
  350. this.app = this.view.app;
  351. this.data = item;
  352. this.isWholeday = isWholeday;
  353. this.load();
  354. },
  355. load: function(){
  356. //var sTime = Date.parse(this.data.startTime);
  357. //
  358. //var bdate = sTime.format(this.app.lp.dateFormatDay);
  359. //
  360. //var btime = sTime.format("%H:%M");
  361. //var etime = Date.parse(this.data.completedTime).format("%H:%M");
  362. if( this.isWholeday ){
  363. this.node = new Element("tr",{
  364. "html": "<td width='30'><div></div></td><td width='100'>全天</td><td>"+this.data.data.title +"</td><td>"+ (this.data.data.locationName || "") +"</td>"
  365. }).inject(this.container);
  366. }else{
  367. var bdate = this.data.start;
  368. var edate = this.data.end;
  369. this.node = new Element("tr",{
  370. "html": "<td width='30'><div></div></td><td>"+bdate+" - "+edate+"</td><td>"+this.data.data.title +"</td><td>"+(this.data.data.locationName || "") +"</td>"
  371. }).inject(this.container);
  372. }
  373. if( this.day.isToday ){
  374. this.node.getElements("td").setStyles(this.css.listViewTableTd_today2);
  375. }else{
  376. this.node.getElements("td").setStyles(this.css.listViewTableTd);
  377. }
  378. var colorNode = this.node.getElement("div");
  379. colorNode.setStyles(this.css.colorTdNode);
  380. colorNode.setStyle("background-color", this.data.data.color );
  381. this.node.addEvents({
  382. "mouseover" : function(){
  383. this.node.getElements("td").setStyles( this.css.listViewTableTd_over )
  384. }.bind(this),
  385. "mouseout" : function(){
  386. this.node.getElements("td").setStyles( this.day.isToday ? this.css.listViewTableTd_today2 : this.css.listViewTableTd );
  387. }.bind(this)
  388. });
  389. this.node.addEvent("click", function(e){
  390. this.openCalendar(e);
  391. }.bind(this));
  392. },
  393. openCalendar: function(e){
  394. this.form = new MWF.xApplication.Calendar.EventForm(this,this.data.data, {
  395. isFull : true
  396. }, {app:this.app});
  397. this.form.view = this.view;
  398. this.form.edit();
  399. },
  400. destroy: function(){
  401. if (this.node) this.node.destroy();
  402. //MWF.release(this);
  403. }
  404. });