]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalMainView.m
initial sync
[scalable-opengroupware.org] / UI / Scheduler / UIxCalMainView.m
1 /* UIxCalMainView.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSCalendarDate.h>
25 #import <Foundation/NSString.h>
26 #import <Foundation/NSUserDefaults.h>
27 #import <Foundation/NSValue.h>
28
29 #import <NGObjWeb/WOResponse.h>
30
31 #import <SOGo/SOGoUser.h>
32
33 #import "UIxCalMainView.h"
34
35 #import <Appointments/SOGoAppointmentFolder.h>
36
37 static NSMutableArray *monthMenuItems = nil;
38 static NSMutableArray *yearMenuItems = nil;
39
40 @implementation UIxCalMainView
41
42 - (NSArray *) monthMenuItems
43 {
44   unsigned int count;
45  
46   if (!monthMenuItems)
47     {
48       monthMenuItems = [NSMutableArray arrayWithCapacity: 12];
49       
50       for (count = 1; count < 13; count++)
51         [monthMenuItems addObject:
52                           [NSString stringWithFormat: @"%.2d", count]];
53       [monthMenuItems retain];
54     }
55
56   return monthMenuItems;
57 }
58
59 - (void) setMonthMenuItem: (NSString *) aMonthMenuItem
60 {
61   monthMenuItem = aMonthMenuItem;
62 }
63
64 - (NSString *) monthMenuItem
65 {
66   return monthMenuItem;
67 }
68
69 - (NSString *) monthMenuItemLabel
70 {
71   return [self localizedNameForMonthOfYear: [monthMenuItem intValue]];
72 }
73
74 - (NSArray *) yearMenuItems
75 {
76   int count, year;
77  
78   if (!yearMenuItems)
79     {
80       year = [[NSCalendarDate date] yearOfCommonEra];
81       yearMenuItems = [NSMutableArray arrayWithCapacity: 11];
82       for (count = -5; count < 6; count++)
83         [yearMenuItems addObject: [NSNumber numberWithInt: year + count]];
84       [yearMenuItems retain];
85     }
86
87   return yearMenuItems;
88 }
89
90 - (void) setYearMenuItem: (NSNumber *) aYearMenuItem
91 {
92   yearMenuItem = aYearMenuItem;
93 }
94
95 - (NSNumber *) yearMenuItem
96 {
97   return yearMenuItem;
98 }
99
100 - (id) batchDeleteAction
101 {
102   NSArray *ids;
103   SOGoAppointmentFolder *clientObject;
104
105   ids = [[self queryParameterForKey: @"ids"] componentsSeparatedByString: @"/"];
106   if (ids)
107     {
108       clientObject = [self clientObject];
109       [clientObject deleteEntriesWithIds: ids];
110     }
111
112   return self;
113 }
114
115 - (id <WOActionResults>) updateCalendarsAction
116 {
117   WOResponse *response;
118   NSUserDefaults *ud;
119
120   ud = [[context activeUser] userDefaults];
121   [ud setObject: [self queryParameterForKey: @"ids"]
122                        forKey: @"calendaruids"];
123   [ud synchronize];
124   response = [context response];
125   [response setStatus: 200];
126   [response setHeader: @"text/html; charset=\"utf-8\"" forKey: @"content-type"];
127
128   return response;
129 }
130
131 - (id <WOActionResults>) checkRightsAction
132 {
133   WOResponse *response;
134   NSUserDefaults *ud;
135   NSString *uids, *uid;
136   NSMutableString *rights;
137   NSArray *ids;
138   unsigned int count, max;
139   BOOL result;
140
141   ud = [[context activeUser] userDefaults];
142   uids = [ud stringForKey: @"calendaruids"];
143
144   response = [context response];
145   [response setStatus: 200];
146   [response setHeader: @"text/plain; charset=\"utf-8\""
147             forKey: @"content-type"];
148   rights = [NSMutableString string];
149   if ([uids length] > 0)
150     {
151       ids = [uids componentsSeparatedByString: @","];
152       max = [ids count];
153       for (count = 0; count < max; count++)
154         {
155           uid = [ids objectAtIndex: count];
156           if ([uid hasPrefix: @"-"])
157             uid = [uid substringFromIndex: 1];
158           result = ([self calendarFolderForUID: uid] != nil);
159           if (count == 0)
160             [rights appendFormat: @"%d", result];
161           else
162             [rights appendFormat: @",%d", result];
163         }
164     }
165   [response appendContentString: rights];
166
167   return response;
168 }
169
170 @end