Main.js 61 KB

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