MeetingView.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.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. var size = this.container.getSize();
  92. var titleSize = this.titleNode.getSize();
  93. var y = size.y-titleSize.y-60;
  94. this.dayNodeHeight = y-60;
  95. this.scrollNode.setStyle("height", ""+y+"px");
  96. var sideBarSize = this.app.sideBar ? this.app.sideBar.getSize() : { x :0 , y :0 };
  97. this.scrollNode.setStyle("width", ""+(size.x - sideBarSize.x) +"px");
  98. var daysWidth = this.days.length * 330 + 30;
  99. var x = size.x - sideBarSize.x - 50;
  100. if (this.contentWarpNode){
  101. this.contentWarpNode.setStyles({
  102. "width": Math.max( x, daysWidth) +"px"
  103. });
  104. };
  105. //if( this.noMeetingNode ){
  106. // this.noMeetingNode.setStyles({
  107. //
  108. // })
  109. //}
  110. this.days.each( function( d ){
  111. d.resetHeight();
  112. });
  113. },
  114. hasSameItem : function( array1, array2 ){
  115. for( var i=0; i<array2.length; i++){
  116. if( array1.contains( array2[i] ) ){
  117. return true;
  118. }
  119. }
  120. return false;
  121. },
  122. loadContent: function( ){
  123. var count = 0;
  124. this.daysData = {};
  125. var months = this.monthSelect.getValue() || this.options.months;
  126. this.app.actions.listMeetingMonths( months , function( json ){
  127. debugger;
  128. json.data.each( function( data ){
  129. if( data.invitePersonList.contains( this.userName ) || data.invitePersonList.contains( this.userId ) || data.applicant == this.userName || this.hasSameItem( data.invitePersonList, this.userIdentity ) ){
  130. if( !data.rejectPersonList.contains( this.userName ) || !data.rejectPersonList.contains( this.userId ) || !this.hasSameItem( data.rejectPersonList, this.userIdentity ) ){
  131. var date = Date.parse( data.startTime ).clone().clearTime();
  132. if( !this.daysData[date] )this.daysData[date] = [];
  133. this.daysData[date].push( data );
  134. count++;
  135. }
  136. }
  137. }.bind(this));
  138. for( var d in this.daysData ){
  139. var day = new MWF.xApplication.Meeting.MeetingView.Day(this, this.dayContainerNode, d , this.daysData[d]);
  140. this.days.push( day )
  141. }
  142. if( count == 0 ){
  143. this.loadEmptyNode();
  144. }
  145. this.resetNodeSize();
  146. }.bind(this));
  147. //this.dayA.loadAction();
  148. },
  149. loadEmptyNode : function(){
  150. this.noMeetingNode = new Element("div",{
  151. "styles" : this.css.noMeetingNode,
  152. "text" : this.app.lp.noComingMeeting.replace("{month}", this.monthSelect.getValue() || this.options.months )
  153. }).inject( this.dayContainerNode );
  154. },
  155. hide: function(){
  156. var fx = new Fx.Morph(this.node, {
  157. "duration": "300",
  158. "transition": Fx.Transitions.Expo.easeOut
  159. });
  160. fx.start({
  161. "opacity": 0
  162. }).chain(function(){
  163. this.node.setStyle("display", "none");
  164. }.bind(this));
  165. },
  166. show: function(){
  167. this.node.setStyles(this.css.node);
  168. var fx = new Fx.Morph(this.node, {
  169. "duration": "800",
  170. "transition": Fx.Transitions.Expo.easeOut
  171. });
  172. this.app.fireAppEvent("resize");
  173. fx.start({
  174. "opacity": 1,
  175. "left": "0px"
  176. }).chain(function(){
  177. this.node.setStyles({
  178. "position": "static",
  179. "width": "auto"
  180. });
  181. }.bind(this))
  182. },
  183. reload: function(){
  184. this.date = (this.days.length > 0 ? this.days[0].date.clone() : this.date);
  185. this.days.each( function(d){
  186. d.destroy();
  187. });
  188. this.dayContainerNode.empty();
  189. this.days = [];
  190. this.loadContent( );
  191. },
  192. destroy : function(){
  193. this.days.each( function(d){
  194. d.destroy();
  195. });
  196. this.app.removeEvent("resize", this.resetNodeSizeFun );
  197. this.node.destroy();
  198. }
  199. });
  200. MWF.xApplication.Meeting.MeetingView.Day = new Class({
  201. Implements: [Events],
  202. initialize: function(view, node, date, data){
  203. this.view = view;
  204. this.css = this.view.css;
  205. this.container = node;
  206. this.app = this.view.app;
  207. this.date = (date) ? Date.parse(date).clone().clearTime() : (new Date()).clearTime();
  208. this.today = new Date().clearTime();
  209. this.isToday = (this.date.diff(this.today)==0);
  210. this.times = [];
  211. this.meetings = [];
  212. this.data = data;
  213. this.load();
  214. },
  215. load : function(){
  216. this.node = new Element("div.dayNode", {"styles": this.css.dayNode}).inject(this.container , this.position);
  217. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  218. this.node.addEvents( {
  219. mouseover : function(){
  220. this.node.setStyles( this.css.dayNode_over );
  221. }.bind(this),
  222. mouseout : function(){
  223. this.node.setStyles( this.css.dayNode );
  224. }.bind(this)
  225. });
  226. this.titleNode = new Element("div.titleNode", { "styles": this.css[ !this.isToday ? "dayTitleNode" : "dayTitleNode_today"] }).inject(this.node);
  227. var className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  228. this.titleTextNode = new Element("div.dayTitleTextNode", {
  229. "styles": this.css[ className ],
  230. "text" : this.date.format("%Y年%m月%d日")
  231. }).inject(this.titleNode);
  232. this.dayWeekNode = new Element("div.dayWeekNode", {
  233. "styles": this.css[ !this.isToday ? "dayWeekNode" : "dayWeekNode_today"],
  234. "text" : this.getWeek()
  235. }).inject(this.titleNode);
  236. this.dayContentNode = new Element("div.dayContentNode", {"styles": this.css.dayContentNode}).inject(this.node);
  237. this.loadMeetings();
  238. },
  239. resetHeight: function(){
  240. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  241. },
  242. getWeek: function(){
  243. var week = this.app.lp.weeks.arr[this.date.getDay()];
  244. var title = "";
  245. var now = this.today;
  246. var d = now.diff(this.date);
  247. if (d==0){
  248. title = this.app.lp.today;
  249. }else{
  250. title = week;
  251. }
  252. return title;
  253. },
  254. destroy: function(){
  255. if( this.calendar ){
  256. this.calendar.container.destroy();
  257. }
  258. this.meetings.each( function(m){
  259. m.destroy();
  260. });
  261. this.node.destroy();
  262. MWF.release(this);
  263. },
  264. loadMeetings: function(){
  265. this.data.each(function(meeting, i){
  266. this.meetings.push(new MWF.xApplication.Meeting.MeetingView.Meeting(this.dayContentNode, this, meeting));
  267. }.bind(this));
  268. },
  269. reload : function(){
  270. this.view.reload();
  271. }
  272. });
  273. MWF.xApplication.Meeting.MeetingView.Meeting = new Class({
  274. Extends : MWF.xApplication.Meeting.MeetingArea
  275. });