CalendarContent.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. if (json.data){
  100. if (json.data.wholeDayEvents && json.data.wholeDayEvents.length){
  101. json.data.wholeDayEvents.each(function(e){
  102. var d = (new Date()).parse(e.startTime);
  103. var i = start.diff(d);
  104. this.setCalenderFlag(tds[i]);
  105. }.bind(this));
  106. }
  107. if (json.data.inOneDayEvents && json.data.inOneDayEvents.length){
  108. json.data.inOneDayEvents.each(function(e){
  109. if (e.inOneDayEvents && e.inOneDayEvents.length){
  110. var d = (new Date()).parse(e.eventDate);
  111. var i = start.diff(d);
  112. this.setCalenderFlag(tds[i]);
  113. }
  114. }.bind(this));
  115. }
  116. }
  117. }.bind(this));
  118. },
  119. setCalenderFlag: function(td){
  120. // var t = td.get("text");
  121. // // td.empty();
  122. // // td.set("text", t);
  123. //td.set("background-color","#fdd9d9");
  124. var flag = new Element("div.o2_homepage_calender_item_flag").inject(this.calenderFlagArea);
  125. flag.position({
  126. "relativeTo": td,
  127. "position": 'topRight',
  128. "edge": 'topRight'
  129. });
  130. flag.store("td", td);
  131. this.dayFlags.push(flag);
  132. },
  133. loadMyCalender: function(d, callback){
  134. //this.loadFile(null, callback);
  135. if (!this.isLoading){
  136. if (!this.calenderContentTab){
  137. this.calenderContentTab = new MWF.xApplication.Homepage.CalendarContent.Calendar(this, this.calenderTab, d, {
  138. "onLoad": function(){ if (callback) callback(); }
  139. });
  140. }else{
  141. this.calenderContentTab.reload(d);
  142. }
  143. this.currentTab = this.calenderContentTab;
  144. }
  145. },
  146. // loadFile: function(e, callback){
  147. // if (!this.isLoading) {
  148. // if (!this.fileContentTab){
  149. // this.fileContentTab = new MWF.xApplication.Homepage.FileContent.File(this, this.meetingTab, {
  150. // "onLoad": function(){ if (callback) callback(); }
  151. // });
  152. // }else{
  153. // this.fileContentTab.load();
  154. // }
  155. // this.currentTab = this.fileContentTab;
  156. // }
  157. // }
  158. });
  159. MWF.xApplication.Homepage.CalendarContent.Calendar = new Class({
  160. Extends: MWF.xApplication.Homepage.TaskContent.Task,
  161. Implements: [Options, Events],
  162. options: {
  163. "itemHeight": 80,
  164. "type": "meetingInvited",
  165. "month": 1
  166. },
  167. initialize: function(content, tab, date, options){
  168. this.setOptions(options);
  169. this.content = content;
  170. this.app = this.content.app;
  171. this.container = this.content.itemContentNode;
  172. this.tab = tab;
  173. this.date = (new Date()).parse(date).clearTime();
  174. this.load();
  175. },
  176. reload: function(date){
  177. if (!this.content.isLoading) {
  178. this.date = (new Date()).parse(date).clearTime();
  179. this.beginLoadContent();
  180. this.showTab();
  181. this.initItemCount(this.page);
  182. this.loadItemsRes();
  183. }
  184. },
  185. loadItemsRes: function(){
  186. var endDate = this.date.clone().increment("day", 1);
  187. var d = {
  188. "startTime": this.date.format("db"),
  189. "endTime": endDate.format("db"),
  190. "createPerson": layout.user.distinguishedName
  191. };
  192. o2.Actions.load("x_calendar_assemble_control").Calendar_EventAction.listWithFilterSample(d, function(json){
  193. if (json.data && json.data.length){
  194. this.loadItems(json.data);
  195. this.loadCalenderInfor(json.data.length);
  196. }else{
  197. this.emptyLoadContent();
  198. this.loadCalenderInfor(0);
  199. }
  200. this.fireEvent("load");
  201. }.bind(this));
  202. },
  203. loadCalenderInfor: function(count){
  204. var text = (count) ? this.app.lp.calenderInfor : this.app.lp.noCalenderInfor;
  205. text = text.replace("{name}", layout.user.name);
  206. var today = new Date();
  207. var dateStr = (this.date.diff(today)===0) ? this.app.lp.today : this.date.format(this.app.lp.dateFormat);
  208. text = text.replace("{date}", dateStr);
  209. text = text.replace("{count}", count);
  210. this.content.calenderInforArea.empty();
  211. this.content.calenderInforArea.set("html", text);
  212. },
  213. emptyLoadContent: function(){
  214. this.container.empty();
  215. this.container.removeClass("o2_homepage_area_content_loading").removeClass("icon_loading");
  216. this.content.pageAreaNode.empty();
  217. //this.itemContentNode.addClass("o2_homepage_task_area_content_empty").addClass("icon_notask");
  218. this.content.noItemNode = new Element("div.o2_homepage_calendar_area_content_empty_node", {"text": this.app.lp.noCalendar}).inject(this.container);
  219. var m = (this.content.contentHeight- this.content.noItemNode.getSize().y)/2;
  220. this.content.noItemNode.setStyle("margin-top", ""+m+"px");
  221. this.content.isLoading = false;
  222. },
  223. loadItems: function(data){
  224. data.each(function(d, i){
  225. this.loadItem(d, i);
  226. }.bind(this));
  227. this.endLoadContent();
  228. },
  229. loadItem: function(d, i){
  230. var row = this.loadItemRow(d, i);
  231. var _self = this;
  232. row.store("data", d);
  233. // row.addEvents({
  234. // "mouseover": function(){
  235. // this.addClass("mainColor_color").addClass("o2_homepage_task_item_row_over");
  236. // },
  237. // "mouseout": function(){
  238. // this.removeClass("mainColor_color").removeClass("o2_homepage_task_item_row_over");
  239. // }
  240. // });
  241. row.addEvent("click", function(e){
  242. layout.openApplication(e, "Calendar");
  243. });
  244. },
  245. getLightColor : function( deepColor ){
  246. var deep = ["#428ffc","#5bcc61","#f9bf24","#f75f59","#f180f7","#9072f1","#909090","#1462be"];
  247. var light = ["#cae2ff","#d0f1b0","#fef4bb","#fdd9d9","#f4c5f7","#d6ccf9","#e7e7e7","#cae2ff"];
  248. var index = deep.indexOf(deepColor);
  249. return index > -1 ? light[index] : light[0];
  250. },
  251. loadItemRow: function(d){
  252. var row = new Element("div.o2_homepage_calender_item_node").inject(this.container);
  253. row.setStyle("background-color", this.getLightColor(d.color));
  254. var locationNode = new Element("div.o2_homepage_calender_item_location", {"text": (d.locationName || ""), "title": (d.locationName || "")}).inject(row);
  255. var inforArea = new Element("div.o2_homepage_calender_item_infor").inject(row);
  256. var titleNode = new Element("div.o2_homepage_calender_item_title").inject(inforArea);
  257. var titleIconNode = new Element("div.o2_homepage_calender_item_title_icon").inject(titleNode);
  258. var titleTextNode = new Element("div.o2_homepage_calender_item_title_text", {"text": d.title, "title": d.title}).inject(titleNode);
  259. var timeNode = new Element("div.o2_homepage_calender_item_time").inject(inforArea);
  260. var timeStr = "";
  261. if (d.isAllDayEvent) {
  262. timeStr = this.app.lp.allDay;
  263. }else{
  264. var start = (new Date()).parse(d.startTime);
  265. var end = (new Date()).parse(d.endTime);
  266. if (start.diff(end)===0){
  267. timeStr = start.format("%Y-%m-%d %H:%M")+" - "+end.format("%H:%M");
  268. }else{
  269. timeStr = start.format("%Y-%m-%d %H:%M")+" - "+end.format("%Y-%m-%d %H:%M");
  270. }
  271. }
  272. timeNode.set("html", timeStr);
  273. return row;
  274. },
  275. });