diff --git a/ChangeLog b/ChangeLog index e2810bb0b..01f8e0089 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2010-06-08 Wolfgang Sourdeau + * UI/WebServerResources/SchedulerUI.js: + (onCalendarsMenuPrepareVisibility): the "export" menu option is + now disabled for non-owner users, since the function itself will + not do anything otherwise. + (onCalendarExport): we make use of the URLForFolderId method, + which reduces code size. + + * UI/Scheduler/UIxCalFolderActions.m (-exportAction): this web + method is now bound to the ICS folder object, thereby removing + duplicate code. + * SoObjects/Appointments/SOGoAppointmentFolderObject.m (-displayName, -davDisplayName): new accessors that are forwarded to the real folder object. diff --git a/UI/Scheduler/UIxCalFolderActions.m b/UI/Scheduler/UIxCalFolderActions.m index d2b75e39a..5de02ca78 100644 --- a/UI/Scheduler/UIxCalFolderActions.m +++ b/UI/Scheduler/UIxCalFolderActions.m @@ -31,6 +31,7 @@ #import #import +#import #import #import #import @@ -42,63 +43,19 @@ - (WOResponse *) exportAction { WOResponse *response; - SOGoAppointmentFolder *folder; - SOGoAppointmentObject *appt; - NSArray *array, *values, *fields; - NSMutableString *rc; + SOGoAppointmentFolderICS *folderICS; NSString *filename; - iCalCalendar *calendar, *component; - int i, count; - fields = [NSArray arrayWithObjects: @"c_name", @"c_content", nil]; - rc = [NSMutableString string]; - - response = [context response]; - - folder = [self clientObject]; - calendar = [iCalCalendar groupWithTag: @"vcalendar"]; - - /* We have to use bareFetchFields because we don't want to process anything - * (RRULES for example) */ - array = [folder bareFetchFields: fields - from: nil - to: nil - title: nil - component: nil - additionalFilters: nil]; - count = [array count]; - for (i = 0; i < count; i++) - { - appt = [folder lookupName: [[array objectAtIndex: i] objectForKey: @"c_name"] - inContext: [self context] - acquire: NO]; - - component = [appt calendar: NO secure: NO]; - values = [component events]; - if (values && [values count]) - [calendar addChildren: values]; - values = [component todos]; - if (values && [values count]) - [calendar addChildren: values]; - values = [component journals]; - if (values && [values count]) - [calendar addChildren: values]; - values = [component freeBusys]; - if (values && [values count]) - [calendar addChildren: values]; - values = [component childrenWithTag: @"vtimezone"]; - if (values && [values count]) - [calendar addChildren: values]; - } - - filename = [NSString stringWithFormat: @"attachment;filename=\"%@.ics\"", - [folder displayName]]; - [response setHeader: @"application/octet-stream; charset=utf-8" - forKey:@"content-type"]; - [response setHeader: filename + folderICS = [self clientObject]; + response = [self responseWithStatus: 200 + andString: [folderICS contentAsString]]; + [response setHeader: @"text/calendar; charset=utf-8" + forKey: @"content-type"]; + filename = [NSString stringWithFormat: @"attachment; filename=\"%@.ics\"", + [folderICS displayName]]; + [response setHeader: filename forKey: @"Content-Disposition"]; - [response setContent: [[calendar versitString] dataUsingEncoding: NSUTF8StringEncoding]]; - + return response; } diff --git a/UI/Scheduler/product.plist b/UI/Scheduler/product.plist index 9f5cebde7..d4de77fad 100644 --- a/UI/Scheduler/product.plist +++ b/UI/Scheduler/product.plist @@ -149,11 +149,6 @@ pageName = "UIxCalView"; actionName = "redirectForUIDs"; }; - export = { - protectedBy = "View"; - actionClass = "UIxCalFolderActions"; - actionName = "export"; - }; import = { protectedBy = "View"; actionClass = "UIxCalFolderActions"; @@ -181,6 +176,16 @@ }; }; + SOGoAppointmentFolderICS = { + methods = { + export = { + protectedBy = "View"; + actionClass = "UIxCalFolderActions"; + actionName = "export"; + }; + }; + }; + SOGoCalendarComponent = { }; diff --git a/UI/WebServerResources/SchedulerUI.js b/UI/WebServerResources/SchedulerUI.js index 9b5332567..5d4620a19 100644 --- a/UI/WebServerResources/SchedulerUI.js +++ b/UI/WebServerResources/SchedulerUI.js @@ -2080,12 +2080,20 @@ function onCalendarsMenuPrepareVisibility() { var selected = folders.getSelectedNodes(); if (selected.length > 0) { var folderOwner = selected[0].getAttribute("owner"); - var sharingOption = $(this).down("ul").childElements().last(); - // Disable the "Sharing" option when calendar is not owned by user - if (folderOwner == UserLogin || IsSuperUser) - sharingOption.removeClassName("disabled"); - else - sharingOption.addClassName("disabled"); + + var lis = $(this).down("ul").childElements(); + + /* distance: sharing = length - 1, export = length - 7 */ + var endDists = [ 1, 7 ]; + for (var i = 0; i < endDists.length; i++) { + var dist = lis.length - endDists[i]; + var option = $(lis[dist]); + if (folderOwner == UserLogin || IsSuperUser) + option.removeClassName("disabled"); + else + option.addClassName("disabled"); + } + var deleteCalendarOption = $("deleteCalendarMenuItem"); // Swith between Delete and Unsubscribe if (folderOwner == UserLogin) @@ -2312,14 +2320,9 @@ function addWebCalendarCallback (http) { function onCalendarExport(event) { var node = $("calendarList").getSelectedNodes().first(); - var owner = node.getAttribute("owner"); var folderId = node.getAttribute("id"); - if (owner == UserLogin) { - var folderIdElements = folderId.split(":"); - var id = folderIdElements[0].replace (/^\/+/g, ''); - var url = ApplicationBaseURL + "/" + id + "/export"; - window.location.href = url; - } + var url = URLForFolderID(folderId) + ".ics/export"; + window.location.href = url; } function onCalendarImport(event) {