WeekView.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. MWF.require("MWF.widget.Calendar", null, false);
  2. MWF.xApplication.Meeting.WeekView = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "date" : ""
  8. },
  9. initialize: function(node, app, options){
  10. this.setOptions(options);
  11. this.path = "../x_component_Meeting/$WeekView/";
  12. this.cssPath = "../x_component_Meeting/$WeekView/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.app = app;
  15. this.container = $(node);
  16. this.weekBegin = this.app.meetingConfig.weekBegin || "0";
  17. this.load();
  18. },
  19. load: function(){
  20. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  21. //this.loadSideBar();
  22. this.resetNodeSize();
  23. this.app.addEvent("resize", this.resetNodeSize.bind(this));
  24. this.loadCalendar();
  25. },
  26. resetNodeSize: function(){
  27. var size = this.container.getSize();
  28. var y = size.y-60;
  29. this.node.setStyle("height", ""+y+"px");
  30. if( !this.app.inContainer ){
  31. this.node.setStyle("margin-top", "60px");
  32. }
  33. var sideBarSize = this.app.sideBar ? this.app.sideBar.getSize() : { x : 0, y:0 };
  34. this.node.setStyle("width", ""+(size.x - sideBarSize.x)+"px");
  35. this.node.setStyle("margin-right", ""+sideBarSize.x+"px");
  36. //var size = this.container.getSize();
  37. //
  38. //this.scrollNode.setStyle("height", ""+(size.y-60)+"px");
  39. //this.scrollNode.setStyle("margin-top", "60px");
  40. //
  41. //if (this.contentWarpNode){
  42. // this.contentWarpNode.setStyles({
  43. // "width": (size.x - 50) +"px"
  44. // });
  45. //}
  46. },
  47. loadCalendar: function(){
  48. var date = "";
  49. if( this.options.date ){
  50. date = Date.parse( this.options.date )
  51. }else{
  52. date = new Date();
  53. }
  54. this.currentWeek = this.getWeekNumber( date );
  55. this.calendar = new MWF.xApplication.Meeting.WeekView.Calendar(this, date );
  56. },
  57. hide: function(){
  58. var fx = new Fx.Morph(this.node, {
  59. "duration": "300",
  60. "transition": Fx.Transitions.Expo.easeOut
  61. });
  62. fx.start({
  63. "opacity": 0
  64. }).chain(function(){
  65. this.node.setStyle("display", "none");
  66. }.bind(this));
  67. },
  68. show: function(){
  69. this.node.setStyles(this.css.node);
  70. if( this.app.inContainer ){
  71. this.node.setStyles({
  72. "opacity": 1,
  73. "position": "static",
  74. "width": "auto"
  75. });
  76. }else{
  77. var fx = new Fx.Morph(this.node, {
  78. "duration": "800",
  79. "transition": Fx.Transitions.Expo.easeOut
  80. });
  81. this.app.fireAppEvent("resize");
  82. fx.start({
  83. "opacity": 1,
  84. "left": "0px"
  85. }).chain(function(){
  86. this.node.setStyles({
  87. "position": "static",
  88. "width": "auto"
  89. });
  90. }.bind(this));
  91. }
  92. },
  93. reload: function(){
  94. if (this.calendar) this.calendar.reLoadCalendar();
  95. },
  96. recordStatus : function(){
  97. return {
  98. date : (this.calendar && this.calendar.baseDate) ? this.calendar.baseDate.format("db") : ""
  99. };
  100. },
  101. destroy: function(){
  102. if (this.calendar){
  103. this.calendar.destroy();
  104. }
  105. this.node.destroy();
  106. //MWF.release( this );
  107. },
  108. getWeekNumber: function(d){
  109. // Create a copy of this date object
  110. var target = d.clone();
  111. // ISO week date weeks start on monday
  112. // so correct the day number
  113. //var dayNr = (d.getDay() + 6) % 7;
  114. var dayNr = ( 7 + d.getDay() - parseInt( this.weekBegin ) ) % 7;
  115. // ISO 8601 states that week 1 is the week
  116. // with the first thursday of that year.
  117. // Set the target date to the thursday in the target week
  118. target.setDate(target.getDate() - dayNr + 3);
  119. // Store the millisecond value of the target date
  120. var firstThursday = target.valueOf();
  121. // Set the target to the first thursday of the year
  122. // First set the target to january first
  123. target.setMonth(0, 1);
  124. // Not a thursday? Correct the date to the next thursday
  125. if (target.getDay() != 4) {
  126. target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
  127. }
  128. // The weeknumber is the number of weeks between the
  129. // first thursday of the year and the thursday in the target week
  130. return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
  131. }
  132. });
  133. MWF.xApplication.Meeting.WeekView.Calendar = new Class({
  134. Implements: [Events],
  135. initialize: function(view, date){
  136. this.view = view;
  137. this.css = this.view.css;
  138. this.container = this.view.node;
  139. this.app = this.view.app;
  140. this.weekBegin = this.app.meetingConfig.weekBegin || "0";
  141. this.baseDate = date || new Date();
  142. this.today = new Date();
  143. this.days = {};
  144. this.load();
  145. },
  146. load: function(){
  147. this.date = this.getWeekBeginDate( this.baseDate );
  148. this.titleNode = new Element("div", {"styles": this.css.calendarTitleNode}).inject(this.container);
  149. this.scrollNode = new Element("div", {
  150. "styles": this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode
  151. }).inject(this.container);
  152. this.contentWarpNode = new Element("div", {
  153. "styles": this.css.contentWarpNode
  154. }).inject(this.scrollNode);
  155. this.contentContainerNode = new Element("div",{
  156. "styles" : this.css.contentContainerNode
  157. }).inject(this.contentWarpNode);
  158. this.bodyNode = new Element("div", {
  159. "styles": this.css.contentNode
  160. }).inject(this.contentContainerNode);
  161. //this.bodyNode = new Element("div", {"styles": this.css.calendarBodyNode}).inject(this.container);
  162. this.setTitleNode();
  163. this.listRoom( function(){
  164. this.setBodyNode();
  165. }.bind(this) );
  166. this.resetBodySize();
  167. this.app.addEvent("resize", this.resetBodySize.bind(this));
  168. },
  169. getWeekBeginDate: function( d ){
  170. var date = d.clone();
  171. //var week = date.getDay();
  172. //if( this.weekBegin == "1" ){
  173. // var decrementDay = ((week-1)<0) ? 6 : week-1;
  174. //}else{
  175. // var decrementDay = week;
  176. //}
  177. var decrementDay = ( 7 + d.getDay() - parseInt( this.weekBegin ) ) % 7;
  178. return date.decrement("day", decrementDay);
  179. },
  180. resetBodySize: function(){
  181. //if( this.app.inContainer )return;
  182. var size = this.container.getSize();
  183. var titleSize = this.titleNode.getSize();
  184. var y = size.y-titleSize.y;
  185. //this.bodyNode.setStyle("height", ""+y+"px");
  186. //var size = this.container.getSize();
  187. this.scrollNode.setStyle("height", ""+y+"px");
  188. //this.scrollNode.setStyle("margin-top", "60px");
  189. if (this.contentWarpNode){
  190. this.contentWarpNode.setStyles({
  191. "width": (size.x - 40) +"px"
  192. });
  193. }
  194. //var tdy = (y-30)/6;
  195. //tdy = tdy-34;
  196. //var tds = this.calendarTable.getElements("td");
  197. //tds.each(function(td){
  198. // var yy = tdy;
  199. // var node = td.getLast("div");
  200. // if (node.childNodes.length>=4){
  201. // if (yy<92) yy = 69;
  202. // }
  203. // node.setStyle("height", ""+yy+"px");
  204. //}.bind(this));
  205. },
  206. setTitleNode: function(){
  207. this.prevWeekNode = new Element("div.o2icon-triangle_left", {"styles": this.css.calendarPrevWeekNode}).inject(this.titleNode);
  208. // var text = this.baseDate.format(this.app.lp.dateFormatMonth)
  209. // + ",第" + this.view.getWeekNumber( this.baseDate ) + "周";
  210. var month = this.baseDate.format(this.app.lp.dateFormatMonth);
  211. var week = this.view.getWeekNumber( this.baseDate );
  212. var text = this.app.lp.weeklyViewTitle.replace("{month}", month ).replace("{week}",week);
  213. this.titleTextNode = new Element("div", {"styles": this.css.calendarTitleTextNode, "text": text}).inject(this.titleNode);
  214. this.nextWeekNode = new Element("div.o2icon-triangle_right", {"styles": this.css.calendarNextWeekNode}).inject(this.titleNode);
  215. this.prevWeekNode.addEvents({
  216. "mouseover": function(){
  217. this.prevWeekNode.setStyles(this.css.calendarPrevWeekNode_over);
  218. this.prevWeekNode.addClass("mainColor_color");
  219. }.bind(this),
  220. "mouseout": function(){
  221. this.prevWeekNode.setStyles(this.css.calendarPrevWeekNode);
  222. this.prevWeekNode.removeClass("mainColor_color");
  223. }.bind(this),
  224. "mousedown": function(){this.prevWeekNode.setStyles(this.css.calendarPrevWeekNode_down);}.bind(this),
  225. "mouseup": function(){this.prevWeekNode.setStyles(this.css.calendarPrevWeekNode_over);}.bind(this),
  226. "click": function(){this.changeWeekPrev();}.bind(this)
  227. });
  228. this.nextWeekNode.addEvents({
  229. "mouseover": function(){
  230. this.nextWeekNode.setStyles(this.css.calendarNextWeekNode_over);
  231. this.nextWeekNode.addClass("mainColor_color");
  232. }.bind(this),
  233. "mouseout": function(){
  234. this.nextWeekNode.setStyles(this.css.calendarNextWeekNode);
  235. this.nextWeekNode.removeClass("mainColor_color");
  236. }.bind(this),
  237. "mousedown": function(){this.nextWeekNode.setStyles(this.css.calendarNextWeekNode_down);}.bind(this),
  238. "mouseup": function(){this.nextWeekNode.setStyles(this.css.calendarNextWeekNode_over);}.bind(this),
  239. "click": function(){this.changeWeekNext();}.bind(this)
  240. });
  241. this.titleTextNode.addEvents({
  242. "mouseover": function(){
  243. this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);
  244. this.titleTextNode.addClass("mainColor_color");
  245. }.bind(this),
  246. "mouseout": function(){
  247. this.titleTextNode.setStyles(this.css.calendarTitleTextNode);
  248. this.titleTextNode.removeClass("mainColor_color");
  249. }.bind(this),
  250. "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  251. "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this)
  252. //"click": function(){this.changeWeekSelect();}.bind(this)
  253. });
  254. this.createWeekSelector();
  255. },
  256. changeWeekPrev: function(){
  257. this.date.decrement("week", 1);
  258. this.baseDate = this.date;
  259. // var text = this.baseDate.format(this.app.lp.dateFormatMonth) + ",第" + this.view.getWeekNumber( this.baseDate ) + "周";
  260. var month = this.baseDate.format(this.app.lp.dateFormatMonth);
  261. var week = this.view.getWeekNumber( this.baseDate );
  262. var text = this.app.lp.weeklyViewTitle.replace("{month}", month ).replace("{week}",week);
  263. this.titleTextNode.set("text", text);
  264. this.reLoadCalendar();
  265. },
  266. changeWeekNext: function(){
  267. this.date.increment("week", 1);
  268. this.baseDate = this.date;
  269. var month = this.baseDate.format(this.app.lp.dateFormatMonth);
  270. var week = this.view.getWeekNumber( this.baseDate );
  271. var text = this.app.lp.weeklyViewTitle.replace("{month}", month ).replace("{week}",week);
  272. // var text = this.baseDate.format(this.app.lp.dateFormatMonth) + ",第" + this.view.getWeekNumber( this.baseDate ) + "周";
  273. this.titleTextNode.set("text", text);
  274. this.reLoadCalendar();
  275. },
  276. changeWeekSelect: function(){
  277. if (!this.monthSelector) this.createWeekSelector();
  278. //this.monthSelector.show();
  279. },
  280. createWeekSelector: function(){
  281. //this.monthSelector = new MWF.xApplication.Meeting.WeekView.Calendar.WeekSelector(this.date, this);
  282. this.weekCalendar = new MWF.xApplication.Meeting.WeekView.WeekCalendar(this.titleTextNode, {
  283. "style":"meeting_blue",
  284. "weekBegin" : this.weekBegin,
  285. "target": this.node,
  286. "baseDate" : this.baseDate,
  287. "onInit" : function(){
  288. this.options.dayPath = this.options.path+this.options.style+"/day_week.html";
  289. },
  290. "onQueryComplate": function(e, dv, date){
  291. var selectedDate = new Date.parse(dv);
  292. this.changeWeekTo(selectedDate);
  293. }.bind(this)
  294. });
  295. //this.weekCalendar.app = this.app;
  296. },
  297. changeWeekTo: function(d){
  298. this.baseDate = d;
  299. this.date = this.getWeekBeginDate( d );
  300. //var text = this.date.format(this.app.lp.dateFormatWeek);
  301. //this.titleTextNode.set("text", text);
  302. var month = this.baseDate.format(this.app.lp.dateFormatMonth);
  303. var week = this.view.getWeekNumber( this.baseDate );
  304. var text = this.app.lp.weeklyViewTitle.replace("{month}", month ).replace("{week}",week);
  305. // var text = this.baseDate.format(this.app.lp.dateFormatMonth) + ",第" + this.view.getWeekNumber( this.baseDate ) + "周";
  306. this.titleTextNode.set("text", text);
  307. this.reLoadCalendar();
  308. },
  309. listRoom : function( callback ){
  310. this.app.actions.listBuilding( function( json ){
  311. json.data.push({
  312. id: "noRoom",
  313. name: "noRoom",
  314. roomList: [{
  315. id: "noRoom",
  316. name: "noRoom",
  317. available: true
  318. }]
  319. });
  320. this.bulidingData = json.data;
  321. if(callback)callback();
  322. }.bind(this) )
  323. },
  324. setBodyNode: function(){
  325. this.roomTooltips = [];
  326. this.roomTrMap = {};
  327. //var html = "<tr><th>"+this.app.lp.room+"</th><th>"+this.app.lp.weeks.Mon+"</th><th>"+this.app.lp.weeks.Tues+"</th><th>"+this.app.lp.weeks.Wed+"</th>" +
  328. // "<th>"+this.app.lp.weeks.Thur+"</th><th>"+this.app.lp.weeks.Fri+"</th><th>"+this.app.lp.weeks.Sat+"</th><th>"+this.app.lp.weeks.Sun+"</th></tr>";
  329. //html += "<tr><td valign='top'></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  330. //html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  331. //html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  332. //html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  333. //html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  334. //html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  335. this.calendarTable = new Element("table", {
  336. "styles": this.css.calendarTable,
  337. "height": "100%",
  338. "border": "0",
  339. "cellPadding": "0",
  340. "cellSpacing": "0"
  341. }).inject(this.bodyNode);
  342. this.loadTableHead();
  343. this.bulidingData.each( function( buliding ){
  344. buliding.roomList.each( function( room ){
  345. var tr = new Element( "tr").inject( this.calendarTable );
  346. if( buliding.id === "noRoom" ){
  347. tr.set("noRoom", "yes")
  348. this.noRoomTr = tr;
  349. }
  350. var td = new Element( "td", {
  351. "tdType" : "room"
  352. } ).inject( tr );
  353. var node = new Element("div",{
  354. //text : room.name,
  355. styles : this.css.calendarTableCell_room
  356. }).inject( td );
  357. td.store("room",room );
  358. for( var i=0; i<7; i++ ){
  359. new Element( "td" , {
  360. "tdType" : "meeting",
  361. "room" : room.id,
  362. "index" : i+1
  363. }).inject( tr );
  364. }
  365. this.roomTrMap[ room.id ] = tr;
  366. this.rooms = this.rooms || {};
  367. this.rooms[ room.id ] = new MWF.xApplication.Meeting.WeekView.Room(this, node, room, buliding.name);
  368. if( buliding.id !== "noRoom" ){
  369. this.roomTooltips.push(
  370. new MWF.xApplication.Meeting.RoomTooltip(this.app.content, node, this.app, room, {
  371. axis : "x",
  372. hiddenDelay : 300,
  373. displayDelay : 300
  374. })
  375. );
  376. }
  377. }.bind(this))
  378. }.bind(this));
  379. this.loadCalendar();
  380. },
  381. loadTableHead: function(){
  382. var d = this.date.clone();
  383. var today = new Date();
  384. if( !this.tableHead ){
  385. var head = this.tableHead = new Element("tr", {
  386. "styles" : this.css.calendarTableTitleTr
  387. }).inject( this.calendarTable );
  388. new Element("th", {
  389. "styles" : this.css.calendarTableTh,
  390. text : this.app.lp.room
  391. }).inject(head);
  392. for( var i=0; i<7; i++ ) {
  393. //if( this.weekBegin == "0" ){
  394. // var index = i
  395. //}else{
  396. // var index = i == 6 ? 0 : i+1
  397. //}
  398. var index = ( i + parseInt( this.weekBegin ) ) % 7;
  399. var th = new Element("th", {
  400. "styles": (d < today) ? this.css.calendarTableTh_pre : this.css.calendarTableTh,
  401. text: this.app.lp.weeks.arr[index] + "(" + d.format("%m.%d") + ")"
  402. }).inject(head);
  403. d.increment("day", 1);
  404. }
  405. }else{
  406. this.tableHead.getElements("th").each( function( th, i ){
  407. if( i == 0 )return;
  408. //if( this.weekBegin == "0" ){
  409. // var index = i-1
  410. //}else{
  411. // var index = i == 7 ? 0 : i
  412. //}
  413. th.setStyles( (d < today) ? this.css.calendarTableTh_pre : this.css.calendarTableTh);
  414. var index = ( i - 1 + parseInt( this.weekBegin ) ) % 7;
  415. th.set("text", this.app.lp.weeks.arr[index] + "(" + d.format("%m.%d") + ")");
  416. d.increment("day", 1);
  417. }.bind(this))
  418. }
  419. },
  420. reLoadCalendar: function(){
  421. for( var key in this.days ){
  422. this.days[key].destroy();
  423. delete this.days[key];
  424. }
  425. this.calendarTable.getElements("td[tdType='meeting']").each( function(td){
  426. td.empty();
  427. }.bind(this));
  428. this.loadTableHead();
  429. this.loadCalendar();
  430. },
  431. loadCalendar: function(){
  432. this.noRoomTr.setStyle("display","none");
  433. var date = this.date.clone();
  434. for( var i = 1; i<8; i++ ){
  435. this.loadDay(i, date);
  436. date.increment();
  437. }
  438. //var tds = this.calendarTable.getElements("td");
  439. //tds.each(function(td){
  440. // this.loadDay(td, date);
  441. // date.increment();
  442. //}.bind(this));
  443. },
  444. loadDay: function(index, date){
  445. var type = "thisWeek";
  446. var m = date.get("month");
  447. var y = date.get("year");
  448. var d = date.get("date");
  449. var mm = this.date.get("month");
  450. var yy = this.date.get("year");
  451. var mmm = this.today.get("month");
  452. var yyy = this.today.get("year");
  453. var ddd = this.today.get("date");
  454. if ((m==mmm) && (y==yyy) && (d==ddd)) {
  455. type = "today";
  456. }else{
  457. type = "thisWeek";
  458. }
  459. //}else if ( this.view.getWeekNumber( date ) == this.view.currentWeek ){
  460. // type = "thisWeek";
  461. //}else{
  462. // type = "otherWeek";
  463. //}
  464. var key = date.format("%Y%m%d");
  465. this.days[key] = new MWF.xApplication.Meeting.WeekView.Calendar.Day(index, date, this, type);
  466. },
  467. reload : function(){
  468. this.view.reload();
  469. },
  470. destroy: function(){
  471. for( var key in this.days ){
  472. this.days[key].destroy();
  473. delete this.days[key];
  474. }
  475. for( var key in this.rooms ){
  476. this.rooms[key].destroy();
  477. }
  478. this.roomTooltips.each( function(tooltip){
  479. tooltip.destroy();
  480. }.bind(this));
  481. this.calendarTable.getElements("td[tdType='meeting']").each( function(td){
  482. td.empty();
  483. }.bind(this));
  484. this.container.empty();
  485. }
  486. });
  487. MWF.xApplication.Meeting.WeekView.Room = new Class({
  488. Implements: [Events],
  489. initialize: function(view, node, data, buildingName ){
  490. this.data = data;
  491. this.view = view;
  492. this.css = this.view.css;
  493. this.container = node;
  494. this.app = this.view.app;
  495. this.meetings = [];
  496. this.buildingName = buildingName;
  497. this.enable = this.data.available;
  498. this.load();
  499. },
  500. load : function(){
  501. this.node = new Element("div.roomItemNode", {"styles": this.css.roomItemNode}).inject(this.container);
  502. this.node.setStyle("min-height",""+this.view.roomNodeHeight+"px");
  503. this.node.addEvents( {
  504. mouseover : function(){
  505. this.node.setStyles( this.css.roomItemNode_over );
  506. }.bind(this),
  507. mouseout : function(){
  508. this.node.setStyles( this.css.roomItemNode );
  509. }.bind(this)
  510. });
  511. this.titleNode = new Element("div.titleNode", { "styles": this.css.roomItemTitleNode }).inject(this.node);
  512. if( this.data.id !== "noRoom" ){
  513. this.titleNode.addEvents({
  514. click : function(){
  515. this.openRoom()
  516. }.bind(this)
  517. });
  518. }
  519. if( this.enable ){
  520. this.titleNode.addEvents({
  521. mouseenter : function(){
  522. this.titleTextNode.setStyles( this.css.roomItemTitleTextNode_over );
  523. }.bind(this),
  524. mouseleave : function(){
  525. this.titleTextNode.setStyles( this.css.roomItemTitleTextNode );
  526. }.bind(this)
  527. });
  528. }
  529. this.topNode = new Element("div.topNode", { styles : this.css.roomItemTitleTopNode }).inject( this.titleNode );
  530. // this.descriptNode = new Element("div.roomItemDescriptNode",{
  531. // styles : this.css.roomItemDescriptNode
  532. // }).inject(this.titleNode);
  533. //
  534. // if( this.data.capacity ){
  535. // this.titleCountNode = new Element("div.titleCountNode", {
  536. // "styles": this.enable ? this.css.roomItemTitleCountNode : this.css.roomItemTitleCountNode_disable,
  537. // "text" : this.data.capacity+ this.app.lp.person
  538. // }).inject(this.descriptNode);
  539. // }
  540. // if( this.data.roomNumber ){
  541. // new Element("div.titleCountNode", {
  542. // "styles": this.enable ? this.css.roomItemTitleCountNode : this.css.roomItemTitleCountNode_disable,
  543. // "text" : this.data.roomNumber
  544. // }).inject(this.descriptNode);
  545. // }
  546. if( this.buildingName && this.buildingName !== "noRoom" ){
  547. this.buildingTextNode = new Element("div.buildingTextNode", {
  548. "styles": this.enable ? this.css.roomItemBuildingTextNode : this.css.roomItemBuildingTextNode_disable,
  549. "text" : this.buildingName
  550. }).inject(this.titleNode);
  551. }
  552. this.titleTextNode = new Element("div.roomItemTitleTextNode", {
  553. "styles": this.enable ? this.css.roomItemTitleTextNode : this.css.roomItemTitleTextNode_disable ,
  554. "text" : this.data.name === "noRoom" ? this.app.lp.noRoomBuilding : this.data.name
  555. }).inject(this.topNode);
  556. if( this.data.name === "noRoom" ){
  557. this.topNode.setStyles({
  558. "height": "auto",
  559. "padding-top": "30px"
  560. })
  561. this.titleTextNode.setStyles({
  562. "white-space": "pre-wrap",
  563. "line-height": "28px"
  564. })
  565. }
  566. //this.middleNode = new Element("div.middleNode", {
  567. // "styles": this.css.roomItemTitleMiddleNode
  568. //}).inject(this.titleNode);
  569. //
  570. //this.iconsNode = new Element("div.iconsNode", {
  571. // "styles": this.css.roomItemTitleIconsNode
  572. //}).inject(this.middleNode);
  573. //
  574. //var deviceList = this.data.device.split("#");
  575. //deviceList.each(function(name){
  576. // var node = new Element("div", {"styles": this.css.roomItemIconNode, "title": this.app.lp.device[name]}).inject(this.iconsNode);
  577. // node.setStyle("background-image", "url(../x_component_Meeting/$RoomView/default/icon/device/"+ name + ( this.enable ? "" : "_disable" ) +".png)");
  578. //}.bind(this));
  579. //
  580. //this.actionsNode = new Element("div.actionsNode", {
  581. // "styles": this.css.roomItemTitleActionsNode
  582. //}).inject(this.middleNode);
  583. //
  584. //this.loadActions();
  585. },
  586. loadActions: function(){
  587. if( MWF.AC.isMeetingAdministrator() ){
  588. this.editAction = new Element("div.o2icon-edit2", {
  589. styles: this.css.roomAction_edit,
  590. events : {
  591. mouseover : function(){
  592. this.editAction.setStyles( this.css.roomAction_edit_over );
  593. this.editAction.addClass("mainColor_color");
  594. }.bind(this),
  595. mouseout : function(){
  596. this.editAction.setStyles( this.css.roomAction_edit );
  597. this.editAction.removeClass("mainColor_color");
  598. }.bind(this),
  599. click : function(e){
  600. this.editRoom();
  601. e.stopPropagation();
  602. }.bind(this)
  603. }
  604. }).inject(this.actionsNode);
  605. this.removeAction = new Element("div.o2icon-delete", {
  606. styles: this.css.roomAction_remove,
  607. events : {
  608. mouseover : function(){
  609. this.removeAction.setStyles( this.css.roomAction_remove_over );
  610. this.removeAction.addClass("mainColor_color");
  611. }.bind(this),
  612. mouseout : function(){
  613. this.removeAction.setStyles( this.css.roomAction_remove );
  614. this.removeAction.removeClass("mainColor_color");
  615. }.bind(this),
  616. click : function( e ){
  617. this.removeRoom(e);
  618. e.stopPropagation();
  619. }.bind(this)
  620. }
  621. }).inject(this.actionsNode);
  622. }
  623. if( this.enable ){
  624. this.createMeetingAction = new Element("div.o2icon-create", {
  625. tltile : this.app.lp.addMeeting,
  626. styles: this.css.createMeetingAction,
  627. events : {
  628. mouseover : function(){
  629. this.createMeetingAction.setStyles( this.css.createMeetingAction_over );
  630. this.createMeetingAction.addClass("mainColor_color");
  631. }.bind(this),
  632. mouseout : function(){
  633. this.createMeetingAction.setStyles( this.css.createMeetingAction );
  634. this.removeAction.addClass("mainColor_color");
  635. }.bind(this),
  636. click : function(e){
  637. this.app.addMeeting( this.view.date, this.view.hours, this.view.minutes, this.data.id);
  638. e.stopPropagation();
  639. }.bind(this)
  640. }
  641. }).inject(this.actionsNode);
  642. }
  643. },
  644. editRoom : function(){
  645. var form = new MWF.xApplication.Meeting.RoomForm(this.app,this.data, {}, {app:this.app});
  646. form.view = this;
  647. form.edit();
  648. },
  649. openRoom : function(){
  650. var form = new MWF.xApplication.Meeting.RoomForm(this.app,this.data, {}, {app:this.app});
  651. form.view = this;
  652. form.open();
  653. },
  654. reload : function(){
  655. this.view.reload( this.view.date, this.view.hours, this.view.minutes );
  656. },
  657. removeRoom: function(e) {
  658. var info = this.app.lp.delete_room;
  659. info = info.replace(/{name}/g, this.data.name);
  660. var _self = this;
  661. this.app.confirm("warn", e, this.app.lp.delete_building_title, info, 300, 120, function(){
  662. _self.remove();
  663. this.close();
  664. }, function(){
  665. this.close();
  666. });
  667. },
  668. remove: function(){
  669. var view = this.view;
  670. this.app.actions.deleteRoom(this.data.id, function(){
  671. view.reload();
  672. }.bind(this));
  673. },
  674. resetHeight: function(){
  675. this.node.setStyle("min-height",""+this.view.roomNodeHeight+"px");
  676. if( this.noMeetingNode ){
  677. this.noMeetingNode.setStyle("min-height",""+(this.view.roomNodeHeight - 170)+"px");
  678. this.noMeetingNode.setStyle("line-height",""+(this.view.roomNodeHeight - 170)+"px");
  679. }
  680. },
  681. destroy: function(){
  682. if( this.calendar ){
  683. this.calendar.container.destroy();
  684. }
  685. if( this.tooltip ){
  686. this.tooltip.destroy();
  687. }
  688. this.meetings.each( function(m){
  689. m.destroy();
  690. });
  691. this.node.destroy();
  692. MWF.release(this);
  693. }
  694. });
  695. MWF.xApplication.Meeting.WeekView.Calendar.Day = new Class({
  696. Implements: [Events],
  697. initialize: function(index, date, calendar, type){
  698. this.index = index;
  699. this.calendar = calendar;
  700. this.view = this.calendar.view;
  701. this.css = this.calendar.css;
  702. this.app = this.calendar.app;
  703. this.date = date.clone();
  704. this.key = this.date.format(this.app.lp.dateFormat);
  705. this.type = type; //today, otherMonth, thisMonth
  706. this.meetings = [];
  707. this.load();
  708. },
  709. load: function(){
  710. this.color = "#666";
  711. //if( this.type == "thisWeek" ){
  712. //}else if( this.type == "otherWeek" ){
  713. // //this.color = "#ccc";
  714. //}
  715. this.day = this.date.getDate();
  716. this.month = this.date.getMonth();
  717. this.year = this.date.getYear();
  718. this.loadMeetings();
  719. this.roomMeetingObject = {};
  720. this.containerObject = {};
  721. this.calendar.calendarTable.getElements("td[index='"+ this.index +"']").each( function(td){
  722. this.containerObject[ td.get("room") ] = td;
  723. }.bind(this));
  724. },
  725. loadEmpty: function(){
  726. for( var key in this.containerObject ){
  727. var td = this.containerObject[key];
  728. if( !this.roomMeetingObject[ key ] ){
  729. var node = new Element("div", {
  730. "styles" : this.css["calendarTableCell_"+this.type]
  731. }).inject( td );
  732. //var titleNode = new Element("div", {"styles": this.css["dayTitle_" + this.type]}).inject(node);
  733. //var titleDayNode = new Element("div", {
  734. // "styles": this.css["dayTitleDay_" + this.type],
  735. // "text": this.day
  736. //}).inject(titleNode);
  737. //
  738. //if ((new Date()).diff(this.date) >= 0) {
  739. // titleNode.set("title", this.app.lp.titleNode);
  740. // titleNode.addEvent("click", function () {
  741. // this.app.addMeeting(this.date);
  742. // }.bind(this));
  743. //}
  744. var contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(node);
  745. var textNode = new Element("div", {
  746. "styles": {
  747. "line-height": "60px",
  748. "font-size": "14px",
  749. "text-align" : "center",
  750. "color" : this.color,
  751. "padding": "20px 10px"
  752. }
  753. }).inject( contentNode);
  754. textNode.set("text", this.app.lp.noMeeting);
  755. }
  756. }
  757. },
  758. loadMeetings: function(){
  759. this.app.isMeetingViewer( function( isAll ){
  760. this._loadMeetings( isAll );
  761. }.bind(this))
  762. },
  763. _loadMeetings: function( isAll ){
  764. var y = this.date.getFullYear();
  765. var m = this.date.getMonth()+1;
  766. var d = this.date.getDate();
  767. this.app.actions[ isAll ? "listMeetingDayAll" : "listMeetingDay" ](y, m, d, function(json){
  768. var length = json.data.length;
  769. json.data.each(function(meeting, i){
  770. if( !meeting.room ){
  771. meeting.room = "noRoom";
  772. this.calendar.noRoomTr.setStyle("display", "");
  773. }
  774. if( !this.roomMeetingObject[ meeting.room ] ){
  775. this.roomMeetingObject[ meeting.room ] = [];
  776. }
  777. this.roomMeetingObject[ meeting.room].push( meeting );
  778. }.bind(this));
  779. this.loadEmpty();
  780. this.loadRoomMeeting();
  781. }.bind(this));
  782. },
  783. loadRoomMeeting : function(){
  784. var meetingCount = 0;
  785. var firstStatus = "";
  786. var lastStatus = "";
  787. for( var key in this.roomMeetingObject ) {
  788. var td = this.containerObject[key];
  789. var node = new Element("div", {
  790. "styles": this.css["calendarTableCell_" + this.type]
  791. }).inject(td);
  792. var titleNode = new Element("div", {"styles": this.css["dayTitle_" + this.type]}).inject(node);
  793. var titleDayNode = new Element("div", {
  794. "styles": this.css["dayTitleDay_" + this.type],
  795. "text": this.day
  796. }).inject(titleNode);
  797. if( this.type === "today" )titleDayNode.addClass("mainColor_bg");
  798. if ((new Date()).diff(this.date) >= 0) {
  799. titleNode.set("title", this.app.lp.titleNode);
  800. titleNode.addEvent("click", function () {
  801. this.app.addMeeting(this.date);
  802. }.bind(this));
  803. }
  804. var contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(node);
  805. var meetingCount = 0;
  806. var myRejectCount = 0;
  807. var length = this.roomMeetingObject[key].length;
  808. this.roomMeetingObject[key].each(function (meeting, idx) {
  809. if (!meeting.myReject) {
  810. meetingCount++;
  811. if (meetingCount == 3) {
  812. //this.contentNode.setStyle("height", "100px");
  813. }
  814. if (meetingCount == 1) {
  815. firstStatus = meeting.status;
  816. if (meeting.myWaitAccept)firstStatus = "myWaitAccept"
  817. }
  818. if (meetingCount + myRejectCount == length ) {
  819. lastStatus = meeting.status;
  820. if (meeting.myWaitAccept)lastStatus = "myWaitAccept"
  821. }
  822. //if (meetingCount<4)
  823. var m = new MWF.xApplication.Meeting.WeekView.Calendar.Day.Meeting(this, contentNode, meeting, meetingCount);
  824. m.parentNode = node;
  825. m.parentTd = td;
  826. this.meetings.push( m );
  827. }else{
  828. myRejectCount++;
  829. }
  830. }.bind(this));
  831. if (meetingCount == 0) {
  832. //var node = new Element("div", {
  833. // "styles": {
  834. // "line-height": "40px",
  835. // "font-size": "14px",
  836. // "text-align" : "center",
  837. // "color" : this.color,
  838. // "padding": "0px 10px"
  839. // }
  840. //}).inject(this.contentNode);
  841. //node.set("text", this.app.lp.noMeeting);
  842. } else {
  843. var titleInforNode = new Element("div", {"styles": this.css["dayTitleInfor_" + this.type]}).inject(titleNode);
  844. if( this.app.isViewAvailable( "toDay" ) ){
  845. titleInforNode.addEvent("click", function (e) {
  846. this.app.toDay(this.date);
  847. e.stopPropagation();
  848. }.bind(this));
  849. }else{
  850. titleInforNode.setStyle("cursor","default");
  851. }
  852. titleInforNode.set("text", "" + meetingCount + this.app.lp.countMeetings + "");
  853. if (meetingCount > 3) {
  854. node.addEvents({
  855. "mouseenter": function () {
  856. this.obj.expend( this.td, this.node );
  857. }.bind({ obj : this, td : td, node : node }),
  858. "mouseleave": function (){
  859. this.obj.collapseReady = true;
  860. this.obj.collapse( this.td, this.node );
  861. }.bind({ obj : this, td : td, node : node })
  862. })
  863. } else {
  864. titleInforNode.setStyle("color", this.type == "otherMonth" ? "#ccc" : "#999");
  865. }
  866. if (firstStatus) {
  867. switch (firstStatus) {
  868. case "wait":
  869. titleNode.setStyles({"border-left": "6px solid #51B749"});
  870. break;
  871. case "processing":
  872. titleNode.setStyles({"border-left": "6px solid #5484ED"});
  873. break;
  874. case "completed":
  875. titleNode.setStyles({"border-left": "6px solid #FBD75B"});
  876. break;
  877. case "applying":
  878. titleNode.setStyles({"border-left": "6px solid #F9905A"});
  879. break;
  880. case "myWaitAccept":
  881. titleNode.setStyles({"border-left": "6px solid #F6A623"});
  882. break
  883. }
  884. }
  885. if (lastStatus) {
  886. var heigth = 0;
  887. if (meetingCount >= 3) {
  888. heigth = 10;
  889. } else {
  890. heigth = 100 - meetingCount * 30;
  891. }
  892. var bottomEmptyNode = new Element("div", {
  893. styles: {
  894. "height": "" + heigth + "px"
  895. }
  896. }).inject(node);
  897. switch (lastStatus) {
  898. case "wait":
  899. bottomEmptyNode.setStyles({"border-left": "6px solid #51B749"});
  900. break;
  901. case "processing":
  902. bottomEmptyNode.setStyles({"border-left": "6px solid #5484ED"});
  903. break;
  904. case "completed":
  905. bottomEmptyNode.setStyles({"border-left": "6px solid #FBD75B"});
  906. break;
  907. case "applying":
  908. bottomEmptyNode.setStyles({"border-left": "6px solid #F9905A"});
  909. break;
  910. case "myWaitAccept":
  911. bottomEmptyNode.setStyles({"border-left": "6px solid #F6A623"});
  912. break
  913. }
  914. }
  915. }
  916. }
  917. },
  918. expend : function( container, node ){
  919. this.oSize = node.getSize();
  920. container.setStyles({
  921. "position" : "relative"
  922. });
  923. this.tempNode = new Element("div",{
  924. styles : {
  925. width : (node.getSize().x ) + "px",
  926. height : "1px",
  927. margin : "7px"
  928. }
  929. }).inject(container);
  930. node.setStyles({
  931. "height" : node.getScrollSize().y + "px",
  932. "width" : (node.getSize().x ) + "px",
  933. "position" : "absolute",
  934. "top" : "0px",
  935. "left" : "0px",
  936. "box-shadow": "0 0 8px 0 rgba(0,0,0,0.25)"
  937. });
  938. var nodeCoordinate = node.getCoordinates();
  939. var contentNode = this.calendar.contentWarpNode;
  940. var contentCoordinate = contentNode.getCoordinates();
  941. if( nodeCoordinate.bottom > contentCoordinate.bottom ){
  942. this.contentHeight = contentCoordinate.height;
  943. contentNode.setStyle("height", ( nodeCoordinate.bottom - contentCoordinate.top )+"px" );
  944. }
  945. this.isCollapse = false;
  946. },
  947. collapse : function(container, node){
  948. if( !this.collapseDisable && this.collapseReady){
  949. container.setStyles({
  950. "position" : "static"
  951. });
  952. if( this.tempNode )this.tempNode.destroy();
  953. node.setStyles({
  954. "height" : "140px",
  955. "width" : "auto",
  956. "position" : "static",
  957. "box-shadow": "none"
  958. });
  959. if( this.contentHeight ){
  960. var contentNode = this.calendar.contentWarpNode;
  961. contentNode .setStyle("height", ( this.contentHeight )+"px" );
  962. this.contentHeight = null;
  963. }
  964. this.isCollapse = true;
  965. }
  966. },
  967. destroy: function(){
  968. this.meetings.each(function(meeting){
  969. meeting.destroy();
  970. }.bind(this));
  971. this.meetings = [];
  972. if(this.titleNode){
  973. this.titleNode.destroy();
  974. this.titleNode = null;
  975. }
  976. this.titleDayNode = null;
  977. this.titleInforNode = null;
  978. delete this.calendar.days[this.key];
  979. //this.container.empty();
  980. MWF.release(this);
  981. },
  982. reload: function(){
  983. this.view.reload();
  984. }
  985. });
  986. MWF.xApplication.Meeting.WeekView.Calendar.Day.Meeting = new Class({
  987. initialize: function(day, node, data, index){
  988. this.day = day;
  989. this.css = this.day.css;
  990. this.view = this.day.view;
  991. this.app = this.day.app;
  992. this.container = node;
  993. this.data = data;
  994. this.index = index;
  995. this.load();
  996. },
  997. load: function(){
  998. this.nodeStyles = (this.day.type == "today") ? this.css.meetingNode_today : this.css.meetingNode;
  999. this.node = new Element("div", {
  1000. "styles": this.nodeStyles
  1001. }).inject(this.container);
  1002. this.iconNode = new Element("div", {"styles": this.css.meetingIconNode}).inject(this.node);
  1003. this.timeNode = new Element("div", {"styles": this.css.meetingTimeNode}).inject(this.node);
  1004. this.textNode = new Element("div", {"styles": this.css.meetingTextNode}).inject(this.node);
  1005. var timeStr = Date.parse(this.data.startTime).format("%H:%M");
  1006. this.timeNode.set("text", timeStr);
  1007. this.textNode.set("text", this.data.subject);
  1008. //this.node.set("title", this.data.subject);
  1009. //
  1010. //if (this.data.myWaitAccept){
  1011. // this.iconNode.setStyle("background", "url(../x_component_Meeting/$WeekView/"+this.app.options.style+"/icon/invite.png) no-repeat center center");
  1012. //}
  1013. switch (this.data.status){
  1014. case "wait":
  1015. this.node.setStyles({
  1016. "border-left": "6px solid #51B749"
  1017. });
  1018. break;
  1019. case "processing":
  1020. this.node.setStyles({
  1021. "border-left": "6px solid #5484ED"
  1022. });
  1023. break;
  1024. case "completed":
  1025. //add attachment
  1026. this.node.setStyles({
  1027. "border-left": "6px solid #FBD75B"
  1028. });
  1029. //this.textNode.setStyle("color", "#666");
  1030. break;
  1031. case "applying":
  1032. //add attachment
  1033. this.node.setStyles({
  1034. "border-left": "6px solid #F9905A"
  1035. });
  1036. //this.textNode.setStyle("color", "#666");
  1037. break;
  1038. }
  1039. if (this.data.myWaitAccept){
  1040. this.node.setStyles({
  1041. "border-left": "6px solid #F6A623"
  1042. });
  1043. }
  1044. this.node.addEvents({
  1045. mouseenter : function(){
  1046. this.day.collapseReady = false;
  1047. this.node.setStyles( this.css.meetingNode_over );
  1048. this.textNode.addClass("mainColor_color");
  1049. //this.showTooltip();
  1050. }.bind(this),
  1051. mouseleave : function(){
  1052. this.node.setStyles( this.nodeStyles );
  1053. this.textNode.removeClass("mainColor_color");
  1054. }.bind(this),
  1055. "click": function(){this.openMeeting();}.bind(this)
  1056. });
  1057. this.loadTooltip();
  1058. },
  1059. loadTooltip : function(){
  1060. this.tooltip = new MWF.xApplication.Meeting.MeetingTooltip(this.app.content, this.node, this.app, this.data, {
  1061. axis : "x",
  1062. hiddenDelay : 300,
  1063. displayDelay : 300,
  1064. onShow : function(){
  1065. this.day.collapseDisable = true;
  1066. }.bind(this),
  1067. onQueryCreate : function(){
  1068. this.day.collapseDisable = true;
  1069. }.bind(this),
  1070. onHide : function(){
  1071. this.day.collapseDisable = false;
  1072. this.day.collapse(this.parentTd, this.parentNode);
  1073. }.bind(this)
  1074. });
  1075. },
  1076. showTooltip: function( ){
  1077. //if( this.index > 3 && this.day.isCollapse ){
  1078. //}else{
  1079. if( this.tooltip ){
  1080. this.tooltip.load();
  1081. }else{
  1082. this.tooltip = new MWF.xApplication.Meeting.MeetingTooltip(this.app.content, this.node, this.app, this.data, {
  1083. axis : "x", "delay" : 150
  1084. //onShow : function(){
  1085. // this.day.collapseDisable = true;
  1086. //}.bind(this),
  1087. //onQueryCreate : function(){
  1088. // this.day.collapseDisable = true;
  1089. //}.bind(this),
  1090. //onHide : function(){
  1091. // this.day.collapseDisable = false;
  1092. //}.bind(this)
  1093. });
  1094. this.tooltip.load();
  1095. }
  1096. //}
  1097. },
  1098. openMeeting: function(){
  1099. this.form = new MWF.xApplication.Meeting.MeetingForm(this,this.data, {}, {app:this.app});
  1100. this.form.view = this;
  1101. this.form.open();
  1102. },
  1103. destroy: function(){
  1104. if(this.tooltip)this.tooltip.destroy();
  1105. this.node.destroy();
  1106. MWF.release(this);
  1107. },
  1108. reload: function(){
  1109. this.view.reload();
  1110. }
  1111. });
  1112. MWF.xApplication.Meeting.WeekView.WeekCalendar = new Class({
  1113. Extends : MWF.widget.Calendar,
  1114. initialize: function(node, options){
  1115. this.options.weekBegin = "0";
  1116. Locale.use("zh-CHS");
  1117. this.options.defaultTime = ""+this.options.baseDate.getHours()+":"+this.options.baseDate.getMinutes()+":"+this.options.baseDate.getSeconds();
  1118. this.setOptions(options);
  1119. this.path = MWF.defaultPath+"/widget/$Calendar/";
  1120. this.cssPath = MWF.defaultPath+"/widget/$Calendar/"+this.options.style+"/css.wcss";
  1121. this._loadCss();
  1122. // this.options.containerPath = this.path+this.style+"/container.html";
  1123. // this.options.dayPath = this.path+this.style+"/day.html";
  1124. // this.options.monthPath = this.path+this.style+"/month.html";
  1125. // this.options.yearPath = this.path+this.style+"/year.html";
  1126. // this.options.timePath = this.path+this.style+"/time.html";
  1127. if (!this.options.format){
  1128. if (this.options.isTime){
  1129. //this.options.format = Locale.get("Date").shortDate + " " + Locale.get("Date").shortTime;
  1130. if(this.options.timeOnly){
  1131. this.options.format="%H:%M";
  1132. }
  1133. else{
  1134. this.options.format = Locale.get("Date").shortDate + " " + "%H:%M";
  1135. }
  1136. }else{
  1137. this.options.format = Locale.get("Date").shortDate;
  1138. }
  1139. }
  1140. this.options.containerPath = this.options.path+this.options.style+"/container.html";
  1141. this.options.dayPath = this.options.path+this.options.style+"/day_week.html";
  1142. this.options.monthPath = this.options.path+this.options.style+"/month.html";
  1143. this.options.yearPath = this.options.path+this.options.style+"/year.html";
  1144. this.options.timePath = this.options.path+this.options.style+"/time.html";
  1145. this.today = new Date();
  1146. this.currentView = this.options.defaultView;
  1147. this.node = $(node);
  1148. this.visible = false;
  1149. this.container = this.createContainer();
  1150. this.container.inject((this.options.target) || $(document.body));
  1151. this.contentTable = this.createContentTable();
  1152. this.contentTable.inject(this.contentDateNode);
  1153. this.addEvents();
  1154. this.container.set({
  1155. styles: {
  1156. "display": "none",
  1157. "opacity": 1
  1158. }
  1159. });
  1160. this.fireEvent("init");
  1161. //this.move = true;
  1162. //this.containerDrag = new Drag.Move(this.container);
  1163. },
  1164. showDay: function(year, month){
  1165. this._setDayTitle(null, year, month);
  1166. this._setDayWeekTitleTh();
  1167. this._setDayDate(null, year, month);
  1168. // if (!this.move){
  1169. // this.move = true;
  1170. // this.containerDrag = new Drag.Move(this.container);
  1171. // }
  1172. },
  1173. _setDayTitle: function(node, year, month){
  1174. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  1175. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  1176. thisMonth++;
  1177. var text = thisYear+ o2.LP.widget.year +thisMonth+ o2.LP.widget.month;
  1178. var thisNode = node || this.currentTextNode;
  1179. thisNode.set("text", text);
  1180. thisNode.store("year", thisYear);
  1181. thisNode.store("month", thisMonth);
  1182. },
  1183. _setDayWeekTitleTh: function(table){
  1184. var dayTable = table || this.contentTable;
  1185. var thead = dayTable.getElement("thead");
  1186. var cells = thead.getElements("th");
  1187. if (this.css.calendarDaysContentTh) cells.setStyles(this.css.calendarDaysContentTh);
  1188. //var days_abbr = Locale.get("Date").days_abbr;
  1189. var days_abbr = MWF.LP.widget.days_abbr;
  1190. cells.each(function(item, idx){
  1191. if( idx == 0 ){
  1192. item.set("text", o2.LP.widget.week);
  1193. }else{
  1194. //var index;
  1195. //if( this.options.weekBegin == "0" ){
  1196. // index = idx-1;
  1197. //}else{
  1198. // index = idx == 7 ? 0 : idx;
  1199. //}
  1200. var index = ( idx - 1 + parseInt( this.options.weekBegin ) ) % 7;
  1201. item.set("text", days_abbr[index]);
  1202. }
  1203. }.bind(this));
  1204. return cells;
  1205. },
  1206. _setDayDate: function(table, year, month){
  1207. var dayTable = table || this.contentTable;
  1208. var baseDate = this.options.baseDate;
  1209. if ((year!=undefined) && (month!=undefined)){
  1210. baseDate = new Date();
  1211. baseDate.setDate(1);
  1212. baseDate.setFullYear(year);
  1213. baseDate.setMonth(month);
  1214. }
  1215. var tbody = dayTable.getElement("tbody");
  1216. var tds = tbody.getElements("td");
  1217. var firstDate = baseDate.clone();
  1218. firstDate.setDate(1);
  1219. //if( this.options.weekBegin == "0" ){
  1220. // var day = firstDate.getDay()+1;
  1221. //}else{
  1222. //
  1223. //}
  1224. var day = ( 7 + firstDate.getDay() - parseInt( this.options.weekBegin ) ) % 7 + 1;
  1225. var tmpDate = firstDate.clone();
  1226. for (var i=day-1; i>=0; i--){
  1227. if( i % 8 == 0 ){ //设置周数
  1228. var week = this.getWeekNumber( tmpDate );
  1229. tds[i].set("text", week);
  1230. tds[i].setStyles(this.css.week);
  1231. tds[i].store("weekValue", week.toString());
  1232. tds[i].store("dateValue", tmpDate.toString());
  1233. i--;
  1234. if( i<0 )break;
  1235. }
  1236. tmpDate.increment("day", -1);
  1237. tds[i].set("text", tmpDate.getDate());
  1238. tds[i].addClass("gray_"+this.options.style);
  1239. tds[i].setStyles(this.css["gray_"+this.options.style]);
  1240. tds[i].store("dateValue", tmpDate.toString())
  1241. }
  1242. for (var i=day; i<tds.length; i++){
  1243. if( i % 8 == 0 ){ //设置周数
  1244. var week = this.getWeekNumber( firstDate );
  1245. tds[i].set("text", week );
  1246. //tds[i].addClass("gray_"+this.options.style);
  1247. tds[i].setStyles(this.css.week);
  1248. tds[i].store("weekValue", week.toString());
  1249. tds[i].store("dateValue", firstDate.toString());
  1250. i++;
  1251. if( i>=tds.length )break;
  1252. }
  1253. tds[i].set("text", firstDate.getDate());
  1254. if (firstDate.toString() == this.options.baseDate.toString()){
  1255. tds[i].addClass("current_"+this.options.style);
  1256. tds[i].setStyles(this.css["current_"+this.options.style]);
  1257. tds[i].removeClass("gray_"+this.options.style);
  1258. tds[i].setStyle("border", "1px solid #FFF");
  1259. }else if (firstDate.getMonth()!=baseDate.getMonth()){
  1260. tds[i].addClass("gray_"+this.options.style);
  1261. tds[i].setStyles(this.css["gray_"+this.options.style]);
  1262. tds[i].removeClass("current_"+this.options.style);
  1263. tds[i].setStyle("border", "1px solid #FFF");
  1264. }else{
  1265. tds[i].setStyles(this.css["normal_"+this.options.style]);
  1266. tds[i].removeClass("current_"+this.options.style);
  1267. tds[i].removeClass("gray_"+this.options.style);
  1268. tds[i].setStyle("border", "1px solid #FFF");
  1269. }
  1270. var tmp = firstDate.clone();
  1271. if (tmp.clearTime().toString() == this.today.clearTime().toString()){
  1272. //tds[i].addClass("today_"+this.options.style);
  1273. tds[i].setStyles(this.css["today_"+this.options.style]);
  1274. tds[i].setStyle("border", "0px solid #AAA");
  1275. tds[i].addClass("mainColor_bg");
  1276. }
  1277. tds[i].store("dateValue", firstDate.toString());
  1278. firstDate.increment("day", 1);
  1279. }
  1280. },
  1281. getWeekNumber: function( d ){
  1282. // Create a copy of this date object
  1283. var target = d.clone();
  1284. // ISO week date weeks start on monday
  1285. // so correct the day number
  1286. //if( this.options.weekBegin == "1" ){
  1287. // var dayNr = (d.getDay() + 6) % 7;
  1288. //}else{
  1289. // var dayNr = (d.getDay() + 7) % 7;
  1290. //}
  1291. var dayNr = ( 7 + d.getDay() - parseInt( this.options.weekBegin ) ) % 7;
  1292. // ISO 8601 states that week 1 is the week
  1293. // with the first thursday of that year.
  1294. // Set the target date to the thursday in the target week
  1295. target.setDate(target.getDate() - dayNr + 3);
  1296. // Store the millisecond value of the target date
  1297. var firstThursday = target.valueOf();
  1298. // Set the target to the first thursday of the year
  1299. // First set the target to january first
  1300. target.setMonth(0, 1);
  1301. // Not a thursday? Correct the date to the next thursday
  1302. if (target.getDay() != 4) {
  1303. target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
  1304. }
  1305. // The weeknumber is the number of weeks between the
  1306. // first thursday of the year and the thursday in the target week
  1307. return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
  1308. }
  1309. });