DayView.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. MWF.xApplication.Meeting.DayView = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "date": null
  7. },
  8. initialize: function(node, app, options){
  9. this.setOptions(options);
  10. this.path = "../x_component_Meeting/$DayView/";
  11. this.cssPath = "../x_component_Meeting/$DayView/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.app = app;
  14. this.container = $(node);
  15. var d = this.options.date;
  16. if( d ){
  17. this.date = typeOf( d ) == "string" ? new Date( d ) : d;
  18. }else{
  19. this.date = new Date();
  20. }
  21. this.load();
  22. },
  23. recordStatus : function(){
  24. return {
  25. date : (this.days.length > 0 ? this.days[0].date.clone() : this.date).format("db")
  26. };
  27. },
  28. load: function(){
  29. this.days = [];
  30. this.scrollNode = new Element("div", {
  31. "styles": this.css.scrollNode //this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode
  32. }).inject(this.container);
  33. this.contentWarpNode = new Element("div", {
  34. "styles": this.css.contentWarpNode
  35. }).inject(this.scrollNode);
  36. this.contentContainerNode = new Element("div",{
  37. "styles" : this.css.contentContainerNode
  38. }).inject(this.contentWarpNode);
  39. this.node = new Element("div", {
  40. "styles": this.css.contentNode
  41. }).inject(this.contentContainerNode);
  42. this.leftNode = new Element("div",{
  43. "styles" : this.css.leftNode
  44. }).inject(this.node);
  45. this.leftNode.addEvents( {
  46. "click" : function(){ this.decrementDay() }.bind(this),
  47. "mouseover" : function(){ this.leftNode.setStyles( this.css.leftNode_over ) }.bind(this),
  48. "mouseout" : function(){ this.leftNode.setStyles( this.css.leftNode ) }.bind(this)
  49. });
  50. this.dayContainerNode = new Element("div", {
  51. "styles": this.css.dayContainerNode
  52. }).inject(this.node);
  53. this.rightNode = new Element("div",{
  54. "styles" : this.css.rightNode
  55. }).inject(this.node);
  56. this.rightNode.addEvents( {
  57. "click" : function(){ this.incrementDay() }.bind(this),
  58. "mouseover" : function(){ this.rightNode.setStyles( this.css.rightNode_over ) }.bind(this),
  59. "mouseout" : function(){ this.rightNode.setStyles( this.css.rightNode ) }.bind(this)
  60. });
  61. //this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  62. //this.loadSideBar();
  63. this.resetNodeSize();
  64. this.resetNodeSizeFun = this.resetNodeSize.bind(this);
  65. this.app.addEvent("resize", this.resetNodeSizeFun );
  66. //this.dateNode = new Element("div", {"styles": this.css.dateNode}).inject(this.node);
  67. },
  68. resetNodeSize: function(){
  69. //if( this.app.inContainer )return;
  70. var size = this.container.getSize();
  71. var leftNodeSize = this.leftNode ? this.leftNode.getSize() : {x:0,y:0};
  72. var rightNodeSize = this.rightNode ? this.rightNode.getSize() : {x:0,y:0};
  73. var sideBarSize = this.app.sideBar ? this.app.sideBar.getSize() : {x:0,y:0};
  74. var availableX = size.x - leftNodeSize.x - rightNodeSize.x - sideBarSize.x ;
  75. this.dayNodeHeight = size.y-110;
  76. var leftTop = ( this.dayNodeHeight - leftNodeSize.y ) / 2;
  77. var rightTop = ( this.dayNodeHeight - rightNodeSize.y ) / 2;
  78. this.leftNode.setStyle("margin-top", ""+leftTop+"px");
  79. this.rightNode.setStyle("margin-top", ""+rightTop+"px");
  80. var dayCount = (availableX/330).toInt();
  81. this.scrollNode.setStyle("height", ""+(size.y-60)+"px");
  82. if( !this.app.inContainer ){
  83. this.scrollNode.setStyle("margin-top", "60px");
  84. }
  85. this.scrollNode.setStyle("margin-right", sideBarSize.x);
  86. if (this.contentWarpNode){
  87. var x = 330 * dayCount + leftNodeSize.x + rightNodeSize.x + sideBarSize.x;
  88. var m = (size.x - x)/2-10;
  89. this.contentWarpNode.setStyles({
  90. "width": ""+x+"px",
  91. "margin-left": ""+m+"px"
  92. });
  93. }
  94. if( this.dayCount != dayCount ){
  95. this.dayCount = dayCount;
  96. this.adjustDay();
  97. }else{
  98. for(var i = 0; i<this.days.length; i++ ){
  99. this.days[i].resetHeight();
  100. }
  101. }
  102. },
  103. toDay: function(date){
  104. this.date = date;
  105. this.dayContainerNode.empty();
  106. this.days = [];
  107. this.adjustDay();
  108. },
  109. adjustDay: function(){
  110. if( this.dayCount <= this.days.length ){
  111. this.date = this.days[this.dayCount].date.clone();
  112. for(var i = 0; i<this.days.length; i++ ){
  113. if( i < this.dayCount ){
  114. this.days[i].resetHeight();
  115. }else{
  116. if(this.days[i])this.days[i].destroy();
  117. }
  118. }
  119. this.days.splice( this.dayCount, (this.days.length - this.dayCount) );
  120. }else{
  121. for(var i = 0; i<this.days.length; i++ ){
  122. this.days[i].resetHeight();
  123. }
  124. if( this.days.length )this.date = this.days[this.days.length-1].date.clone().increment();
  125. this.loadDay( this.dayCount - this.days.length, this.days.length==0 )
  126. }
  127. },
  128. incrementDay : function(){
  129. if( this.days.length > 1 ) {
  130. var date = this.date = this.days[this.days.length-1].date.clone().increment();
  131. var node = this.days[this.days.length-1].node;
  132. this.days[0].destroy();
  133. this.days.splice(0, 1);
  134. this.days[0].setFrist();
  135. var day = new MWF.xApplication.Meeting.DayView.Day(this, node, "after", date, false );
  136. this.days.push(day);
  137. }else if( this.days.length == 1 ){
  138. var date = this.date = this.days[this.days.length-1].date.clone().increment();
  139. this.days[0].destroy();
  140. this.days.splice(0, 1);
  141. var day = new MWF.xApplication.Meeting.DayView.Day(this, this.dayContainerNode, null, date, false );
  142. this.days.push(day);
  143. }
  144. },
  145. decrementDay : function( node ){
  146. if( this.days.length > 1 ){
  147. var date = this.days[0].date.clone().decrement();
  148. this.days[0].disposeFrist();
  149. this.date = this.days[this.days.length-1].date.clone().decrement();
  150. this.days[this.days.length-1].destroy();
  151. this.days.splice(this.days.length-1, 1);
  152. var node = this.days[0].node;
  153. var day = new MWF.xApplication.Meeting.DayView.Day(this, node, "before", date, true);
  154. this.days.unshift( day )
  155. }else if( this.days.length == 1 ){
  156. var date = this.days[0].date.clone().decrement();
  157. this.date = this.days[this.days.length-1].date.clone().decrement();
  158. this.days[this.days.length-1].destroy();
  159. this.days.splice(this.days.length-1, 1);
  160. var day = new MWF.xApplication.Meeting.DayView.Day(this, this.dayContainerNode, null, date, true);
  161. this.days.unshift( day )
  162. }
  163. },
  164. loadDay: function( count, setFirst ){
  165. if (!this.date) this.date = new Date();
  166. if( !count )count = this.dayCount;
  167. var date = this.date;
  168. for( var i = 0; i< ( count || this.dayCount ); i++ ){
  169. var day = new MWF.xApplication.Meeting.DayView.Day(this, this.dayContainerNode, null,date, setFirst && i==0);
  170. this.days.push( day );
  171. date.increment();
  172. }
  173. //this.dayA.loadAction();
  174. },
  175. hide: function(){
  176. //this.app.removeEvent("resize", this.resetNodeSizeFun );
  177. var fx = new Fx.Morph(this.scrollNode, {
  178. "duration": "300",
  179. "transition": Fx.Transitions.Expo.easeOut
  180. });
  181. fx.start({
  182. "opacity": 0
  183. }).chain(function(){
  184. this.scrollNode.setStyle("display", "none");
  185. }.bind(this));
  186. },
  187. show: function() {
  188. //this.app.addEvent("resize", this.resetNodeSizeFun );
  189. this.scrollNode.setStyles(this.css.scrollNode);
  190. this.scrollNode.setStyles({"display": ""});
  191. if (this.app.inContainer) {
  192. this.node.setStyles({
  193. "opacity": 1,
  194. "position": "static",
  195. "width": "auto",
  196. "display": ""
  197. });
  198. } else {
  199. var fx = new Fx.Morph(this.scrollNode, {
  200. "duration": "800",
  201. "transition": Fx.Transitions.Expo.easeOut
  202. });
  203. this.app.fireAppEvent("resize");
  204. fx.start({
  205. "opacity": 1,
  206. "left": "0px"
  207. }).chain(function () {
  208. this.scrollNode.setStyles({
  209. "position": "static",
  210. "width": "auto",
  211. "display": ""
  212. });
  213. }.bind(this));
  214. }
  215. },
  216. reload: function(){
  217. this.date = (this.days.length > 0 ? this.days[0].date.clone() : this.date);
  218. this.days.each( function(d){
  219. d.destroy();
  220. });
  221. this.dayContainerNode.empty();
  222. this.days = [];
  223. this.loadDay( null, true );
  224. },
  225. destroy : function(){
  226. this.days.each( function(d){
  227. d.destroy();
  228. });
  229. this.app.removeEvent("resize", this.resetNodeSizeFun );
  230. this.scrollNode.destroy();
  231. }
  232. });
  233. MWF.xApplication.Meeting.DayView.Day = new Class({
  234. Implements: [Events],
  235. initialize: function(view, node, position, date, isFirst){
  236. this.view = view;
  237. this.css = this.view.css;
  238. this.container = node;
  239. this.position = position || "bottom";
  240. this.app = this.view.app;
  241. this.date = (date) ? date.clone().clearTime() : (new Date()).clearTime();
  242. this.today = new Date().clearTime();
  243. this.isToday = (this.date.diff(this.today)==0);
  244. this.times = [];
  245. this.meetings = [];
  246. this.isFirst = isFirst;
  247. this.load();
  248. },
  249. load : function(){
  250. this.node = new Element("div.dayNode", {"styles": this.css.dayNode}).inject(this.container , this.position);
  251. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  252. this.node.addEvents( {
  253. mouseover : function(){
  254. this.node.setStyles( this.css.dayNode_over );
  255. }.bind(this),
  256. mouseout : function(){
  257. this.node.setStyles( this.css.dayNode );
  258. }.bind(this)
  259. });
  260. this.titleNode = new Element("div.titleNode", { "styles": this.css[ !this.isToday ? "dayTitleNode" : "dayTitleNode_today"] }).inject(this.node);
  261. if( this.isToday ){
  262. this.titleNode.addClass("mainColor_bg");
  263. }
  264. if( this.today.diff(this.date) >= 0 ){
  265. var className;
  266. className = !this.isToday ? "dayCreateIconNode" : "dayCreateIconNode_today";
  267. this.dayCreateIconNode = new Element("div.dayCreateIconNode", {
  268. "styles": this.css[ className ],
  269. "events" : {
  270. "click" : function(){
  271. this.app.addMeeting( this.date.clone().clearTime() );
  272. }.bind(this)
  273. }
  274. }).inject(this.titleNode);
  275. }
  276. if( this.isFirst ){
  277. className = !this.isToday ? "dayTitleTextNode_first" : "dayTitleTextNode_today_first";
  278. }else{
  279. className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  280. }
  281. this.titleTextNode = new Element("div.dayTitleTextNode", {
  282. "styles": this.css[ className ],
  283. "text" : this.date.format(this.app.lp.dateFormatDay)
  284. }).inject(this.titleNode);
  285. if( this.isFirst ){
  286. MWF.require("MWF.widget.Calendar", function(){
  287. this.calendar = new MWF.widget.Calendar(this.titleTextNode, {
  288. "style":"meeting_blue",
  289. "todayClass": "mainColor_bg",
  290. "target": this.node,
  291. "baseDate" : this.date,
  292. "onQueryComplate": function(e, dv, date){
  293. var selectedDate = new Date.parse(dv);
  294. this.view.toDay(selectedDate);
  295. }.bind(this)
  296. });
  297. }.bind(this));
  298. }
  299. this.dayWeekNode = new Element("div.dayWeekNode", {
  300. "styles": this.css[ !this.isToday ? "dayWeekNode" : "dayWeekNode_today"],
  301. "text" : this.getWeek()
  302. }).inject(this.titleNode);
  303. if( this.isToday ){
  304. this.dayWeekNode.addClass("overColor_bg");
  305. }else{
  306. this.dayWeekNode.addClass("mainColor_bg");
  307. }
  308. this.dayContentNode = new Element("div.dayContentNode", {"styles": this.css.dayContentNode}).inject(this.node);
  309. this.loadMeetings();
  310. },
  311. resetHeight: function(){
  312. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  313. if( this.noMeetingNode ){
  314. this.noMeetingNode.setStyle("min-height",""+(this.view.dayNodeHeight - 220)+"px");
  315. this.noMeetingNode.setStyle("line-height",""+(this.view.dayNodeHeight - 220)+"px");
  316. }
  317. },
  318. getWeek: function(){
  319. var week = this.app.lp.weeks.arr[this.date.getDay()];
  320. var title = "";
  321. var now = this.today;
  322. var d = now.diff(this.date);
  323. if (d==0){
  324. title = this.app.lp.today;
  325. }else{
  326. title = week;
  327. }
  328. return title;
  329. },
  330. setFrist: function(){
  331. if( this.isFirst )return;
  332. this.isFirst = true;
  333. className = !this.isToday ? "dayTitleTextNode_first" : "dayTitleTextNode_today_first";
  334. this.titleTextNode.setStyles( this.css[ className ] );
  335. MWF.require("MWF.widget.Calendar", function(){
  336. this.calendar = new MWF.widget.Calendar(this.titleTextNode, {
  337. "style":"meeting_blue",
  338. "target": this.node,
  339. "baseDate" : this.date,
  340. "onQueryComplate": function(e, dv, date){
  341. var selectedDate = new Date.parse(dv);
  342. this.view.toDay(selectedDate);
  343. }.bind(this)
  344. });
  345. }.bind(this));
  346. },
  347. disposeFrist : function(){
  348. if( !this.isFirst )return;
  349. this.isFirst = false;
  350. this.titleTextNode.removeEvent("click");
  351. this.titleTextNode.removeEvent("focus");
  352. var className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  353. this.titleTextNode.setStyles( this.css[ className ] );
  354. this.calendar.container.destroy();
  355. this.calendar = null;
  356. },
  357. destroy: function(){
  358. if( this.calendar ){
  359. this.calendar.container.destroy();
  360. }
  361. this.meetings.each( function(m){
  362. m.destroy();
  363. });
  364. this.meetings = [];
  365. this.node.destroy();
  366. },
  367. loadMeetings: function(){
  368. this.app.isMeetingViewer( function( isAll ){
  369. this._loadMeetings( isAll );
  370. }.bind(this))
  371. },
  372. _loadMeetings: function( isAll ){
  373. var y = this.date.getFullYear();
  374. var m = this.date.getMonth()+1;
  375. var d = this.date.getDate();
  376. this.app.actions[ isAll ? "listMeetingDayAll" : "listMeetingDay" ](y, m, d, function(json){
  377. var flag = true;
  378. if( !json.data || json.data.length == 0 ){
  379. }else{
  380. json.data.each(function(meeting, i){
  381. if (!meeting.myReject){
  382. flag = false;
  383. this.meetings.push(new MWF.xApplication.Meeting.DayView.Meeting(this.dayContentNode, this, meeting));
  384. }
  385. }.bind(this));
  386. }
  387. if( flag ){
  388. this.noMeetingNode = new Element("div.noMeetingNode", {
  389. "styles": this.css.noMeetingNode,
  390. "text" : this.app.lp.noMeeting
  391. }).inject(this.dayContentNode);
  392. this.noMeetingNode.setStyle("min-height",""+(this.view.dayNodeHeight - 220)+"px");
  393. this.noMeetingNode.setStyle("line-height",""+(this.view.dayNodeHeight - 220)+"px");
  394. }
  395. //this.checkMeetingWidth();
  396. //this.checkMeetingWidthFun = this.checkMeetingWidth.bind(this);
  397. //this.app.addEvent("resize", this.checkMeetingWidthFun);
  398. }.bind(this));
  399. },
  400. reload : function(){
  401. this.view.reload();
  402. }
  403. });
  404. MWF.xApplication.Meeting.DayView.Meeting = new Class({
  405. Extends : MWF.xApplication.Meeting.MeetingArea
  406. });