WeekView.js 51 KB

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