DayView.js 16 KB

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