]> err.no Git - scalable-opengroupware.org/blobdiff - UI/Common/UIxPageFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1265 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Common / UIxPageFrame.m
index b093fa75b4c05260b7c6110884cac67ee66c718a..9aaa5df61b8b5f360a43bc3df6afef4b2aecbdc2 100644 (file)
 #import <NGObjWeb/SoComponent.h>
 #import <NGObjWeb/WOComponent.h>
 
+#import <SoObjects/SOGo/SOGoUser.h>
+#import <SoObjects/SOGo/NSDictionary+Utilities.h>
+
 #import <SOGoUI/UIxComponent.h>
-#import <SOGo/SOGoUser.h>
 
 #import <Main/build.h>
 
 {
   if ((self = [super init]))
     {
+      item = nil;
+      title = nil;
       toolbar = nil;
+      additionalJSFiles = nil;
     }
 
   return self;
@@ -46,8 +51,8 @@
 {
   [item release];
   [title release];
-  if (toolbar)
-    [toolbar release];
+  [toolbar release];
+  [additionalJSFiles release];
   [super dealloc];
 }
 
@@ -55,7 +60,7 @@
 
 - (void) setTitle: (NSString *) _value
 {
-  ASSIGNCOPY(title, _value);
+  ASSIGN (title, _value);
 }
 
 - (NSString *) title
@@ -68,7 +73,7 @@
 
 - (void) setItem: (id) _item
 {
-  ASSIGN(item, _item);
+  ASSIGN (item, _item);
 }
 
 - (id) item
 
 /* page based JavaScript */
 
+- (NSString *) _stringsForFramework: (NSString *) framework
+{
+  NSString *language, *frameworkName;
+  id table;
+
+  frameworkName = [NSString stringWithFormat: @"%@.SOGo",
+                           (framework ? framework : [self frameworkName])];
+  language = [[context activeUser] language];
+  if (!language)
+    language = [SOGoUser language];
+
+  table
+    = [[self resourceManager] stringTableWithName: @"Localizable"
+                             inFramework: frameworkName
+                             languages: [NSArray arrayWithObject: language]];
+
+  /* table is not really an NSDictionary but a hackish variation thereof */
+  return [[NSDictionary dictionaryWithDictionary: table] jsonRepresentation];
+}
+
+- (NSString *) commonLocalizableStrings
+{
+  return [NSString stringWithFormat: @"var clabels = %@;",
+                  [self _stringsForFramework: nil]];
+}
+
+- (NSString *) productLocalizableStrings
+{
+  NSString *frameworkName;
+
+  frameworkName = [[context page] frameworkName];
+
+  return [NSString stringWithFormat: @"var labels = %@;",
+                  [self _stringsForFramework: frameworkName]];
+}
+
 - (NSString *) pageJavaScriptURL
 {
   WOComponent *page;
   NSString *pageJSFilename;
   
-  page     = [[self context] page];
+  page     = [context page];
   pageJSFilename = [NSString stringWithFormat: @"%@.js",
                             NSStringFromClass([page class])];
 
   WOComponent *page;
   NSString *fwJSFilename;
 
-  page = [[self context] page];
+  page = [context page];
   fwJSFilename = [NSString stringWithFormat: @"%@.js",
                           [page frameworkName]];
   
   return [self urlForResourceFilename: fwJSFilename];
 }
 
-- (NSString *) productFrameworkName
+- (BOOL) hasPageSpecificJavaScript
 {
-  WOComponent *page;
+  return ([[self pageJavaScriptURL] length] > 0);
+}
+
+- (BOOL) hasProductSpecificJavaScript
+{
+  return ([[self productJavaScriptURL] length] > 0);
+}
 
-  page = [[self context] page];
+- (void) setCssFiles: (NSString *) newCSSFiles
+{
+  NSEnumerator *cssFiles;
+  NSString *currentFile, *filename;
+
+  [additionalCSSFiles release];
+  additionalCSSFiles = [NSMutableArray new];
+
+  cssFiles
+    = [[newCSSFiles componentsSeparatedByString: @","] objectEnumerator];
+  while ((currentFile = [cssFiles nextObject]))
+    {
+      filename = [self urlForResourceFilename:
+                        [currentFile stringByTrimmingSpaces]];
+      [additionalCSSFiles addObject: filename];
+    }
+}
 
-  return [NSString stringWithFormat: @"%@.SOGo", [page frameworkName]];
+- (NSArray *) additionalCSSFiles
+{
+  return additionalCSSFiles;
 }
 
-- (BOOL) hasPageSpecificJavaScript
+- (void) setJsFiles: (NSString *) newJSFiles
 {
-  return ([[self pageJavaScriptURL] length] > 0);
+  NSEnumerator *jsFiles;
+  NSString *currentFile, *filename;
+
+  [additionalJSFiles release];
+  additionalJSFiles = [NSMutableArray new];
+
+  jsFiles = [[newJSFiles componentsSeparatedByString: @","] objectEnumerator];
+  while ((currentFile = [jsFiles nextObject]))
+    {
+      filename = [self urlForResourceFilename:
+                        [currentFile stringByTrimmingSpaces]];
+      [additionalJSFiles addObject: filename];
+    }
 }
 
-- (BOOL) hasProductSpecificJavaScript
+- (NSArray *) additionalJSFiles
 {
-  return ([[self productJavaScriptURL] length] > 0);
+  return additionalJSFiles;
 }
 
 - (NSString *) pageCSSURL
   WOComponent *page;
   NSString *pageJSFilename;
 
-  page = [[self context] page];
+  page = [context page];
   pageJSFilename = [NSString stringWithFormat: @"%@.css",
                             NSStringFromClass([page class])];
 
   WOComponent *page;
   NSString *fwJSFilename;
 
-  page = [[self context] page];
+  page = [context page];
   fwJSFilename = [NSString stringWithFormat: @"%@.css",
                           [page frameworkName]];
   
 
 - (NSString *) thisPageURL
 {
-  return [[[self context] page] uri];
+  return [[context page] uri];
 }
 
 - (BOOL) hasPageSpecificCSS
   return toolbar;
 }
 
+/* browser/os identification */
+
+- (BOOL) isCompatibleBrowser
+{
+  WEClientCapabilities *cc;
+
+  cc = [[context request] clientCapabilities];
+
+  //NSLog(@"Browser = %@", [cc description]);
+  NSLog(@"User agent = %@", [cc userAgent]);
+  //NSLog(@"Browser major version = %i", [cc majorVersion]);
+
+  return (([[cc userAgentType] isEqualToString: @"IE"]
+          && [cc majorVersion] >= 7)
+         || ([[cc userAgentType] isEqualToString: @"Mozilla"]
+             && [cc majorVersion] >= 5)
+         || ([[cc userAgentType] isEqualToString: @"Safari"]
+             && [cc majorVersion] >= 4)
+         //      ([[cc userAgentType] isEqualToString: @"Konqueror"])
+          );
+}
+
+- (BOOL) isIE7Compatible
+{
+  WEClientCapabilities *cc;
+
+  cc = [[context request] clientCapabilities];
+  
+  return ([cc isWindowsBrowser] &&
+         ([[cc userAgent] rangeOfString: @"NT 5.1"].location != NSNotFound ||
+          [[cc userAgent] rangeOfString: @"NT 6"].location != NSNotFound));
+}
+
+- (BOOL) isMac
+{
+  WEClientCapabilities *cc;
+
+  cc = [[context request] clientCapabilities];
+
+  return [cc isMacBrowser];
+}
+
 @end /* UIxPageFrame */