]> err.no Git - scalable-opengroupware.org/blob - UI/Common/UIxPageFrame.m
efda984ef4f5f2ced97dff63dc0d41106ccbe1ad
[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) setJsFiles: (NSString *) newJSFiles
245 {
246   NSEnumerator *jsFiles;
247   NSString *currentFile, *filename;
248
249   [additionalJSFiles release];
250   additionalJSFiles = [NSMutableArray new];
251
252   jsFiles = [[newJSFiles componentsSeparatedByString: @","] objectEnumerator];
253   while ((currentFile = [jsFiles nextObject]))
254     {
255       filename = [self urlForResourceFilename:
256                          [currentFile stringByTrimmingSpaces]];
257       [additionalJSFiles addObject: filename];
258     }
259 }
260
261 - (NSArray *) additionalJSFiles
262 {
263   return additionalJSFiles;
264 }
265
266 - (NSString *) pageCSSURL
267 {
268   WOComponent *page;
269   NSString *pageJSFilename;
270
271   page = [context page];
272   pageJSFilename = [NSString stringWithFormat: @"%@.css",
273                              NSStringFromClass([page class])];
274
275   return [self urlForResourceFilename: pageJSFilename];
276 }
277
278 - (NSString *) productCSSURL
279 {
280   WOComponent *page;
281   NSString *fwJSFilename;
282
283   page = [context page];
284   fwJSFilename = [NSString stringWithFormat: @"%@.css",
285                            [page frameworkName]];
286   
287   return [self urlForResourceFilename: fwJSFilename];
288 }
289
290 - (NSString *) thisPageURL
291 {
292   return [[context page] uri];
293 }
294
295 - (BOOL) hasPageSpecificCSS
296 {
297   return ([[self pageCSSURL] length] > 0);
298 }
299
300 - (BOOL) hasProductSpecificCSS
301 {
302   return ([[self productCSSURL] length] > 0);
303 }
304
305 - (void) setToolbar: (NSString *) newToolbar
306 {
307   ASSIGN (toolbar, newToolbar);
308 }
309
310 - (NSString *) toolbar
311 {
312   return toolbar;
313 }
314
315 /* browser/os identification */
316
317 - (BOOL) isCompatibleBrowser
318 {
319   WEClientCapabilities *cc;
320
321   cc = [[context request] clientCapabilities];
322
323   //NSLog(@"Browser = %@", [cc description]);
324   NSLog(@"User agent = %@", [cc userAgent]);
325   //NSLog(@"Browser major version = %i", [cc majorVersion]);
326
327   return (([[cc userAgentType] isEqualToString: @"IE"]
328            && [cc majorVersion] >= 7)
329           || ([[cc userAgentType] isEqualToString: @"Mozilla"]
330               && [cc majorVersion] >= 5)
331           || ([[cc userAgentType] isEqualToString: @"Safari"]
332               && [cc majorVersion] >= 4)
333           //      ([[cc userAgentType] isEqualToString: @"Konqueror"])
334            );
335 }
336
337 - (BOOL) isIE7Compatible
338 {
339   WEClientCapabilities *cc;
340
341   cc = [[context request] clientCapabilities];
342   
343   return ([cc isWindowsBrowser] &&
344           ([[cc userAgent] rangeOfString: @"NT 5.1"].location != NSNotFound ||
345            [[cc userAgent] rangeOfString: @"NT 6"].location != NSNotFound));
346 }
347
348 - (BOOL) isMac
349 {
350   WEClientCapabilities *cc;
351
352   cc = [[context request] clientCapabilities];
353
354   return [cc isMacBrowser];
355 }
356
357 @end /* UIxPageFrame */