DayView.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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 //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.today.diff(this.date) >= 0 ){
  262. var className;
  263. className = !this.isToday ? "dayCreateIconNode" : "dayCreateIconNode_today";
  264. this.dayCreateIconNode = new Element("div.dayCreateIconNode", {
  265. "styles": this.css[ className ],
  266. "events" : {
  267. "click" : function(){
  268. this.app.addMeeting( this.date.clone().clearTime() );
  269. }.bind(this)
  270. }
  271. }).inject(this.titleNode);
  272. }
  273. if( this.isFirst ){
  274. className = !this.isToday ? "dayTitleTextNode_first" : "dayTitleTextNode_today_first";
  275. }else{
  276. className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  277. }
  278. this.titleTextNode = new Element("div.dayTitleTextNode", {
  279. "styles": this.css[ className ],
  280. "text" : this.date.format("%Y年%m月%d日")
  281. }).inject(this.titleNode);
  282. if( this.isFirst ){
  283. MWF.require("MWF.widget.Calendar", function(){
  284. this.calendar = new MWF.widget.Calendar(this.titleTextNode, {
  285. "style":"meeting_blue",
  286. "target": this.node,
  287. "baseDate" : this.date,
  288. "onQueryComplate": function(e, dv, date){
  289. var selectedDate = new Date.parse(dv);
  290. this.view.toDay(selectedDate);
  291. }.bind(this)
  292. });
  293. }.bind(this));
  294. }
  295. this.dayWeekNode = new Element("div.dayWeekNode", {
  296. "styles": this.css[ !this.isToday ? "dayWeekNode" : "dayWeekNode_today"],
  297. "text" : this.getWeek()
  298. }).inject(this.titleNode);
  299. this.dayContentNode = new Element("div.dayContentNode", {"styles": this.css.dayContentNode}).inject(this.node);
  300. this.loadMeetings();
  301. },
  302. resetHeight: function(){
  303. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  304. if( this.noMeetingNode ){
  305. this.noMeetingNode.setStyle("min-height",""+(this.view.dayNodeHeight - 220)+"px");
  306. this.noMeetingNode.setStyle("line-height",""+(this.view.dayNodeHeight - 220)+"px");
  307. }
  308. },
  309. getWeek: function(){
  310. var week = this.app.lp.weeks.arr[this.date.getDay()];
  311. var title = "";
  312. var now = this.today;
  313. var d = now.diff(this.date);
  314. if (d==0){
  315. title = this.app.lp.today;
  316. }else{
  317. title = week;
  318. }
  319. return title;
  320. },
  321. setFrist: function(){
  322. if( this.isFirst )return;
  323. this.isFirst = true;
  324. className = !this.isToday ? "dayTitleTextNode_first" : "dayTitleTextNode_today_first";
  325. this.titleTextNode.setStyles( this.css[ className ] );
  326. MWF.require("MWF.widget.Calendar", function(){
  327. this.calendar = new MWF.widget.Calendar(this.titleTextNode, {
  328. "style":"meeting_blue",
  329. "target": this.node,
  330. "baseDate" : this.date,
  331. "onQueryComplate": function(e, dv, date){
  332. var selectedDate = new Date.parse(dv);
  333. this.view.toDay(selectedDate);
  334. }.bind(this)
  335. });
  336. }.bind(this));
  337. },
  338. disposeFrist : function(){
  339. if( !this.isFirst )return;
  340. this.isFirst = false;
  341. this.titleTextNode.removeEvent("click");
  342. this.titleTextNode.removeEvent("focus");
  343. var className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  344. this.titleTextNode.setStyles( this.css[ className ] );
  345. this.calendar.container.destroy();
  346. this.calendar = null;
  347. },
  348. destroy: function(){
  349. if( this.calendar ){
  350. this.calendar.container.destroy();
  351. }
  352. this.meetings.each( function(m){
  353. m.destroy();
  354. });
  355. this.meetings = [];
  356. this.node.destroy();
  357. },
  358. loadMeetings: function(){
  359. this.app.isMeetingViewer( function( isAll ){
  360. this._loadMeetings( isAll );
  361. }.bind(this))
  362. },
  363. _loadMeetings: function( isAll ){
  364. var y = this.date.getFullYear();
  365. var m = this.date.getMonth()+1;
  366. var d = this.date.getDate();
  367. this.app.actions[ isAll ? "listMeetingDayAll" : "listMeetingDay" ](y, m, d, function(json){
  368. var flag = true;
  369. if( !json.data || json.data.length == 0 ){
  370. }else{
  371. json.data.each(function(meeting, i){
  372. if (!meeting.myReject){
  373. flag = false;
  374. this.meetings.push(new MWF.xApplication.Meeting.DayView.Meeting(this.dayContentNode, this, meeting));
  375. }
  376. }.bind(this));
  377. }
  378. if( flag ){
  379. this.noMeetingNode = new Element("div.noMeetingNode", {
  380. "styles": this.css.noMeetingNode,
  381. "text" : this.app.lp.noMeeting
  382. }).inject(this.dayContentNode);
  383. this.noMeetingNode.setStyle("min-height",""+(this.view.dayNodeHeight - 220)+"px");
  384. this.noMeetingNode.setStyle("line-height",""+(this.view.dayNodeHeight - 220)+"px");
  385. }
  386. //this.checkMeetingWidth();
  387. //this.checkMeetingWidthFun = this.checkMeetingWidth.bind(this);
  388. //this.app.addEvent("resize", this.checkMeetingWidthFun);
  389. }.bind(this));
  390. },
  391. reload : function(){
  392. this.view.reload();
  393. }
  394. });
  395. MWF.xApplication.Meeting.DayView.Meeting = new Class({
  396. Extends : MWF.xApplication.Meeting.MeetingArea
  397. });