]> err.no Git - scalable-opengroupware.org/blob - UI/Common/UIxPageFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1277 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Common / UIxPageFrame.m
1 /*
2   Copyright (C) 2004-2005 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 #import "common.h"
23 #import <NGObjWeb/SoComponent.h>
24 #import <NGObjWeb/WOComponent.h>
25
26 #import <SoObjects/SOGo/SOGoUser.h>
27 #import <SoObjects/SOGo/NSDictionary+Utilities.h>
28
29 #import <SOGoUI/UIxComponent.h>
30
31 #import <Main/build.h>
32
33 #import "UIxPageFrame.h"
34
35 @implementation UIxPageFrame
36
37 - (id) init
38 {
39   if ((self = [super init]))
40     {
41       item = nil;
42       title = nil;
43       toolbar = nil;
44       additionalJSFiles = nil;
45     }
46
47   return self;
48 }
49
50 - (void) dealloc
51 {
52   [item release];
53   [title release];
54   [toolbar release];
55   [additionalJSFiles release];
56   [super dealloc];
57 }
58
59 /* accessors */
60
61 - (void) setTitle: (NSString *) _value
62 {
63   ASSIGN (title, _value);
64 }
65
66 - (NSString *) title
67 {
68   if ([self isUIxDebugEnabled])
69     return title;
70
71   return [self labelForKey: @"SOGo"];
72 }
73
74 - (void) setItem: (id) _item
75 {
76   ASSIGN (item, _item);
77 }
78
79 - (id) item
80 {
81   return item;
82 }
83
84 - (NSString *) buildDate
85 {
86   return SOGoBuildDate;
87 }
88
89 - (NSString *) ownerInContext
90 {
91   return [[self clientObject] ownerInContext: nil];
92 }
93
94 - (NSString *) doctype
95 {
96   return (@"<?xml version=\"1.0\"?>\n"
97           @"<!DOCTYPE html"
98           @" PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
99           @" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
100 }
101
102 /* Help URL/target */
103
104 - (NSString *) helpURL
105 {
106   return [NSString stringWithFormat: @"help/%@.html", title];
107 }
108
109 - (NSString *) helpWindowTarget
110 {
111   return [NSString stringWithFormat: @"Help_%@", title];
112 }
113
114 /* notifications */
115
116 - (void) sleep
117 {
118   [item release];
119   item = nil;
120   [super sleep];
121 }
122
123 /* URL generation */
124 // TODO: I think all this should be done by the clientObject?!
125
126 - (NSString *) relativeHomePath
127 {
128   return [self relativePathToUserFolderSubPath: @""];
129 }
130
131 - (NSString *) relativeCalendarPath
132 {
133   return [self relativePathToUserFolderSubPath: @"Calendar/"];
134 }
135
136 - (NSString *) relativeContactsPath
137 {
138   return [self relativePathToUserFolderSubPath: @"Contacts/"];
139 }
140
141 - (NSString *) relativeMailPath
142 {
143   return [self relativePathToUserFolderSubPath: @"Mail/"];
144 }
145
146 - (NSString *) relativePreferencesPath
147 {
148   return [self relativePathToUserFolderSubPath: @"preferences"];
149 }
150
151 - (NSString *) logoffPath
152 {
153   return [self relativePathToUserFolderSubPath: @"logoff"];
154 }
155
156 /* popup handling */
157 - (void) setPopup: (BOOL) popup
158 {
159   isPopup = popup;
160 }
161
162 - (BOOL) isPopup
163 {
164   return isPopup;
165 }
166
167 - (NSString *) bodyClasses
168 {
169   return (isPopup ? @"popup" : @"main");
170 }
171
172 /* page based JavaScript */
173
174 - (NSString *) _stringsForFramework: (NSString *) framework
175 {
176   NSString *language, *frameworkName;
177   id table;
178
179   frameworkName = [NSString stringWithFormat: @"%@.SOGo",
180                             (framework ? framework : [self frameworkName])];
181   language = [[context activeUser] language];
182   if (!language)
183     language = [SOGoUser language];
184
185   table
186     = [[self resourceManager] stringTableWithName: @"Localizable"
187                               inFramework: frameworkName
188                               languages: [NSArray arrayWithObject: language]];
189
190   /* table is not really an NSDictionary but a hackish variation thereof */
191   return [[NSDictionary dictionaryWithDictionary: table] jsonRepresentation];
192 }
193
194 - (NSString *) commonLocalizableStrings
195 {
196   return [NSString stringWithFormat: @"var clabels = %@;",
197                    [self _stringsForFramework: nil]];
198 }
199
200 - (NSString *) productLocalizableStrings
201 {
202   NSString *frameworkName;
203
204   frameworkName = [[context page] frameworkName];
205
206   return [NSString stringWithFormat: @"var labels = %@;",
207                    [self _stringsForFramework: frameworkName]];
208 }
209
210 - (NSString *) pageJavaScriptURL
211 {
212   WOComponent *page;
213   NSString *pageJSFilename;
214   
215   page     = [context page];
216   pageJSFilename = [NSString stringWithFormat: @"%@.js",
217                              NSStringFromClass([page class])];
218
219   return [self urlForResourceFilename: pageJSFilename];
220 }
221
222 - (NSString *) productJavaScriptURL
223 {
224   WOComponent *page;
225   NSString *fwJSFilename;
226
227   page = [context page];
228   fwJSFilename = [NSString stringWithFormat: @"%@.js",
229                            [page frameworkName]];
230   
231   return [self urlForResourceFilename: fwJSFilename];
232 }
233
234 - (BOOL) hasPageSpecificJavaScript
235 {
236   return ([[self pageJavaScriptURL] length] > 0);
237 }
238
239 - (BOOL) hasProductSpecificJavaScript
240 {
241   return ([[self productJavaScriptURL] length] > 0);
242 }
243
244 - (void) setCssFiles: (NSString *) newCSSFiles
245 {
246   NSEnumerator *cssFiles;
247   NSString *currentFile, *filename;
248
249   [additionalCSSFiles release];
250   additionalCSSFiles = [NSMutableArray new];
251
252   cssFiles
253     = [[newCSSFiles componentsSeparatedByString: @","] objectEnumerator];
254   while ((currentFile = [cssFiles nextObject]))
255     {
256       filename = [self urlForResourceFilename:
257                          [currentFile stringByTrimmingSpaces]];
258       [additionalCSSFiles addObject: filename];
259     }
260 }
261
262 - (NSArray *) additionalCSSFiles
263 {
264   return additionalCSSFiles;
265 }
266
267 - (void) setJsFiles: (NSString *) newJSFiles
268 {
269   NSEnumerator *jsFiles;
270   NSString *currentFile, *filename;
271
272   [additionalJSFiles release];
273   additionalJSFiles = [NSMutableArray new];
274
275   jsFiles = [[newJSFiles componentsSeparatedByString: @","] objectEnumerator];
276   while ((currentFile = [jsFiles nextObject]))
277     {
278       filename = [self urlForResourceFilename:
279                          [currentFile stringByTrimmingSpaces]];
280       [additionalJSFiles addObject: filename];
281     }
282 }
283
284 - (NSArray *) additionalJSFiles
285 {
286   return additionalJSFiles;
287 }
288
289 - (NSString *) pageCSSURL
290 {
291   WOComponent *page;
292   NSString *pageJSFilename;
293
294   page = [context page];
295   pageJSFilename = [NSString stringWithFormat: @"%@.css",
296                              NSStringFromClass([page class])];
297
298   return [self urlForResourceFilename: pageJSFilename];
299 }
300
301 - (NSString *) productCSSURL
302 {
303   WOComponent *page;
304   NSString *fwJSFilename;
305
306   page = [context page];
307   fwJSFilename = [NSString stringWithFormat: @"%@.css",
308                            [page frameworkName]];
309   
310   return [self urlForResourceFilename: fwJSFilename];
311 }
312
313 - (NSString *) thisPageURL
314 {
315   return [[context page] uri];
316 }
317
318 - (BOOL) hasPageSpecificCSS
319 {
320   return ([[self pageCSSURL] length] > 0);
321 }
322
323 - (BOOL) hasProductSpecificCSS
324 {
325   return ([[self productCSSURL] length] > 0);
326 }
327
328 - (void) setToolbar: (NSString *) newToolbar
329 {
330   ASSIGN (toolbar, newToolbar);
331 }
332
333 - (NSString *) toolbar
334 {
335   return toolbar;
336 }
337
338 - (BOOL) isSuperUser
339 {
340   SOGoUser *user;
341
342   user = [context activeUser];
343
344   return ([user respondsToSelector: @selector (isSuperUser)]
345           && [user isSuperUser]);
346 }
347
348 - (BOOL) userHasCalendarAccess
349 {
350   SOGoUser *user;
351
352   user = [context activeUser];
353
354   return [user canAccessModule: @"Calendar"];
355 }
356
357 - (BOOL) userHasMailAccess
358 {
359   SOGoUser *user;
360
361   user = [context activeUser];
362
363   return [user canAccessModule: @"Mail"];
364 }
365
366 /* browser/os identification */
367
368 - (BOOL) isCompatibleBrowser
369 {
370   WEClientCapabilities *cc;
371
372   cc = [[context request] clientCapabilities];
373
374   //NSLog(@"Browser = %@", [cc description]);
375   NSLog(@"User agent = %@", [cc userAgent]);
376   //NSLog(@"Browser major version = %i", [cc majorVersion]);
377
378   return (([[cc userAgentType] isEqualToString: @"IE"]
379            && [cc majorVersion] >= 7)
380           || ([[cc userAgentType] isEqualToString: @"Mozilla"]
381               && [cc majorVersion] >= 5)
382           || ([[cc userAgentType] isEqualToString: @"Safari"]
383               && [cc majorVersion] >= 4)
384           //      ([[cc userAgentType] isEqualToString: @"Konqueror"])
385            );
386 }
387
388 - (BOOL) isIE7Compatible
389 {
390   WEClientCapabilities *cc;
391
392   cc = [[context request] clientCapabilities];
393   
394   return ([cc isWindowsBrowser] &&
395           ([[cc userAgent] rangeOfString: @"NT 5.1"].location != NSNotFound ||
396            [[cc userAgent] rangeOfString: @"NT 6"].location != NSNotFound));
397 }
398
399 - (BOOL) isMac
400 {
401   WEClientCapabilities *cc;
402
403   cc = [[context request] clientCapabilities];
404
405   return [cc isMacBrowser];
406 }
407
408 @end /* UIxPageFrame */