Common.js 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  1. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  2. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. MWF.xDesktop.requireApp("Selector", "package", null, false);
  5. MWF.require("MWF.widget.AttachmentController",null,false);
  6. var MWFCalendar = MWF.xApplication.Calendar = MWF.xApplication.Calendar || {};
  7. MWFCalendar.ColorOptions = {
  8. deep : ["#428ffc","#5bcc61","#f9bf24","#f75f59","#f180f7","#9072f1","#909090","#1462be"],
  9. light : ["#cae2ff","#d0f1b0","#fef4bb","#fdd9d9","#f4c5f7","#d6ccf9","#e7e7e7","#cae2ff"],
  10. getLightColor : function( deepColor ){
  11. var index = this.deep.indexOf(deepColor);
  12. return index > -1 ? this.light[index] : this.light[0];
  13. },
  14. getDeepColor : function( lightColor ){
  15. var index = this.light.indexOf(lightColor);
  16. return index > -1 ? this.deep[index] : this.deep[0];
  17. }
  18. };
  19. MWFCalendar.EventForm = new Class({
  20. Extends: MPopupForm,
  21. Implements: [Options, Events],
  22. options: {
  23. "style": "meeting",
  24. "okClass": "mainColor_bg",
  25. "width": "800",
  26. "height": "475",
  27. "hasTop": true,
  28. "hasIcon": false,
  29. "hasTopIcon" : false,
  30. "hasTopContent" : false,
  31. "draggable": true,
  32. "maxAction" : true,
  33. "closeAction": true,
  34. "isFull" : false,
  35. "startTime" : null,
  36. "endTime" : null,
  37. "isWholeday" : false,
  38. "defaultCalendarId" : ""
  39. },
  40. open: function (e) {
  41. if( this.options.isFull ){
  42. this.options.width = "800";
  43. this.options.height = "630";
  44. }
  45. this.fireEvent("queryOpen");
  46. this.isNew = false;
  47. this.isEdited = false;
  48. this._open();
  49. this.fireEvent("postOpen");
  50. },
  51. create: function () {
  52. if( this.options.isFull ){
  53. this.options.width = "1100";
  54. this.options.height = "630";
  55. }
  56. this.fireEvent("queryCreate");
  57. this.isNew = true;
  58. this._open();
  59. this.fireEvent("postCreate");
  60. },
  61. edit: function () {
  62. if( this.options.isFull ){
  63. this.options.width = "1100";
  64. this.options.height = "630";
  65. }
  66. this.fireEvent("queryEdit");
  67. this.isEdited = true;
  68. this._open();
  69. this.fireEvent("postEdit");
  70. },
  71. _createTableContent : function(){
  72. this.getEventData( function(){
  73. this.loadEventContent()
  74. }.bind(this))
  75. },
  76. loadEventContent : function(){
  77. var path = "../o2_lib/rrule/";
  78. COMMON.AjaxModule.load(path+"rrule.js", function () {
  79. if( this.isEdited || this.isNew ) {
  80. this.app.actions.listMyCalendar(function (json) {
  81. this.calendarIds = [];
  82. this.calendarNames = [];
  83. this.calendarList = [];
  84. (json.data.myCalendars || []).each(function (c) {
  85. if ((c.publishable || c.manageable) && (c.status !== "CLOSE")) this.calendarList.push(c);
  86. }.bind(this));
  87. (json.data.unitCalendars || []).each(function (c) {
  88. if ((c.publishable || c.manageable) && (c.status !== "CLOSE")) this.calendarList.push(c);
  89. }.bind(this));
  90. this.calendarList.each(function (d) {
  91. this.calendarIds.push(d.id);
  92. this.calendarNames.push(d.name);
  93. }.bind(this));
  94. this._createTableContent_Edit();
  95. }.bind(this))
  96. }else{
  97. this.app.actions.getCalendar( this.data.calendarId, function (json) {
  98. this.calendarName = json.data.name;
  99. this._createTableContent_Read();
  100. }.bind(this))
  101. }
  102. }.bind(this));
  103. },
  104. _createTableContent_Read : function(){
  105. this.formTopTextNode.set( "text", this.lp.readEvent );
  106. this.formTableContainer.setStyle("width","86%");
  107. var data = this.data;
  108. var beginD = Date.parse(data.startTime);
  109. var endD = Date.parse(data.endTime);
  110. var begin = beginD.format(this.lp.dateFormatAll) + "(" + this.lp.weeks.arr[beginD.get("day")] + ")";
  111. var end = endD.format(this.lp.dateFormatAll) + "(" + this.lp.weeks.arr[endD.get("day")] + ")";
  112. if( data.recurrenceRule ){
  113. this.oldRecurrenceRule = data.recurrenceRule;
  114. this.rRule = RRule.fromString(data.recurrenceRule).origOptions;
  115. }else{
  116. this.rRule = {};
  117. }
  118. var text = this.lp.repeatFrequencyArr;
  119. var value = ["NONE",RRule["DAILY"],RRule["WEEKLY"],RRule["MONTHLY"],RRule["YEARLY"] ];
  120. var repeat;
  121. if( this.rRule.freq ){
  122. repeat = text[ value.indexOf( this.rRule.freq ) ];
  123. if( this.rRule.byweekday ){
  124. var repeatWeeks = this.rRule.byweekday.toString().split(",");
  125. var repeatWeekTextList = [];
  126. var weekArr = this.lp.weeks.arr;
  127. var rruleArr = this.lp.weeks.rruleArr;
  128. repeatWeeks.each( function(r){
  129. repeatWeekTextList.push( weekArr[ rruleArr.indexOf( r ) ] );
  130. });
  131. repeat = this.lp.repeatInfor.replace("{frequency}", repeatWeekTextList.join("、"));
  132. }else{
  133. repeat = repeat + this.lp.repeat;
  134. }
  135. if( this.rRule.until && ( repeat !== "不重复" || repeat !== this.lp.notRepeat ) ){
  136. repeat += " "+ this.lp.endDate +":"+this.rRule.until.format("%Y-%m-%d");
  137. }
  138. }else{
  139. repeat = this.lp.notRepeat
  140. }
  141. var remind;
  142. if( data.valarmTime_config ){ //天、时、分、秒
  143. if( data.valarmTime_config === "0,0,0,-5" ){
  144. remind = this.lp.remindWhenBegin;
  145. }else{
  146. var valarmTime_configList = data.valarmTime_config.split(",");
  147. valarmTime_configList.each( function( v, i ){
  148. var unit;
  149. if( i == 0 ){
  150. unit = this.lp.date;
  151. }else if( i == 1 ){
  152. unit = this.lp.hour;
  153. }else if( i==2 ){
  154. unit = this.lp.minute;
  155. }else{
  156. unit = this.lp.second;
  157. }
  158. if( v && v!="0" ){
  159. remind = this.lp.remindInAdvance.replace("{text}", Math.abs(v)+unit );
  160. }
  161. }.bind(this))
  162. }
  163. }
  164. debugger;
  165. var calendarName = this.calendarName; //this.calendarNames[ this.calendarIds.indexOf( data.calendarId ) ];
  166. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='table-layout:fixed;'>" +
  167. //"<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  168. "<tr><td styles='formTableTitle' width='40'>"+this.lp.calendar+":</td>" +
  169. " <td styles='formTableValue' width='400'>"+calendarName+"</td>" +
  170. "</tr>" +
  171. "<tr><td styles='formTableTitle'>"+this.lp.subject+":</td>" +
  172. " <td styles='formTableValue'><div styles='colorItem'></div>"+ data.title +"</td></tr>" +
  173. "<tr><td styles='formTableTitle'>"+this.lp.beginTime+":</td>" +
  174. " <td styles='formTableValue'>"+ begin +"</td>" +
  175. "</tr>" +
  176. "<tr><td styles='formTableTitle'>"+this.lp.endTime+":</td>" +
  177. " <td styles='formTableValue'>"+end+"</td>" +
  178. "</tr>"+
  179. "<tr><td styles='formTableTitle'>"+this.lp.address+":</td>" +
  180. " <td styles='formTableValue'>"+( data.locationName || "" )+"</td>" +
  181. "</tr>";
  182. if( remind ){
  183. html += "<tr><td styles='formTableTitle'>"+this.lp.remind+":</td>" +
  184. " <td styles='formTableValue'>"+remind+"</td>" +
  185. "</tr>";
  186. }else{
  187. html += "<tr><td styles='formTableTitle'>"+this.lp.remind+":</td>" +
  188. " <td styles='formTableValue'>"+ this.lp.remindIntervalArr[0] +"</td>" +
  189. "</tr>";
  190. }
  191. if( repeat && repeat!==this.lp.no && repeat !== this.lp.notRepeat ){
  192. html += "<tr><td styles='formTableTitle'>"+this.lp.repeat+":</td>" +
  193. " <td styles='formTableValue'>"+ repeat +"</td>" +
  194. "</tr>";
  195. }else{
  196. html += "<tr><td styles='formTableTitle'>"+this.lp.repeat+":</td>" +
  197. " <td styles='formTableValue'>"+ this.lp.notRepeat +"</td>" +
  198. "</tr>";
  199. }
  200. if( data.comment ){
  201. html += "<tr><td styles='formTableTitle' valign='top'><div style='padding-top: 15px;'>"+ this.lp.content +":</div></td>" +
  202. " <td styles='formTableValue'>"+ this.parseHtml(data.comment)+"</td>" +
  203. "</tr>";
  204. }else{
  205. html += "<tr><td styles='formTableTitle' valign='top'>"+ this.lp.content +":</td>" +
  206. " <td styles='formTableValue'>"+this.lp.none+"</td>" +
  207. "</tr>";
  208. }
  209. this.formTableArea.set("html", html );
  210. this.formTableArea.getElements("[styles='formTableTitle']").setStyles({
  211. "color" : "#333",
  212. "font-size": "16px",
  213. "padding": "0px 20px 0px 0px",
  214. "height" : "35px",
  215. "line-height" : "35px",
  216. "text-align": "left"
  217. });
  218. this.formTableArea.getElements("[styles='formTableValue']").setStyles({
  219. "text-align": "left",
  220. "font-size": "16px"
  221. });
  222. var colorItem = this.formTableArea.getElement("[styles='colorItem']");
  223. var div = new Element("div", {
  224. styles : this.css.colorNode
  225. }).inject( colorItem );
  226. div.setStyle("background-color",this.data.color);
  227. },
  228. _createTableContent_Edit: function () {
  229. this.oldCoordinate = null;
  230. var editEnable = this.editEnable = ( this.isEdited || this.isNew );
  231. this.userName = layout.desktop.session.user.distinguishedName;
  232. this.userId = layout.desktop.session.user.id;
  233. if( this.options.isFull ){
  234. this.formTableContainer.setStyles({
  235. "width" : "auto",
  236. "padding-left" : "40px"
  237. });
  238. }else{
  239. this.formTableContainer.setStyle("width","80%");
  240. }
  241. if( this.isNew ){
  242. this.formTopTextNode.set( "text", this.lp.addEvent );
  243. }else if( this.isEdited ){
  244. this.formTopTextNode.set( "text", this.lp.editEvent );
  245. this.options.height = "590";
  246. }
  247. var startTime, endTime, defaultStartDate, defaultStartTime, defaultEndDate, defaultEndTime;
  248. if( this.options.startTime && this.options.endTime ){
  249. startTime= this.date = typeOf( this.options.startTime )=="string" ? Date.parse( this.options.startTime ) : this.options.startTime;
  250. endTime= typeOf( this.options.endTime )=="string" ? Date.parse( this.options.endTime ) : this.options.endTime;
  251. defaultStartDate = startTime.format("%Y-%m-%d");
  252. defaultStartTime = startTime.format("%H:%M");
  253. defaultEndDate = endTime.format("%Y-%m-%d");
  254. defaultEndTime = endTime.format("%H:%M");
  255. }else{
  256. startTime = this.date = new Date().increment("hour",1);
  257. endTime = startTime.clone().increment("hour",1);
  258. defaultStartDate = startTime.format("%Y-%m-%d");
  259. defaultStartTime = startTime.format("%H") + ":00";
  260. defaultEndDate = endTime.format("%Y-%m-%d");
  261. defaultEndTime = endTime.format("%H") + ":00";
  262. }
  263. var data = this.data;
  264. if( data.comment ){
  265. data.comment = this.parseHtml(data.comment);
  266. }
  267. if( this.options.isWholeday && this.isNew ){
  268. data.isAllDayEvent = true;
  269. }
  270. if( data.startTime ){
  271. var beignDate = Date.parse( data.startTime );
  272. data.startDateInput = beignDate.format("%Y-%m-%d");
  273. data.startTimeInput = this.getString( beignDate.getHours() ) + ":" + this.getString( beignDate.getMinutes() );
  274. }
  275. if( data.endTime ){
  276. var endDate = Date.parse( data.endTime );
  277. data.endDateInput = endDate.format("%Y-%m-%d");
  278. data.endTimeInput = this.getString( endDate.getHours() ) + ":" + this.getString( endDate.getMinutes() );
  279. }
  280. //data.rRuleString = "FREQ=WEEKLY;DTSTART=20180523T090000Z;UNTIL=20180523T160000Z;BYDAY=WE,TH,FR";
  281. if( data.recurrenceRule ){
  282. this.oldRecurrenceRule = data.recurrenceRule;
  283. this.rRule = RRule.fromString(data.recurrenceRule).origOptions;
  284. }else{
  285. this.rRule = {};
  286. }
  287. data.repeat = this.rRule.freq || "";
  288. if( this.rRule.until ){
  289. data.repeatUntilAvailable = "AVAILABLE";
  290. data.repeatUntilDate = this.rRule.until.format("%Y-%m-%d");
  291. }
  292. if( this.rRule.byweekday ){
  293. data.repeatWeeks = this.rRule.byweekday.toString().split(",");
  294. }
  295. if( data.valarmTime_config ){ //天、时、分、秒
  296. var valarmTime_configList = data.valarmTime_config.split(",");
  297. valarmTime_configList.each( function( v, i ){
  298. var unit;
  299. if( i == 0 ){
  300. unit = "d"
  301. }else if( i == 1 ){
  302. unit = "h";
  303. }else if( i==2 ){
  304. unit = "m"
  305. }else{
  306. unit = "s"
  307. }
  308. if( v && v!="0" ){
  309. data.remind = v+"_"+unit;
  310. }
  311. }.bind(this))
  312. }
  313. this.formTableArea.set("html", this.getHtml());
  314. this.colorItem = this.formTableArea.getElement("[item='color']");
  315. //this.attachmentTr = this.formTableArea.getElement("[item='attachmentTr']");
  316. //this.attachmentArea = this.formTableArea.getElement("[item='attachment']");
  317. if( !this.data.color ){
  318. if( this.options.defaultCalendarId ){
  319. this.data.color = this.getColorByCalendarId( this.options.defaultCalendarId );
  320. }else{
  321. this.data.color = this.calendarList[0].color;
  322. }
  323. }
  324. MWF.xDesktop.requireApp("Template", "MForm", function () {
  325. this.form = new MForm(this.formTableArea, data, {
  326. isEdited: this.isEdited || this.isNew,
  327. style : "meeting",
  328. hasColon : true,
  329. itemTemplate: {
  330. calendarId : { text : this.lp.calendar, defaultValue : this.options.defaultCalendarId, type : "select", selectValue : this.calendarIds, selectText : this.calendarNames, event : {
  331. change : function( item ){
  332. this.setColorByCalendarId( item.getValue() )
  333. }.bind(this)
  334. }},
  335. startDateInput: { text : this.lp.beginTime ,tType: "date", defaultValue: defaultStartDate , notEmpty : true },
  336. startTimeInput: { tType: "time",
  337. defaultValue: defaultStartTime, className : ( (this.isNew || this.isEdited ) ? "inputTimeUnformatWidth" : "" ),
  338. disable : data.isAllDayEvent
  339. },
  340. endDateInput: { text : this.lp.endTime, tType: "date", defaultValue: defaultEndDate, notEmpty : true },
  341. endTimeInput: { tType: "time",
  342. defaultValue: defaultEndTime, className : ( (this.isNew || this.isEdited ) ? "inputTimeUnformatWidth" : "" ),
  343. disable : data.isAllDayEvent
  344. },
  345. remind : { text : this.lp.remind, type : "select", selectText : this.lp.remindIntervalArr,
  346. selectValue : ["", "-5_s","-5_m","-10_m","-15_m","-30_m","-1_h","-2_h"] },
  347. isAllDayEvent : { type : "checkbox", selectValue : ["true"], selectText : [ this.lp.allDay ], event : {
  348. change : function(item ){
  349. var itemStart = item.form.getItem("startTimeInput");
  350. var itemEnd = item.form.getItem("endTimeInput");
  351. if( item.getValue() == "true" && !itemStart.options.disable && !itemEnd.options.disable ){
  352. itemStart.getElements().setStyle("display","none");
  353. itemEnd.getElements().setStyle("display","none")
  354. }else{
  355. if( itemStart.options.disable )itemStart.enable();
  356. if( itemEnd.options.disable )itemEnd.enable();
  357. itemStart.getElements().setStyle("display","");
  358. itemEnd.getElements().setStyle("display","")
  359. }
  360. }.bind(this)
  361. } },
  362. title: { text : this.lp.eventSubject, notEmpty : true },
  363. description: {type: "textarea"},
  364. locationName : { text : this.lp.locationName },
  365. repeat : { text : this.lp.repeat, type : "select", defaultValue : "NONE",
  366. selectText : this.lp.repeatFrequencyArr2,
  367. selectValue : ["NONE",RRule["DAILY"],RRule["WEEKLY"],RRule["MONTHLY"],RRule["YEARLY"] ], event : {
  368. change : function(item){
  369. var val = item.getValue();
  370. var area = this.formTableArea.getElement("[item='repeatUntilArea']");
  371. area.setStyle("display", val == "NONE" ? "none" : "");
  372. if( val == RRule["WEEKLY"] ){
  373. this.showWeek()
  374. }else{
  375. area = this.formTableArea.getElement("[item='repeatWeekArea']");
  376. area.setStyle("display","none");
  377. }
  378. }.bind(this)
  379. }},
  380. repeatUntilAvailable : { text : this.lp.repeatUntilAvailable, type : "radio",
  381. selectText : this.lp.repeatUntilAvailableTextArr,
  382. selectValue : ["NONE", "AVAILABLE"],
  383. defaultValue : "NONE"
  384. },
  385. repeatUntilDate : { tType : "date", event : {
  386. click : function(){ this.form.getItem("repeatUntilAvailable").setValue("AVAILABLE") }.bind(this)
  387. }},
  388. comment : { text : this.lp.content, type : "rtf", RTFConfig : {
  389. skin : "bootstrapck",
  390. "resize_enabled": false,
  391. toolbar : [
  392. { name: 'document', items : [ 'Preview' ] },
  393. //{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  394. { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  395. //{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  396. { name: 'list', items : [ 'NumberedList','BulletedList'] },
  397. //{ name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
  398. //{ name: 'colors', items : [ 'TextColor','BGColor' ] },
  399. { name: 'links', items : [ 'Link','Unlink' ] }
  400. //{ name: 'insert', items : [ 'Image' ] },
  401. //{ name: 'tools', items : [ 'Maximize','-','About' ] }
  402. ]
  403. }
  404. }}
  405. }, this.app);
  406. this.form.load();
  407. if( this.data.repeat == RRule["WEEKLY"] ){
  408. this.showWeek()
  409. }
  410. this.loadColor();
  411. //if( this.data.id )
  412. // this.loadAttachment();
  413. }.bind(this), true);
  414. },
  415. getRRuleString : function( data ){
  416. if( !data )data = this.form.getResult(false,null,false,false,false);
  417. if( !data.repeat || data.repeat == "NONE" )return "";
  418. //var startDate;
  419. //if( data.isAllDayEvent == "true" ){
  420. // startDate = Date.parse( data.startDateInput )
  421. //}else{
  422. // startDate = Date.parse( data.startDateInput + " " + data.startTimeInput )
  423. //}
  424. var options = {
  425. freq : data.repeat //RRule[data.repeat],
  426. //dtstart : startDate
  427. };
  428. if( data.repeatUntilAvailable != "NONE" && data.repeatUntilDate!="" ){
  429. options.until = Date.parse( data.repeatUntilDate )
  430. }
  431. if( data.repeat == RRule["WEEKLY"] ){
  432. options.byweekday = [];
  433. this.getSelectWeek().each( function( w ){
  434. options.byweekday.push( RRule[w] )
  435. })
  436. }
  437. var rule = new RRule( options );
  438. return rule.toString();
  439. },
  440. getHtml : function(){
  441. var boxStyle = (this.isEdited || this.isNew) ? "border:1px solid #ccc; border-radius: 4px;overflow: hidden;padding:8px;" : "";
  442. if( this.options.isFull ){
  443. var html = "<div style='overflow: hidden;'>" +
  444. "<div item='baseInforContainer' style='float: left; width : 500px;'>" +
  445. "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='table-layout:fixed;'>" +
  446. //"<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  447. "<tr><td styles='formTableTitle' width='80' lable='calendarId'></td>" +
  448. " <td styles='formTableValue' item='calendarId' colspan='2' width='400'></td>" +
  449. "</tr>" +
  450. "<tr><td styles='formTableTitle' lable='title'></td>" +
  451. " <td styles='formTableValue' item='title' colspan='2'></td></tr>" +
  452. "<tr><td styles='formTableTitle' lable='startDateInput'></td>" +
  453. " <td styles='formTableValue' item='startDateInput' width='" + ( this.editEnable ? "260" : "100" ) + "'></td>" +
  454. " <td styles='formTableValue' item='startTimeInput'></td>" +
  455. "</tr>" +
  456. "<tr><td styles='formTableTitle' lable='endDateInput'></td>" +
  457. " <td styles='formTableValue' item='endDateInput'></td>" +
  458. " <td styles='formTableValue' item='endTimeInput'></td>" +
  459. "</tr>"+
  460. "<tr><td styles='formTableTitle'></td>" +
  461. " <td styles='formTableValue' item='isAllDayEvent' colspan='2'></td>" +
  462. "</tr>"+
  463. "<tr><td styles='formTableTitle' lable='locationName'></td>" +
  464. " <td styles='formTableValue' item='locationName' colspan='2'></td>" +
  465. "</tr>" +
  466. "<tr><td styles='formTableTitle' lable='remind'></td>" +
  467. " <td styles='formTableValue' item='remind' colspan='2'></td>" +
  468. "</tr>" +
  469. "<tr><td styles='formTableTitle' lable='repeat'></td>" +
  470. " <td styles='formTableValue' item='repeat' colspan='2'></td>" +
  471. "</tr>" +
  472. "<tr item='repeatWeekArea' style='display:"+ ( this.data.repeat == RRule["WEEKLY"] ? "" : "none") +";'><td styles='formTableTitle'></td>" +
  473. " <td styles='formTableValue' item='repeatWeek' colspan='2' style='overflow:hidden;'></td>" +
  474. "</tr>" +
  475. "<tr item='repeatUntilArea' style='display:"+ ( (!this.data.repeat || this.data.repeat == "") ? "none" : "") +";'><td styles='formTableTitle'></td>" +
  476. " <td styles='formTableValue' colspan='2' style='overflow: hidden;line-height:34px;'>" +
  477. " <div lable='repeatUntilAvailable' style='float: left;'></div>"+
  478. " <div item='repeatUntilAvailable' style='float: left;'></div>"+
  479. " <div item='repeatUntilDate' style='float: left;width:170px;'></div>"+
  480. " </td>" +
  481. "</tr>" +
  482. "<tr><td styles='formTableTitle'>"+this.lp.color+":</td>" +
  483. " <td styles='formTableValue' item='color' colspan='2' style='overflow: hidden;'></td>" +
  484. "</tr>" +
  485. "</table>"+
  486. "</div>" +
  487. "<div style='float: left; width : 500px;' item='commentContainer'>" +
  488. "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable'>" +
  489. //"<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  490. "<tr><td styles='formTableTitle' ></td>" +
  491. " <td styles='formTableValue' lable='comment' colspan='2'></td>" +
  492. "</tr>" +
  493. "<tr><td styles='formTableTitle' ></td>" +
  494. " <td styles='formTableValue' item='comment' colspan='2'></td>" +
  495. "</tr>" +
  496. //"<tr><td styles='formTableTitle'>"+this.lp.eventDescription+":</td>" +
  497. //" <td styles='formTableValue' item='description' colspan='2'></td></tr>" +
  498. "<tr item='attachmentTr'><td styles='formTableTitle'></td>" +
  499. " <td styles='formTableValue' item='attachment'></td></tr>" +
  500. "</table>"+
  501. "</div>" +
  502. "</div>";
  503. return html;
  504. }else{
  505. return "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable'>" +
  506. //"<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  507. "<tr><td styles='formTableTitle' lable='calendarId'></td>" +
  508. " <td styles='formTableValue' item='calendarId' colspan='2'></td></tr>" +
  509. "<tr><td styles='formTableTitle' lable='title'></td>" +
  510. " <td styles='formTableValue' item='title' colspan='2'></td></tr>" +
  511. "<tr><td styles='formTableTitle' width='100' lable='startDateInput'></td>" +
  512. " <td styles='formTableValue' item='startDateInput' width='300'></td>" +
  513. " <td styles='formTableValue' item='startTimeInput'></td>" +
  514. "</tr>" +
  515. "<tr><td styles='formTableTitle' lable='endDateInput'></td>" +
  516. " <td styles='formTableValue' item='endDateInput'></td>" +
  517. " <td styles='formTableValue' item='endTimeInput'></td>" +
  518. "</tr>" +
  519. "<tr><td styles='formTableTitle'></td>" +
  520. " <td styles='formTableValue' item='isAllDayEvent' colspan='2'></td>" +
  521. "</tr>" +
  522. "<tr><td styles='formTableTitle' lable='remind'></td>" +
  523. " <td styles='formTableValue' item='remind' colspan='2'></td>" +
  524. "</tr>" +
  525. "</table>";
  526. }
  527. },
  528. _setNodesSize : function(width, height, formContentHeight, formTableHeight ){
  529. if( this.options.isFull ){
  530. var baseInforContainer = this.formAreaNode.getElement("[item='baseInforContainer']");
  531. var commentContainer = this.formAreaNode.getElement("[item='commentContainer']");
  532. if(baseInforContainer)baseInforContainer.setStyle("width", (width-100) / 2);
  533. if(commentContainer)commentContainer.setStyle("width", (width-100) / 2)
  534. }
  535. },
  536. getColorByCalendarId : function( calendarId ){
  537. var color;
  538. this.calendarList.each( function( d ){
  539. if( d.id == calendarId ){
  540. color = d.color;
  541. }
  542. }.bind(this));
  543. return color;
  544. },
  545. setColorByCalendarId : function( calendarId ){
  546. var color = this.getColorByCalendarId( calendarId );
  547. if( color ){
  548. this.data.color = color;
  549. this.setColor(color);
  550. }
  551. },
  552. setColor : function( color ){
  553. (this.colorOptions || []).each( function( div ){
  554. if( div.retrieve("color") == color ){
  555. div.click();
  556. }
  557. })
  558. },
  559. loadColor : function(){
  560. if( this.isEdited || this.isNew ){
  561. this.loadColor_Edited();
  562. }else{
  563. this.loadColor_Read();
  564. }
  565. },
  566. loadColor_Read : function(){
  567. if( !this.colorItem )return;
  568. var div = new Element("div", {
  569. styles : this.css.colorNode
  570. }).inject( this.colorItem );
  571. div.setStyle("background-color",this.data.color);
  572. div.setStyles( this.css.colorNode_current );
  573. },
  574. loadColor_Edited : function(){
  575. if( !this.colorItem )return;
  576. this.colorOptions = [];
  577. if( !this.data.color ){
  578. if( this.options.defaultCalendarId ){
  579. this.getColorByCalendarId( this.options.defaultCalendarId );
  580. }else{
  581. this.data.color = this.calendarList[0].color;
  582. }
  583. }
  584. MWFCalendar.ColorOptions.deep.each( function( color , i){
  585. var div = new Element("div", {
  586. styles : this.css.colorNode,
  587. events : {
  588. click : function(ev){
  589. if(this.currentColorNode)this.currentColorNode.setStyles( this.css.colorNode );
  590. ev.target.setStyles( this.css.colorNode_current );
  591. this.currentColorNode = ev.target;
  592. }.bind(this)
  593. }
  594. }).inject( this.colorItem );
  595. div.setStyle("background-color",color);
  596. div.store("color",color);
  597. if( this.data.color ){
  598. if( this.data.color == color ){
  599. div.setStyles( this.css.colorNode_current );
  600. this.currentColorNode = div;
  601. }
  602. }else if(i==0){
  603. div.setStyles( this.css.colorNode_current );
  604. this.currentColorNode = div;
  605. }
  606. this.colorOptions.push( div )
  607. }.bind(this))
  608. },
  609. showWeek : function(){
  610. var area = this.formTableArea.getElement("[item='repeatWeekArea']");
  611. if( !area )return;
  612. area.setStyle("display","");
  613. if( this.isWeekSelectCreated )return;
  614. this.weekItems = [];
  615. var container = this.formTableArea.getElement("[item='repeatWeek']");
  616. var weekDayStyle = this.css.weekDayStyle = {
  617. "border" : "1px solid #ccc",
  618. "border-radius" : "3px",
  619. "height" : "20px",
  620. "line-heigh" : "20px",
  621. "background" : "#f7f7f7",
  622. "color" : "#666",
  623. "padding" : "0px 9px",
  624. "margin-right" : "9px",
  625. "float" : "left",
  626. "font-size" : "12px",
  627. "cursor" : "pointer"
  628. };
  629. var weekDayOnStyle = this.css.weekDayOnStyle = Object.merge( Object.clone(weekDayStyle), {
  630. "border" : "1px solid #3c75b7",
  631. "background" : "#3c75b7",
  632. "color" : "#fff"
  633. });
  634. var repeatWeeks = this.data.repeatWeeks || [ this.lp.weeks.rruleArr[ this.date.getDay() ] ];
  635. for( var i=0; i<7; i++ ){
  636. var rruleWeekString = this.lp.weeks.rruleArr[i];
  637. var isCurrentDay = repeatWeeks.contains( rruleWeekString );
  638. var div = new Element("div",{
  639. styles : isCurrentDay ? weekDayOnStyle : weekDayStyle,
  640. text : this.lp.weeks.arr[i],
  641. events : {
  642. click : function(ev){
  643. this.triggerWeek( ev.target )
  644. }.bind(this)
  645. }
  646. }).inject(container);
  647. if( isCurrentDay ){
  648. if( this.date.getDay() == i ){
  649. this.currrentWeekDayItem = div;
  650. }
  651. div.store("isOn", true);
  652. }
  653. div.store( "weekDay", rruleWeekString );
  654. this.weekItems.push(div);
  655. }
  656. this.isWeekSelectCreated = true;
  657. },
  658. triggerWeek : function(item){
  659. if(item.retrieve("isOn")){
  660. item.store("isOn", false);
  661. item.setStyles( this.css.weekDayStyle )
  662. }else{
  663. item.store("isOn", true);
  664. item.setStyles( this.css.weekDayOnStyle )
  665. }
  666. if( this.getSelectWeek().length==0 ){
  667. this.triggerWeek( this.currrentWeekDayItem );
  668. }
  669. },
  670. getSelectWeek : function(){
  671. if( !this.weekItems )return [];
  672. var weekDay = [];
  673. this.weekItems.each(function(item){
  674. if( item.retrieve("isOn") ){
  675. weekDay.push( item.retrieve("weekDay"));
  676. }
  677. });
  678. return weekDay;
  679. },
  680. isEditable: function(){
  681. if( MWF.AC.isAdministrator() )return true;
  682. if( (this.data.manageablePersonList || []).contains( layout.desktop.session.user.distinguishedName ) )return true;
  683. if( this.data.createPerson === layout.desktop.session.user.distinguishedName )return true;
  684. return false;
  685. },
  686. _createBottomContent : function(){
  687. var editable = this.isEditable( this.data );
  688. var html = "<div style='width:724px;margin:0px auto;'><table width='724' bordr='0' cellpadding='7' cellspacing='0' styles='formTable'>" +
  689. "<tr><td styles='formTableValue' width='80'></td>" +
  690. " <td styles='formTableValue' style='padding-top: 15px;'>"+
  691. " <div item='saveAction' style='float:left;display:"+ (( (editable && this.isEdited) || this.isNew) ? "" : "none") +";'></div>"+
  692. " <div item='editAction' style='float:left;display:"+ ((!editable || (this.isEdited || this.isNew)) ? "none" : "") +";'></div>"+
  693. " <div item='removeAction' style='float:left;display:"+ ( ( editable && this.isEdited ) ? "" : "none") +";'></div>"+
  694. " <div item='cancelAction' style='"+( (editable && (this.isEdited || this.isNew )) ? "float:left;" : "float:left;wdith:100px;")+"'></div>"+
  695. " <div item='moreInfor' style='float: right;margin-top:5px;'></div>"+
  696. " </td></tr>" +
  697. "</table></div>";
  698. this.formBottomNode.set("html", html);
  699. MWF.xDesktop.requireApp("Template", "MForm", function () {
  700. var form = new MForm(this.formBottomNode, {}, {
  701. isEdited: this.isEdited || this.isNew,
  702. style : "meeting",
  703. hasColon : true,
  704. itemTemplate: {
  705. moreInfor : {
  706. type : "a", value : this.lp.editMore, clazz : "mainColor_color", event : {
  707. click : function(){ this.openMoreInfor() }.bind(this)
  708. }, disable : this.options.isFull
  709. },
  710. saveAction : { type : "button", className : "inputOkButton", clazz : "mainColor_bg", value : this.lp.save, event : {
  711. click : function(){ this.save();}.bind(this)
  712. } },
  713. removeAction : { type : "button", className : "inputCancelButton", value : this.lp.cancelEvent , event : {
  714. click : function( item, ev ){ this.cancelEvent(ev); }.bind(this)
  715. } },
  716. editAction : { type : "button", className : "inputOkButton", clazz : "mainColor_bg", value : this.lp.editEvent , event : {
  717. click : function(){ this.editEvent(); }.bind(this)
  718. } },
  719. cancelAction : { type : "button", className : "inputCancelButton", value : this.lp.close , event : {
  720. click : function(){ this.close(); }.bind(this)
  721. } }
  722. }
  723. }, this.app);
  724. form.load();
  725. }.bind(this), true);
  726. },
  727. openMoreInfor : function(){
  728. this.options.isFull = true;
  729. this.options.width = "1100";
  730. this.options.height = "620";
  731. this.isWeekSelectCreated = false;
  732. this.reload( true );
  733. },
  734. getString : function( str ){
  735. var s = "00" + str;
  736. return s.substr(s.length - 2, 2 );
  737. },
  738. getEventData : function( callback ){
  739. if( this.data && this.data.id ){
  740. this.app.actions.getEvent( this.data.id, function( json ){
  741. this.data = json.data;
  742. if(callback)callback();
  743. }.bind(this))
  744. }else{
  745. if(callback)callback();
  746. }
  747. },
  748. editEvent : function(){
  749. this.isWeekSelectCreated = false;
  750. this.formTopNode = null;
  751. if(this.setFormNodeSizeFun && this.app && this.app.removeEvent ){
  752. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  753. }
  754. if( this.formMaskNode )this.formMaskNode.destroy();
  755. this.formAreaNode.destroy();
  756. this.edit();
  757. },
  758. reset: function(){
  759. this.formTableArea.empty();
  760. this._createTableContent();
  761. },
  762. loadAttachment: function(){
  763. if(!this.attachmentTr)return;
  764. this.attachmentTr.setStyle("display","");
  765. this.attachmentNode = new Element("div", {"styles": this.css.createEventAttachmentNode}).inject(this.attachmentArea);
  766. var attachmentContentNode = new Element("div", {"styles": this.css.createEventAttachmentContentNode}).inject(this.attachmentNode);
  767. MWF.require("MWF.widget.AttachmentController", function(){
  768. this.attachmentController = new MWF.widget.AttachmentController(attachmentContentNode, this, {
  769. "size": "min",
  770. "isSizeChange": false,
  771. "isReplace": false,
  772. "isUpload": this.isNew || this.isEdited,
  773. "isDelete": this.isNew || this.isEdited,
  774. "isDownload": true,
  775. "readonly": !this.isNew && !this.isEdited
  776. });
  777. this.attachmentController.load();
  778. if( this.data.attachmentList ){
  779. this.data.attachmentList.each(function (att) {
  780. att.person = att.lastUpdatePerson.split("@")[0];
  781. var at = this.attachmentController.addAttachment(att);
  782. }.bind(this));
  783. }
  784. }.bind(this));
  785. },
  786. uploadAttachment: function(e, node){
  787. if (!this.uploadFileAreaNode){
  788. this.createUploadFileNode();
  789. }
  790. this.fileUploadNode.click();
  791. },
  792. createUploadFileNode: function(){
  793. this.uploadFileAreaNode = new Element("div");
  794. var html = "<input name=\"file\" type=\"file\" multiple/>";
  795. this.uploadFileAreaNode.set("html", html);
  796. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  797. this.fileUploadNode.addEvent("change", function(){
  798. var files = this.fileUploadNode.files;
  799. if (files.length){
  800. for (var i = 0; i < files.length; i++) {
  801. var file = files.item(i);
  802. var formData = new FormData();
  803. formData.append('file', file);
  804. //formData.append('folder', folderId);
  805. this.app.actions.addAttachment(function(o, text){
  806. if (o.id){
  807. this.app.actions.getAttachment(o.id, function(json){
  808. if (json.data) this.attachmentController.addAttachment(json.data);
  809. this.attachmentController.checkActions();
  810. }.bind(this))
  811. }
  812. this.attachmentController.checkActions();
  813. }.bind(this), null, formData, this.data.id, file);
  814. }
  815. }
  816. }.bind(this));
  817. },
  818. deleteAttachments: function(e, node, attachments){
  819. var names = [];
  820. attachments.each(function(attachment){
  821. names.push(attachment.data.name);
  822. }.bind(this));
  823. var _self = this;
  824. var confirm = ( this.app && this.app.confirm ) ? this.app.confirm : MWF.xDesktop.confirm;
  825. confirm("warn", e, this.lp.deleteAttachmentTitle, this.lp.deleteAttachment+"( "+names.join(", ")+" )", 300, 120, function(){
  826. while (attachments.length){
  827. attachment = attachments.shift();
  828. _self.deleteAttachment(attachment);
  829. }
  830. this.close();
  831. }, function(){
  832. this.close();
  833. }, null);
  834. },
  835. deleteAttachment: function(attachment){
  836. this.app.actions.deleteFile(attachment.data.id, function(josn){
  837. this.attachmentController.removeAttachment(attachment);
  838. this.attachmentController.checkActions();
  839. }.bind(this));
  840. },
  841. downloadAttachment: function(e, node, attachments){
  842. attachments.each(function(att){
  843. this.app.actions.getFileDownload(att.data.id);
  844. }.bind(this));
  845. },
  846. openAttachment: function(e, node, attachments){
  847. attachments.each(function(att){
  848. this.app.actions.getFile(att.data.id);
  849. }.bind(this));
  850. },
  851. getAttachmentUrl: function(attachment, callback){
  852. this.app.actions.getFileUrl(attachment.data.id, callback);
  853. },
  854. cancelEvent: function(e){
  855. var _self = this;
  856. var data = this.data;
  857. var postDelete = function(){
  858. if(this.view)this.view.reload();
  859. this.close();
  860. }.bind(this);
  861. if( this.oldRecurrenceRule ) { //如果是原来是重复的
  862. this.openDeleteOptionForm( function( saveOptions ){
  863. if( saveOptions == "single" ){
  864. this.app.actions.deleteSingleEvent(data.id, function(json){ postDelete(json); }.bind(this));
  865. }else if( saveOptions == "after" ){
  866. this.app.actions.deleteAfterEvent(data.id, function(json){ postDelete(json); }.bind(this));
  867. }else if( saveOptions == "all" ){
  868. this.app.actions.deleteAllEventsWithRepeatMaster(data.id, function(json){ postDelete(json); }.bind(this));
  869. }
  870. }.bind(this))
  871. }else if( data.id ){ //编辑
  872. var text = this.app.lp.cancel_confirm.replace(/{name}/g, this.data.title);
  873. var confirm = MWF.xDesktop.confirm; //( this.app && this.app.confirm ) ? this.app.confirm : MWF.xDesktop.confirm;
  874. confirm("infor", e, this.app.lp.cancel_confirm_title, text, 380, 200, function(){
  875. _self._cancelEvent();
  876. this.close();
  877. }, function(){
  878. this.close();
  879. });
  880. }
  881. },
  882. _cancelEvent: function(){
  883. var view = this.view;
  884. this.app.actions.deleteSingleEvent(this.data.id, function(){
  885. if(view)view.reload();
  886. this.close();
  887. }.bind(this))
  888. },
  889. openDeleteOptionForm : function( callback ){
  890. this.deleteOptionsForm = new MWFCalendar.DeleteOptionDialog( this, {}, {
  891. onPostOk : function( saveOptions ){
  892. if(callback){
  893. callback(saveOptions)
  894. }
  895. }.bind(this)
  896. }, {});
  897. this.deleteOptionsForm.edit();
  898. },
  899. save: function(){
  900. this._save(function(){
  901. if( this.app && this.app.notice ){
  902. this.app.notice(this.lp.event_saveSuccess, "success");
  903. }else{
  904. MWF.xDesktop.notice("ok", {"x": "right", "y": "top"}, this.lp.event_saveSuccess, $(document.body))
  905. }
  906. this.close();
  907. //if (!this.attachmentNode){
  908. // this.loadAttachment();
  909. //}
  910. }.bind(this));
  911. },
  912. _save: function(callback){
  913. var data = this.getSaveData();
  914. if( !data )return;
  915. var errorText = "";
  916. if (!data.title) errorText +=this.lp.event_input_subject_error;
  917. if( data.startTime ){
  918. if ( (Date.parse(data.startTime) - Date.parse(data.endTime)) > 0) errorText +=this.lp.event_input_time_error;
  919. //if (now.diff(this.data.startTime, "minute")<0) errorText +=this.lp.event_input_date_error;
  920. //
  921. //delete this.data.startTimeDate;
  922. //delete this.data.completedTimeDate;
  923. }
  924. if (errorText){
  925. if( this.app && this.app.notice ){
  926. this.app.notice(this.lp.event_input_error+errorText, "error");
  927. }else{
  928. MWF.xDesktop.notice("error", {"x": "right", "y": "top"}, this.lp.event_input_error+errorText, $(document.body));
  929. }
  930. return false;
  931. }
  932. var postSave = function( json ){
  933. this.data.id = json.data.id;
  934. this.oldRecurrenceRule = data.recurrenceRule;
  935. this.waitReload = true;
  936. if (callback) callback();
  937. }.bind(this);
  938. this.data = data;
  939. if( this.oldRecurrenceRule ) { //如果是原来是重复的
  940. this.openSaveOptionForm( function( saveOptions ){
  941. if( saveOptions == "single" ){
  942. this.app.actions.updateSingleEvent(data.id, this.data, function(json){ postSave(json); }.bind(this));
  943. }else if( saveOptions == "after" ){
  944. this.app.actions.updateAfterEvent(data.id, this.data, function(json){ postSave(json); }.bind(this));
  945. }else if( saveOptions == "all" ){
  946. this.app.actions.updateAllEventsWithRepeatMaster(data.id, this.data, function(json){ postSave(json); }.bind(this));
  947. }
  948. }.bind(this))
  949. }else if( data.id ){ //编辑
  950. this.app.actions.updateSingleEvent(data.id, this.data, function(json){ postSave(json); }.bind(this));
  951. }else{ //新增
  952. this.app.actions.addEvent(this.data, function(json){ postSave(json); }.bind(this));
  953. }
  954. },
  955. openSaveOptionForm : function( callback ){
  956. this.saveOptionsForm = new MWFCalendar.SaveOptionDialog( this, {}, {
  957. onPostOk : function( saveOptions ){
  958. if(callback){
  959. callback(saveOptions)
  960. }
  961. }.bind(this)
  962. }, {});
  963. this.saveOptionsForm.edit();
  964. },
  965. getSaveData: function(){
  966. var data = this.form.getResult(true,"",true,false,true);
  967. if( !data )return null;
  968. if( data ){
  969. data.isAllDayEvent = typeOf( data.isAllDayEvent ) == "array" ? data.isAllDayEvent.join("") : data.isAllDayEvent;
  970. if( data.isAllDayEvent == "true"){
  971. data.startTime = this.data.startDateInput + " " + "00:00:00";
  972. data.endTime = this.data.endDateInput + " " + "23:59:59";
  973. }else{
  974. data.startTime = this.data.startDateInput + " " + this.data.startTimeInput + ":00";
  975. data.endTime = this.data.endDateInput + " " + this.data.endTimeInput + ":00";
  976. }
  977. data.recurrenceRule = this.getRRuleString( data );
  978. if( data.remind ){
  979. var valarmTime_config = [0,0,0,0];
  980. var r = data.remind.split("_");
  981. var n = parseInt( r[0] );
  982. if( r[1] == "d" ){
  983. valarmTime_config[0] = n;
  984. }else if( r[1] == "h" ){
  985. valarmTime_config[1] = n;
  986. }else if( r[1] == "m" ){
  987. valarmTime_config[2] = n;
  988. }else if( r[1] == "s" ){
  989. valarmTime_config[3] = n;
  990. }
  991. data.valarmTime_config = valarmTime_config.join(",");
  992. }
  993. if( !data.calendarId ){
  994. data.calendarId = this.app.currentCalendarData.id;
  995. }
  996. if( this.currentColorNode ){
  997. data.color = this.currentColorNode.retrieve("color");
  998. }else if( data.calendarId ){
  999. data.color = this.getColorByCalendarId(data.calendarId);
  1000. }else{
  1001. data.color = MWFCalendar.ColorOptions.deep[0];
  1002. }
  1003. delete data.range;
  1004. }
  1005. return data;
  1006. },
  1007. close: function (e) {
  1008. this.fireEvent("queryClose");
  1009. this._close();
  1010. //if( this.form ){
  1011. // this.form.destroy();
  1012. //}
  1013. if(this.setFormNodeSizeFun && this.app && this.app.removeEvent ){
  1014. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  1015. }
  1016. if( this.formMaskNode )this.formMaskNode.destroy();
  1017. this.formAreaNode.destroy();
  1018. this.fireEvent("postClose");
  1019. if( this.waitReload && this.view)this.view.reload();
  1020. delete this;
  1021. },
  1022. getAttrRegExp: function( attr ){
  1023. return "\\s+" + attr + "\\s*=\\s*[\"|\'](.*?)[\"|\']";
  1024. },
  1025. getAttributeValue: function(str, attribute){
  1026. var regexp = new RegExp( this.getAttrRegExp(attribute) , "i");
  1027. var array = str.match( regexp );
  1028. return (o2.typeOf(array) === "array" && array.length === 2) ? array[1] : "";
  1029. },
  1030. addAttribute: function(str, attribute, value){
  1031. var regexp = new RegExp( "\\/*\\s*>" , "i");
  1032. return str.replace( regexp, ' ' + attribute + '="' + value + '"' + " />");
  1033. },
  1034. removeAttribute: function(str, attribute){
  1035. var regexp = new RegExp( this.getAttrRegExp(attribute) , "ig");
  1036. return str.replace( regexp, "" );
  1037. },
  1038. parseHtml: function(html){
  1039. html = this.replaceHrefJavascriptStr(html);
  1040. html = this.replaceOnAttribute(html);
  1041. return html;
  1042. },
  1043. replaceOnAttribute: function (htmlString){
  1044. var tempDiv = document.createElement('div');
  1045. tempDiv.innerHTML = htmlString;
  1046. var elements = tempDiv.getElementsByTagName('*');
  1047. for (var i = 0; i < elements.length; i++) {
  1048. var element = elements[i];
  1049. var attributeNames = element.getAttributeNames();
  1050. for (var j = 0; j < attributeNames.length; j++) {
  1051. var attributeName = attributeNames[j];
  1052. if (attributeName.substr(0,2).toLowerCase() === 'on') {
  1053. element.removeAttribute(attributeName);
  1054. }
  1055. }
  1056. }
  1057. return tempDiv.innerHTML;
  1058. },
  1059. replaceHrefJavascriptStr: function( html ){
  1060. debugger;
  1061. var regexp_a_all = /(i?)(<a)([^>]+>)/gmi;
  1062. var as = html.match(regexp_a_all);
  1063. if(as){
  1064. if (as.length){
  1065. for (var i=0; i<as.length; i++){
  1066. var a = as[i];
  1067. var href = this.getAttributeValue(a, "href");
  1068. if( href.indexOf('javascript:') > -1 ){
  1069. var a1 = this.removeAttribute(a, "href");
  1070. html = html.replace(a, a1);
  1071. }
  1072. }
  1073. }
  1074. }
  1075. return html;
  1076. }
  1077. });
  1078. MWFCalendar.CalendarForm = new Class({
  1079. Extends: MPopupForm,
  1080. Implements: [Options, Events],
  1081. options: {
  1082. "style": "meeting",
  1083. "okClass": "mainColor_bg",
  1084. "width": "800",
  1085. "height": "500",
  1086. "hasTop": true,
  1087. "hasIcon": false,
  1088. "hasTopIcon" : false,
  1089. "hasTopContent" : false,
  1090. "draggable": true,
  1091. "maxAction" : true,
  1092. "resizeable" : true,
  1093. "closeAction": true,
  1094. "resultSeparator" : null
  1095. },
  1096. _createTableContent: function () {
  1097. var data = this.data;
  1098. var editEnable = this.editEnable = ( !this.isEdited && !this.isNew && this.data.manageable );
  1099. this.userName = ( layout.desktop.session.user || layout.user ).distinguishedName;
  1100. this.userId = ( layout.desktop.session.user || layout.user ).id;
  1101. if( data.type == "UNIT" ){
  1102. this.options.height = "650"
  1103. }
  1104. if( this.isNew ){
  1105. this.formTopTextNode.set( "text", this.lp.createCalendar );
  1106. }else if( this.isEdited ){
  1107. this.formTopTextNode.set( "text", this.lp.editCalendar );
  1108. }else{
  1109. this.formTopTextNode.set( "text", this.lp.calendar );
  1110. }
  1111. this.formTableArea.set("html", this.getHtml());
  1112. this.formTableContainer.setStyle("width","80%");
  1113. this.colorItem = this.formTableArea.getElement("[item='color']");
  1114. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1115. this.form = new MForm(this.formTableArea, data, {
  1116. isEdited: this.isEdited || this.isNew,
  1117. style : "meeting",
  1118. hasColon : true,
  1119. itemTemplate: {
  1120. name: { text : this.lp.calendarName, notEmpty : true },
  1121. description: {text : this.lp.description, type: "textarea"},
  1122. type : { text : this.lp.type, type : "select", isEdited : this.isNew,
  1123. selectValue : ["PERSON", "UNIT"],
  1124. selectText : this.lp.canlendarTypeArr,
  1125. defaultValue : "PERSON",
  1126. event : {
  1127. change : function(item){
  1128. this.changeType( item.getValue() )
  1129. }.bind(this)
  1130. }
  1131. },
  1132. target : { text : this.lp.unit, type : "org", orgType : "unit", validRule : { empty : function( value, item){
  1133. if( item.form.getItem("type").getValue() == "UNIT" && value == ""){ return false }else{ return true };
  1134. }}, validMessage : { empty : this.lp.unitEmptyNotice } },
  1135. isPublic : { text : this.lp.isOpened, type : "select", selectValue : ["true","false"], selectText : this.lp.trueFalseArr, defaultValue : "false" },
  1136. status : { text : this.lp.isAvaliable, type : "radio", selectValue : ["OPEN","CLOSE"], selectText : this.lp.trueFalseArr, defaultValue : "OPEN" },
  1137. manageablePersonList : { text : this.lp.manager, type : "org", orgType : "person", count : 0},
  1138. viewerList : { text : this.lp.viewerRange, type : "org", orgType : ["person","unit","group"], count : 0, value : function(){
  1139. return ( data.viewablePersonList || [] ).combine( data.viewableUnitList || [] ).combine( data.viewableGroupList || [] )
  1140. }.bind(this)},
  1141. publisherList : { text : this.lp.publisherRange, type : "org", orgType : ["person","unit","group"], count : 0, value : function(){
  1142. return ( data.publishablePersonList || [] ).combine( data.publishableUnitList || [] ).combine( data.publishableGroupList || [] )
  1143. }.bind(this)}
  1144. }
  1145. }, this.app);
  1146. this.form.load();
  1147. this.loadColor();
  1148. //this.loadPermission();
  1149. }.bind(this), true);
  1150. },
  1151. getHtml : function(){
  1152. var boxStyle = (this.isEdited || this.isNew) ? "border:1px solid #ccc; border-radius: 4px;overflow: hidden;padding:8px;" : "";
  1153. var targetStyle = this.data.type != "UNIT" ? "style='display:none'" : "";
  1154. var permissionStyle = this.data.type != "UNIT" ? "style='display:none'" : "";
  1155. return "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='table-layout:fixed;'>" +
  1156. "<tr><td styles='formTableTitle' width='80' lable='name'></td>" +
  1157. " <td styles='formTableValue' item='name' width='400' colspan='3'></td></tr>" +
  1158. "<tr><td styles='formTableTitle'>"+this.lp.color+":</td>" +
  1159. " <td styles='formTableValue' item='color' style='overflow: hidden;' colspan='3'></td></tr>" +
  1160. "<tr><td styles='formTableTitle' lable='type' width='80'></td>" +
  1161. " <td styles='formTableValue' item='type'></td>" +
  1162. " <td styles='formTableTitleRight' lable='isPublic' width='50'></td>" +
  1163. " <td styles='formTableValue' item='isPublic'></td></tr>" +
  1164. "<tr><td styles='formTableTitle' lable='description'></td>" +
  1165. " <td styles='formTableValue' item='description' colspan='3'></td></tr>" +
  1166. "<tr "+targetStyle+"><td styles='formTableTitle' lable='target'></td>" +
  1167. " <td styles='formTableValue' item='target' colspan='3'></td></tr>" +
  1168. "<tr "+permissionStyle+"><td styles='formTableTitle' lable='manageablePersonList'></td>" +
  1169. " <td styles='formTableValue' item='manageablePersonList' colspan='3'></td></tr>" +
  1170. "<tr "+permissionStyle+"><td styles='formTableTitle' lable='viewerList'></td>" +
  1171. " <td styles='formTableValue' item='viewerList' colspan='3'></td></tr>" +
  1172. "<tr "+permissionStyle+"><td styles='formTableTitle' lable='publisherList'></td>" +
  1173. " <td styles='formTableValue' item='publisherList' colspan='3'></td></tr>" +
  1174. "</tr>" +
  1175. "<tr><td styles='formTableTitle' lable='status'></td>" +
  1176. " <td styles='formTableValue' item='status' colspan='3'></td></tr>" +
  1177. "</table>"
  1178. },
  1179. changeType : function( type ){
  1180. var changeItemName = ["target","manageablePersonList","viewerList","publisherList"];
  1181. changeItemName.each( function(name){
  1182. this.formTableArea.getElement("[item='"+name+"']").getParent().setStyle("display",type == "UNIT" ? "" : "none");
  1183. }.bind(this));
  1184. this.options.height = type == "UNIT" ? "650" : "500";
  1185. this.setFormNodeSize();
  1186. },
  1187. loadColor : function(){
  1188. if( this.isEdited || this.isNew ){
  1189. this.loadColor_Edited();
  1190. }else{
  1191. this.loadColor_Read();
  1192. }
  1193. },
  1194. loadColor_Read : function(){
  1195. if( !this.colorItem )return;
  1196. var div = new Element("div", {
  1197. styles : this.css.colorNode
  1198. }).inject( this.colorItem );
  1199. div.setStyle("background-color",this.data.color);
  1200. div.setStyles( this.css.colorNode_current );
  1201. },
  1202. loadColor_Edited : function(){
  1203. if( !this.colorItem )return;
  1204. this.colorOptions = [];
  1205. MWFCalendar.ColorOptions.deep.each( function( color , i){
  1206. var div = new Element("div", {
  1207. styles : this.css.colorNode,
  1208. events : {
  1209. click : function(ev){
  1210. if(this.currentColorNode)this.currentColorNode.setStyles( this.css.colorNode );
  1211. ev.target.setStyles( this.css.colorNode_current );
  1212. this.currentColorNode = ev.target;
  1213. }.bind(this)
  1214. }
  1215. }).inject( this.colorItem );
  1216. div.setStyle("background-color",color);
  1217. div.store("color",color);
  1218. if( this.data.color ){
  1219. if( this.data.color == color ){
  1220. div.setStyles( this.css.colorNode_current );
  1221. this.currentColorNode = div;
  1222. }
  1223. }else if(i==0){
  1224. div.setStyles( this.css.colorNode_current );
  1225. this.currentColorNode = div;
  1226. }
  1227. this.colorOptions.push( div )
  1228. }.bind(this))
  1229. },
  1230. _createBottomContent : function(){
  1231. var html = "<div style='width:724px;margin:0px auto;'><table width='724' bordr='0' cellpadding='7' cellspacing='0' styles='formTable'>" +
  1232. "<tr><td styles='formTableValue' width='80'></td>" +
  1233. " <td styles='formTableValue' style='padding-top: 15px;'>"+
  1234. " <div item='saveAction' style='float:left;display:"+ ( (this.isEdited || this.isNew) ? "" : "none") +";'></div>"+
  1235. " <div item='editAction' style='float:left;display:"+ ( this.editEnable ? "" : "none") +";'></div>"+
  1236. " <div item='removeAction' style='float:left;display:"+ ( this.isEdited ? "" : "none") +";'></div>"+
  1237. " <div item='cancelAction' style='"+( (this.isEdited || this.isNew || this.editEnable) ? "float:left;" : "float:right;margin-right:15px;")+"'></div>"+
  1238. " </td></tr>" +
  1239. "</table></div>";
  1240. this.formBottomNode.set("html", html);
  1241. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1242. var form = new MForm(this.formBottomNode, {}, {
  1243. isEdited: this.isEdited || this.isNew,
  1244. style : "meeting",
  1245. hasColon : true,
  1246. itemTemplate: {
  1247. saveAction : { type : "button", className : "inputOkButton", clazz : "mainColor_bg", value : this.lp.save, event : {
  1248. click : function(){ this.ok();}.bind(this)
  1249. } },
  1250. removeAction : { type : "button", className : "inputCancelButton", value : this.lp.deleteCalendar , event : {
  1251. click : function( item, ev ){ this.deleteCalendar(ev); }.bind(this)
  1252. } },
  1253. editAction : { type : "button", className : "inputOkButton", clazz : "mainColor_bg", value : this.lp.editCalendar , event : {
  1254. click : function(){ this.editCalendar(); }.bind(this)
  1255. } },
  1256. cancelAction : { type : "button", className : "inputCancelButton", value : this.lp.close , event : {
  1257. click : function(){ this.close(); }.bind(this)
  1258. } }
  1259. }
  1260. }, this.app);
  1261. form.load();
  1262. }.bind(this), true);
  1263. },
  1264. deleteCalendar : function( e ){
  1265. var _self = this;
  1266. _self.app.confirm("warn", e, _self.lp.deleteCalendarTitle, _self.lp.deleteCalendarContent.replace("{name}", _self.data.name), 300, 120, function(){
  1267. _self.app.actions.deleteCalendar( _self.data.id, function( json ){
  1268. _self.close();
  1269. _self.app.notice( _self.lp.deleteSuccess );
  1270. _self.app.leftNavi.reload();
  1271. }.bind(this));
  1272. this.close();
  1273. }, function(){
  1274. this.close();
  1275. }, null);
  1276. },
  1277. editCalendar : function(){
  1278. this.formTopNode = null;
  1279. if(this.setFormNodeSizeFun && this.app && this.app.removeEvent ){
  1280. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  1281. }
  1282. if( this.formMaskNode )this.formMaskNode.destroy();
  1283. this.formAreaNode.destroy();
  1284. this.edit();
  1285. },
  1286. reset: function(){
  1287. this.formTableArea.empty();
  1288. this._createTableContent();
  1289. },
  1290. _ok : function( data, callback ){
  1291. if( data.type == "UNIT" ){
  1292. var viewerItem = this.form.getItem("viewerList").dom;
  1293. data.viewablePersonList = viewerItem.getValueByType("person");
  1294. data.viewableUnitList = viewerItem.getValueByType("unit");
  1295. data.viewableGroupList = viewerItem.getValueByType("group");
  1296. var publisherItem = this.form.getItem("publisherList").dom;
  1297. data.publishablePersonList = publisherItem.getValueByType("person");
  1298. data.publishableUnitList = publisherItem.getValueByType("unit");
  1299. data.publishableGroupList = publisherItem.getValueByType("group");
  1300. data.target = data.target.join("");
  1301. }else{
  1302. data.target = this.userName;
  1303. ["manageablePersonList","viewablePersonList","publishablePersonList"].each( function( name ){
  1304. data[name] = [ this.userName ];
  1305. }.bind(this));
  1306. ["viewableUnitList","viewableGroupList","publishableUnitList","publishableGroupList"].each( function( name ){
  1307. data[name] = [];
  1308. });
  1309. }
  1310. if( this.currentColorNode ){
  1311. data.color = this.currentColorNode.retrieve("color");
  1312. }else{
  1313. data.color = MWFCalendar.ColorOptions.deep[0];
  1314. }
  1315. delete data.viewerList;
  1316. delete data.publisherList;
  1317. this.app.actions.saveCalendar(data, function(json){
  1318. if( this.view )this.view.reload();
  1319. callback(json);
  1320. }.bind(this));
  1321. },
  1322. close: function (e) {
  1323. this.fireEvent("queryClose");
  1324. this._close();
  1325. //if( this.form ){
  1326. // this.form.destroy();
  1327. //}
  1328. if(this.setFormNodeSizeFun && this.app && this.app.removeEvent){
  1329. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  1330. }
  1331. if( this.formMaskNode )this.formMaskNode.destroy();
  1332. this.formAreaNode.destroy();
  1333. this.fireEvent("postClose");
  1334. if( this.waitReload && this.view)this.view.reload();
  1335. delete this;
  1336. }
  1337. });
  1338. MWFCalendar.SaveOptionDialog = new Class({
  1339. Extends: MPopupForm,
  1340. Implements: [Options, Events],
  1341. options: {
  1342. "style": "meeting",
  1343. "okClass": "mainColor_bg",
  1344. "width": "470",
  1345. "height": "325",
  1346. "hasTop": true,
  1347. "hasIcon": false,
  1348. "hasTopIcon" : false,
  1349. "hasTopContent" : false,
  1350. "draggable": true,
  1351. //"maxAction" : true,
  1352. "closeAction": true,
  1353. "title" : MWF.xApplication.Calendar.LP.saveOptionDialogTitle
  1354. },
  1355. _createTableContent : function(){
  1356. this.formTableContainer.setStyles({
  1357. "width" : "auto",
  1358. "padding-top" : "20px",
  1359. "padding-left" : "40px"
  1360. });
  1361. var lp = MWF.xApplication.Calendar.LP;
  1362. this.lp = { ok : lp.modifyConfirm, cancel : lp.cancel };
  1363. var html = "<table width='80%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1364. //"<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  1365. "<tr><td styles='formTableTitle' lable='saveOption'></td>" +
  1366. "<tr><td styles='formTableValue' item='saveOption'></td></tr>" +
  1367. "</table>";
  1368. this.formTableArea.set("html", html);
  1369. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1370. this.form = new MForm(this.formTableArea, {empName: "xadmin"}, {
  1371. style : "meeting",
  1372. isEdited: this.isEdited || this.isNew,
  1373. itemTemplate: {
  1374. saveOption: {
  1375. defaultValue : "single",
  1376. text: lp.selectModifyCalendarTypeNotice,
  1377. type: "radio",
  1378. selectText: lp.calendarModifyTypeArr,
  1379. selectValue: ["single", "after", "all"]
  1380. }
  1381. }
  1382. }, this.app);
  1383. this.form.load();
  1384. }.bind(this), true);
  1385. },
  1386. ok: function (e) {
  1387. this.fireEvent("queryOk");
  1388. var data = this.form.getResult(true, this.options.resultSeparator, true, false, true);
  1389. if (data) {
  1390. if( this.formMaskNode )this.formMaskNode.destroy();
  1391. this.formAreaNode.destroy();
  1392. this.fireEvent("postOk", data.saveOption );
  1393. }
  1394. }
  1395. });
  1396. MWFCalendar.DeleteOptionDialog = new Class({
  1397. Extends: MPopupForm,
  1398. Implements: [Options, Events],
  1399. options: {
  1400. "style": "meeting",
  1401. "okClass": "mainColor_bg",
  1402. "width": "470",
  1403. "height": "325",
  1404. "hasTop": true,
  1405. "hasIcon": false,
  1406. "hasTopIcon" : false,
  1407. "hasTopContent" : false,
  1408. "draggable": true,
  1409. //"maxAction" : true,
  1410. "closeAction": true,
  1411. "title" : MWF.xApplication.Calendar.LP.deleteOptionDialogTitle
  1412. },
  1413. _createTableContent : function(){
  1414. this.formTableContainer.setStyles({
  1415. "width" : "auto",
  1416. "padding-top" : "20px",
  1417. "padding-left" : "40px"
  1418. });
  1419. var lp = MWF.xApplication.Calendar.LP;
  1420. this.lp = { ok : lp.modifyConfirm, cancel : lp.cancel };
  1421. var html = "<table width='80%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1422. //"<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  1423. "<tr><td styles='formTableTitle' lable='saveOption'></td>" +
  1424. "<tr><td styles='formTableValue' item='saveOption'></td></tr>" +
  1425. "</table>";
  1426. this.formTableArea.set("html", html);
  1427. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1428. this.form = new MForm(this.formTableArea, {empName: "xadmin"}, {
  1429. isEdited: this.isEdited || this.isNew,
  1430. style : "meeting",
  1431. itemTemplate: {
  1432. saveOption: {
  1433. defaultValue : "single",
  1434. text: lp.selectDeleteCalendarTypeNotice,
  1435. type: "radio",
  1436. selectText: lp.calendarDeleteTypeArr,
  1437. selectValue: ["single", "after", "all"]
  1438. }
  1439. }
  1440. }, this.app);
  1441. this.form.load();
  1442. }.bind(this), true);
  1443. },
  1444. ok: function (e) {
  1445. this.fireEvent("queryOk");
  1446. var data = this.form.getResult(true, this.options.resultSeparator, true, false, true);
  1447. if (data) {
  1448. if( this.formMaskNode )this.formMaskNode.destroy();
  1449. this.formAreaNode.destroy();
  1450. this.fireEvent("postOk", data.saveOption );
  1451. }
  1452. }
  1453. });
  1454. MWFCalendar.EventTooltip = new Class({
  1455. Extends: MTooltips,
  1456. options : {
  1457. displayDelay : 300
  1458. },
  1459. _loadCustom : function( callback ){
  1460. this.loadAttachment();
  1461. this.loadButton();
  1462. if(callback)callback();
  1463. },
  1464. _getHtml : function(){
  1465. var titleStyle = "font-size:14px;color:#333";
  1466. var valueStyle = "font-size:14px;color:#666;padding-right:10px";
  1467. var data = this.data;
  1468. var html =
  1469. "<div style='font-size: 16px;color:#333;padding:10px 10px 10px 20px;'>"+ o2.common.encodeHtml(data.title) +"</div>"+
  1470. "<div style='height:1px;margin:0px 20px;border-bottom:1px solid #ccc;'></div>"+
  1471. "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' style='margin:13px 13px 13px 13px;'>" +
  1472. "<tr><td style='"+titleStyle+";' width='40'>"+this.lp.begin+":</td>" +
  1473. " <td style='"+valueStyle+"' item='begin'></td></tr>" +
  1474. "<tr><td style='"+titleStyle+"'>"+this.lp.end+":</td>" +
  1475. " <td style='"+valueStyle+ "' item='end'></td></tr>" +
  1476. "<tr><td style='"+titleStyle+"'>"+this.lp.locationName+":</td>" +
  1477. " <td style='"+valueStyle+ "' item='locationName'></td></tr>" +
  1478. //( this.options.isHideAttachment ? "" :
  1479. //"<tr><td style='"+titleStyle+"'>"+this.lp.eventAttachment+":</td>" +
  1480. //" <td style='"+valueStyle+"' item='attachment'></td></tr>"+
  1481. //)+
  1482. "<tr><td style='"+titleStyle+"'></td>" +
  1483. " <td style='"+valueStyle+ "' item='seeMore'></td></tr>"+
  1484. "</table>";
  1485. return html;
  1486. },
  1487. _customNode : function( node, contentNode ){
  1488. var data = this.data;
  1489. var beginD = Date.parse(this.data.startTime);
  1490. var endD = Date.parse(this.data.endTime);
  1491. var begin = beginD.format(this.lp.dateFormatAll) + "(" + this.lp.weeks.arr[beginD.get("day")] + ")";
  1492. var end = endD.format(this.lp.dateFormatAll) + "(" + this.lp.weeks.arr[endD.get("day")] + ")";
  1493. contentNode.getElement("[item='begin']").set("text", begin );
  1494. contentNode.getElement("[item='end']").set("text", end );
  1495. contentNode.getElement("[item='locationName']").set("text", (this.data.locationName||"") );
  1496. this.fireEvent("customContent", [contentNode, node])
  1497. },
  1498. destroy: function(){
  1499. if( this.node ){
  1500. this.node.destroy();
  1501. this.node = null;
  1502. }
  1503. },
  1504. isEditable: function(){
  1505. if( MWF.AC.isAdministrator() )return true;
  1506. if( (this.data.manageablePersonList || []).contains( layout.desktop.session.user.distinguishedName ) )return true;
  1507. if( this.data.createPerson === layout.desktop.session.user.distinguishedName )return true;
  1508. return false;
  1509. },
  1510. loadButton : function(){
  1511. var area = this.node.getElement("[item='seeMore']");
  1512. new Element("div",{
  1513. styles : {
  1514. "background-color" : "#3c75b7",
  1515. "height" : "28px",
  1516. "line-height" : "28px",
  1517. "border-radius" : "5px",
  1518. "width" : "80px",
  1519. "text-align" : "center",
  1520. "font-size" : "12px",
  1521. "cursor" : "pointer",
  1522. "color" : "#fff"
  1523. },
  1524. class: "mainColor_bg",
  1525. events : { click : function() {
  1526. debugger;
  1527. var form = new MWFCalendar.EventForm(this, this.data, {
  1528. isFull : true
  1529. }, {app:this.app});
  1530. form.view = this.view;
  1531. this.isEditable() ? form.edit() : form.open();
  1532. this.hide();
  1533. }.bind(this)},
  1534. text : this.lp.seeMore
  1535. }).inject(area);
  1536. },
  1537. loadAttachment: function(){
  1538. if( this.options.isHideAttachment )return;
  1539. if( typeOf(this.data.attachmentList)=="array" && this.data.attachmentList[0] ){
  1540. var area = this.node.getElement("[item='attachment']");
  1541. this.attachmentNode = new Element("div"
  1542. //{"styles": this.css.createCalendarAttachmentNode}
  1543. ).inject(area);
  1544. var attachmentContentNode = new Element("div", {
  1545. //"styles": this.css.createCalendarAttachmentContentNode
  1546. }).inject(this.attachmentNode);
  1547. this.attachmentController = new MWFCalendar.EventTooltip.AttachmentController(attachmentContentNode, this, {
  1548. "size": "min",
  1549. "isSizeChange": false,
  1550. "isReplace": false,
  1551. "isUpload": false,
  1552. "isDelete": false,
  1553. "isDownload": true,
  1554. "readonly": true
  1555. });
  1556. this.attachmentController.load();
  1557. this.data.attachmentList.each(function (att) {
  1558. att.person = att.lastUpdatePerson.split("@")[0];
  1559. var at = this.attachmentController.addAttachment(att);
  1560. }.bind(this));
  1561. }
  1562. },
  1563. downloadAttachment: function(e, node, attachments){
  1564. attachments.each(function(att){
  1565. this.app.actions.getFileDownload(att.data.id);
  1566. }.bind(this));
  1567. },
  1568. openAttachment: function(e, node, attachments){
  1569. attachments.each(function(att){
  1570. this.app.actions.getFile(att.data.id);
  1571. }.bind(this));
  1572. },
  1573. getAttachmentUrl: function(attachment, callback){
  1574. this.app.actions.getFileUrl(attachment.data.id, callback);
  1575. }
  1576. });
  1577. MWFCalendar.EventTooltip.AttachmentController = new Class({
  1578. Extends : MWF.widget.AttachmentController,
  1579. loadMin: function(){
  1580. if (!this.node) this.node = new Element("div", {"styles": this.css.container_min});
  1581. if (!this.minActionAreaNode){
  1582. //this.minActionAreaNode = new Element("div", {"styles": this.css.minActionAreaNode}).inject(this.node);
  1583. this.minContent = new Element("div", {"styles": this.css.minContentNode}).inject(this.node);
  1584. this.minContent.setStyles({
  1585. "margin-right" : "0px"
  1586. });
  1587. //this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download, function(e, node){
  1588. // this.downloadAttachment(e, node);
  1589. //}.bind(this));
  1590. this.node.inject(this.container);
  1591. //if (this.options.readonly) this.setReadonly();
  1592. this.checkActions();
  1593. this.setEvent();
  1594. }else{
  1595. //this.minActionAreaNode.setStyle("display", "block");
  1596. this.minContent.setStyle("display", "block");
  1597. this.minContent.empty();
  1598. }
  1599. var atts = [];
  1600. while (this.attachments.length){
  1601. var att = this.attachments.shift();
  1602. atts.push(new MWFCalendar.EventTooltip.AttachmentMin(att.data, this));
  1603. }
  1604. this.attachments = atts;
  1605. },
  1606. addAttachment: function(data){
  1607. if (this.options.size=="min"){
  1608. this.attachments.push(new MWFCalendar.EventTooltip.AttachmentMin(data, this));
  1609. }else{
  1610. this.attachments.push(new MWF.widget.AttachmentController.Attachment(data, this));
  1611. }
  1612. }
  1613. });
  1614. MWFCalendar.EventTooltip.AttachmentMin = new Class({
  1615. Extends : MWF.widget.AttachmentController.AttachmentMin,
  1616. setEvent: function(){
  1617. this.node.addEvents({
  1618. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["minAttachmentNode_list_over"])}.bind(this),
  1619. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["minAttachmentNode_list"])}.bind(this),
  1620. "mousedown": function(e){this.selected(e);}.bind(this),
  1621. "click": function(e){this.downloadAttachment(e);}.bind(this)
  1622. });
  1623. },
  1624. downloadAttachment: function(e){
  1625. if (this.controller.module) this.controller.module.downloadAttachment(e, null, [this]);
  1626. }
  1627. });