]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Scheduler/UIxCalScheduleOverview.m
visual changes and important bugfixes
[scalable-opengroupware.org] / SOGo / UI / Scheduler / UIxCalScheduleOverview.m
1 /*
2  Copyright (C) 2004 SKYRIX Software AG
3  
4  This file is part of OpenGroupware.org
5  
6  OGo is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License as published by the
8  Free Software Foundation; either version 2, or (at your option) any
9  later version.
10  
11  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12  WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14  License for more details.
15  
16  You should have received a copy of the GNU Lesser General Public
17  License along with OGo; see the file COPYING.  If not, write to the
18  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20  */
21
22 #include <SOGoUI/UIxComponent.h>
23
24 @class NSMutableArray;
25
26 @interface UIxCalScheduleOverview : UIxComponent
27 {
28   NSMutableArray *userApts;
29   NSMutableArray *foreignApts;
30   id             item;
31   NSArray        *partNames;
32   NSArray        *partStates;
33   unsigned       participantIndex;
34 }
35
36 - (NSCalendarDate *)startDate;
37 - (NSCalendarDate *)endDate;
38
39 - (NSArray *)userAppointments;
40 - (NSArray *)foreignAppointments;
41
42 - (BOOL)hasUserAppointments;
43 - (BOOL)hasForeignAppointments;
44 - (BOOL)hasAnyAppointments;
45
46 - (void)fetchInfos;
47
48 - (NSString *)appointmentBaseURL;
49
50 - (unsigned)participantsCount;
51 - (unsigned)maxRenderedParticipantsCount;
52 - (unsigned)renderedParticipantsCount;
53 - (unsigned)truncatedParticipantsCount;
54 - (BOOL)didTruncateParticipants;
55
56 @end
57
58 #include <NGObjWeb/SoComponent.h>
59 #include "UIxComponent+Agenor.h"
60 #include "SoObjects/Appointments/SOGoAppointmentFolder.h"
61 #include "common.h"
62
63 @implementation UIxCalScheduleOverview
64
65 - (void)dealloc {
66   [self->userApts    release];
67   [self->foreignApts release];
68   [self->partNames   release];
69   [self->partStates  release];
70   [self->item        release];
71   [super dealloc];
72 }
73
74
75 /* accessors */
76
77 - (void)setItem:(id)_item {
78   NSString *ps;
79
80   ASSIGN(self->item, _item);
81
82   [self->partNames release];
83   [self->partStates release];
84   ps               = [self->item valueForKey:@"participants"];
85   self->partNames  = [[ps componentsSeparatedByString:@"\n"] retain];
86   ps               = [self->item valueForKey:@"partstates"];
87   self->partStates = [[ps componentsSeparatedByString:@"\n"] retain];
88 }
89 - (id)item {
90   return self->item;
91 }
92
93 - (void)setParticipantIndex:(unsigned)_participantIndex {
94   self->participantIndex = _participantIndex;
95 }
96 - (unsigned)participantIndex {
97   return self->participantIndex;
98 }
99
100 - (BOOL)isFirstParticipant {
101   return self->participantIndex == 0 ? YES : NO;
102 }
103
104 - (BOOL)hasUserAppointments {
105   return [[self userAppointments] count] > 0;
106 }
107 - (BOOL)hasForeignAppointments {
108   return [[self foreignAppointments] count] > 0;
109 }
110 - (BOOL)hasAnyAppointments {
111   return ([self hasUserAppointments] ||
112           [self hasForeignAppointments]) ? YES : NO;
113 }
114
115 - (unsigned)participantsCount {
116   return [self->partNames count];
117 }
118
119 - (NSString *)participant {
120   return [self->partNames objectAtIndex:self->participantIndex];
121 }
122
123 - (NSString *)participationStatus {
124   return [self->partStates objectAtIndex:self->participantIndex];
125 }
126
127 - (unsigned)maxRenderedParticipantsCount {
128   return 3;
129 }
130
131 - (unsigned)renderedParticipantsCount {
132   if ([self didTruncateParticipants])
133     return [self maxRenderedParticipantsCount];
134   return [self participantsCount];
135 }
136
137 - (unsigned)truncatedParticipantsCount {
138   return [self participantsCount] - [self renderedParticipantsCount];
139 }
140
141 - (BOOL)didTruncateParticipants {
142   return [self participantsCount] >
143          ([self maxRenderedParticipantsCount] + 1) ? YES : NO;
144 }
145
146 - (unsigned)rowspan {
147   unsigned count;
148   
149   count = [self renderedParticipantsCount];
150   if ([self didTruncateParticipants])
151     count += 1;
152   return count;
153 }
154
155 - (NSString *)userParticipationStatus {
156   NSString *pms;
157   NSArray  *partmails;
158   unsigned idx;
159
160   pms       = [self->item valueForKey:@"partmails"];
161   partmails = [pms componentsSeparatedByString:@"\n"];
162   idx       = [partmails indexOfObject:[self emailForUser]];
163   if (idx == NSNotFound)
164     return @"";
165   return [self->partStates objectAtIndex:idx];
166 }
167
168
169 /* fetching */
170
171 - (NSCalendarDate *)startDate {
172   return [[NSCalendarDate date] beginOfDay];
173 }
174
175 /* ZNeK: is a month ok? */
176 - (NSCalendarDate *)endDate {
177   NSCalendarDate *date;
178   
179   date = [NSCalendarDate date];
180   date = [date dateByAddingYears:0 months:1 days:0
181                            hours:0 minutes:0 seconds:0];
182   date = [date endOfDay];
183   return date;
184 }
185
186 - (NSArray *)userAppointments {
187   if (!self->userApts) {
188     [self fetchInfos];
189   }
190   return self->userApts;
191 }
192
193 - (NSArray *)foreignAppointments {
194   if (!self->foreignApts) {
195     [self fetchInfos];
196   }
197   return self->foreignApts;
198 }
199
200 - (void)fetchInfos {
201   static NSArray *orders = nil;
202   id       aptFolder;
203   NSArray  *apts;
204   NSString *userEmail;
205   unsigned i, count;
206
207   if (!orders) {
208     EOSortOrdering *so;
209     so     = [EOSortOrdering sortOrderingWithKey:@"startDate"
210                              selector:EOCompareAscending];
211     orders = [[NSArray alloc] initWithObjects:so, nil];
212   }
213
214   aptFolder = [self clientObject];
215   apts      = [aptFolder fetchCoreInfosFrom:[self startDate]
216                          to:[self endDate]];
217   userEmail = [self emailForUser];
218   count     = [apts count];
219
220   self->userApts    = [[NSMutableArray alloc] initWithCapacity:count];
221   self->foreignApts = [[NSMutableArray alloc] initWithCapacity:count];
222
223   for (i = 0; i < count; i++) {
224     id       apt;
225     NSString *orgEmail;
226
227     apt      = [apts objectAtIndex:i];
228     orgEmail = [apt objectForKey:@"orgmail"];
229     if (orgEmail && [orgEmail isEqualToString:userEmail])
230       [self->userApts addObject:apt];
231     else
232       [self->foreignApts addObject:apt];
233   }
234   [self->userApts    sortUsingKeyOrderArray:orders];
235   [self->foreignApts sortUsingKeyOrderArray:orders];
236 }
237
238
239 /* URLs */
240
241 - (NSString *)appointmentBaseURL {
242   id pkey;
243   
244   if (![(pkey = [self->item valueForKey:@"uid"]) isNotNull])
245     return nil;
246   
247   return [[self clientObject] baseURLForAptWithUID:[pkey stringValue]
248                               inContext:[self context]];
249 }
250 - (NSString *)appointmentViewURL {
251   return [[self appointmentBaseURL] stringByAppendingPathComponent:@"view"];
252 }
253 - (NSString *)acceptAppointmentURL {
254   return [[self appointmentBaseURL] stringByAppendingPathComponent:@"accept"];
255 }
256 - (NSString *)declineAppointmentURL {
257   return [[self appointmentBaseURL] stringByAppendingPathComponent:@"decline"];
258 }
259
260
261 /* access protection */
262
263 - (BOOL)canAccess {
264   NSString *owner;
265   
266   owner = [[self clientObject] ownerInContext:[self context]];
267   if (!owner)
268     return NO;
269   return [[[[self context] activeUser] login] isEqualToString:owner];
270 }
271
272 @end