Schedule.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. var MWFCalendar = MWF.xApplication.Calendar = MWF.xApplication.Calendar || {};
  2. //MWF.xApplication.Calendar.widget = MWF.xApplication.Calendar.widget || {};
  3. MWF.xDesktop.requireApp("Calendar", "lp."+MWF.language, null, false);
  4. MWF.xDesktop.requireApp("Calendar", "Common", null, false);
  5. o2.widget.Schedule = o2.Schedule = new Class({
  6. Implements: [Options, Events],
  7. Extends: o2.widget.Common,
  8. options: {
  9. "style": "default",
  10. "weekBegin" : 0,
  11. "date" : "",
  12. "title" : ""
  13. },
  14. initialize: function(container, app, options){
  15. this.setOptions(options);
  16. this.container = container;
  17. this._app = app;
  18. this.path = this.options.path || "../x_component_Calendar/widget/$Schedule/";
  19. this.cssPath = "../x_component_Calendar/widget/$Schedule/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.fireEvent("init");
  22. this.load() ;
  23. },
  24. load: function(){
  25. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  26. var date = "";
  27. if( this.options.date ){
  28. date = Date.parse( this.options.date )
  29. }
  30. this.app = {
  31. actions : MWF.Actions.get("x_calendar_assemble_control"),
  32. lp : MWF.xApplication.Calendar.LP,
  33. content : this._app.content
  34. };
  35. this.calendar = new o2.Schedule.Calendar(this, date );
  36. },
  37. reload: function(){
  38. if (this.calendar) this.calendar.reLoadCalendar();
  39. },
  40. destroy: function(){
  41. if (this.calendar){
  42. this.calendar.destroy();
  43. }
  44. this.node.destroy();
  45. }
  46. });
  47. o2.Schedule.Calendar = new Class({
  48. Implements: [Events],
  49. initialize: function(view, date){
  50. this.view = view;
  51. this.css = this.view.css;
  52. this.container = this.view.node;
  53. this.date = date || new Date();
  54. this.today = new Date();
  55. this.days = {};
  56. this.app = this.view.app;
  57. this.lp = MWF.xApplication.Calendar.LP;
  58. this.weekBegin = this.view.options.weekBegin;
  59. this.load();
  60. },
  61. load: function(){
  62. this.titleNode = new Element("div", {"styles": this.css.calendarTitleNode}).inject(this.container);
  63. this.contentNode = new Element("div", {"styles": { "overflow" : "hidden" }}).inject(this.container);
  64. this.leftContentNode = new Element("div", {"styles": { "float" : "left" }}).inject(this.contentNode);
  65. this.rightContentNode = new Element("div", {"styles": this.css.rightContentNode }).inject(this.contentNode);
  66. this.titleTableContainer = new Element("div", {"styles": this.css.calendarTitleTableContainer}).inject(this.leftContentNode);
  67. //this.scrollNode = new Element("div", {
  68. // "styles": this.css.scrollNode
  69. //}).inject(this.container);
  70. //this.contentWarpNode = new Element("div", {
  71. // "styles": this.css.contentWarpNode
  72. //}).inject(this.scrollNode);
  73. //
  74. //this.contentContainerNode = new Element("div",{
  75. // "styles" : this.css.contentContainerNode
  76. //}).inject(this.contentWarpNode);
  77. this.bodyNode = new Element("div", {
  78. "styles": this.css.contentNode
  79. }).inject(this.leftContentNode);
  80. //this.bodyNode.setStyle("position","relative");
  81. //this.bodyNode = new Element("div", {"styles": this.css.calendarBodyNode}).inject(this.container);
  82. this.setTitleNode();
  83. this.setTitleTableNode();
  84. this.setBodyNode();
  85. //this.app.addEvent("resize", this.resetBodySize.bind(this));
  86. },
  87. resetBodySize: function(){
  88. var size = this.view.container.getSize();
  89. var titleSize = this.titleNode.getSize();
  90. var titleTableSize = this.titleTable.getSize();
  91. var y = size.y-titleSize.y-titleTableSize.y;
  92. this.leftContentNode.setStyle( "width", size.x - 160 + "px" );
  93. this.rightContentNode.setStyle("height", size.y - titleSize.y - 35 + "px" );
  94. o2.Schedule.TdHeight = y / 6;
  95. o2.Schedule.TdWidth = (size.x - 160 )/ 7;
  96. //this.bodyNode.setStyle("height", ""+y+"px");
  97. //var size = this.container.getSize();
  98. //this.scrollNode.setStyle("height", ""+y+"px");
  99. //this.titleTableContainer.setStyles({
  100. // "width": (size.x - 40) +"px"
  101. //});
  102. //if (this.contentWarpNode){
  103. // this.contentWarpNode.setStyles({
  104. // "width": (size.x - 40) +"px"
  105. // });
  106. //}
  107. //var tableSize = this.calendarTable.getSize();
  108. //o2.Schedule.WeekWidth = tableSize.x;
  109. //o2.Schedule.DayWidth = tableSize.x / 7;
  110. //this.dataTdList.each( function( td ){
  111. // td.setStyle("width", o2.Schedule.WeekWidth)
  112. //});
  113. //if( this.wholeDayDocumentList && this.wholeDayDocumentList.length ){
  114. // this.wholeDayDocumentList.each( function( doc ){
  115. // doc.resize();
  116. // }.bind(this))
  117. //}
  118. //
  119. //if( this.oneDayDocumentList && this.oneDayDocumentList.length ){
  120. // this.oneDayDocumentList.each( function( doc ){
  121. // doc.resize();
  122. // }.bind(this))
  123. //}
  124. //var top = 30;
  125. //var trs = this.calendarTable.getElements("tr");
  126. //this.calendarTrHeight = [];
  127. //for( var key in this.usedYIndex ){
  128. // var idx = this.usedYIndex[key];
  129. // var maxLength = Math.max( idx[0].length, idx[1].length, idx[2].length, idx[3].length, idx[4].length, idx[5].length, idx[6].length );
  130. // if( maxLength > 4 ){
  131. // this.dataTableList[key].setStyle("top", top );
  132. // var height = 30 + maxLength * (22 + 2);
  133. // top = top + height;
  134. // trs[ parseInt(key) ].getElements("td").each( function(td){
  135. // td.setStyle("height", height )
  136. // });
  137. // this.calendarTrHeight.push( height );
  138. // }else{
  139. // this.dataTableList[key].setStyle("top", top );
  140. // top = top + o2.Schedule.WeekHeight + 1;
  141. // trs[ parseInt(key) ].getElements("td").each( function(td){
  142. // td.setStyle("height", o2.Schedule.WeekHeight )
  143. // });
  144. // this.calendarTrHeight.push( o2.Schedule.WeekHeight );
  145. // }
  146. //}
  147. //var tdy = (y-30)/6;
  148. //tdy = tdy-34;
  149. //var tds = this.calendarTable.getElements("td");
  150. //tds.each(function(td){
  151. // var yy = tdy;
  152. // var node = td.getLast("div");
  153. // if (node.childNodes.length>=4){
  154. // if (yy<92) yy = 69;
  155. // }
  156. // node.setStyle("height", ""+yy+"px");
  157. //}.bind(this));
  158. },
  159. setTitleNode: function(){
  160. //this.view.titleContainer.getElements("div:only-child").setStyle("display","none");
  161. //if( this.titleNode ){
  162. // this.titleNode.setStyle("display","")
  163. //}
  164. //this.titleNode = new Element("div").inject(this.view.titleContainer);
  165. if( this.view.options.title ){
  166. new Element("div", {"styles": this.css.titleNameNode, "text" : this.view.options.title }).inject(this.titleNode);
  167. }
  168. var text = this.date.format(this.lp.dateFormatDay);
  169. this.titleTextNode = new Element("div", {"styles": this.css.calendarTitleTextNode, "text": text}).inject(this.titleNode);
  170. this.nextMonthNode = new Element("div", {"styles": this.css.calendarNextMonthNode}).inject(this.titleNode);
  171. this.prevMonthNode = new Element("div", {"styles": this.css.calendarPrevMonthNode}).inject(this.titleNode);
  172. this.prevMonthNode.addEvents({
  173. "mouseover": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  174. "mouseout": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode);}.bind(this),
  175. "mousedown": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_down);}.bind(this),
  176. "mouseup": function(){this.prevMonthNode.setStyles(this.css.calendarPrevMonthNode_over);}.bind(this),
  177. "click": function(){this.changeMonthPrev();}.bind(this)
  178. });
  179. this.nextMonthNode.addEvents({
  180. "mouseover": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  181. "mouseout": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode);}.bind(this),
  182. "mousedown": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_down);}.bind(this),
  183. "mouseup": function(){this.nextMonthNode.setStyles(this.css.calendarNextMonthNode_over);}.bind(this),
  184. "click": function(){this.changeMonthNext();}.bind(this)
  185. });
  186. this.titleTextNode.addEvents({
  187. "mouseover": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  188. "mouseout": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode);}.bind(this),
  189. "mousedown": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_down);}.bind(this),
  190. "mouseup": function(){this.titleTextNode.setStyles(this.css.calendarTitleTextNode_over);}.bind(this),
  191. "click": function(){this.changeMonthSelect();}.bind(this)
  192. });
  193. },
  194. changeMonthPrev: function(){
  195. this.date.decrement("month", 1);
  196. var text = this.date.format(this.lp.dateFormatDay);
  197. this.titleTextNode.set("text", text);
  198. this.reLoadCalendar();
  199. },
  200. changeMonthNext: function(){
  201. this.date.increment("month", 1);
  202. var text = this.date.format(this.lp.dateFormatDay);
  203. this.titleTextNode.set("text", text);
  204. this.reLoadCalendar();
  205. },
  206. changeMonthSelect: function(){
  207. if (!this.monthSelector) this.createMonthSelector();
  208. this.monthSelector.show();
  209. },
  210. createMonthSelector: function(){
  211. this.monthSelector = new o2.Schedule.MonthSelector(this.date, this);
  212. },
  213. changeMonthTo: function(d){
  214. this.date = d;
  215. var text = this.date.format(this.lp.dateFormatDay);
  216. this.titleTextNode.set("text", text);
  217. this.reLoadCalendar();
  218. },
  219. setTitleTableNode : function(){
  220. if( this.weekBegin == "1" ){
  221. var html = "<tr><th>"+this.lp.weeksShort.Mon+"</th><th>"+this.lp.weeksShort.Tues+"</th><th>"+this.lp.weeksShort.Wed+"</th>" +
  222. "<th>"+this.lp.weeksShort.Thur+"</th><th>"+this.lp.weeksShort.Fri+"</th><th>"+this.lp.weeksShort.Sat+"</th><th>"+this.lp.weeksShort.Sun+"</th></tr>";
  223. }else{
  224. var html = "<tr><th>"+this.lp.weeksShort.Sun+"</th><th>"+this.lp.weeksShort.Mon+"</th><th>"+this.lp.weeksShort.Tues+"</th><th>"+this.lp.weeksShort.Wed+"</th>" +
  225. "<th>"+this.lp.weeksShort.Thur+"</th><th>"+this.lp.weeksShort.Fri+"</th><th>"+this.lp.weeksShort.Sat+"</th></tr>";
  226. }
  227. this.titleTable = new Element("table", {
  228. "styles": this.css.calendarTable,
  229. "height": "100%",
  230. "border": "0",
  231. "cellPadding": "0",
  232. "cellSpacing": "0",
  233. "html": html
  234. }).inject(this.titleTableContainer);
  235. this.calendarTableTitleTr = this.titleTable.getElement("tr");
  236. this.calendarTableTitleTr.setStyles(this.css.calendarTableTitleTr);
  237. var ths = this.calendarTableTitleTr.getElements("th");
  238. ths.setStyles(this.css.calendarTableTh);
  239. },
  240. setBodyNode: function(){
  241. var html = "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  242. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  243. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  244. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  245. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  246. html += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
  247. this.calendarTable = new Element("table", {
  248. "styles": this.css.calendarTable,
  249. "height": "100%",
  250. "border": "0",
  251. "cellPadding": "0",
  252. "cellSpacing": "0",
  253. "html": html
  254. }).inject(this.bodyNode);
  255. //var tds = this.calendarTable.getElements("td");
  256. //tds.setStyles(this.css.calendarTableCell);
  257. this.loadCalendar();
  258. },
  259. reLoadCalendar: function(){
  260. //if( this.wholeDayDocumentList && this.wholeDayDocumentList.length ){
  261. // this.wholeDayDocumentList.each( function( doc ){
  262. // doc.destroy();
  263. // }.bind(this))
  264. //}
  265. //this.wholeDayDocumentList = [];
  266. //
  267. //if( this.oneDayDocumentList && this.oneDayDocumentList.length ){
  268. // this.oneDayDocumentList.each( function( doc ){
  269. // doc.destroy();
  270. // }.bind(this))
  271. //}
  272. //this.oneDayDocumentList = [];
  273. this.loadCalendar();
  274. },
  275. calculateMonthRange : function(){
  276. var date = this.date.clone();
  277. var start = new Date( date.get("year"), date.get("month"), 1, 0, 0, 0 );
  278. var week = start.getDay();
  279. if( this.weekBegin == "1" ){
  280. var decrementDay = ((week-1)<0) ? 6 : week-1;
  281. }else{
  282. var decrementDay = week;
  283. }
  284. start.decrement("day", decrementDay);
  285. this.monthStart = start;
  286. this.monthStartStr = this.monthStart.format("db");
  287. var end = start.clone();
  288. end.increment("day", 41);
  289. this.monthEnd = new Date( end.get("year"), end.get("month"), end.get("date"), 23, 59, 59 );
  290. this.monthEndStr = this.monthEnd.format("db");
  291. //this.calculateWeekRange();
  292. },
  293. //calculateWeekRange: function(){
  294. // this.weekRangeList = [];
  295. // var start = this.monthStart.clone();
  296. // var end;
  297. // for( var i=0; i<6; i++ ){
  298. // end = start.clone().increment("day", 6);
  299. // end = new Date( end.get("year"), end.get("month"), end.get("date"), 23, 59, 59 );
  300. // this.weekRangeList.push( {
  301. // start : start,
  302. // end : end
  303. // });
  304. // start = end.clone().increment("second",1);
  305. // }
  306. //
  307. // this.weekDaysList = [];
  308. // start = this.monthStart.clone();
  309. // for( var i=0; i<this.weekRangeList.length; i++ ){
  310. // var j =0;
  311. // var days = [];
  312. // while( j<7 ){
  313. // days.push( start.format("%Y-%m-%d") );
  314. // start.increment("day",1);
  315. // j++;
  316. // }
  317. // this.weekDaysList.push(days);
  318. // }
  319. //
  320. //
  321. // this.usedYIndex = {};
  322. // for( var i=0; i<this.weekRangeList.length; i++ ){
  323. // this.usedYIndex[i] = {};
  324. // var j =0;
  325. // while( j<7 ){
  326. // this.usedYIndex[i][j] = [];
  327. // j++;
  328. // }
  329. // }
  330. //},
  331. //getDateIndexOfWeek : function( weekIndex, days ){
  332. // var weekDays = this.weekDaysList[weekIndex];
  333. // var indexs = [];
  334. // for( var i=0; i<days.length;i++ ){
  335. // indexs.push( weekDays.indexOf( days[i] ) );
  336. // }
  337. // return indexs;
  338. //},
  339. inCurrentMonth : function( time ){
  340. return time > this.monthStart && time < this.monthEnd;
  341. },
  342. //getTimeRange : function( bDate, eDate ){
  343. // if( bDate > this.monthEnd || eDate < this.monthStart )return null;
  344. // var range = {
  345. // startTime : bDate,
  346. // endTime : eDate,
  347. // start: ( bDate <= this.monthStart ) ? this.monthStart.clone() : bDate.clone(),
  348. // end: ( this.monthEnd <= eDate ) ? this.monthEnd.clone() : eDate.clone()
  349. // };
  350. // range.firstDay = range.start.clone().clearTime();
  351. // range.diff = range.start - range.end;
  352. // range.weekInforList = this.getWeekInfor(bDate, eDate);
  353. // return range;
  354. //},
  355. //getWeekInfor : function( startTime, endTime ){
  356. // if( startTime > this.monthEnd || endTime < this.monthStart )return null;
  357. // var rangeWeekInfor = {};
  358. // for( var i=0 ; i<this.weekRangeList.length; i++ ){
  359. // var range = this.weekRangeList[i];
  360. // if(startTime > range.end || endTime < range.start )continue;
  361. // var isStart = startTime >= range.start;
  362. // var isEnd = range.end >= endTime;
  363. // var start = isStart ? startTime : range.start;
  364. // var end = isEnd ? endTime : range.end;
  365. // var diff = end - start;
  366. // var left = start - range.start;
  367. // var days = this.getDaysByRange(start, end);
  368. // var daysIndex = this.getDateIndexOfWeek( i, days );
  369. // rangeWeekInfor[i] = {
  370. // index : i,
  371. // isEventStart : isStart,
  372. // isEventEnd : isEnd,
  373. // start : start,
  374. // end : end,
  375. // diff : diff,
  376. // days : days,
  377. // left : left,
  378. // daysIndex : daysIndex
  379. // };
  380. // if( isEnd )break;
  381. // }
  382. // return rangeWeekInfor;
  383. //},
  384. //getDaysByRange : function( startTime, endTime ){
  385. // var start = startTime.clone();
  386. // var end = endTime;
  387. // var days = [];
  388. // while( start < end ){
  389. // days.push( start.clone().format("%Y-%m-%d") );
  390. // start.increment()
  391. // }
  392. // return days;
  393. //},
  394. loadCalendar: function(){
  395. //this.app.currentDate = this.date.clone();
  396. this.calculateMonthRange();
  397. this.cancelCurrentTd();
  398. this.loadData( function(){
  399. this.resetBodySize();
  400. this._loadCalendar( false );
  401. this.loadDayContent( this.date );
  402. //this.loadWholeDay( this.wholeDayData );
  403. //this.loadOneDay( this.inOneDayEvents );
  404. }.bind(this));
  405. },
  406. _loadCalendar : function( isCreate ){
  407. var date = this.date.clone();
  408. date.set("date", 1);
  409. var week = date.getDay();
  410. if( this.weekBegin == "1" ){
  411. var decrementDay = ((week-1)<0) ? 6 : week-1;
  412. }else{
  413. var decrementDay = week;
  414. }
  415. date.decrement("day", decrementDay);
  416. var tds = this.calendarTable.getElements("td");
  417. tds.each(function(td){
  418. this.loadDay(td, date, isCreate);
  419. date.increment();
  420. }.bind(this));
  421. },
  422. loadData : function( callback ){
  423. this.app.actions.listMyCalendar( function( json ){
  424. var ids = [];
  425. json.data.myCalendars.each( function( d ){ ids.push( d.id ) });
  426. json.data.unitCalendars.each( function( d ){ ids.push( d.id ) });
  427. json.data.followCalendars.each( function( d ){ ids.push( d.id ) });
  428. this.app.actions.listEventWithFilter( {
  429. calendarIds : ids,
  430. startTime : this.monthStartStr,
  431. endTime : this.monthEndStr //,
  432. //createPerson : this.app.userName
  433. }, function(json){
  434. this.wholeDayData = ( json.data && json.data.wholeDayEvents ) ? json.data.wholeDayEvents : [];
  435. this.wholeDayData.each( function(d){
  436. d.start = Date.parse( d.startTimeStr );
  437. d.end = Date.parse( d.endTimeStr );
  438. });
  439. this.inOneDayEventMap = {};
  440. var array = ( json.data && json.data.inOneDayEvents ) ? json.data.inOneDayEvents : [];
  441. array.each( function(d){
  442. if( d.inOneDayEvents && d.inOneDayEvents.length ){
  443. this.inOneDayEventMap[d.eventDate] = d.inOneDayEvents;
  444. }
  445. }.bind(this));
  446. //(( json.data && json.data.inOneDayEvents) ? json.data.inOneDayEvents : []).each( function( d ){
  447. // if(d.inOneDayEvents.length > 0 ){
  448. // this.inOneDayEvents.push( d );
  449. // }
  450. //}.bind(this));
  451. if(callback)callback();
  452. }.bind(this));
  453. }.bind(this));
  454. },
  455. isDateHasData : function( date ){
  456. debugger;
  457. var dStr = typeOf( date ) === "string" ? date : date.format("%Y-%m-%d");
  458. var array = [];
  459. if( this.inOneDayEventMap[ dStr ] && this.inOneDayEventMap[ dStr].length )return true;
  460. var start = Date.parse( dStr + " 00:00:00" );
  461. var end = Date.parse( dStr + " 23:59:59" );
  462. for( var i=0; i<this.wholeDayData.length; i++ ){
  463. var data = this.wholeDayData[i];
  464. if( data.start <= start && data.end >= end )return true;
  465. }
  466. return false;
  467. },
  468. getDataByDate : function( date ){
  469. var dStr = typeOf( date ) === "string" ? date : date.format("%Y-%m-%d");
  470. var array = [];
  471. if( this.inOneDayEventMap[ dStr ] && this.inOneDayEventMap[ dStr].length )array = this.inOneDayEventMap[ dStr].clone();
  472. var start = Date.parse( dStr + " 00:00:00" );
  473. var end = Date.parse( dStr + " 23:59:59" );
  474. this.wholeDayData.each( function( data ){
  475. if( data.start <= start && data.end >= end )array.push( data );
  476. }.bind(this));
  477. return array;
  478. },
  479. loadDay: function(td, date, isCreate){
  480. debugger;
  481. var _self = this;
  482. td.empty();
  483. var type = "thisMonth";
  484. var m = date.get("month");
  485. var y = date.get("year");
  486. var d = date.get("date");
  487. var mm = this.date.get("month");
  488. var yy = this.date.get("year");
  489. var dd = this.date.get("date");
  490. var mmm = this.today.get("month");
  491. var yyy = this.today.get("year");
  492. var ddd = this.today.get("date");
  493. if ((m==mmm) && (y==yyy) && (d==ddd)){
  494. type = "today";
  495. }else if ((m==mm) && (y==yy)){
  496. type = "thisMonth";
  497. }else{
  498. type = "otherMonth";
  499. }
  500. var hasData = this.isDateHasData( date );
  501. //var node = new Element("div", {
  502. // "styles" : this.css["calendarTableCell_"+type]
  503. //}).inject( td );
  504. //td.set( "valign","top");
  505. td.set( "align","center");
  506. td.set("height", o2.Schedule.TdHeight );
  507. //td.set("line-height","40px");
  508. td.setStyles( this.css["calendarTableCell_"+type] );
  509. td.store("dateStr",date.format("%Y-%m-%d"));
  510. td.store("type", type );
  511. td.addEvent("click", function(ev){
  512. _self.setCurrentTd( this.td );
  513. _self.loadDayContent( this.date );
  514. }.bind({ td : td, date : date.format("%Y-%m-%d") }));
  515. td.addEvent("dblclick", function(ev){
  516. //_self.cancelCurrentTd();
  517. //var form = new MWF.xApplication.Calendar.EventForm(_self,{}, {
  518. // startTime : Date.parse( this.retrieve("dateStr") + " 08:00") ,
  519. // endTime : Date.parse( this.retrieve("dateStr") + " 09:00")
  520. //}, {app:_self.app});
  521. //form.view = _self;
  522. //form.create();
  523. _self.toDay( this.retrieve("dateStr") );
  524. }.bind(td));
  525. //var titleNode = new Element("div", {"styles": this.css["dayTitle_"+ type]}).inject(td);
  526. var titleDayNode = new Element("div", {"styles": this.css["dayTitleDay_"+ type], "text": d }).inject(td);
  527. td.store("titleDayNode", titleDayNode );
  528. if( hasData ){
  529. new Element("div", {"styles": type === "today" ? this.css.dayHasData_today : this.css.dayHasData }).inject(titleDayNode);
  530. }
  531. if( type === "today" ){
  532. var size = Math.min( o2.Schedule.TdHeight, o2.Schedule.TdWidth );
  533. size = size > 26 ? 26 : size;
  534. titleDayNode.setStyles({
  535. "width" : size+"px",
  536. "height" : size+"px",
  537. "line-height" : size+"px"
  538. })
  539. }else if( (m==mm) && (y==yy) && (d==dd) ){
  540. this.setCurrentTd( td )
  541. }
  542. //titleDayNode.addEvent("click", function(){
  543. // _self.setCurrentTd();
  544. // _self.loadDayContent( this.date );
  545. //}.bind({ date : date.format("%Y-%m-%d") }));
  546. //var contentNode = new Element("div", {"styles": this.css.dayContentNode}).inject(node);
  547. },
  548. create : function( dateStr ){
  549. var _self = this;
  550. var form = new MWF.xApplication.Calendar.EventForm(_self,{}, {
  551. startTime : dateStr + " 08:00",
  552. endTime : dateStr + " 09:00"
  553. }, {app:_self.app});
  554. form.view = _self;
  555. form.create();
  556. },
  557. isEditable: function(){
  558. if( MWF.AC.isAdministrator() )return true;
  559. if( (this.data.manageablePersonList || []).contains( layout.desktop.session.user.distinguishedName ) )return true;
  560. if( this.data.createPerson === layout.desktop.session.user.distinguishedName )return true;
  561. return false;
  562. },
  563. openEventForm : function(data){
  564. var form = new MWF.xApplication.Calendar.EventForm(this, data, {
  565. isFull : true
  566. }, {app:this.app});
  567. form.view = this.view;
  568. this.isEditable(data) ? form.edit() : form.open();
  569. },
  570. toDay : function( date ){
  571. var appId = "Calendar";
  572. if (layout.desktop.apps[appId]){
  573. var app = layout.desktop.apps[appId];
  574. app.status = {
  575. options : { "date" : date }
  576. };
  577. app.toMonth();
  578. app.setCurrent();
  579. }else {
  580. var options = {
  581. "defaultAction": "toMonth",
  582. onQueryLoad : function(){
  583. this.status = {
  584. options : { "date" : date }
  585. }
  586. }
  587. };
  588. layout.desktop.openApplication(null, "Calendar", options);
  589. }
  590. },
  591. setCurrentTd : function(td){
  592. this.cancelCurrentTd();
  593. var type = td.retrieve("type");
  594. if( type != "today" ){
  595. td.retrieve( "titleDayNode" ).setStyles( this.css["dayTitleDay_current"] )
  596. }
  597. this.currentSelectedTd = td;
  598. },
  599. cancelCurrentTd : function(){
  600. if( this.currentSelectedTd ){
  601. var type = this.currentSelectedTd.retrieve("type");
  602. if( type != "today" ){
  603. this.currentSelectedTd.retrieve( "titleDayNode" ).setStyles( this.css["dayTitleDay_"+ type] )
  604. }
  605. }
  606. this.currentSelectedTd = null;
  607. },
  608. reload : function(){
  609. this.view.reload();
  610. },
  611. destroy: function(){
  612. Object.each(this.days, function(day){
  613. day.destroy();
  614. }.bind(this));
  615. this.container.empty();
  616. },
  617. loadDayContent : function( date ){
  618. date = typeOf( date ) === "string" ? date : date.format("%Y-%m-%d");
  619. var _self = this;
  620. this.rightContentNode.empty();
  621. var text = Date.parse(date).format(this.lp.dateFormatDay);
  622. this.titleTextNode.set("text", text);
  623. var data = this.getDataByDate( date );
  624. if( data.length == 0 ){
  625. var titleNode = new Element("div", { styles : this.css.rightContentTitle }).inject( this.rightContentNode );
  626. new Element("div", { styles : this.css.rightContentTitle_text, text : this.lp.schedule.noEvent }).inject( titleNode );
  627. var itemContainer = new Element("div", { styles : this.css.rightContentItemContainer }).inject( this.rightContentNode );
  628. }else{
  629. var titleNode = new Element("div", { styles : { overflow : "hidden" } }).inject( this.rightContentNode );
  630. new Element("div", { styles : this.css.rightContentTitle_text, text : this.lp.schedule.current }).inject( titleNode );
  631. new Element("div", { styles : this.css.rightContentTitle_count, text : data.length }).inject( titleNode );
  632. new Element("div", { styles : this.css.rightContentTitle_text, text : this.lp.schedule.someEvent }).inject( titleNode );
  633. var itemContainer = new Element("div", { styles : this.css.rightContentItemContainer }).inject( this.rightContentNode );
  634. for( var i=0; i<data.length && i<2; i++ ){
  635. var d = data[i];
  636. var itemNode = new Element("div", { styles : this.css.rightContentItem }).inject( itemContainer );
  637. itemNode.addEvent("click", function(){
  638. _self.openEventForm( this.data );
  639. }.bind({ data : d }));
  640. new Element("div", { styles : this.css.rightContentItemDot }).inject( itemNode );
  641. new Element("div", { styles : this.css.rightContentItemText, text : d.title }).inject( itemNode );
  642. var start = Date.parse( d.startTime );
  643. var end = Date.parse( d.endTime );
  644. var startDateOnly = start.format("%Y-%m-%d");
  645. var endDateOnly = end.format("%Y-%m-%d");
  646. var timeText ;
  647. if( startDateOnly === endDateOnly ){
  648. timeText =start.format("%H:%M") + this.lp.to + end.format("%H:%M");
  649. }else{
  650. timeText = start.format("%m-%d") + this.lp.to + end.format("%m-%d");
  651. }
  652. new Element("div", { styles : this.css.rightContentItemTime, text : timeText }).inject( itemNode );
  653. }
  654. }
  655. var rightToolbar = new Element("div", { styles : this.css.rightToolbar }).inject( this.rightContentNode );
  656. var rightTool_add = new Element("div", { styles : this.css.rightTool_add, "text" : this.lp.add }).inject( this.rightContentNode );
  657. rightTool_add.addEvent( "click", function(){
  658. this.create( date )
  659. }.bind(this));
  660. var rightTool_more = new Element("div", { styles : this.css.rightTool_more, "text" : this.lp.more }).inject( this.rightContentNode );
  661. rightTool_more.addEvent( "click", function(){
  662. this.toDay( date )
  663. }.bind(this))
  664. }
  665. });
  666. o2.Schedule.TdHeight = 30;
  667. o2.Schedule.TdWidth = 40;
  668. o2.Schedule.MonthSelector = new Class({
  669. Implements: [Events],
  670. initialize: function(date, calendar){
  671. this.calendar = calendar;
  672. this.css = this.calendar.css;
  673. this.app = this.calendar.app;
  674. this.lp = this.app.lp;
  675. this.date = date;
  676. this.year = this.date.get("year");
  677. this.load();
  678. },
  679. load: function(){
  680. this.monthSelectNode = new Element("div", {"styles": this.css.calendarMonthSelectNode}).inject(this.calendar.container);
  681. this.monthSelectNode.position({
  682. relativeTo: this.calendar.titleTextNode,
  683. position: 'bottomCenter',
  684. edge: 'upperCenter'
  685. });
  686. this.monthSelectNode.addEvent("mousedown", function(e){e.stopPropagation();});
  687. this.monthSelectTitleNode = new Element("div", {"styles": this.css.calendarMonthSelectTitleNode}).inject(this.monthSelectNode);
  688. this.monthSelectPrevYearNode = new Element("div", {"styles": this.css.calendarMonthSelectTitlePrevYearNode}).inject(this.monthSelectTitleNode);
  689. this.monthSelectNextYearNode = new Element("div", {"styles": this.css.calendarMonthSelectTitleNextYearNode}).inject(this.monthSelectTitleNode);
  690. this.monthSelectTextNode = new Element("div", {"styles": this.css.calendarMonthSelectTitleTextNode}).inject(this.monthSelectTitleNode);
  691. this.monthSelectTextNode.set("text", this.year);
  692. var html = "<tr><td></td><td></td><td></td></tr>";
  693. html += "<tr><td></td><td></td><td></td></tr>";
  694. html += "<tr><td></td><td></td><td></td></tr>";
  695. html += "<tr><td></td><td></td><td></td></tr>";
  696. this.monthSelectTable = new Element("table", {
  697. "styles": {"margin-top": "10px"},
  698. "height": "200px",
  699. "width": "90%",
  700. "align": "center",
  701. "border": "0",
  702. "cellPadding": "0",
  703. "cellSpacing": "0", //5
  704. "html": html
  705. }).inject(this.monthSelectNode);
  706. //this.loadMonth();
  707. this.monthSelectBottomNode = new Element("div", {"styles": this.css.calendarMonthSelectBottomNode, "text": this.lp.today}).inject(this.monthSelectNode);
  708. this.setEvent();
  709. },
  710. loadMonth: function(){
  711. this.monthSelectTextNode.set("text", this.year);
  712. var d = new Date();
  713. var todayY = d.get("year");
  714. var todayM = d.get("month");
  715. var thisY = this.date.get("year");
  716. var thisM = this.date.get("month");
  717. var _self = this;
  718. var tds = this.monthSelectTable.getElements("td");
  719. tds.each(function(td, idx){
  720. td.empty();
  721. td.removeEvents("mouseover");
  722. td.removeEvents("mouseout");
  723. td.removeEvents("mousedown");
  724. td.removeEvents("mouseup");
  725. td.removeEvents("click");
  726. var m = idx+1;
  727. td.store("month", m);
  728. td.setStyles(this.css.calendarMonthSelectTdNode);
  729. td.setStyle("background-color", "#FFF");
  730. if ((this.year == todayY) && (idx == todayM)){
  731. new Element("div", {
  732. styles : _self.css.calendarMonthSelectTodayNode,
  733. text : ""+m+this.lp.month
  734. }).inject( td );
  735. }else if ((this.year == thisY) && (idx == thisM)){
  736. //td.setStyle("background-color", "#EEE");
  737. new Element("div", {
  738. styles : _self.css.calendarMonthSelectCurrentNode,
  739. text : ""+m+this.lp.month
  740. }).inject( td );
  741. }else{
  742. td.set("text", ""+m+this.lp.month);
  743. }
  744. td.addEvents({
  745. "mouseover": function(){this.setStyles(_self.css.calendarMonthSelectTdNode_over);},
  746. "mouseout": function(){this.setStyles(_self.css.calendarMonthSelectTdNode);},
  747. "mousedown": function(){this.setStyles(_self.css.calendarMonthSelectTdNode_down);},
  748. "mouseup": function(){this.setStyles(_self.css.calendarMonthSelectTdNode_over);},
  749. "click": function(){
  750. _self.selectedMonth(this);
  751. }
  752. });
  753. }.bind(this));
  754. },
  755. setEvent: function(){
  756. this.monthSelectPrevYearNode.addEvent("click", function(){
  757. this.prevYear();
  758. }.bind(this));
  759. this.monthSelectNextYearNode.addEvent("click", function(){
  760. this.nextYear();
  761. }.bind(this));
  762. this.monthSelectBottomNode.addEvents({
  763. "mouuseover" : function(){ this.monthSelectBottomNode.setStyles( this.css.calendarMonthSelectBottomNode_over ); }.bind(this),
  764. "mouuseout" : function(){ this.monthSelectBottomNode.setStyles( this.css.calendarMonthSelectBottomNode ); }.bind(this),
  765. "click" : function(){ this.todayMonth(); }.bind(this)
  766. });
  767. },
  768. prevYear: function(){
  769. this.year--;
  770. if (this.year<1900) this.year=1900;
  771. this.monthSelectTextNode.set("text", this.year);
  772. this.loadMonth();
  773. },
  774. nextYear: function(){
  775. this.year++;
  776. //if (this.year<1900) this.year=1900;
  777. this.monthSelectTextNode.set("text", this.year);
  778. this.loadMonth();
  779. },
  780. todayMonth: function(){
  781. var d = new Date();
  782. this.calendar.changeMonthTo(d);
  783. this.hide();
  784. },
  785. selectedMonth: function(td){
  786. var m = td.retrieve("month");
  787. var d = Date.parse(this.year+"/"+m+"/1");
  788. this.calendar.changeMonthTo(d);
  789. this.hide();
  790. },
  791. show: function(){
  792. this.date = this.calendar.date;
  793. this.year = this.date.get("year");
  794. this.loadMonth();
  795. this.monthSelectNode.setStyle("display", "block");
  796. this.hideFun = this.hide.bind(this);
  797. document.body.addEvent("mousedown", this.hideFun);
  798. },
  799. hide: function(){
  800. this.monthSelectNode.setStyle("display", "none");
  801. document.body.removeEvent("mousedown", this.hideFun);
  802. },
  803. destroy: function(){
  804. //this.titleNode.destroy();
  805. //this.titleNode = null;
  806. //this.titleDayNode = null;
  807. //this.titleInforNode = null;
  808. //
  809. //delete this.calendar.days[this.key];
  810. //
  811. //this.node.empty();
  812. //MWF.release(this);
  813. }
  814. });