MeetingView.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  2. MWF.xDesktop.requireApp("Meeting", "Common", null, false);
  3. MWF.xApplication.Meeting.MeetingView = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "months": 1
  9. },
  10. initialize: function(node, app, options){
  11. this.setOptions(options);
  12. this.path = "../x_component_Meeting/$MeetingView/";
  13. this.cssPath = "../x_component_Meeting/$MeetingView/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.app = app;
  16. this.container = $(node);
  17. this.days = [];
  18. this.load();
  19. },
  20. recordStatus : function(){
  21. return {
  22. months : this.monthSelect.getValue()
  23. };
  24. },
  25. load: function(){
  26. this.userName = layout.desktop.session.user.distinguishedName;
  27. this.userId = layout.desktop.session.user.id;
  28. this.userIdentity = [];
  29. ( layout.desktop.session.user.identityList || [] ).each( function( i ){
  30. this.userIdentity.push( i.distinguishedName )
  31. }.bind(this));
  32. this.date = new Date();
  33. this.node = new Element("div#meetingNode", {"styles": this.css.node}).inject(this.container);
  34. this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.node);
  35. this.todayNode = new Element("div", {"styles": this.css.todayNode}).inject(this.titleNode);
  36. var d = this.date.format(this.app.lp.dateFormatMonthDay);
  37. var w = this.app.lp.weeks.arr[this.date.getDay()];
  38. this.todayNode.set("text", d+","+w);
  39. this.scrollNode = new Element("div", {
  40. "styles": this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode
  41. }).inject(this.node);
  42. this.contentWarpNode = new Element("div", {
  43. "styles": this.css.contentWarpNode
  44. }).inject(this.scrollNode);
  45. this.contentContainerNode = new Element("div",{
  46. "styles" : this.css.contentContainerNode
  47. }).inject(this.contentWarpNode);
  48. this.contentNode = new Element("div", {
  49. "styles": this.css.contentNode
  50. }).inject(this.contentContainerNode);
  51. this.dayContainerNode = new Element("div", {
  52. "styles": this.css.dayContainerNode
  53. }).inject(this.contentNode);
  54. this.loadMonthSelect();
  55. this.loadContent( );
  56. //this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  57. this.resetNodeSizeFun = this.resetNodeSize.bind(this);
  58. this.app.addEvent("resize", this.resetNodeSizeFun );
  59. //this.dateNode = new Element("div", {"styles": this.css.dateNode}).inject(this.node);
  60. },
  61. loadMonthSelect: function(){
  62. this.monthSelectContainer = new Element("div", {
  63. "styles": this.css.monthSelectContainer
  64. }).inject(this.titleNode);
  65. new Element("div", {
  66. "styles" : this.css.monthSelectTextNode,
  67. "text" : this.app.lp.monthSelectTextPrev
  68. }).inject(this.monthSelectContainer);
  69. var c = new Element("div", {
  70. "styles" : this.css.monthSelectTextNode
  71. }).inject(this.monthSelectContainer);
  72. this.monthSelect = new MDomItem( c, {
  73. name : "monthSelect",
  74. type : "select",
  75. style : this.css.monthSelect,
  76. defaultValue : this.options.months,
  77. selectValue : [1,2,3,4,5,6,7,8,9,10,11,12],
  78. event : {
  79. change : function(){
  80. this.reload();
  81. }.bind(this)
  82. }
  83. });
  84. this.monthSelect.load();
  85. new Element("div", {
  86. "styles" : this.css.monthSelectTextNode,
  87. "text" : this.app.lp.monthSelectTextAfter
  88. }).inject(this.monthSelectContainer);
  89. },
  90. resetNodeSize: function(){
  91. //if( this.app.inContainer )return;
  92. var size = this.container.getSize();
  93. if( !this.app.inContainer ){
  94. var y = size.y-60;
  95. this.node.setStyle("height", ""+y+"px");
  96. this.node.setStyle("margin-top", "60px");
  97. }
  98. var titleSize = this.titleNode.getSize();
  99. var y = size.y-titleSize.y-60;
  100. this.dayNodeHeight = y-60;
  101. this.scrollNode.setStyle("height", ""+y+"px");
  102. var sideBarSize = this.app.sideBar ? this.app.sideBar.getSize() : { x :0 , y :0 };
  103. this.scrollNode.setStyle("width", ""+(size.x - sideBarSize.x) +"px");
  104. var daysWidth = this.days.length * 330 + 30;
  105. var x = size.x - sideBarSize.x - 50;
  106. if (this.contentWarpNode){
  107. this.contentWarpNode.setStyles({
  108. "width": Math.max( x, daysWidth) +"px"
  109. });
  110. };
  111. //if( this.noMeetingNode ){
  112. // this.noMeetingNode.setStyles({
  113. //
  114. // })
  115. //}
  116. this.days.each( function( d ){
  117. d.resetHeight();
  118. });
  119. },
  120. hasSameItem : function( array1, array2 ){
  121. for( var i=0; i<array2.length; i++){
  122. if( array1.contains( array2[i] ) ){
  123. return true;
  124. }
  125. }
  126. return false;
  127. },
  128. loadContent: function( ){
  129. var count = 0;
  130. this.daysData = {};
  131. var months = this.monthSelect.getValue() || this.options.months;
  132. this.app.actions.listMeetingMonths( months , function( json ){
  133. json.data.each( function( data ){
  134. if( data.invitePersonList.contains( this.userName ) || data.invitePersonList.contains( this.userId ) || data.applicant == this.userName || this.hasSameItem( data.invitePersonList, this.userIdentity ) ){
  135. if( !data.rejectPersonList.contains( this.userName ) || !data.rejectPersonList.contains( this.userId ) || !this.hasSameItem( data.rejectPersonList, this.userIdentity ) ){
  136. var date = Date.parse( data.startTime ).clone().clearTime();
  137. if( !this.daysData[date] )this.daysData[date] = [];
  138. this.daysData[date].push( data );
  139. count++;
  140. }
  141. }
  142. }.bind(this));
  143. for( var d in this.daysData ){
  144. var day = new MWF.xApplication.Meeting.MeetingView.Day(this, this.dayContainerNode, d , this.daysData[d]);
  145. this.days.push( day )
  146. }
  147. if( count == 0 ){
  148. this.loadEmptyNode();
  149. }
  150. this.resetNodeSize();
  151. }.bind(this));
  152. //this.dayA.loadAction();
  153. },
  154. loadEmptyNode : function(){
  155. this.noMeetingNode = new Element("div",{
  156. "styles" : this.css.noMeetingNode,
  157. "text" : this.app.lp.noComingMeeting.replace("{month}", this.monthSelect.getValue() || this.options.months )
  158. }).inject( this.dayContainerNode );
  159. },
  160. hide: function(){
  161. var fx = new Fx.Morph(this.node, {
  162. "duration": "300",
  163. "transition": Fx.Transitions.Expo.easeOut
  164. });
  165. fx.start({
  166. "opacity": 0
  167. }).chain(function(){
  168. this.node.setStyle("display", "none");
  169. }.bind(this));
  170. },
  171. show: function(){
  172. this.node.setStyles(this.css.node);
  173. if( this.app.inContainer ){
  174. this.node.setStyles({
  175. "opacity": 1,
  176. "position": "static",
  177. "width": "auto"
  178. });
  179. }else{
  180. var fx = new Fx.Morph(this.node, {
  181. "duration": "800",
  182. "transition": Fx.Transitions.Expo.easeOut
  183. });
  184. this.app.fireAppEvent("resize");
  185. fx.start({
  186. "opacity": 1,
  187. "left": "0px"
  188. }).chain(function(){
  189. this.node.setStyles({
  190. "position": "static",
  191. "width": "auto"
  192. });
  193. }.bind(this))
  194. }
  195. },
  196. reload: function(){
  197. this.date = (this.days.length > 0 ? this.days[0].date.clone() : this.date);
  198. this.days.each( function(d){
  199. d.destroy();
  200. });
  201. this.dayContainerNode.empty();
  202. this.days = [];
  203. this.loadContent( );
  204. },
  205. destroy : function(){
  206. this.days.each( function(d){
  207. d.destroy();
  208. });
  209. this.app.removeEvent("resize", this.resetNodeSizeFun );
  210. this.node.destroy();
  211. }
  212. });
  213. MWF.xApplication.Meeting.MeetingView.Day = new Class({
  214. Implements: [Events],
  215. initialize: function(view, node, date, data){
  216. this.view = view;
  217. this.css = this.view.css;
  218. this.container = node;
  219. this.app = this.view.app;
  220. this.date = (date) ? Date.parse(date).clone().clearTime() : (new Date()).clearTime();
  221. this.today = new Date().clearTime();
  222. this.isToday = (this.date.diff(this.today)==0);
  223. this.times = [];
  224. this.meetings = [];
  225. this.data = data;
  226. this.load();
  227. },
  228. load : function(){
  229. this.node = new Element("div.dayNode", {"styles": this.css.dayNode}).inject(this.container , this.position);
  230. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  231. this.node.addEvents( {
  232. mouseover : function(){
  233. this.node.setStyles( this.css.dayNode_over );
  234. }.bind(this),
  235. mouseout : function(){
  236. this.node.setStyles( this.css.dayNode );
  237. }.bind(this)
  238. });
  239. this.titleNode = new Element("div.titleNode", { "styles": this.css[ !this.isToday ? "dayTitleNode" : "dayTitleNode_today"] }).inject(this.node);
  240. if( this.isToday ){
  241. this.titleNode.addClass("mainColor_bg");
  242. }
  243. var className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  244. this.titleTextNode = new Element("div.dayTitleTextNode", {
  245. "styles": this.css[ className ],
  246. "text" : this.date.format( this.app.lp.dateFormatDay )
  247. }).inject(this.titleNode);
  248. this.dayWeekNode = new Element("div.dayWeekNode", {
  249. "styles": this.css[ !this.isToday ? "dayWeekNode" : "dayWeekNode_today"],
  250. "text" : this.getWeek()
  251. }).inject(this.titleNode);
  252. if( this.isToday ){
  253. this.dayWeekNode.addClass("overColor_bg");
  254. }else{
  255. this.dayWeekNode.addClass("mainColor_bg");
  256. }
  257. this.dayContentNode = new Element("div.dayContentNode", {"styles": this.css.dayContentNode}).inject(this.node);
  258. this.loadMeetings();
  259. },
  260. resetHeight: function(){
  261. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  262. },
  263. getWeek: function(){
  264. var week = this.app.lp.weeks.arr[this.date.getDay()];
  265. var title = "";
  266. var now = this.today;
  267. var d = now.diff(this.date);
  268. if (d==0){
  269. title = this.app.lp.today;
  270. }else{
  271. title = week;
  272. }
  273. return title;
  274. },
  275. destroy: function(){
  276. if( this.calendar ){
  277. this.calendar.container.destroy();
  278. }
  279. this.meetings.each( function(m){
  280. m.destroy();
  281. });
  282. this.node.destroy();
  283. MWF.release(this);
  284. },
  285. loadMeetings: function(){
  286. this.data.each(function(meeting, i){
  287. this.meetings.push(new MWF.xApplication.Meeting.MeetingView.Meeting(this.dayContentNode, this, meeting));
  288. }.bind(this));
  289. },
  290. reload : function(){
  291. this.view.reload();
  292. }
  293. });
  294. MWF.xApplication.Meeting.MeetingView.Meeting = new Class({
  295. Extends : MWF.xApplication.Meeting.MeetingArea
  296. });