CalendarContent.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. MWF.xApplication.Homepage.CalendarContent = new Class({
  2. Extends: MWF.xApplication.Homepage.TaskContent,
  3. Implements: [Options, Events],
  4. options: {
  5. "view": "calendarContent.html"
  6. },
  7. load: function(){
  8. this.tabs = {};
  9. this.dayFlags = [];
  10. this.container.loadHtml(this.viewPath, {"bind": {"lp": this.app.lp}, "module": this}, function(){
  11. this.initSize();
  12. this.loadCalender(function(){
  13. this.fireEvent("load");
  14. }.bind(this));
  15. // this.loadMyCalender(function(){
  16. // this.fireEvent("load");
  17. // }.bind(this));
  18. // //是否需要定时自动刷新 @todo
  19. // this.startProcessAction.addEvent("click", this.startProcess.bind(this));
  20. //this.moreInforAction.addEvent("click", this.moreInfor.bind(this));
  21. }.bind(this));
  22. },
  23. openCalender: function(e){
  24. layout.openApplication(e, "Calendar");
  25. },
  26. setContentSize: function(){
  27. var total = this.container.getSize().y;
  28. var calenderHeight = this.calenderArea.getSize().y+this.calenderArea.getEdgeHeight();
  29. var titleHeight = this.calenderTitleNode.getSize().y+this.calenderTitleNode.getEdgeHeight();
  30. var bottomHeight = this.pageAreaNode.getSize().y+this.pageAreaNode.getEdgeHeight();
  31. var inforHeight = this.calenderInforArea.getSize().y+this.calenderInforArea.getEdgeHeight();
  32. var thisHeight = this.itemContentNode.getEdgeHeight();
  33. var contentHeight = total-titleHeight-bottomHeight-thisHeight-inforHeight-calenderHeight;
  34. this.itemContentNode.setStyle("height", ""+contentHeight+"px");
  35. this.contentHeight = contentHeight;
  36. //this.pageSize = (this.options.itemHeight/this.contentHeight).toInt();
  37. if (this.noItemNode){
  38. var m = (this.contentHeight- this.noItemNode.getSize().y)/2;
  39. this.noItemNode.setStyle("margin-top", ""+m+"px");
  40. }
  41. if (this.dayFlags && this.dayFlags.length){
  42. this.dayFlags.each(function(flag){
  43. var td = flag.retrieve("td");
  44. if (td) flag.position({
  45. "relativeTo": td,
  46. "position": 'topRight',
  47. "edge": 'topRight'
  48. });
  49. });
  50. }
  51. },
  52. loadCalender: function(callback){
  53. o2.require("o2.widget.CalendarPage", function(){
  54. this.calender = new o2.widget.CalendarPage(this.calenderArea, {
  55. "style": "homepage",
  56. "onQueryComplate": function (d) {
  57. this.loadMyCalender(d, callback);
  58. //if (callback) callback();
  59. }.bind(this),
  60. "onChangeViewToDay": function(){
  61. this.loadMonthCalender();
  62. }.bind(this),
  63. "onChangeViewToMonth": function(){
  64. this.calenderFlagArea.empty();
  65. this.dayFlags = [];
  66. }.bind(this),
  67. "onChangeViewToYear": function(){
  68. this.calenderFlagArea.empty();
  69. this.dayFlags = [];
  70. }.bind(this)
  71. });
  72. this.calender.show();
  73. this.calender._selectDate((new Date()).toString());
  74. var m = this.calender.currentNode.getStyle("margin-right").toInt();
  75. m = m +40;
  76. this.calender.currentNode.setStyle("margin-right", ""+m+"px");
  77. this.calender.todayNode = new Element("div.mainColor_color", {"styles": this.calender.css.todayNode, "text": this.app.lp.today}).inject(this.calender.currentNode, "before");
  78. this.calender.todayNode.addEvent("click", function(){
  79. this.calender.changeViewToDay();
  80. // this.calender.showDay();
  81. this.calender._selectDate((new Date()).toString());
  82. // this.loadMonthCalender();
  83. }.bind(this));
  84. }.bind(this));
  85. },
  86. loadMonthCalender: function(){
  87. this.calenderFlagArea.empty();
  88. this.dayFlags = [];
  89. var tds = this.calender.contentTable.getElements("td");
  90. var start = new Date(tds[0].retrieve("dateValue")).clearTime();
  91. var end = new Date(tds[tds.length-1].retrieve("dateValue")).clearTime();
  92. end.increment("day", 1);
  93. var d = {
  94. "startTime": start.format("db"),
  95. "endTime": end.format("db"),
  96. "createPerson": layout.user.distinguishedName
  97. };
  98. o2.Actions.load("x_calendar_assemble_control").Calendar_EventAction.listWithFilter(d, function(json){
  99. debugger;
  100. if (json.data){
  101. if (json.data.wholeDayEvents && json.data.wholeDayEvents.length){
  102. json.data.wholeDayEvents.each(function(e){
  103. var ds = (new Date()).parse(e.startTime);
  104. var de = (new Date()).parse(e.endTime);
  105. if( start > ds )ds = start.clone();
  106. if( de < start )return;
  107. while( ds < de && ds <= end ){
  108. var i = start.diff(ds);
  109. this.setCalenderFlag(tds[i]);
  110. ds.increment('day',1);
  111. }
  112. }.bind(this));
  113. }
  114. if (json.data.inOneDayEvents && json.data.inOneDayEvents.length){
  115. json.data.inOneDayEvents.each(function(e){
  116. if (e.inOneDayEvents && e.inOneDayEvents.length){
  117. var d = (new Date()).parse(e.eventDate);
  118. var i = start.diff(d);
  119. this.setCalenderFlag(tds[i]);
  120. }
  121. }.bind(this));
  122. }
  123. }
  124. }.bind(this));
  125. },
  126. setCalenderFlag: function(td){
  127. // var t = td.get("text");
  128. // // td.empty();
  129. // // td.set("text", t);
  130. //td.set("background-color","#fdd9d9");
  131. var flag = new Element("div.o2_homepage_calender_item_flag").inject(this.calenderFlagArea);
  132. flag.position({
  133. "relativeTo": td,
  134. "position": 'topRight',
  135. "edge": 'topRight'
  136. });
  137. flag.store("td", td);
  138. this.dayFlags.push(flag);
  139. },
  140. loadMyCalender: function(d, callback){
  141. //this.loadFile(null, callback);
  142. if (!this.isLoading){
  143. if (!this.calenderContentTab){
  144. this.calenderContentTab = new MWF.xApplication.Homepage.CalendarContent.Calendar(this, this.calenderTab, d, {
  145. "onLoad": function(){ if (callback) callback(); }
  146. });
  147. }else{
  148. this.calenderContentTab.reload(d);
  149. }
  150. this.currentTab = this.calenderContentTab;
  151. }
  152. },
  153. // loadFile: function(e, callback){
  154. // if (!this.isLoading) {
  155. // if (!this.fileContentTab){
  156. // this.fileContentTab = new MWF.xApplication.Homepage.FileContent.File(this, this.meetingTab, {
  157. // "onLoad": function(){ if (callback) callback(); }
  158. // });
  159. // }else{
  160. // this.fileContentTab.load();
  161. // }
  162. // this.currentTab = this.fileContentTab;
  163. // }
  164. // }
  165. });
  166. MWF.xApplication.Homepage.CalendarContent.Calendar = new Class({
  167. Extends: MWF.xApplication.Homepage.TaskContent.Task,
  168. Implements: [Options, Events],
  169. options: {
  170. "itemHeight": 80,
  171. "type": "meetingInvited",
  172. "month": 1
  173. },
  174. initialize: function(content, tab, date, options){
  175. this.setOptions(options);
  176. this.content = content;
  177. this.app = this.content.app;
  178. this.container = this.content.itemContentNode;
  179. this.tab = tab;
  180. this.date = (new Date()).parse(date).clearTime();
  181. this.load();
  182. },
  183. reload: function(date){
  184. if (!this.content.isLoading) {
  185. this.date = (new Date()).parse(date).clearTime();
  186. this.beginLoadContent();
  187. this.showTab();
  188. this.initItemCount(this.page);
  189. this.loadItemsRes();
  190. }
  191. },
  192. loadItemsRes: function(){
  193. var endDate = this.date.clone().increment("day", 1);
  194. var d = {
  195. "startTime": this.date.format("db"),
  196. "endTime": endDate.format("db"),
  197. "createPerson": layout.user.distinguishedName
  198. };
  199. o2.Actions.load("x_calendar_assemble_control").Calendar_EventAction.listWithFilterSample(d, function(json){
  200. if (json.data && json.data.length){
  201. this.loadItems(json.data);
  202. this.loadCalenderInfor(json.data.length);
  203. }else{
  204. this.emptyLoadContent();
  205. this.loadCalenderInfor(0);
  206. }
  207. this.fireEvent("load");
  208. }.bind(this));
  209. },
  210. loadCalenderInfor: function(count){
  211. var text = (count) ? this.app.lp.calenderInfor : this.app.lp.noCalenderInfor;
  212. text = text.replace("{name}", layout.user.name);
  213. var today = new Date().clearTime();
  214. var dateStr = (this.date.diff(today)===0) ? this.app.lp.today : this.date.format(this.app.lp.dateFormat);
  215. text = text.replace("{date}", dateStr);
  216. text = text.replace("{count}", count);
  217. this.content.calenderInforArea.empty();
  218. this.content.calenderInforArea.set("html", text);
  219. },
  220. emptyLoadContent: function(){
  221. this.container.empty();
  222. this.container.removeClass("o2_homepage_area_content_loading").removeClass("icon_loading");
  223. this.content.pageAreaNode.empty();
  224. //this.itemContentNode.addClass("o2_homepage_task_area_content_empty").addClass("icon_notask");
  225. this.content.noItemNode = new Element("div.o2_homepage_calendar_area_content_empty_node", {"text": this.app.lp.noCalendar}).inject(this.container);
  226. var m = (this.content.contentHeight- this.content.noItemNode.getSize().y)/2;
  227. this.content.noItemNode.setStyle("margin-top", ""+m+"px");
  228. this.content.isLoading = false;
  229. },
  230. loadItems: function(data){
  231. data.each(function(d, i){
  232. this.loadItem(d, i);
  233. }.bind(this));
  234. this.endLoadContent();
  235. },
  236. loadItem: function(d, i){
  237. var row = this.loadItemRow(d, i);
  238. var _self = this;
  239. row.store("data", d);
  240. // row.addEvents({
  241. // "mouseover": function(){
  242. // this.addClass("mainColor_color").addClass("o2_homepage_task_item_row_over");
  243. // },
  244. // "mouseout": function(){
  245. // this.removeClass("mainColor_color").removeClass("o2_homepage_task_item_row_over");
  246. // }
  247. // });
  248. row.addEvent("click", function(e){
  249. layout.openApplication(e, "Calendar");
  250. });
  251. },
  252. getLightColor : function( deepColor ){
  253. var deep = ["#428ffc","#5bcc61","#f9bf24","#f75f59","#f180f7","#9072f1","#909090","#1462be"];
  254. var light = ["#cae2ff","#d0f1b0","#fef4bb","#fdd9d9","#f4c5f7","#d6ccf9","#e7e7e7","#cae2ff"];
  255. var index = deep.indexOf(deepColor);
  256. return index > -1 ? light[index] : light[0];
  257. },
  258. loadItemRow: function(d){
  259. var row = new Element("div.o2_homepage_calender_item_node").inject(this.container);
  260. row.setStyle("background-color", this.getLightColor(d.color));
  261. var locationNode = new Element("div.o2_homepage_calender_item_location", {"text": (d.locationName || ""), "title": (d.locationName || "")}).inject(row);
  262. var inforArea = new Element("div.o2_homepage_calender_item_infor").inject(row);
  263. var titleNode = new Element("div.o2_homepage_calender_item_title").inject(inforArea);
  264. var titleIconNode = new Element("div.o2_homepage_calender_item_title_icon").inject(titleNode);
  265. var titleTextNode = new Element("div.o2_homepage_calender_item_title_text", {"text": d.title, "title": d.title}).inject(titleNode);
  266. var timeNode = new Element("div.o2_homepage_calender_item_time").inject(inforArea);
  267. var timeStr = "";
  268. if (d.isAllDayEvent) {
  269. timeStr = this.app.lp.allDay;
  270. }else{
  271. var start = (new Date()).parse(d.startTime);
  272. var end = (new Date()).parse(d.endTime);
  273. if (start.diff(end)===0){
  274. timeStr = start.format("%Y-%m-%d %H:%M")+" - "+end.format("%H:%M");
  275. }else{
  276. timeStr = start.format("%Y-%m-%d %H:%M")+" - "+end.format("%Y-%m-%d %H:%M");
  277. }
  278. }
  279. timeNode.set("html", timeStr);
  280. return row;
  281. },
  282. });