WeekView.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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. if( this.data.capacity ){
  534. this.titleCountNode = new Element("div.titleCountNode", {
  535. "styles": this.enable ? this.css.roomItemTitleCountNode : this.css.roomItemTitleCountNode_disable,
  536. "text" : this.data.capacity+ this.app.lp.person
  537. }).inject(this.descriptNode);
  538. }
  539. if( this.data.roomNumber ){
  540. new Element("div.titleCountNode", {
  541. "styles": this.enable ? this.css.roomItemTitleCountNode : this.css.roomItemTitleCountNode_disable,
  542. "text" : this.data.roomNumber
  543. }).inject(this.descriptNode);
  544. }
  545. if( this.buildingName && this.buildingName !== "noRoom" ){
  546. this.buildingTextNode = new Element("div.buildingTextNode", {
  547. "styles": this.enable ? this.css.roomItemBuildingTextNode : this.css.roomItemBuildingTextNode_disable,
  548. "text" : this.buildingName
  549. }).inject(this.titleNode);
  550. }
  551. this.titleTextNode = new Element("div.roomItemTitleTextNode", {
  552. "styles": this.enable ? this.css.roomItemTitleTextNode : this.css.roomItemTitleTextNode_disable ,
  553. "text" : this.data.name === "noRoom" ? this.app.lp.noRoomBuilding : this.data.name
  554. }).inject(this.topNode);
  555. if( this.data.name === "noRoom" ){
  556. this.topNode.setStyles({
  557. "height": "auto",
  558. "padding-top": "30px"
  559. })
  560. this.titleTextNode.setStyles({
  561. "white-space": "pre-wrap",
  562. "line-height": "28px"
  563. })
  564. }
  565. //this.middleNode = new Element("div.middleNode", {
  566. // "styles": this.css.roomItemTitleMiddleNode
  567. //}).inject(this.titleNode);
  568. //
  569. //this.iconsNode = new Element("div.iconsNode", {
  570. // "styles": this.css.roomItemTitleIconsNode
  571. //}).inject(this.middleNode);
  572. //
  573. //var deviceList = this.data.device.split("#");
  574. //deviceList.each(function(name){
  575. // var node = new Element("div", {"styles": this.css.roomItemIconNode, "title": this.app.lp.device[name]}).inject(this.iconsNode);
  576. // node.setStyle("background-image", "url(../x_component_Meeting/$RoomView/default/icon/device/"+ name + ( this.enable ? "" : "_disable" ) +".png)");
  577. //}.bind(this));
  578. //
  579. //this.actionsNode = new Element("div.actionsNode", {
  580. // "styles": this.css.roomItemTitleActionsNode
  581. //}).inject(this.middleNode);
  582. //
  583. //this.loadActions();
  584. },
  585. loadActions: function(){
  586. if( MWF.AC.isMeetingAdministrator() ){
  587. this.editAction = new Element("div.o2icon-edit2", {
  588. styles: this.css.roomAction_edit,
  589. events : {
  590. mouseover : function(){
  591. this.editAction.setStyles( this.css.roomAction_edit_over );
  592. this.editAction.addClass("mainColor_color");
  593. }.bind(this),
  594. mouseout : function(){
  595. this.editAction.setStyles( this.css.roomAction_edit );
  596. this.editAction.removeClass("mainColor_color");
  597. }.bind(this),
  598. click : function(e){
  599. this.editRoom();
  600. e.stopPropagation();
  601. }.bind(this)
  602. }
  603. }).inject(this.actionsNode);
  604. this.removeAction = new Element("div.o2icon-delete", {
  605. styles: this.css.roomAction_remove,
  606. events : {
  607. mouseover : function(){
  608. this.removeAction.setStyles( this.css.roomAction_remove_over );
  609. this.removeAction.addClass("mainColor_color");
  610. }.bind(this),
  611. mouseout : function(){
  612. this.removeAction.setStyles( this.css.roomAction_remove );
  613. this.removeAction.removeClass("mainColor_color");
  614. }.bind(this),
  615. click : function( e ){
  616. this.removeRoom(e);
  617. e.stopPropagation();
  618. }.bind(this)
  619. }
  620. }).inject(this.actionsNode);
  621. }
  622. if( this.enable ){
  623. this.createMeetingAction = new Element("div.o2icon-create", {
  624. tltile : this.app.lp.addMeeting,
  625. styles: this.css.createMeetingAction,
  626. events : {
  627. mouseover : function(){
  628. this.createMeetingAction.setStyles( this.css.createMeetingAction_over );
  629. this.createMeetingAction.addClass("mainColor_color");
  630. }.bind(this),
  631. mouseout : function(){
  632. this.createMeetingAction.setStyles( this.css.createMeetingAction );
  633. this.removeAction.addClass("mainColor_color");
  634. }.bind(this),
  635. click : function(e){
  636. this.app.addMeeting( this.view.date, this.view.hours, this.view.minutes, this.data.id);
  637. e.stopPropagation();
  638. }.bind(this)
  639. }
  640. }).inject(this.actionsNode);
  641. }
  642. },
  643. editRoom : function(){
  644. var form = new MWF.xApplication.Meeting.RoomForm(this.app,this.data, {}, {app:this.app});
  645. form.view = this;
  646. form.edit();
  647. },
  648. openRoom : function(){
  649. var form = new MWF.xApplication.Meeting.RoomForm(this.app,this.data, {}, {app:this.app});
  650. form.view = this;
  651. form.open();
  652. },
  653. reload : function(){
  654. this.view.reload( this.view.date, this.view.hours, this.view.minutes );
  655. },
  656. removeRoom: function(e) {
  657. var info = this.app.lp.delete_room;
  658. info = info.replace(/{name}/g, this.data.name);
  659. var _self = this;
  660. this.app.confirm("warn", e, this.app.lp.delete_building_title, info, 300, 120, function(){
  661. _self.remove();
  662. this.close();
  663. }, function(){
  664. this.close();
  665. });
  666. },
  667. remove: function(){
  668. var view = this.view;
  669. this.app.actions.deleteRoom(this.data.id, function(){
  670. view.reload();
  671. }.bind(this));
  672. },
  673. resetHeight: function(){
  674. this.node.setStyle("min-height",""+this.view.roomNodeHeight+"px");
  675. if( this.noMeetingNode ){
  676. this.noMeetingNode.setStyle("min-height",""+(this.view.roomNodeHeight - 170)+"px");
  677. this.noMeetingNode.setStyle("line-height",""+(this.view.roomNodeHeight - 170)+"px");
  678. }
  679. },
  680. destroy: function(){
  681. if( this.calendar ){
  682. this.calendar.container.destroy();
  683. }
  684. if( this.tooltip ){
  685. this.tooltip.destroy();
  686. }
  687. this.meetings.each( function(m){
  688. m.destroy();
  689. });
  690. this.node.destroy();
  691. MWF.release(this);
  692. }
  693. });
  694. MWF.xApplication.Meeting.WeekView.Calendar.Day = new Class({
  695. Implements: [Events],
  696. initialize: function(index, date, calendar, type){
  697. this.index = index;
  698. this.calendar = calendar;
  699. this.view = this.calendar.view;
  700. this.css = this.calendar.css;
  701. this.app = this.calendar.app;
  702. this.date = date.clone();
  703. this.key = this.date.format(this.app.lp.dateFormat);
  704. this.type = type; //today, otherMonth, thisMonth
  705. this.meetings = [];
  706. this.load();
  707. },
  708. load: function(){
  709. this.color = "#666";
  710. //if( this.type == "thisWeek" ){
  711. //}else if( this.type == "otherWeek" ){
  712. // //this.color = "#ccc";
  713. //}
  714. this.day = this.date.getDate();
  715. this.month = this.date.getMonth();
  716. this.year = this.date.getYear();
  717. this.loadMeetings();
  718. this.roomMeetingObject = {};
  719. this.containerObject = {};
  720. this.calendar.calendarTable.getElements("td[index='"+ this.index +"']").each( function(td){
  721. this.containerObject[ td.get("room") ] = td;
  722. }.bind(this));
  723. },
  724. loadEmpty: function(){
  725. for( var key in this.containerObject ){
  726. var td = this.containerObject[key];
  727. if( !this.roomMeetingObject[ key ] ){
  728. var node = new Element("div", {
  729. "styles" : this.css["calendarTableCell_"+this.type]
  730. }).inject( td );
  731. //var titleNode = new Element("div", {"styles": this.css["dayTitle_" + this.type]}).inject(node);
  732. //var titleDayNode = new Element("div", {
  733. // "styles": this.css["dayTitleDay_" + this.type],
  734. // "text": this.day
  735. //}).inject(titleNode);
  736. //
  737. //if ((new Date()).diff(this.date) >= 0) {
  738. // titleNode.set("title", this.app.lp.titleNode);
  739. // titleNode.addEvent("click", function () {
  740. // this.app.addMeeting(this.date);
  741. // }.bind(this));
  742. //}
  743. var contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(node);
  744. var textNode = new Element("div", {
  745. "styles": {
  746. "line-height": "60px",
  747. "font-size": "14px",
  748. "text-align" : "center",
  749. "color" : this.color,
  750. "padding": "20px 10px"
  751. }
  752. }).inject( contentNode);
  753. textNode.set("text", this.app.lp.noMeeting);
  754. }
  755. }
  756. },
  757. loadMeetings: function(){
  758. this.app.isMeetingViewer( function( isAll ){
  759. this._loadMeetings( isAll );
  760. }.bind(this))
  761. },
  762. _loadMeetings: function( isAll ){
  763. var y = this.date.getFullYear();
  764. var m = this.date.getMonth()+1;
  765. var d = this.date.getDate();
  766. this.app.actions[ isAll ? "listMeetingDayAll" : "listMeetingDay" ](y, m, d, function(json){
  767. var length = json.data.length;
  768. json.data.each(function(meeting, i){
  769. if( !meeting.room ){
  770. meeting.room = "noRoom";
  771. this.calendar.noRoomTr.setStyle("display", "");
  772. }
  773. if( !this.roomMeetingObject[ meeting.room ] ){
  774. this.roomMeetingObject[ meeting.room ] = [];
  775. }
  776. this.roomMeetingObject[ meeting.room].push( meeting );
  777. }.bind(this));
  778. this.loadEmpty();
  779. this.loadRoomMeeting();
  780. }.bind(this));
  781. },
  782. loadRoomMeeting : function(){
  783. var meetingCount = 0;
  784. var firstStatus = "";
  785. var lastStatus = "";
  786. for( var key in this.roomMeetingObject ) {
  787. var td = this.containerObject[key];
  788. var node = new Element("div", {
  789. "styles": this.css["calendarTableCell_" + this.type]
  790. }).inject(td);
  791. var titleNode = new Element("div", {"styles": this.css["dayTitle_" + this.type]}).inject(node);
  792. var titleDayNode = new Element("div", {
  793. "styles": this.css["dayTitleDay_" + this.type],
  794. "text": this.day
  795. }).inject(titleNode);
  796. if( this.type === "today" )titleDayNode.addClass("mainColor_bg");
  797. if ((new Date()).diff(this.date) >= 0) {
  798. titleNode.set("title", this.app.lp.titleNode);
  799. titleNode.addEvent("click", function () {
  800. this.app.addMeeting(this.date);
  801. }.bind(this));
  802. }
  803. var contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(node);
  804. var meetingCount = 0;
  805. var myRejectCount = 0;
  806. var length = this.roomMeetingObject[key].length;
  807. this.roomMeetingObject[key].each(function (meeting, idx) {
  808. if (!meeting.myReject) {
  809. meetingCount++;
  810. if (meetingCount == 3) {
  811. //this.contentNode.setStyle("height", "100px");
  812. }
  813. if (meetingCount == 1) {
  814. firstStatus = meeting.status;
  815. if (meeting.myWaitAccept)firstStatus = "myWaitAccept"
  816. }
  817. if (meetingCount + myRejectCount == length ) {
  818. lastStatus = meeting.status;
  819. if (meeting.myWaitAccept)lastStatus = "myWaitAccept"
  820. }
  821. //if (meetingCount<4)
  822. var m = new MWF.xApplication.Meeting.WeekView.Calendar.Day.Meeting(this, contentNode, meeting, meetingCount);
  823. m.parentNode = node;
  824. m.parentTd = td;
  825. this.meetings.push( m );
  826. }else{
  827. myRejectCount++;
  828. }
  829. }.bind(this));
  830. if (meetingCount == 0) {
  831. //var node = new Element("div", {
  832. // "styles": {
  833. // "line-height": "40px",
  834. // "font-size": "14px",
  835. // "text-align" : "center",
  836. // "color" : this.color,
  837. // "padding": "0px 10px"
  838. // }
  839. //}).inject(this.contentNode);
  840. //node.set("text", this.app.lp.noMeeting);
  841. } else {
  842. var titleInforNode = new Element("div", {"styles": this.css["dayTitleInfor_" + this.type]}).inject(titleNode);
  843. if( this.app.isViewAvailable( "toDay" ) ){
  844. titleInforNode.addEvent("click", function (e) {
  845. this.app.toDay(this.date);
  846. e.stopPropagation();
  847. }.bind(this));
  848. }else{
  849. titleInforNode.setStyle("cursor","default");
  850. }
  851. titleInforNode.set("text", "" + meetingCount + this.app.lp.countMeetings + "");
  852. if (meetingCount > 3) {
  853. node.addEvents({
  854. "mouseenter": function () {
  855. this.obj.expend( this.td, this.node );
  856. }.bind({ obj : this, td : td, node : node }),
  857. "mouseleave": function (){
  858. this.obj.collapseReady = true;
  859. this.obj.collapse( this.td, this.node );
  860. }.bind({ obj : this, td : td, node : node })
  861. })
  862. } else {
  863. titleInforNode.setStyle("color", this.type == "otherMonth" ? "#ccc" : "#999");
  864. }
  865. if (firstStatus) {
  866. switch (firstStatus) {
  867. case "wait":
  868. titleNode.setStyles({"border-left": "6px solid #4990E2"});
  869. break;
  870. case "processing":
  871. titleNode.setStyles({"border-left": "6px solid #66CC7F"});
  872. break;
  873. case "completed":
  874. titleNode.setStyles({"border-left": "6px solid #ccc"});
  875. break;
  876. case "myWaitAccept":
  877. titleNode.setStyles({"border-left": "6px solid #F6A623"});
  878. break
  879. }
  880. }
  881. if (lastStatus) {
  882. var heigth = 0;
  883. if (meetingCount >= 3) {
  884. heigth = 10;
  885. } else {
  886. heigth = 100 - meetingCount * 30;
  887. }
  888. var bottomEmptyNode = new Element("div", {
  889. styles: {
  890. "height": "" + heigth + "px"
  891. }
  892. }).inject(node);
  893. switch (lastStatus) {
  894. case "wait":
  895. bottomEmptyNode.setStyles({"border-left": "6px solid #4990E2"});
  896. break;
  897. case "processing":
  898. bottomEmptyNode.setStyles({"border-left": "6px solid #66CC7F"});
  899. break;
  900. case "completed":
  901. bottomEmptyNode.setStyles({"border-left": "6px solid #ccc"});
  902. break;
  903. case "myWaitAccept":
  904. bottomEmptyNode.setStyles({"border-left": "6px solid #F6A623"});
  905. break
  906. }
  907. }
  908. }
  909. }
  910. },
  911. expend : function( container, node ){
  912. this.oSize = node.getSize();
  913. container.setStyles({
  914. "position" : "relative"
  915. });
  916. this.tempNode = new Element("div",{
  917. styles : {
  918. width : (node.getSize().x ) + "px",
  919. height : "1px",
  920. margin : "7px"
  921. }
  922. }).inject(container);
  923. node.setStyles({
  924. "height" : node.getScrollSize().y + "px",
  925. "width" : (node.getSize().x ) + "px",
  926. "position" : "absolute",
  927. "top" : "0px",
  928. "left" : "0px",
  929. "box-shadow": "0 0 8px 0 rgba(0,0,0,0.25)"
  930. });
  931. var nodeCoordinate = node.getCoordinates();
  932. var contentNode = this.calendar.contentWarpNode;
  933. var contentCoordinate = contentNode.getCoordinates();
  934. if( nodeCoordinate.bottom > contentCoordinate.bottom ){
  935. this.contentHeight = contentCoordinate.height;
  936. contentNode.setStyle("height", ( nodeCoordinate.bottom - contentCoordinate.top )+"px" );
  937. }
  938. this.isCollapse = false;
  939. },
  940. collapse : function(container, node){
  941. if( !this.collapseDisable && this.collapseReady){
  942. container.setStyles({
  943. "position" : "static"
  944. });
  945. if( this.tempNode )this.tempNode.destroy();
  946. node.setStyles({
  947. "height" : "140px",
  948. "width" : "auto",
  949. "position" : "static",
  950. "box-shadow": "none"
  951. });
  952. if( this.contentHeight ){
  953. var contentNode = this.calendar.contentWarpNode;
  954. contentNode .setStyle("height", ( this.contentHeight )+"px" );
  955. this.contentHeight = null;
  956. }
  957. this.isCollapse = true;
  958. }
  959. },
  960. destroy: function(){
  961. this.meetings.each(function(meeting){
  962. meeting.destroy();
  963. }.bind(this));
  964. this.meetings = [];
  965. if(this.titleNode){
  966. this.titleNode.destroy();
  967. this.titleNode = null;
  968. }
  969. this.titleDayNode = null;
  970. this.titleInforNode = null;
  971. delete this.calendar.days[this.key];
  972. //this.container.empty();
  973. MWF.release(this);
  974. },
  975. reload: function(){
  976. this.view.reload();
  977. }
  978. });
  979. MWF.xApplication.Meeting.WeekView.Calendar.Day.Meeting = new Class({
  980. initialize: function(day, node, data, index){
  981. this.day = day;
  982. this.css = this.day.css;
  983. this.view = this.day.view;
  984. this.app = this.day.app;
  985. this.container = node;
  986. this.data = data;
  987. this.index = index;
  988. this.load();
  989. },
  990. load: function(){
  991. this.nodeStyles = (this.day.type == "today") ? this.css.meetingNode_today : this.css.meetingNode;
  992. this.node = new Element("div", {
  993. "styles": this.nodeStyles
  994. }).inject(this.container);
  995. this.iconNode = new Element("div", {"styles": this.css.meetingIconNode}).inject(this.node);
  996. this.timeNode = new Element("div", {"styles": this.css.meetingTimeNode}).inject(this.node);
  997. this.textNode = new Element("div", {"styles": this.css.meetingTextNode}).inject(this.node);
  998. var timeStr = Date.parse(this.data.startTime).format("%H:%M");
  999. this.timeNode.set("text", timeStr);
  1000. this.textNode.set("text", this.data.subject);
  1001. //this.node.set("title", this.data.subject);
  1002. //
  1003. //if (this.data.myWaitAccept){
  1004. // this.iconNode.setStyle("background", "url(../x_component_Meeting/$WeekView/"+this.app.options.style+"/icon/invite.png) no-repeat center center");
  1005. //}
  1006. switch (this.data.status){
  1007. case "wait":
  1008. this.node.setStyles({
  1009. "border-left": "6px solid #4990E2"
  1010. });
  1011. break;
  1012. case "processing":
  1013. this.node.setStyles({
  1014. "border-left": "6px solid #66CC7F"
  1015. });
  1016. break;
  1017. case "completed":
  1018. //add attachment
  1019. this.node.setStyles({
  1020. "border-left": "6px solid #ccc"
  1021. });
  1022. //this.textNode.setStyle("color", "#666");
  1023. break;
  1024. }
  1025. if (this.data.myWaitAccept){
  1026. this.node.setStyles({
  1027. "border-left": "6px solid #F6A623"
  1028. });
  1029. }
  1030. this.node.addEvents({
  1031. mouseenter : function(){
  1032. this.day.collapseReady = false;
  1033. this.node.setStyles( this.css.meetingNode_over );
  1034. this.textNode.addClass("mainColor_color");
  1035. //this.showTooltip();
  1036. }.bind(this),
  1037. mouseleave : function(){
  1038. this.node.setStyles( this.nodeStyles );
  1039. this.textNode.removeClass("mainColor_color");
  1040. }.bind(this),
  1041. "click": function(){this.openMeeting();}.bind(this)
  1042. });
  1043. this.loadTooltip();
  1044. },
  1045. loadTooltip : function(){
  1046. this.tooltip = new MWF.xApplication.Meeting.MeetingTooltip(this.app.content, this.node, this.app, this.data, {
  1047. axis : "x",
  1048. hiddenDelay : 300,
  1049. displayDelay : 300,
  1050. onShow : function(){
  1051. this.day.collapseDisable = true;
  1052. }.bind(this),
  1053. onQueryCreate : function(){
  1054. this.day.collapseDisable = true;
  1055. }.bind(this),
  1056. onHide : function(){
  1057. this.day.collapseDisable = false;
  1058. this.day.collapse(this.parentTd, this.parentNode);
  1059. }.bind(this)
  1060. });
  1061. },
  1062. showTooltip: function( ){
  1063. //if( this.index > 3 && this.day.isCollapse ){
  1064. //}else{
  1065. if( this.tooltip ){
  1066. this.tooltip.load();
  1067. }else{
  1068. this.tooltip = new MWF.xApplication.Meeting.MeetingTooltip(this.app.content, this.node, this.app, this.data, {
  1069. axis : "x", "delay" : 150
  1070. //onShow : function(){
  1071. // this.day.collapseDisable = true;
  1072. //}.bind(this),
  1073. //onQueryCreate : function(){
  1074. // this.day.collapseDisable = true;
  1075. //}.bind(this),
  1076. //onHide : function(){
  1077. // this.day.collapseDisable = false;
  1078. //}.bind(this)
  1079. });
  1080. this.tooltip.load();
  1081. }
  1082. //}
  1083. },
  1084. openMeeting: function(){
  1085. this.form = new MWF.xApplication.Meeting.MeetingForm(this,this.data, {}, {app:this.app});
  1086. this.form.view = this;
  1087. this.form.open();
  1088. },
  1089. destroy: function(){
  1090. if(this.tooltip)this.tooltip.destroy();
  1091. this.node.destroy();
  1092. MWF.release(this);
  1093. },
  1094. reload: function(){
  1095. this.view.reload();
  1096. }
  1097. });
  1098. MWF.xApplication.Meeting.WeekView.WeekCalendar = new Class({
  1099. Extends : MWF.widget.Calendar,
  1100. initialize: function(node, options){
  1101. this.options.weekBegin = "0";
  1102. Locale.use("zh-CHS");
  1103. this.options.defaultTime = ""+this.options.baseDate.getHours()+":"+this.options.baseDate.getMinutes()+":"+this.options.baseDate.getSeconds();
  1104. this.setOptions(options);
  1105. this.path = MWF.defaultPath+"/widget/$Calendar/";
  1106. this.cssPath = MWF.defaultPath+"/widget/$Calendar/"+this.options.style+"/css.wcss";
  1107. this._loadCss();
  1108. // this.options.containerPath = this.path+this.style+"/container.html";
  1109. // this.options.dayPath = this.path+this.style+"/day.html";
  1110. // this.options.monthPath = this.path+this.style+"/month.html";
  1111. // this.options.yearPath = this.path+this.style+"/year.html";
  1112. // this.options.timePath = this.path+this.style+"/time.html";
  1113. if (!this.options.format){
  1114. if (this.options.isTime){
  1115. //this.options.format = Locale.get("Date").shortDate + " " + Locale.get("Date").shortTime;
  1116. if(this.options.timeOnly){
  1117. this.options.format="%H:%M";
  1118. }
  1119. else{
  1120. this.options.format = Locale.get("Date").shortDate + " " + "%H:%M";
  1121. }
  1122. }else{
  1123. this.options.format = Locale.get("Date").shortDate;
  1124. }
  1125. }
  1126. this.options.containerPath = this.options.path+this.options.style+"/container.html";
  1127. this.options.dayPath = this.options.path+this.options.style+"/day_week.html";
  1128. this.options.monthPath = this.options.path+this.options.style+"/month.html";
  1129. this.options.yearPath = this.options.path+this.options.style+"/year.html";
  1130. this.options.timePath = this.options.path+this.options.style+"/time.html";
  1131. this.today = new Date();
  1132. this.currentView = this.options.defaultView;
  1133. this.node = $(node);
  1134. this.visible = false;
  1135. this.container = this.createContainer();
  1136. this.container.inject((this.options.target) || $(document.body));
  1137. this.contentTable = this.createContentTable();
  1138. this.contentTable.inject(this.contentDateNode);
  1139. this.addEvents();
  1140. this.container.set({
  1141. styles: {
  1142. "display": "none",
  1143. "opacity": 1
  1144. }
  1145. });
  1146. this.fireEvent("init");
  1147. //this.move = true;
  1148. //this.containerDrag = new Drag.Move(this.container);
  1149. },
  1150. showDay: function(year, month){
  1151. this._setDayTitle(null, year, month);
  1152. this._setDayWeekTitleTh();
  1153. this._setDayDate(null, year, month);
  1154. // if (!this.move){
  1155. // this.move = true;
  1156. // this.containerDrag = new Drag.Move(this.container);
  1157. // }
  1158. },
  1159. _setDayTitle: function(node, year, month){
  1160. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  1161. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  1162. thisMonth++;
  1163. var text = thisYear+ o2.LP.widget.year +thisMonth+ o2.LP.widget.month;
  1164. var thisNode = node || this.currentTextNode;
  1165. thisNode.set("text", text);
  1166. thisNode.store("year", thisYear);
  1167. thisNode.store("month", thisMonth);
  1168. },
  1169. _setDayWeekTitleTh: function(table){
  1170. var dayTable = table || this.contentTable;
  1171. var thead = dayTable.getElement("thead");
  1172. var cells = thead.getElements("th");
  1173. if (this.css.calendarDaysContentTh) cells.setStyles(this.css.calendarDaysContentTh);
  1174. //var days_abbr = Locale.get("Date").days_abbr;
  1175. var days_abbr = MWF.LP.widget.days_abbr;
  1176. cells.each(function(item, idx){
  1177. if( idx == 0 ){
  1178. item.set("text", o2.LP.widget.week);
  1179. }else{
  1180. //var index;
  1181. //if( this.options.weekBegin == "0" ){
  1182. // index = idx-1;
  1183. //}else{
  1184. // index = idx == 7 ? 0 : idx;
  1185. //}
  1186. var index = ( idx - 1 + parseInt( this.options.weekBegin ) ) % 7;
  1187. item.set("text", days_abbr[index]);
  1188. }
  1189. }.bind(this));
  1190. return cells;
  1191. },
  1192. _setDayDate: function(table, year, month){
  1193. var dayTable = table || this.contentTable;
  1194. var baseDate = this.options.baseDate;
  1195. if ((year!=undefined) && (month!=undefined)){
  1196. baseDate = new Date();
  1197. baseDate.setDate(1);
  1198. baseDate.setFullYear(year);
  1199. baseDate.setMonth(month);
  1200. }
  1201. var tbody = dayTable.getElement("tbody");
  1202. var tds = tbody.getElements("td");
  1203. var firstDate = baseDate.clone();
  1204. firstDate.setDate(1);
  1205. //if( this.options.weekBegin == "0" ){
  1206. // var day = firstDate.getDay()+1;
  1207. //}else{
  1208. //
  1209. //}
  1210. var day = ( 7 + firstDate.getDay() - parseInt( this.options.weekBegin ) ) % 7 + 1;
  1211. var tmpDate = firstDate.clone();
  1212. for (var i=day-1; i>=0; i--){
  1213. if( i % 8 == 0 ){ //设置周数
  1214. var week = this.getWeekNumber( tmpDate );
  1215. tds[i].set("text", week);
  1216. tds[i].setStyles(this.css.week);
  1217. tds[i].store("weekValue", week.toString());
  1218. tds[i].store("dateValue", tmpDate.toString());
  1219. i--;
  1220. if( i<0 )break;
  1221. }
  1222. tmpDate.increment("day", -1);
  1223. tds[i].set("text", tmpDate.getDate());
  1224. tds[i].addClass("gray_"+this.options.style);
  1225. tds[i].setStyles(this.css["gray_"+this.options.style]);
  1226. tds[i].store("dateValue", tmpDate.toString())
  1227. }
  1228. for (var i=day; i<tds.length; i++){
  1229. if( i % 8 == 0 ){ //设置周数
  1230. var week = this.getWeekNumber( firstDate );
  1231. tds[i].set("text", week );
  1232. //tds[i].addClass("gray_"+this.options.style);
  1233. tds[i].setStyles(this.css.week);
  1234. tds[i].store("weekValue", week.toString());
  1235. tds[i].store("dateValue", firstDate.toString());
  1236. i++;
  1237. if( i>=tds.length )break;
  1238. }
  1239. tds[i].set("text", firstDate.getDate());
  1240. if (firstDate.toString() == this.options.baseDate.toString()){
  1241. tds[i].addClass("current_"+this.options.style);
  1242. tds[i].setStyles(this.css["current_"+this.options.style]);
  1243. tds[i].removeClass("gray_"+this.options.style);
  1244. tds[i].setStyle("border", "1px solid #FFF");
  1245. }else if (firstDate.getMonth()!=baseDate.getMonth()){
  1246. tds[i].addClass("gray_"+this.options.style);
  1247. tds[i].setStyles(this.css["gray_"+this.options.style]);
  1248. tds[i].removeClass("current_"+this.options.style);
  1249. tds[i].setStyle("border", "1px solid #FFF");
  1250. }else{
  1251. tds[i].setStyles(this.css["normal_"+this.options.style]);
  1252. tds[i].removeClass("current_"+this.options.style);
  1253. tds[i].removeClass("gray_"+this.options.style);
  1254. tds[i].setStyle("border", "1px solid #FFF");
  1255. }
  1256. var tmp = firstDate.clone();
  1257. if (tmp.clearTime().toString() == this.today.clearTime().toString()){
  1258. //tds[i].addClass("today_"+this.options.style);
  1259. tds[i].setStyles(this.css["today_"+this.options.style]);
  1260. tds[i].setStyle("border", "0px solid #AAA");
  1261. tds[i].addClass("mainColor_bg");
  1262. }
  1263. tds[i].store("dateValue", firstDate.toString());
  1264. firstDate.increment("day", 1);
  1265. }
  1266. },
  1267. getWeekNumber: function( d ){
  1268. // Create a copy of this date object
  1269. var target = d.clone();
  1270. // ISO week date weeks start on monday
  1271. // so correct the day number
  1272. //if( this.options.weekBegin == "1" ){
  1273. // var dayNr = (d.getDay() + 6) % 7;
  1274. //}else{
  1275. // var dayNr = (d.getDay() + 7) % 7;
  1276. //}
  1277. var dayNr = ( 7 + d.getDay() - parseInt( this.options.weekBegin ) ) % 7;
  1278. // ISO 8601 states that week 1 is the week
  1279. // with the first thursday of that year.
  1280. // Set the target date to the thursday in the target week
  1281. target.setDate(target.getDate() - dayNr + 3);
  1282. // Store the millisecond value of the target date
  1283. var firstThursday = target.valueOf();
  1284. // Set the target to the first thursday of the year
  1285. // First set the target to january first
  1286. target.setMonth(0, 1);
  1287. // Not a thursday? Correct the date to the next thursday
  1288. if (target.getDay() != 4) {
  1289. target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
  1290. }
  1291. // The weeknumber is the number of weeks between the
  1292. // first thursday of the year and the thursday in the target week
  1293. return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
  1294. }
  1295. });