WeekView.js 51 KB

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