Main.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  1. var MWFCalendar = MWF.xApplication.Calendar = MWF.xApplication.Calendar || {};
  2. MWF.require("MWF.xDesktop.UserData", null, false);
  3. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  4. //MWF.xDesktop.requireApp("Calendar", "Actions.RestActions", null, false);
  5. MWF.xDesktop.requireApp("Calendar", "Common", null, false);
  6. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  7. MWF.xApplication.Calendar.options.multitask = false;
  8. MWFCalendar.LeftNaviWidth = 250;
  9. MWF.xApplication.Calendar.Main = new Class({
  10. Extends: MWF.xApplication.Common.Main,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "name": "Calendar",
  15. "icon": "icon.png",
  16. "width": "1000",
  17. "height": "600",
  18. "isResize": true,
  19. "isMax": true,
  20. "eventId" : "",
  21. "title": MWF.xApplication.Calendar.LP.title
  22. },
  23. onQueryLoad: function(){
  24. this.lp = MWF.xApplication.Calendar.LP;
  25. this.menuMode="show";
  26. this.isManager = MWF.AC.isAdministrator();
  27. this.userName = ( layout.desktop.session.user || layout.user ).distinguishedName;
  28. if (!this.actions) this.actions = MWF.Actions.get("x_calendar_assemble_control"); //new MWF.xApplication.Calendar.Actions.RestActions();
  29. //if (!this.personActions) this.personActions = MWF.Actions.get("x_organization_assemble_express");
  30. },
  31. loadApplication: function(callback) {
  32. this.canlendarData = null;
  33. this.content.loadCss("../x_component_Calendar/$Main/default/style.css");
  34. MWF.UD.getDataJson("calendarConfig", function(json){
  35. this.calendarConfig = json || {};
  36. MWF.UD.getPublicData("calendarConfig", function(json){
  37. var jsonData = json || {};
  38. if (jsonData.process){
  39. this.calendarConfig.process = jsonData.process;
  40. }else{
  41. this.calendarConfig.process = null;
  42. }
  43. if( jsonData.weekBegin ){
  44. this.calendarConfig.weekBegin = jsonData.weekBegin;
  45. }
  46. for( var key in jsonData ){
  47. if( key != "process" && key != "weekBegin" ){
  48. this.calendarConfig[ key ] = jsonData[key];
  49. }
  50. }
  51. if( !this.calendarConfig.disableViewList ) this.calendarConfig.disableViewList = [];
  52. this.createNode();
  53. if (!this.options.isRefresh) {
  54. this.maxSize(function () {
  55. this.listCalendar( function(){
  56. this.loadLayout();
  57. }.bind(this));
  58. }.bind(this));
  59. } else {
  60. this.listCalendar( function(){
  61. this.loadLayout();
  62. }.bind(this))
  63. }
  64. if (callback) callback();
  65. }.bind(this));
  66. }.bind(this));
  67. },
  68. listCalendar : function( callback ){
  69. if( this.canlendarData ){
  70. if(callback)callback( this.canlendarData )
  71. }else{
  72. this.actions.listMyCalendar( function( json ){
  73. if( ( json.data.myCalendars || [] ).length == 0 ){
  74. this.createDefaultCalendar(function(){
  75. if(callback)callback( json.data )
  76. });
  77. }else{
  78. this.canlendarData = json.data;
  79. this.calendarDataList = json.data.myCalendars;
  80. this.currentCalendarData = json.data.myCalendars[0];
  81. if(callback)callback( json.data )
  82. }
  83. }.bind(this))
  84. }
  85. },
  86. getSelectedCalendarId : function(){
  87. if( this.leftNavi ){
  88. return this.leftNavi.getSelectedCalendarId();
  89. }else{
  90. return null;
  91. }
  92. },
  93. createDefaultCalendar : function( callback, notCreate ){
  94. this.actions.listMyCalendar( function( json ){
  95. if( json.data.myCalendars && json.data.myCalendars.length ){
  96. this.canlendarData = json.data;
  97. this.calendarDataList = json.data.myCalendars;
  98. this.currentCalendarData = json.data.myCalendars[0];
  99. if(callback)callback();
  100. }else if( json.data.unitCalendars && json.data.unitCalendars.length ){
  101. this.canlendarData = json.data;
  102. this.calendarDataList = json.data.unitCalendars;
  103. this.currentCalendarData = json.data.unitCalendars[0];
  104. if(callback)callback();
  105. }else if( json.data.followCalendars && json.data.followCalendars.length ){
  106. this.canlendarData = json.data;
  107. this.calendarDataList = json.data.followCalendars;
  108. this.currentCalendarData = json.data.followCalendars[0];
  109. if(callback)callback();
  110. }else if( !notCreate ){
  111. this.actions.saveCalendar({
  112. name : "我的日历",
  113. type : "PERSON",
  114. color : "",
  115. description : "",
  116. source : "PERSON",
  117. isPublic : false,
  118. manageablePersonList : [this.userName]
  119. }, function(){
  120. this.createDefaultCalendar( callback, true );
  121. }.bind(this));
  122. }
  123. }.bind(this))
  124. },
  125. createNode: function(){
  126. this.content.setStyle("overflow", "hidden");
  127. this.node = new Element("div", {
  128. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  129. }).inject(this.content);
  130. this.naviContainerNode = new Element("div.naviContainerNode", {
  131. "styles": this.css.naviContainerNode
  132. }).inject(this.node);
  133. this.leftTitleNode = new Element("div.leftTitleNode", {
  134. "styles": this.css.leftTitleNode
  135. }).inject(this.naviContainerNode);
  136. this.rightContentNode = new Element("div", {
  137. "styles":this.css.rightContentNode
  138. }).inject(this.node);
  139. },
  140. loadLayout: function(){
  141. debugger;
  142. if( this.status && this.status.action ) {
  143. this.defaultAction = this.status.action;
  144. }else if( this.options.defaultAction ){
  145. this.defaultAction = this.options.defaultAction;
  146. }else if (this.calendarConfig.defaultView){
  147. this.defaultAction = this.calendarConfig.defaultView;
  148. }else{
  149. this.defaultAction = "toMonth";
  150. }
  151. if( this.calendarConfig.disableViewList.contains( this.defaultAction ) ){
  152. this.defaultAction = "";
  153. }
  154. this.loadNaviTitleNode();
  155. this.loadLeftNavi();
  156. this.topMenu = new Element("div", {"styles": this.css.topMenu}).inject(this.rightContentNode);
  157. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.rightContentNode);
  158. this.loadTopMenus();
  159. //this.loadSideBar();
  160. this.resizeNodes();
  161. this.resizeNodesFun = this.resizeNodes.bind(this);
  162. this.addEvent("resize", this.resizeNodesFun )
  163. },
  164. loadNaviTitleNode: function(){
  165. this.titleContentNode = new Element("div.titleContentNode", {
  166. "styles": this.css.titleContentNode
  167. }).inject(this.leftTitleNode);
  168. this.newCalendarNode = new Element("div", {
  169. styles : this.css.newCalendarNode,
  170. text : this.lp.createNewCalendar,
  171. events : {
  172. mouseover : function( ev ){
  173. this.newCalendarNode.setStyles( this.css.newCalendarNode_over );
  174. this.newCalendarNode.addClass("mainColor_color");
  175. this.newCalendarIcon.setStyles( this.css.newCalendarIcon_over );
  176. this.newCalendarIcon.addClass("mainColor_color");
  177. }.bind(this),
  178. mouseout : function( ev ){
  179. this.newCalendarNode.setStyles( this.css.newCalendarNode );
  180. this.newCalendarNode.removeClass("mainColor_color");
  181. this.newCalendarIcon.setStyles( this.css.newCalendarIcon );
  182. this.newCalendarIcon.removeClass("mainColor_color");
  183. }.bind(this),
  184. click : function(){ this.addCalendar() }.bind(this)
  185. }
  186. }).inject( this.titleContentNode );
  187. this.newCalendarIcon = new Element("i.o2icon-newfiles", {
  188. styles : this.css.newCalendarIcon
  189. }).inject(this.newCalendarNode, "top");
  190. //var iconAreaNode = this.iconAreaNode = new Element("div",{
  191. // "styles" : this.css.titleIconAreaNode
  192. //}).inject(this.titleContentNode);
  193. //
  194. //var iconNode = this.iconNode = new Element("img",{
  195. // "styles" : this.css.titleIconNode,
  196. // "src" : "../x_component_Calendar/$Main/appicon.png"
  197. //}).inject(iconAreaNode);
  198. //
  199. //this.titleTextNode = new Element("div.titleTextNode", {
  200. // "styles": this.css.titleTextNode,
  201. // "text": this.lp.title
  202. //}).inject(this.titleContentNode);
  203. //this.titleDescriptionNode = new Element("div.titleDescriptionNode", {
  204. // "styles": this.css.titleDescriptionNode
  205. //}).inject(this.titleContentNode);
  206. },
  207. loadLeftNavi : function(){
  208. this.naviNode = new Element("div.naviNode", {
  209. "styles": this.css.naviNode
  210. }).inject(this.naviContainerNode);
  211. this.leftNavi = new MWF.xApplication.Calendar.Navi(this, this.naviNode, {});
  212. },
  213. loadTopMenus_middle : function(){
  214. },
  215. loadTopMenus_right: function(){
  216. this.topMenuRight = new Element("div", {"styles": this.css.topMenuRight }).inject(this.topMenu);
  217. this.createTopMenu_right(this.lp.addEvent, "o2icon-create", "addCalendarEvent");
  218. //this.createTopMenu_right("新建日历", "icon_newapply", "addCalendar");
  219. //var refreshNode = this.createTopMenu_right(this.lp.refresh, "refresh", "refresh");
  220. //refreshNode.setStyle("float", "right");
  221. var configNode = this.createTopMenu_right(this.lp.setting, "o2icon-config", "config");
  222. configNode.setStyle("float", "right");
  223. },
  224. createTopMenu_right : function(text, icon, action){
  225. var actionNode = new Element("div", {"styles": this.css.topMenuNode_right, "title" : text}).inject(this.topMenuRight);
  226. var actionIconNode = new Element("div."+icon, {"styles": this.css.topMenuIconNode}).inject(actionNode);
  227. var actionTextNode = new Element("div",{styles: this.css.topMenuTextNode, "text":text}).inject(actionNode);
  228. // actionIconNode.setStyle("background", "url(../x_component_Calendar/$Main/default/icon/"+icon+".png) no-repeat center center");
  229. actionNode.store("icon",icon);
  230. actionNode.store("iconNode",actionIconNode);
  231. var _self = this;
  232. actionNode.addEvents({
  233. "mouseover": function(){
  234. this.node.setStyles(_self.css.topMenuNode_over);
  235. this.node.addClass("mainColor_color");
  236. this.node.retrieve("iconNode").setStyles( _self.css.topMenuIconNode_over ).addClass("mainColor_color");
  237. // this.node.retrieve("iconNode").setStyle( "background","url(../x_component_Calendar/$Main/default/icon/"+this.node.retrieve("icon")+"_click.png) no-repeat center center" );
  238. }.bind( { node : actionNode } ),
  239. "mouseout": function(){
  240. this.node.setStyles(_self.css.topMenuNode_right);
  241. this.node.removeClass("mainColor_color");
  242. this.node.retrieve("iconNode").setStyles( _self.css.topMenuIconNode ).removeClass("mainColor_color");
  243. // this.node.retrieve("iconNode").setStyle( "background","url(../x_component_Calendar/$Main/default/icon/"+this.node.retrieve("icon")+".png) no-repeat center center" );
  244. }.bind({ node:actionNode }),
  245. "click": function(){
  246. this.node.setStyles(_self.css.topMenuNode_down);
  247. // this.node.retrieve("iconNode").setStyle( "background","url(../x_component_Calendar/$Main/default/icon/"+this.node.retrieve("icon")+"_click.png) no-repeat center center" );
  248. if (_self[action]) _self[action].apply(_self);
  249. }.bind({ node : actionNode })
  250. });
  251. return actionNode;
  252. },
  253. loadTopMenus: function(){
  254. this.topMenuNodeMap = {};
  255. //this.createTopMenu(this.lp.myCalendar, "icon_huiyi", "toMyCalendar");
  256. this.createTopMenu(this.lp.month, "o2icon-month", "toMonth");
  257. this.createTopMenu(this.lp.week, "o2icon-week", "toWeek");
  258. this.createTopMenu(this.lp.day, "o2icon-day", "toDay");
  259. this.createTopMenu(this.lp.list, "o2icon-list", "toList");
  260. this.loadTopMenus_middle();
  261. this.loadTopMenus_right();
  262. },
  263. isViewAvailable : function( action ){
  264. return !this.calendarConfig.disableViewList.contains( action );
  265. },
  266. createTopMenu: function(text, icon, action){
  267. if( this.calendarConfig.disableViewList.contains( action ) )return;
  268. if( this.calendarConfig[ action + "ViewName" ] ){
  269. text = this.calendarConfig[ action + "ViewName" ];
  270. }
  271. var actionNode = new Element("div", {"styles": this.css.topMenuNode}).inject(this.topMenu);
  272. var actionIconNode = new Element("div."+icon, {"styles": this.css.topMenuIconNode}).inject(actionNode);
  273. this.topMenuNodeMap[action] = actionNode;
  274. // actionIconNode.setStyle("background", "url(../x_component_Calendar/$Main/default/icon/"+icon+".png) no-repeat center center");
  275. var actionTextNode = new Element("div", {"styles": this.css.topMenuTextNode, "text": text}).inject(actionNode);
  276. actionNode.store("icon",icon);
  277. actionNode.store("iconNode",actionIconNode);
  278. actionNode.store("action",action);
  279. var _self = this;
  280. actionNode.addEvents({
  281. "mouseover": function(){
  282. if( this.node != _self.currentTopMenuNode ){
  283. this.node.setStyles(_self.css.topMenuNode_over);
  284. this.node.addClass("mainColor_color");
  285. this.node.retrieve("iconNode").setStyles( _self.css.topMenuIconNode_over ).addClass("mainColor_color");
  286. // this.node.retrieve("iconNode").setStyle( "background","url(../x_component_Calendar/$Main/default/icon/"+this.node.retrieve("icon")+"_click.png) no-repeat center center" );
  287. }
  288. }.bind( { node : actionNode } ),
  289. "mouseout": function(){
  290. if(this.node != _self.currentTopMenuNode){
  291. this.node.setStyles(_self.css.topMenuNode);
  292. this.node.removeClass("mainColor_color");
  293. this.node.retrieve("iconNode").setStyles( _self.css.topMenuIconNode ).removeClass("mainColor_color");
  294. // this.node.retrieve("iconNode").setStyle( "background","url(../x_component_Calendar/$Main/default/icon/"+this.node.retrieve("icon")+".png) no-repeat center center" );
  295. }
  296. }.bind({ node:actionNode }),
  297. //"mousedown": function(){this.setStyles(_self.css.topMenuNode_down);},
  298. //"mouseup": function(){this.setStyles(_self.css.topMenuNode_over);},
  299. "click": function(){
  300. _self.switchTopMenuNode( this.node );
  301. if (_self[action]) _self[action].apply(_self);
  302. }.bind({ node : actionNode })
  303. });
  304. if( this.defaultAction ){
  305. if( this.defaultAction == action ){
  306. actionNode.click();
  307. }
  308. }else if( !this.loaded ){
  309. actionNode.click();
  310. this.loaded = true;
  311. }
  312. this.resizeNodes();
  313. return actionNode;
  314. },
  315. switchTopMenuNode:function ( node ){
  316. if( node !== this.currentTopMenuNode ){
  317. node.setStyles( this.css.topMenuNode_down );
  318. node.addClass("mainColor_color");
  319. node.retrieve("iconNode").setStyles( this.css.topMenuIconNode_over ).addClass("mainColor_color");
  320. }
  321. if( this.currentTopMenuNode && node !== this.currentTopMenuNode){
  322. this.currentTopMenuNode.setStyles( this.css.topMenuNode );
  323. this.currentTopMenuNode.removeClass("mainColor_color");
  324. this.currentTopMenuNode.retrieve("iconNode").setStyles( this.css.topMenuIconNode ).removeClass("mainColor_color");
  325. }
  326. this.currentTopMenuNode = node;
  327. },
  328. hideCurrentView: function(){
  329. if (this.currentView){
  330. this.currentView.hide();
  331. this.currentView = null;
  332. }
  333. },
  334. toList: function(){
  335. if(this.contentNode)this.contentNode.setStyle("background", "#EEE");
  336. if( this.currentView ){
  337. this.currentView.destroy();
  338. this.currentView = null;
  339. }
  340. this.listView = null;
  341. this.getListView(function(){
  342. this.listView.show();
  343. this.currentView = this.listView;
  344. if( this.options.eventId ){
  345. this.openEvent( this.options.eventId );
  346. this.options.eventId = "";
  347. }
  348. }.bind(this));
  349. },
  350. getListView: function(callback){
  351. if (!this.listView){
  352. MWF.xDesktop.requireApp("Calendar", "ListView", function(){
  353. var options;
  354. if( this.status && this.status.options ){
  355. options = this.status.options
  356. }else if( this.currentDate ){
  357. //options = { date : this.currentDate };
  358. }
  359. this.listView = new MWF.xApplication.Calendar.ListView(this.contentNode, this, options);
  360. if( options && this.status)this.status.options = null;
  361. if (callback) callback();
  362. }.bind(this));
  363. }else{
  364. if (callback) callback();
  365. }
  366. },
  367. toMonth: function(){
  368. if(this.contentNode)this.contentNode.setStyle("background", "#EEE");
  369. if( this.currentView ){
  370. this.currentView.destroy();
  371. this.currentView = null;
  372. }
  373. this.monthView = null;
  374. this.getMonthView(function(){
  375. this.monthView.show();
  376. this.currentView = this.monthView;
  377. debugger;
  378. if( this.options.eventId ){
  379. this.openEvent( this.options.eventId );
  380. this.options.eventId = "";
  381. }
  382. }.bind(this));
  383. },
  384. getMonthView: function(callback){
  385. if (!this.monthView){
  386. MWF.xDesktop.requireApp("Calendar", "MonthView", function(){
  387. var options;
  388. if( this.status && this.status.options ){
  389. options = this.status.options
  390. }else if( this.currentDate ){
  391. //options = { date : this.currentDate.format("%Y-%m-%d") };
  392. }
  393. this.monthView = new MWF.xApplication.Calendar.MonthView(this.contentNode, this, options);
  394. if( options && this.status)this.status.options = null;
  395. if (callback) callback();
  396. }.bind(this));
  397. }else{
  398. if (callback) callback();
  399. }
  400. },
  401. toWeek: function(){
  402. if(this.contentNode)this.contentNode.setStyle("background", "#EEE");
  403. if( this.currentView ){
  404. this.currentView.destroy();
  405. this.currentView = null;
  406. }
  407. this.weekView = null;
  408. this.getWeekView(function(){
  409. this.weekView.show();
  410. this.currentView = this.weekView;
  411. if( this.options.eventId ){
  412. this.openEvent( this.options.eventId );
  413. this.options.eventId = "";
  414. }
  415. }.bind(this));
  416. },
  417. getWeekView: function(callback){
  418. if (!this.weekView){
  419. MWF.xDesktop.requireApp("Calendar", "WeekView", function(){
  420. var options;
  421. if( this.status && this.status.options ){
  422. options = this.status.options
  423. }else if( this.currentDate ){
  424. //options = { date : this.currentDate.format("%Y-%m-%d") };
  425. }
  426. this.weekView = new MWF.xApplication.Calendar.WeekView(this.contentNode, this, options);
  427. if( options && this.status)this.status.options = null;
  428. if (callback) callback();
  429. }.bind(this));
  430. }else{
  431. if (callback) callback();
  432. }
  433. },
  434. toDay: function(d){
  435. if(this.contentNode)this.contentNode.setStyle("background", "#EEE");
  436. if( this.currentView ){
  437. this.currentView.destroy();
  438. this.currentView = null;
  439. }
  440. this.dayView = null;
  441. this.getDayView(function(){
  442. this.dayView.show();
  443. this.currentView = this.dayView;
  444. if( this.options.eventId ){
  445. this.openEvent( this.options.eventId );
  446. this.options.eventId = "";
  447. }
  448. }.bind(this), d);
  449. },
  450. getDayView: function(callback, d){
  451. if (!this.dayView){
  452. MWF.xDesktop.requireApp("Calendar", "DayView", function(){
  453. var options;
  454. if( this.status && this.status.options ){
  455. options = this.status.options
  456. }else if( d ){
  457. options = {"date": d};
  458. }else if( this.currentDate ){
  459. //options = { date : this.currentDate.format("%Y-%m-%d") };
  460. }
  461. this.dayView = new MWF.xApplication.Calendar.DayView(this.contentNode, this, options);
  462. if(this.status && this.status)this.status.options = null;
  463. if (callback) callback();
  464. }.bind(this));
  465. }else{
  466. this.dayView.toDay(d);
  467. if (callback) callback();
  468. }
  469. },
  470. addCalendarEvent: function(date, hour, minute, calendarId){
  471. MWF.UD.getPublicData("calendarConfig", function(json){
  472. var process = (json) ? json.process : null;
  473. if (process){
  474. this.loadCalendarProcess(process);
  475. }else{
  476. //new MWF.xApplication.Calendar.Creator(this, date, hour, room);
  477. var form = new MWF.xApplication.Calendar.EventForm(this,{}, {
  478. date : date,
  479. hour : hour,
  480. minute : minute,
  481. defaultCalendarId : calendarId
  482. }, {app:this});
  483. form.view = this;
  484. form.create();
  485. //this.hideMenu();
  486. }
  487. }.bind(this));
  488. },
  489. addCalendar: function(){
  490. var form = new MWF.xApplication.Calendar.CalendarForm(this,{}, {
  491. }, {app:this});
  492. form.view = this.leftNavi;
  493. form.create();
  494. },
  495. editCalendar: function( data ){
  496. var form = new MWF.xApplication.Calendar.CalendarForm(this, data, {
  497. }, {app:this});
  498. form.view = this.leftNavi;
  499. this.isEventEditable(data) ? form.edit() : form.open();
  500. },
  501. openCalendar: function( data ){
  502. var form = new MWF.xApplication.Calendar.CalendarForm(this,data, {
  503. }, {app:this});
  504. form.view = this.leftNavi;
  505. form.open();
  506. },
  507. loadCalendarProcess: function(id){
  508. this.getProcess(id, function(process){
  509. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  510. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(process, this, {
  511. "onStarted": function(data, title, processName){
  512. this.afterStartProcess(data, title, processName);
  513. }.bind(this)
  514. });
  515. starter.load();
  516. }.bind(this));
  517. }.bind(this));
  518. },
  519. afterStartProcess: function(data, title, processName){
  520. var workInfors = [];
  521. var currentTask = [];
  522. data.each(function(work){
  523. if (work.currentTaskIndex !== -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  524. workInfors.push(this.getStartWorkInforObj(work));
  525. }.bind(this));
  526. if (currentTask.length===1){
  527. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  528. this.desktop.openApplication(null, "process.Work", options);
  529. this.createStartWorkResault(workInfors, title, processName, false);
  530. }else{
  531. this.createStartWorkResault(workInfors, title, processName, true);
  532. }
  533. },
  534. createStartWorkResault: function(workInfors, title, processName, isopen){
  535. var content = "";
  536. workInfors.each(function(infor){
  537. var users = [];
  538. infor.users.each(function(uname){
  539. users.push(MWF.name.cn(uname));
  540. });
  541. content += "<div><b>"+this.lp.nextActivity+"<font style=\"color: #ea621f\">"+infor.activity+"</font>, "+this.lp.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b>";
  542. if (infor.currentTask && isopen){
  543. content += "&nbsp;&nbsp;&nbsp;&nbsp;<span value=\""+infor.currentTask+"\">"+this.lp.deal+"</span></div>";
  544. }else{
  545. content += "</div>";
  546. }
  547. }.bind(this));
  548. var msg = {
  549. "subject": this.lp.processStarted,
  550. "content": "<div>"+this.lp.processStartedMessage+"“["+processName+"]"+title+"”</div>"+content
  551. };
  552. var tooltip = layout.desktop.message.addTooltip(msg);
  553. var item = layout.desktop.message.addMessage(msg);
  554. this.setStartWorkResaultAction(tooltip);
  555. this.setStartWorkResaultAction(item);
  556. },
  557. getStartWorkInforObj: function(work){
  558. var users = [];
  559. var currentTask = "";
  560. work.taskList.each(function(task, idx){
  561. users.push(task.person+"("+task.department + ")");
  562. if (work.currentTaskIndex===idx) currentTask = task.id;
  563. }.bind(this));
  564. return {"activity": work.fromActivityName, "users": users, "currentTask": currentTask};
  565. },
  566. setStartWorkResaultAction: function(item){
  567. var node = item.node.getElements("span");
  568. node.setStyles(this.app.css.dealStartedWorkAction);
  569. var _self = this;
  570. node.addEvent("click", function(e){
  571. var options = {"taskId": this.get("value"), "appId": this.get("value")};
  572. _self.desktop.openApplication(e, "process.Work", options);
  573. });
  574. },
  575. getProcess: function(id, callback){
  576. // MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", function(){
  577. // var action = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  578. // action.getProcess(id, function(json){
  579. if (callback) callback(id);
  580. // }.bind(this));
  581. // }.bind(this));
  582. },
  583. config: function(){
  584. new MWF.xApplication.Calendar.Config(this, this.calendarConfig);
  585. //this.hideMenu();
  586. },
  587. recordStatus: function(){
  588. //alert( JSON.stringify(
  589. // {
  590. // action : this.currentTopMenuNode ? this.currentTopMenuNode.retrieve("action") : "toMyCalendar",
  591. // options : this.currentView.recordStatus ? this.currentView.recordStatus() : null
  592. // }
  593. //) )
  594. return {
  595. action : this.currentTopMenuNode ? this.currentTopMenuNode.retrieve("action") : "toMyCalendar",
  596. options : this.currentView.recordStatus ? this.currentView.recordStatus() : null
  597. };
  598. },
  599. reloadView : function(){
  600. if( this.currentView ){
  601. this.currentView.reload();
  602. }
  603. },
  604. reload: function( ){
  605. this.refresh()
  606. },
  607. loadSideBar : function(){
  608. //this.sideBar = new MWF.xApplication.Calendar.SideBar(this.node, this);
  609. //this.sideBar.show();
  610. },
  611. resizeNodes : function(){
  612. this.showLeftNavi = true;
  613. if( this.inContainer ){
  614. var size = this.container.getSize();
  615. }else{
  616. var size = this.node.getSize();
  617. }
  618. this.naviContainerNode.setStyle("height", ""+size.y+"px");
  619. if( this.showLeftNavi ){
  620. this.rightContentNode.setStyle("width",size.x - MWFCalendar.LeftNaviWidth );
  621. //this.topMenu.setStyle("width",size.x - leftNaviSize.x);
  622. //this.contentNode.setStyle("width",size.x - leftNaviSize.x);
  623. }
  624. if( this.currentView ){
  625. this.currentView.resetNodeSize();
  626. }
  627. if( this.leftNavi )this.leftNavi.resizeNode();
  628. },
  629. openEvent : function (id) {
  630. debugger;
  631. this.actions.getEvent( id, function (json) {
  632. var form = new MWF.xApplication.Calendar.EventForm(this, json.data, {
  633. isFull : true
  634. }, {app:this});
  635. form.view = this.currentView;
  636. form.open();
  637. }.bind(this))
  638. },
  639. isEventEditable: function (data) {
  640. if( MWF.AC.isAdministrator() )return true;
  641. if( (data.manageablePersonList || []).contains( layout.desktop.session.user.distinguishedName ) )return true;
  642. if( data.createPerson === layout.desktop.session.user.distinguishedName )return true;
  643. return false;
  644. }
  645. });
  646. MWF.xApplication.Calendar.Navi = new Class({
  647. Implements: [Options, Events],
  648. options : {
  649. },
  650. initialize: function(app, node, options){
  651. this.setOptions(options);
  652. this.app = app;
  653. this.lp = this.app.lp;
  654. this.node = $(node);
  655. this.css = this.app.css;
  656. this.load();
  657. },
  658. load : function(){
  659. this.naviContainer = new Element("div", {
  660. styles : {
  661. overflow : "hidden"
  662. }
  663. }).inject(this.node);
  664. this.naviNode = new Element("div").inject(this.naviContainer);
  665. this.myCalendarNaviItem = [];
  666. this.unitCalendarNaviItem = [];
  667. this.followCalendarNaviItem = [];
  668. this.app.listCalendar( function( data ){
  669. this.myCalendars = data.myCalendars;
  670. this.unitCalendars = data.unitCalendars;
  671. this.followCalendars = data.followCalendars;
  672. this.app.canlendarData = null;
  673. this.loadNode();
  674. }.bind(this));
  675. o2.require("MWF.widget.ScrollBar", function(){
  676. this.scrollBar = new MWF.widget.ScrollBar(this.naviContainer, {
  677. "indent": false,
  678. "style": "default",
  679. "where": "before",
  680. "distance": 60,
  681. "friction": 4,
  682. "axis": {"x": false, "y": true},
  683. "onScroll": function (y) {
  684. }.bind(this)
  685. });
  686. }.bind(this));
  687. },
  688. loadNode: function(){
  689. this.loadMyCalendar();
  690. this.loadUnitCalendar();
  691. this.loadFollowCalendar();
  692. this.loadMoreCalendarNode();
  693. //this.resizeNode();
  694. },
  695. reload : function(){
  696. this.node.empty();
  697. this.load();
  698. },
  699. loadMoreCalendarNode : function(){
  700. this.seeMore = new Element("div.seeMore", {
  701. styles : this.css.seeMoreNode,
  702. "text" : this.lp.calendarMarket,
  703. "events" : {
  704. mouseover : function(ev){
  705. this.seeMore.setStyles( this.css.seeMoreNode_over );
  706. this.seeMore.addClass("mainColor_color");
  707. this.seeMoreIcon.setStyles( this.css.seeMoreIcon_over );
  708. this.seeMoreIcon.addClass("mainColor_color");
  709. }.bind(this),
  710. mouseout : function(ev){
  711. this.seeMore.setStyles( this.css.seeMoreNode );
  712. this.seeMore.removeClass("mainColor_color");
  713. this.seeMoreIcon.setStyles( this.css.seeMoreIcon );
  714. this.seeMoreIcon.removeClass("mainColor_color");
  715. }.bind(this),
  716. click : function(ev){
  717. var form = new MWF.xApplication.Calendar.CalendarMarket(this.app,{}, {
  718. }, {app:this.app});
  719. form.view = this.leftNavi;
  720. form.create();
  721. }.bind(this)
  722. }
  723. }).inject( this.node );
  724. this.seeMoreIcon = new Element("i.o2icon-calendar-add", {
  725. styles : this.css.seeMoreIcon
  726. }).inject(this.seeMore, "top");
  727. },
  728. selectSingleCalendar : function( id ){
  729. this.myCalendarNaviItem.each( function( item ){
  730. if( item.isSelected && item.data.id !== id ){
  731. item.cancelSelect()
  732. }
  733. if( !item.isSelected && item.data.id == id ){
  734. item.select()
  735. }
  736. });
  737. this.unitCalendarNaviItem.each( function( item ){
  738. if( item.isSelected && item.data.id !== id ){
  739. item.cancelSelect()
  740. }
  741. if( !item.isSelected && item.data.id == id ){
  742. item.select()
  743. }
  744. });
  745. this.followCalendarNaviItem.each( function( item ){
  746. if( item.isSelected && item.data.id !== id ){
  747. item.cancelSelect()
  748. }
  749. if( !item.isSelected && item.data.id == id ){
  750. item.select()
  751. }
  752. });
  753. this.app.reloadView();
  754. },
  755. getSelectedCalendarId : function(){
  756. var ids = [];
  757. this.myCalendarNaviItem.each( function( navi ){
  758. if( navi.isSelected )ids.push( navi.data.id );
  759. });
  760. this.unitCalendarNaviItem.each( function( navi ){
  761. if( navi.isSelected )ids.push( navi.data.id );
  762. });
  763. this.followCalendarNaviItem.each( function( navi ){
  764. if( navi.isSelected )ids.push( navi.data.id );
  765. });
  766. return ids;
  767. },
  768. loadMyCalendar : function(){
  769. var listNode = this.createCategoryNode(this.lp.myCalendar);
  770. this.myCalendars.each( function( d ){
  771. this.myCalendarNaviItem.push( new MWF.xApplication.Calendar.NaviItem( this, listNode, d, {
  772. isSelected : true
  773. } ) );
  774. }.bind(this))
  775. },
  776. loadUnitCalendar : function(){
  777. var listNode = this.createCategoryNode(this.lp.unitCalendar);
  778. this.unitCalendars.each( function( d ){
  779. this.unitCalendarNaviItem.push( new MWF.xApplication.Calendar.NaviItem( this, listNode, d, {
  780. isSelected : true
  781. } ));
  782. }.bind(this))
  783. },
  784. loadFollowCalendar : function(){
  785. var listNode = this.createCategoryNode(this.lp.myFollowCalendar);
  786. this.followCalendars.each( function( d ){
  787. this.followCalendarNaviItem.push( new MWF.xApplication.Calendar.NaviItem( this, listNode, d, {
  788. isSelected : true
  789. } ));
  790. }.bind(this));
  791. //var seeMore = new Element("div", {
  792. // styles : this.css.seeMoreNode,
  793. // "text" : "查看日历广场",
  794. // "events" : {
  795. // mouseover : function(ev){ ev.target.setStyles( this.css.seeMoreNode_over ) }.bind(this),
  796. // mouseout : function(ev){ ev.target.setStyles( this.css.seeMoreNode ) }.bind(this),
  797. // click : function(ev){
  798. // var form = new MWF.xApplication.Calendar.CalendarMarket(this.app,{}, {
  799. // }, {app:this.app});
  800. // form.view = this.leftNavi;
  801. // form.create();
  802. // }.bind(this)
  803. // }
  804. //}).inject( this.naviNode );
  805. },
  806. createCategoryNode : function( text ){
  807. var _self = this;
  808. var categoryNaviNode = new Element("div.categoryNaviNode", {
  809. "styles": this.css.categoryNaviNode
  810. }).inject(this.naviNode);
  811. var expendNode = new Element("div.categoryExpendNode", {
  812. styles : this.css.categoryExpendNode
  813. }).inject(categoryNaviNode);
  814. categoryNaviNode.addEvent( "click" , function(ev){
  815. var target = this.categoryNaviNode;
  816. if( target.retrieve("isExpended") ){
  817. target.store("isExpended" , false);
  818. target.retrieve("expendNode").setStyles( _self.css.categoryCollapseNode );
  819. target.retrieve("listNode").setStyle("display","none")
  820. }else{
  821. target.store("isExpended" , true);
  822. target.retrieve("expendNode").setStyles( _self.css.categoryExpendNode );
  823. target.retrieve("listNode").setStyle("display","")
  824. }
  825. }.bind( { categoryNaviNode : categoryNaviNode } ));
  826. var textNode = new Element("div.categoryNaviTextNode",{
  827. "styles": this.css.categoryNaviTextNode,
  828. "text": text //this.defaultRevealData.id == "defaultList" ? this.data.name : this.defaultRevealData.showName
  829. }).inject( categoryNaviNode);
  830. var listNode = new Element("div.viewNaviListNode",{
  831. "styles" : this.css.viewNaviListNode
  832. }).inject(this.naviNode);
  833. categoryNaviNode.store("isExpended" , true);
  834. categoryNaviNode.store("expendNode" , expendNode);
  835. categoryNaviNode.store("textNode" , textNode);
  836. categoryNaviNode.store("listNode" , listNode);
  837. return listNode;
  838. },
  839. resizeNode : function(){
  840. if( this.app.inContainer ){
  841. var size = this.app.container.getSize();
  842. }else{
  843. var size = this.app.node.getSize();
  844. }
  845. //var titleSize = this.app.leftTitleNode ? this.app.leftTitleNode.getSize() : {x:0,y:0};
  846. this.node.setStyle("height",size.y - 80 );
  847. this.naviContainer.setStyle("height",size.y - 122 );
  848. }
  849. });
  850. MWF.xApplication.Calendar.NaviItem = new Class({
  851. Implements: [Options, Events],
  852. options: {
  853. "style": "default",
  854. "index" : 0,
  855. "isSelected" : true
  856. },
  857. initialize: function ( navi, container, data, options) {
  858. this.setOptions(options);
  859. this.navi = navi;
  860. this.app = navi.app;
  861. this.data = data;
  862. this.container = $(container);
  863. this.css = this.app.css;
  864. this.load();
  865. },
  866. load: function(){
  867. this.isSelected = this.options.isSelected;
  868. var _self = this;
  869. this.node = new Element("div.naviItemNode", {
  870. "styles": this.css.naviItemNode
  871. }).inject(this.container);
  872. this.node.addEvents({
  873. "mouseover": function(){
  874. this.setStyles(_self.css.naviItemNode_over);
  875. this.addClass("mainColor_color");
  876. _self.actionNode.fade("in");
  877. },
  878. "mouseout": function(){
  879. this.setStyles( _self.css.naviItemNode );
  880. this.removeClass("mainColor_color");
  881. _self.actionNode.fade("out");
  882. },
  883. "click": function (el) {
  884. if( _self.isSelected ){
  885. _self.cancelSelect( true );
  886. }else{
  887. _self.select( true );
  888. }
  889. }
  890. });
  891. this.actionNode = new Element("div.naviItemActionNode",{
  892. styles : this.css.naviItemActionNode,
  893. events : {
  894. click : function( ev ){
  895. ev.stopPropagation();
  896. }.bind(this)
  897. }
  898. }).inject( this.node );
  899. this.actionNode.addClass("mainColor_bg");
  900. this.colorNode = new Element("div", {
  901. styles : this.css.naviColorNode
  902. }).inject( this.node );
  903. this.colorNode.setStyle("border-color", this.data.color);
  904. this.textNode = new Element("div.naviItemTextNode", {
  905. styles : this.css.naviItemTextNode,
  906. "text" : this.data.name,
  907. "title" : this.data.name
  908. }).inject( this.node );
  909. if( this.isSelected ){
  910. this.select()
  911. }
  912. this.loadActionsMenu();
  913. },
  914. select : function( reload ){
  915. //this.node.setStyles( this.css.naviItemNode_selected );
  916. this.isSelected = true;
  917. this.colorNode.setStyle("background-color", this.data.color);
  918. this.colorNode.setStyles(this.css.naviColorNode_selected);
  919. if(reload)this.app.reloadView();
  920. //this.loadView();
  921. },
  922. cancelSelect : function(reload){
  923. this.isSelected = false;
  924. this.colorNode.setStyle("background-color", "transparent");
  925. this.colorNode.setStyles(this.css.naviColorNode);
  926. this.colorNode.setStyle("border-color", this.data.color);
  927. if(reload)this.app.reloadView();
  928. },
  929. loadActionsMenu : function(){
  930. this.menu = new MWF.xApplication.Calendar.CalendarMenu(this.actionNode, {} , this.app, {}, this.app.node);
  931. this.menu.calendarData = this.data;
  932. this.menu.load();
  933. }
  934. //loadView : function( searchKey ){
  935. // this.app.openView( this, this.category.data, this.data, searchKey || "", this );
  936. //}
  937. });
  938. MWF.xDesktop.requireApp("Template", "MSelector", null, false);
  939. MWF.xApplication.Calendar.CalendarMenu = new Class({
  940. Extends: MSelector,
  941. options : {
  942. "style": "arrow",
  943. "width": "150px",
  944. "height": "36px",
  945. "mainColor_bg": "mainColor_bg",
  946. "defaultOptionLp" : MWF.xApplication.Calendar.LP.font,
  947. "textField" : "name",
  948. "valueField" : "val",
  949. "event" : "mouseenter",
  950. "isSetSelectedValue" : false,
  951. "isChangeOptionStyle" : false,
  952. "emptyOptionEnable" : false,
  953. "containerIsTarget" : true,
  954. "tooltipsOptions" : {
  955. axis : "x",
  956. hasArrow : true
  957. }
  958. },
  959. _selectItem : function( itemNode, itemData, ev ){
  960. if( this[itemData.val] ){
  961. this[itemData.val](ev);
  962. }
  963. },
  964. showThis : function(){
  965. this.app.leftNavi.selectSingleCalendar( this.calendarData.id );
  966. },
  967. createEvent : function(){
  968. this.app.addCalendarEvent(null,null,null, this.calendarData.id);
  969. },
  970. openCalendar : function(){
  971. this.app.actions.getCalendar( this.calendarData.id, function( json ){
  972. this.app.openCalendar( json.data );
  973. }.bind(this))
  974. },
  975. editCalendar : function(){
  976. this.app.actions.getCalendar( this.calendarData.id, function( json ){
  977. this.app.editCalendar( json.data );
  978. }.bind(this))
  979. },
  980. deleteCalendar : function( e ){
  981. var lp = MWF.xApplication.Calendar.LP;
  982. var _self = this;
  983. _self.app.confirm("warn", e, lp.deleteCalendarTitle, lp.deleteCalendarContent.replace("{name}", _self.calendarData.name), 300, 120, function(){
  984. _self.app.actions.deleteCalendar( _self.calendarData.id, function( json ){
  985. _self.app.notice( lp.deleteSuccess );
  986. _self.app.leftNavi.reload();
  987. }.bind(this));
  988. this.close();
  989. }, function(){
  990. this.close();
  991. }, null);
  992. },
  993. _loadData : function( callback ){
  994. var lp = MWF.xApplication.Calendar.LP;
  995. var actionList = [{
  996. name: lp.onlyViewCurrent,
  997. val: 'showThis'
  998. }];
  999. if( this.calendarData.publishable || this.calendarData.manageable){
  1000. actionList.push( {
  1001. name: lp.addEvent,
  1002. val: 'createEvent'
  1003. });
  1004. }
  1005. if( this.calendarData.manageable ){
  1006. actionList.push( {
  1007. name: lp.editCalendar,
  1008. val: 'editCalendar'
  1009. }, {
  1010. name: lp.deleteCalendar,
  1011. val: 'deleteCalendar'
  1012. });
  1013. }else{
  1014. actionList.push( {
  1015. name: lp.viewCalendar,
  1016. val: 'openCalendar'
  1017. });
  1018. }
  1019. if(callback)callback( actionList );
  1020. },
  1021. _postCreateItem: function( itemNode, data ){
  1022. itemNode.setStyles( {
  1023. "cursor" : "pointer",
  1024. "font-size" : "14px",
  1025. "min-height" : "36px",
  1026. "line-height" : "36px"
  1027. } );
  1028. }
  1029. });
  1030. MWF.xApplication.Calendar.CalendarMarket = new Class({
  1031. Extends: MPopupForm,
  1032. Implements: [Options, Events],
  1033. options: {
  1034. "style": "meeting",
  1035. "width": "1100",
  1036. "height": "80%",
  1037. "hasTop": true,
  1038. "hasIcon": false,
  1039. "hasBottom": false,
  1040. "hasTopIcon" : false,
  1041. "hasTopContent" : false,
  1042. "draggable": true,
  1043. "maxAction" : true,
  1044. "closeAction": true,
  1045. "title" : MWF.xApplication.Calendar.LP.calendarMarket
  1046. },
  1047. _createTableContent : function(){
  1048. var lp = MWF.xApplication.Calendar.LP;
  1049. var _self = this;
  1050. this.formTableContainer.setStyles({
  1051. "width" : "auto",
  1052. "padding-top" : "20px",
  1053. "padding-left" : "20px"
  1054. });
  1055. this.formTableArea.setStyle("overflow","hidden");
  1056. this.app.actions.listPublicCalendar( function( json ){
  1057. if( !json.data || json.data.length == 0 ){
  1058. this.noCalendarNode = new Element("div",{
  1059. "styles" : this.css.noCalendarNode,
  1060. "text" : lp.noPublicCalendar
  1061. }).inject( this.formTableArea );
  1062. }else{
  1063. ( json.data || [] ).each( function(d){
  1064. var node = new Element("div", { styles : this.css.marketNode }).inject( this.formTableArea );
  1065. node.setStyle("border-left","5px solid "+ d.color);
  1066. var itemNode = new Element("div", { styles : this.css.marketItemNode }).inject( node );
  1067. var topNode = new Element("div", { styles : this.css.marketItemTopNode }).inject( itemNode );
  1068. var titleNode = new Element("div", {
  1069. styles : this.css.marketItemTitleNode,
  1070. text : d.name
  1071. }).inject( topNode );
  1072. titleNode.setStyle("color", d.color);
  1073. var middleNode = new Element("div", { styles : this.css.marketItemMiddleNode }).inject( itemNode );
  1074. new Element("div", {
  1075. styles : this.css.marketItemTopLable,
  1076. text : lp.create + ":"
  1077. }).inject( middleNode );
  1078. new Element("div", {
  1079. styles : this.css.marketItemTopInfor,
  1080. text : d.createor.split("@")[0] + ","
  1081. }).inject( middleNode );
  1082. new Element("div", {
  1083. styles : this.css.marketItemTopLable,
  1084. text : lp.time + ":"
  1085. }).inject( middleNode );
  1086. new Element("div", {
  1087. styles : this.css.marketItemTopInfor,
  1088. text : d.createTime.split(" ")[0]
  1089. }).inject( middleNode );
  1090. var middleNode = new Element("div", { styles : this.css.marketItemMiddleNode }).inject( itemNode );
  1091. new Element("div", {
  1092. styles : this.css.marketItemTopLable,
  1093. text : lp.type + ":"
  1094. }).inject( middleNode );
  1095. new Element("div", {
  1096. styles : this.css.marketItemTopInfor,
  1097. text : d.type == "PERSON" ? lp.personal : lp.unit2
  1098. }).inject( middleNode );
  1099. if( d.type == "UNIT" ){
  1100. new Element("div", {
  1101. styles : this.css.marketItemTopLable,
  1102. text : lp.belongTo + ":"
  1103. }).inject( middleNode );
  1104. new Element("div", {
  1105. styles : this.css.marketItemTopInfor,
  1106. text : d.target.split("@")[0],
  1107. title : d.target.split("@")[0]
  1108. }).inject( middleNode );
  1109. }
  1110. var middleNode = new Element("div", { styles : this.css.marketItemMiddleNode }).inject( itemNode );
  1111. new Element("div", {
  1112. styles : this.css.marketItemTopLable,
  1113. text : lp.description + ":"
  1114. }).inject( middleNode );
  1115. new Element("div", {
  1116. styles : this.css.marketItemDescriptiontInfor,
  1117. text : d.description || "",
  1118. title : d.description || ""
  1119. }).inject( middleNode );
  1120. var followedAction, followAction;
  1121. var followedAction = new Element("div",{
  1122. styles : this.css.marketItemFollowedAction,
  1123. text : lp.followed,
  1124. title : lp.clickToCancelFollow,
  1125. events : {
  1126. click : function(){
  1127. _self.app.actions.followCalendarCancel(d.id, function(){
  1128. _self.app.notice( lp.cancelFollowSuccess );
  1129. _self.needReload = true;
  1130. this.followedAction.setStyle("display","none");
  1131. this.followAction.setStyle("display","");
  1132. }.bind({ followedAction : followedAction, followAction: followAction }))
  1133. }.bind(this)
  1134. }
  1135. }).inject(node);
  1136. if( !d.followed )followedAction.setStyle("display","none");
  1137. var followAction = new Element("div",{
  1138. styles : this.css.marketItemFollowAction,
  1139. text : lp.follow ,
  1140. events : {
  1141. click: function () {
  1142. _self.app.actions.followCalendar(d.id, function () {
  1143. _self.app.notice( lp.followSuccess );
  1144. _self.needReload = true;
  1145. this.followedAction.setStyle("display","");
  1146. this.followAction.setStyle("display","none");
  1147. }.bind({ followedAction : followedAction, followAction: followAction }))
  1148. }.bind(this)
  1149. }
  1150. }).inject(node);
  1151. if( d.followed )followAction.setStyle("display","none");
  1152. //var typeNode = new Element("div", {
  1153. // styles : this.css.marketTypleLabel,
  1154. // text : d.type == "PERSON" ? "个人日历" : "组织日历"
  1155. //}).inject( topNode );
  1156. //typeNode.setStyle( "background-color" , MWFCalendar.ColorOptions.getLightColor(d.color ) );
  1157. }.bind(this))
  1158. }
  1159. }.bind(this))
  1160. },
  1161. _close : function(){
  1162. if( this.needReload )this.app.reload();
  1163. }
  1164. });
  1165. MWF.xApplication.Calendar.Config = new Class({
  1166. Implements: [Events],
  1167. initialize: function(app){
  1168. this.app = app;
  1169. this.css = this.app.css;
  1170. this.lp = this.app.lp;
  1171. this.configData = this.app.calendarConfig || {};
  1172. this.process = null;
  1173. MWF.UD.getPublicData("calendarConfig", function(json){
  1174. var jsonData = json || {};
  1175. //if (jsonData.process){
  1176. // this.configData.process = jsonData.process;
  1177. //}else{
  1178. // this.configData.process = null;
  1179. //}
  1180. if( jsonData.weekBegin ){
  1181. this.configData.weekBegin = jsonData.weekBegin;
  1182. }
  1183. //if( jsonData.mobileCreateEnable ){
  1184. // this.configData.mobileCreateEnable = jsonData.mobileCreateEnable;
  1185. //}
  1186. for( var key in jsonData ){
  1187. if( key != "process" && key != "weekBegin" && key !="mobileCreateEnable"){
  1188. this.configData[ key ] = jsonData[key];
  1189. }
  1190. }
  1191. this.load();
  1192. }.bind(this));
  1193. },
  1194. load: function(){
  1195. this.node = new Element("div", {"styles": this.css.configNode}).inject(this.app.node);
  1196. this.contentNode = new Element("div", {"styles": this.css.configContentNode}).inject(this.node);
  1197. var statusStyle = "overflow: hidden;margin-top:6px;margin-left:10px;";
  1198. var statusIconStyle = "float: left; width: 16px; height: 16px; border-radius: 100px; ";
  1199. var statusIconStyle2 = "float: left; width: 14px; height: 14px; border-radius: 100px; ";
  1200. var statusTextStyle = "margin-left:35px; line-height:16px; height:16px;font-size:14px;color:#666;";
  1201. var viewStyle = "font-size:14px;color:#666;heigh:16px;margin-top:6px;margin-left:10px;";
  1202. var inputTextStyle = "float:right; width:120px; border:1px solid #ccc";
  1203. var d = this.configData;
  1204. var configLp = this.lp.config;
  1205. var html =
  1206. //"<div class='configTitle'>"+this.lp.config.calendarStatus+"</div>" +
  1207. //
  1208. //"<div style='"+ statusStyle +"'>"+
  1209. //" <div style='"+ statusIconStyle + "background-color:#4990E2'></div>" +
  1210. //" <div style='"+ statusTextStyle +"'>"+this.lp.config.wait+"</div></div>" +
  1211. //"</div>"+
  1212. //
  1213. //"<div style='"+ statusStyle +"'>"+
  1214. //" <div style='"+ statusIconStyle + "background-color:#66CC7F'></div>" +
  1215. //" <div style='"+ statusTextStyle +"'>"+this.lp.config.progress+"</div></div>" +
  1216. //"</div>"+
  1217. //
  1218. //"<div style='"+ statusStyle +"'>"+
  1219. //" <div style='"+ statusIconStyle + "background-color:#F6A623'></div>" +
  1220. //" <div style='"+ statusTextStyle +"'>"+this.lp.config.invite+"</div></div>" +
  1221. //"</div>"+
  1222. //
  1223. //"<div style='"+ statusStyle +"'>"+
  1224. //" <div style='"+ statusIconStyle + "background-color:#ccc'></div>" +
  1225. //" <div style='"+ statusTextStyle +"'>"+this.lp.config.completed+"</div></div>" +
  1226. //"</div>"+
  1227. //
  1228. //"<div style='"+ statusStyle +"'>"+
  1229. //" <div style='"+ statusIconStyle2 + "border:2px solid #FF7F7F;'></div>" +
  1230. //" <div style='"+ statusTextStyle +"'>"+this.lp.config.conflict+"</div></div>" +
  1231. //"</div>"+
  1232. //
  1233. //"<div class='line'></div>" +
  1234. "<div class='configTitle'>"+this.lp.config["default"]+"</div>" +
  1235. "<div>";
  1236. if( !d.disableViewList.contains( "toMonth" ) ){
  1237. html +=
  1238. " <div style='"+ viewStyle +"'>" +
  1239. "<input type='radio' name='configSelectDefaultView' "+((d.defaultView=="toMonth") ? "checked" : "")+" value='toMonth'>"+ ( d.toMonthViewName || this.lp.month )+
  1240. " </div>";
  1241. }
  1242. if( !d.disableViewList.contains( "toWeek" ) ){
  1243. html +=
  1244. " <div style='"+ viewStyle +"'>" +
  1245. "<input type='radio' name='configSelectDefaultView' "+((d.defaultView=="toWeek") ? "checked" : "")+" value='toWeek'>"+( d.toWeekViewName || this.lp.week )+
  1246. " </div>";
  1247. }
  1248. if( !d.disableViewList.contains( "toDay" ) ){
  1249. html +=
  1250. " <div style='"+ viewStyle +"'>" +
  1251. "<input type='radio' name='configSelectDefaultView' "+((d.defaultView=="toDay") ? "checked" : "")+" value='toDay'>"+(d.toDayViewName || this.lp.day)+
  1252. " </div>";
  1253. }
  1254. if( !d.disableViewList.contains( "toList" ) ){
  1255. html +=
  1256. " <div style='"+ viewStyle +"'>" +
  1257. "<input type='radio' name='configSelectDefaultView' "+((d.defaultView=="toList") ? "checked" : "")+" value='toList'>"+(d.toListViewName || this.lp.list)+
  1258. " </div>";
  1259. }
  1260. html +="</div>";
  1261. if( MWF.AC.isAdministrator() ){
  1262. d.disableViewList = d.disableViewList || [];
  1263. html += "<div class='line'></div>"+
  1264. "<div class='configTitle'>"+this.lp.config.viewSetting +"</div>" +
  1265. "<div>"+
  1266. " <div style='"+ viewStyle +"'>" +
  1267. "<input type='checkbox' name='configAvailableView' "+( !d.disableViewList.contains( "toMonth" ) ? "checked" : "")+" value='toMonth'>"+this.lp.month+
  1268. "<input type='text' name='toMonthViewName' value='" + (d.toMonthViewName || "") + "' style='"+ inputTextStyle +"' placeholder='"+ this.lp.config.viewCustomName +"' >"+
  1269. " </div>" +
  1270. " <div style='"+ viewStyle +"'>" +
  1271. "<input type='checkbox' name='configAvailableView' "+( !d.disableViewList.contains( "toWeek" ) ? "checked" : "")+" value='toWeek'>"+this.lp.week+
  1272. "<input type='text' name='toWeekViewName' value='" + (d.toWeekViewName || "") + "' style='"+ inputTextStyle +"' placeholder='"+ this.lp.config.viewCustomName +"' >"+
  1273. " </div>" +
  1274. " <div style='"+ viewStyle +"'>" +
  1275. "<input type='checkbox' name='configAvailableView' "+( !d.disableViewList.contains( "toDay" ) ? "checked" : "")+" value='toDay'>"+this.lp.day+
  1276. "<input type='text' name='toDayViewName' value='" + (d.toDayViewName || "") + "' style='"+ inputTextStyle +"' placeholder='"+ this.lp.config.viewCustomName +"' >"+
  1277. " </div>" +
  1278. " <div style='"+ viewStyle +"'>" +
  1279. "<input type='checkbox' name='configAvailableView' "+( !d.disableViewList.contains( "toList" ) ? "checked" : "")+" value='toList'>"+this.lp.list+
  1280. "<input type='text' name='toListViewName' value='" + (d.toListViewName || "") + "' style='"+ inputTextStyle +"' placeholder='"+ this.lp.config.viewCustomName +"' >"+
  1281. " </div>" +
  1282. "</div>" +
  1283. "<div class='line'></div>"+
  1284. "<div class='configTitle'>"+this.lp.config.weekBegin +"</div>" +
  1285. "<div><select name='configSelectWeekBeign'>"+
  1286. "<option value='0' "+((d.weekBegin=="0") ? "selected" : "")+">"+this.lp.weeks.Sun+"</option>"+
  1287. "<option value='1' "+((d.weekBegin=="1") ? "selected" : "")+">"+this.lp.weeks.Mon+"</option>"+
  1288. //"<option value='2'"+((d.weekBegin=="2") ? "selected" : "")+">"+this.lp.weeks.Tues+"</option>"+
  1289. //"<option value='3'"+((d.weekBegin=="3") ? "selected" : "")+">"+this.lp.weeks.Wed+"</option>"+
  1290. //"<option value='4'"+((d.weekBegin=="4") ? "selected" : "")+">"+this.lp.weeks.Thur+"</option>"+
  1291. //"<option value='5'"+((d.weekBegin=="5") ? "selected" : "")+">"+this.lp.weeks.Fri+"</option>"+
  1292. //"<option value='6'"+((d.weekBegin=="6") ? "selected" : "")+">"+this.lp.weeks.Sat+"</option>"+
  1293. "</select></div>"; //+
  1294. //"<div class='line'></div>"+
  1295. //"<div class='configTitle'>"+this.lp.config.applyProcess+"</div>" +
  1296. //"<div item='processArea'></div>" +
  1297. //
  1298. //
  1299. //"<div class='configTitle'>"+this.lp.config.mobileCreateEnable +"</div>" +
  1300. //"<div item='mobileCreateEnable'></div>";
  1301. }
  1302. this.contentNode.set("html", html);
  1303. this.contentNode.getElements("div.line").setStyles(this.css.configContentLine);
  1304. this.contentNode.getElements("div.configTitle").setStyles(this.css.configTitleDiv);
  1305. if( MWF.AC.isAdministrator() ){
  1306. //this.processNode = this.contentNode.getElement("[item='processArea']");
  1307. //this.processNode.setStyles(this.css.configProcessNode);
  1308. //this.createApplicationSelect();
  1309. //
  1310. //this.mobileCreateEnableNode = this.contentNode.getElement("[item='mobileCreateEnable']");
  1311. //this.mobileCreateEnable = new MDomItem(this.mobileCreateEnableNode, {
  1312. // name : "mobileCreateEnable", type : "select", selectValue : ["true","false"], selectText : this.lp.config.mobileCreateEnableOptions,
  1313. // value : d.mobileCreateEnable || "true"
  1314. //} , null, this.app );
  1315. //this.mobileCreateEnable.load();
  1316. }
  1317. this.actionNode = new Element("div", {"styles": this.css.configActionNode}).inject(this.node);
  1318. this.cancelNode = new Element("div", {"styles": this.css.configActionCancelNode, "text": this.app.lp.cancel}).inject(this.actionNode);
  1319. this.saveNode = new Element("div", {"styles": this.css.configActionSaveNode, "text": this.app.lp.save}).inject(this.actionNode);
  1320. this.saveNode.addClass("mainColor_bg");
  1321. this.cancelNode.addEvent("click", this.hide.bind(this));
  1322. this.saveNode.addEvent("click", this.save.bind(this));
  1323. this.node.addEvent("mousedown", function(e){e.stopPropagation();}.bind(this));
  1324. this.setSize();
  1325. this.show();
  1326. },
  1327. setSize : function(){
  1328. var sizeY = this.node.getSize().y;
  1329. if( this.app.inContainer ){
  1330. var y = this.app.container.getSize().y;
  1331. }else{
  1332. var y = this.app.content.getSize().y;
  1333. }
  1334. if( sizeY > y-50 ){
  1335. this.node.setStyle("height", y-50 );
  1336. }
  1337. },
  1338. createApplicationSelect: function(){
  1339. if (this.configData.process){
  1340. MWF.require("MWF.widget.O2Identity", function(){
  1341. var p = new MWF.widget.O2Process(this.configData.process, this.processNode);
  1342. }.bind(this));
  1343. }
  1344. this.processNode.addEvent("click", function(){
  1345. MWF.xDesktop.requireApp("Selector", "package", function(){
  1346. var options = {
  1347. "type": "Process",
  1348. "values": [this.process || this.configData.process],
  1349. "count": 1,
  1350. "onComplete": function (items) {
  1351. this.processNode.empty();
  1352. this.process = null;
  1353. this.configData.process = null;
  1354. if (items.length){
  1355. MWF.require("MWF.widget.O2Identity", function(){
  1356. var p = new MWF.widget.O2Process(items[0].data, this.processNode);
  1357. this.process = {
  1358. "name": items[0].data.name,
  1359. "id": items[0].data.id,
  1360. "application": items[0].data.application,
  1361. "applicationName": items[0].data.applicationName,
  1362. "alias": items[0].data.alias
  1363. };
  1364. this.configData.process = this.process;
  1365. }.bind(this));
  1366. }
  1367. }.bind(this)
  1368. };
  1369. var selector = new MWF.O2Selector(this.app.content, options);
  1370. }.bind(this));
  1371. }.bind(this));
  1372. },
  1373. save: function(){
  1374. //var hideMenu = "auto";
  1375. var defaultView = "toMyCalendar";
  1376. var process = null;
  1377. //var node = this.contentNode.getFirst("div");
  1378. //var hideMenuNode = node.getElement("input");
  1379. //if (hideMenuNode) if (!hideMenuNode.checked) hideMenu = "static";
  1380. //node = node.getNext();
  1381. var viewNodes = this.contentNode.getElements("input[name='configSelectDefaultView']");
  1382. for (var i=0; i<viewNodes.length; i++){
  1383. if (viewNodes[i].checked){
  1384. defaultView = viewNodes[i].get("value");
  1385. break;
  1386. }
  1387. }
  1388. MWF.UD.putData("calendarConfig", {
  1389. //"hideMenu": hideMenu,
  1390. "defaultView": defaultView
  1391. }, null, false);
  1392. if( MWF.AC.isAdministrator() ){
  1393. //if (this.processSelect){
  1394. //process = this.processSelect.options[this.processSelect.selectedIndex].get("value");
  1395. //MWF.UD.putPublicData("calendarConfig", {"process": process});
  1396. //}
  1397. var disableViewList = [];
  1398. var viewAvailableNodes = this.contentNode.getElements("input[name='configAvailableView']");
  1399. for (var i=0; i<viewAvailableNodes.length; i++){
  1400. if ( !viewAvailableNodes[i].checked){
  1401. disableViewList.push( viewAvailableNodes[i].get("value") ) ;
  1402. }
  1403. }
  1404. var weekBeginSelect = this.contentNode.getElement("select[name='configSelectWeekBeign']");
  1405. var weekBeginValue = "0";
  1406. if( weekBeginSelect ){
  1407. weekBeginValue = weekBeginSelect.options[weekBeginSelect.selectedIndex].get("value");
  1408. }
  1409. MWF.UD.putPublicData("calendarConfig", {
  1410. //"process": this.process || this.configData.process,
  1411. "weekBegin" : weekBeginValue,
  1412. //"mobileCreateEnable" : this.mobileCreateEnable.getValue(),
  1413. "disableViewList" : disableViewList,
  1414. "toMonthViewName" : this.contentNode.getElement("input[name='toMonthViewName']").get("value"),
  1415. "toWeekViewName" : this.contentNode.getElement("input[name='toWeekViewName']").get("value"),
  1416. "toDayViewName" : this.contentNode.getElement("input[name='toDayViewName']").get("value"),
  1417. "toListViewName" : this.contentNode.getElement("input[name='toListViewName']").get("value")
  1418. }, null, false);
  1419. }
  1420. this.app.notice( this.app.lp.config_saveSuccess, "success" );
  1421. this.hide();
  1422. },
  1423. show: function(){
  1424. this.node.setStyles(this.css.configNode);
  1425. var fx = new Fx.Morph(this.node, {
  1426. "duration": "500",
  1427. "transition": Fx.Transitions.Expo.easeOut
  1428. });
  1429. fx.start({
  1430. "opacity": 1
  1431. }).chain(function(){
  1432. this.hideFun = this.hide.bind(this);
  1433. this.app.node.addEvent("mousedown", this.hideFun);
  1434. }.bind(this));
  1435. },
  1436. hide: function(){
  1437. this.node.destroy();
  1438. this.app.node.removeEvent("mousedown", this.hideFun);
  1439. MWF.release(this);
  1440. }
  1441. });