]> err.no Git - scalable-opengroupware.org/blob - UI/Common/UIxPageFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1188 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   table
183     = [[self resourceManager] stringTableWithName: @"Localizable"
184                               inFramework: frameworkName
185                               languages: [NSArray arrayWithObject: language]];
186
187   /* table is not really an NSDictionary but a hackish variation thereof */
188   return [[NSDictionary dictionaryWithDictionary: table] jsonRepresentation];
189 }
190
191 - (NSString *) commonLocalizableStrings
192 {
193   return [NSString stringWithFormat: @"var clabels = %@;",
194                    [self _stringsForFramework: nil]];
195 }
196
197 - (NSString *) productLocalizableStrings
198 {
199   NSString *frameworkName;
200
201   frameworkName = [[context page] frameworkName];
202
203   return [NSString stringWithFormat: @"var labels = %@;",
204                    [self _stringsForFramework: frameworkName]];
205 }
206
207 - (NSString *) pageJavaScriptURL
208 {
209   WOComponent *page;
210   NSString *pageJSFilename;
211   
212   page     = [context page];
213   pageJSFilename = [NSString stringWithFormat: @"%@.js",
214                              NSStringFromClass([page class])];
215
216   return [self urlForResourceFilename: pageJSFilename];
217 }
218
219 - (NSString *) productJavaScriptURL
220 {
221   WOComponent *page;
222   NSString *fwJSFilename;
223
224   page = [context page];
225   fwJSFilename = [NSString stringWithFormat: @"%@.js",
226                            [page frameworkName]];
227   
228   return [self urlForResourceFilename: fwJSFilename];
229 }
230
231 - (BOOL) hasPageSpecificJavaScript
232 {
233   return ([[self pageJavaScriptURL] length] > 0);
234 }
235
236 - (BOOL) hasProductSpecificJavaScript
237 {
238   return ([[self productJavaScriptURL] length] > 0);
239 }
240
241 - (void) setJsFiles: (NSString *) newJSFiles
242 {
243   NSEnumerator *jsFiles;
244   NSString *currentFile, *filename;
245
246   [additionalJSFiles release];
247   additionalJSFiles = [NSMutableArray new];
248
249   jsFiles = [[newJSFiles componentsSeparatedByString: @","] objectEnumerator];
250   while ((currentFile = [jsFiles nextObject]))
251     {
252       filename = [self urlForResourceFilename:
253                          [currentFile stringByTrimmingSpaces]];
254       [additionalJSFiles addObject: filename];
255     }
256 }
257
258 - (NSArray *) additionalJSFiles
259 {
260   return additionalJSFiles;
261 }
262
263 - (NSString *) pageCSSURL
264 {
265   WOComponent *page;
266   NSString *pageJSFilename;
267
268   page = [context page];
269   pageJSFilename = [NSString stringWithFormat: @"%@.css",
270                              NSStringFromClass([page class])];
271
272   return [self urlForResourceFilename: pageJSFilename];
273 }
274
275 - (NSString *) productCSSURL
276 {
277   WOComponent *page;
278   NSString *fwJSFilename;
279
280   page = [context page];
281   fwJSFilename = [NSString stringWithFormat: @"%@.css",
282                            [page frameworkName]];
283   
284   return [self urlForResourceFilename: fwJSFilename];
285 }
286
287 - (NSString *) thisPageURL
288 {
289   return [[context page] uri];
290 }
291
292 - (BOOL) hasPageSpecificCSS
293 {
294   return ([[self pageCSSURL] length] > 0);
295 }
296
297 - (BOOL) hasProductSpecificCSS
298 {
299   return ([[self productCSSURL] length] > 0);
300 }
301
302 - (void) setToolbar: (NSString *) newToolbar
303 {
304   ASSIGN (toolbar, newToolbar);
305 }
306
307 - (NSString *) toolbar
308 {
309   return toolbar;
310 }
311
312 /* browser/os identification */
313
314 - (BOOL) isCompatibleBrowser
315 {
316   WEClientCapabilities *cc;
317
318   cc = [[context request] clientCapabilities];
319
320   //NSLog(@"Browser = %@", [cc description]);
321   NSLog(@"User agent = %@", [cc userAgent]);
322   //NSLog(@"Browser major version = %i", [cc majorVersion]);
323
324   return (([[cc userAgentType] isEqualToString: @"IE"]
325            && [cc majorVersion] >= 7)
326           || ([[cc userAgentType] isEqualToString: @"Mozilla"]
327               && [cc majorVersion] >= 5)
328           || ([[cc userAgentType] isEqualToString: @"Safari"]
329               && [cc majorVersion] >= 4)
330           //      ([[cc userAgentType] isEqualToString: @"Konqueror"])
331            );
332 }
333
334 - (BOOL) isIE7Compatible
335 {
336   WEClientCapabilities *cc;
337
338   cc = [[context request] clientCapabilities];
339   
340   return ([cc isWindowsBrowser] &&
341           ([[cc userAgent] rangeOfString: @"NT 5.1"].location != NSNotFound ||
342            [[cc userAgent] rangeOfString: @"NT 6"].location != NSNotFound));
343 }
344
345 - (BOOL) isMac
346 {
347   WEClientCapabilities *cc;
348
349   cc = [[context request] clientCapabilities];
350
351   return [cc isMacBrowser];
352 }
353
354 @end /* UIxPageFrame */