]> err.no Git - scalable-opengroupware.org/blobdiff - UI/MailerUI/UIxMailMainFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1305 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailMainFrame.m
index 43997a083fc4bfbd19de0008bd5c42bc8bdfb257..e45d9d3016b36d8a37b3902ed8628b868131d44a 100644 (file)
   02111-1307, USA.
 */
 
+#import <Foundation/NSUserDefaults.h>
+
+#import <NGObjWeb/WOContext.h>
+#import <NGObjWeb/WORequest.h>
+#import <NGObjWeb/WOResponse.h>
+#import <NGObjWeb/SoComponent.h>
+#import <NGExtensions/NSString+misc.h>
+
 #import <SoObjects/Mailer/SOGoMailObject.h>
 #import <SoObjects/Mailer/SOGoMailAccounts.h>
-#import <SoObjects/SOGo/NSString+Utilities.h>
-#import <SoObjects/SOGo/NSObject+Utilities.h>
+#import <SoObjects/SOGo/NSDictionary+URL.h>
+#import <SoObjects/SOGo/NSArray+Utilities.h>
+#import <SoObjects/SOGo/SOGoUser.h>
 #import <SOGoUI/UIxComponent.h>
-#import "UIxMailMainFrame.h"
 
-#import "common.h"
-#import <NGObjWeb/SoComponent.h>
+#import "UIxMailMainFrame.h"
 
 @implementation UIxMailMainFrame
 
-static NSString *treeRootClassName = nil;
+- (void) _setupContext
+{
+  SOGoUser *activeUser;
+  NSString *login, *module;
+  SOGoMailAccounts *clientObject;
 
-+ (void)initialize {
-  NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
-  
-  treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
-  if (treeRootClassName)
-    NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
-  else
-    treeRootClassName = @"SOGoMailAccounts";
-}
+  activeUser = [context activeUser];
+  login = [activeUser login];
+  clientObject = [self clientObject];
+
+  module = [clientObject nameInContainer];
 
-- (void)dealloc {
-  [self->rootURL     release];
-  [self->userRootURL release];
-  [super dealloc];
+  ud = [activeUser userSettings];
+  moduleSettings = [ud objectForKey: module];
+  if (!moduleSettings)
+    {
+      moduleSettings = [NSMutableDictionary new];
+      [moduleSettings autorelease];
+    }
+  [ud setObject: moduleSettings forKey: module];
 }
 
 /* accessors */
 - (NSString *) mailAccounts
 {
-  SOGoMailAccounts *co;
+  NSArray *accounts, *accountNames;
 
-  co = [self clientObject];
-
-  return [[co fetchAllIdentities] jsonRepresentation];
-}
+  accounts = [[context activeUser] mailAccounts];
+  accountNames = [accounts objectsForKey: @"name"];
 
-- (NSString *)treeRootClassName {
-  return treeRootClassName;
-}
-
-- (void)setHideFolderTree:(BOOL)_flag {
-   self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
-}
-- (BOOL)hideFolderTree {
-  return self->mmfFlags.hideFolderTree ? YES : NO;
+  return [accountNames jsonRepresentation];
 }
 
-- (NSString *) pageFormURL {
+- (NSString *) pageFormURL
+{
   NSString *u;
   NSRange  r;
   
@@ -114,136 +116,51 @@ static NSString *treeRootClassName = nil;
   return [u hasSuffix:@"/"] ? @"view" : @"#";
 }
 
-- (BOOL)showLinkBanner {
-  return YES;
-}
-
-- (NSString *)bannerToolbarStyle {
-  return nil;
-}
-
-- (NSString *)bannerConsumeStyle {
-  return nil;
-}
-
-/* URL generation */
-// TODO: I think all this should be done by the clientObject?!
-// TODO: is the stuff below necessary at all in the mailer frame?
-
-- (NSString *)rootURL {
-  WOContext *ctx;
-  NSArray   *traversalObjects;
+- (id <WOActionResults>) composeAction
+{
+  NSArray *accounts;
+  NSString *firstAccount, *newLocation, *parameters;
+  SOGoMailAccounts *co;
+  NSDictionary *formValues;
 
-  if (self->rootURL != nil)
-    return self->rootURL;
+  co = [self clientObject];
+  accounts = [[context activeUser] mailAccounts];
+  firstAccount = [[accounts objectsForKey: @"name"] objectAtIndex: 0];
+  formValues = [[context request] formValues];
+  parameters = [formValues count] > 0 ? [formValues asURLParameters] : @"?mailto=";
+  newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
+                         [co baseURLInContext: context],
+                         firstAccount,
+                         parameters];
 
-  ctx = [self context];
-  traversalObjects = [ctx objectTraversalStack];
-  self->rootURL = [[[traversalObjects objectAtIndex:0]
-                                      rootURLInContext:ctx]
-                                      copy];
-  return self->rootURL;
+  return [self redirectToLocation: newLocation];
 }
 
-- (NSString *)userRootURL {
-  WOContext *ctx;
-  NSArray   *traversalObjects;
-
-  if (self->userRootURL)
-    return self->userRootURL;
-
-  ctx = [self context];
-  traversalObjects = [ctx objectTraversalStack];
-  self->userRootURL = [[[[traversalObjects objectAtIndex:1]
-                                           baseURLInContext:ctx]
-                                           stringByAppendingString:@"/"]
-                                           retain];
-  return self->userRootURL;
-}
+- (WOResponse *) getFoldersStateAction
+{
+  NSString *expandedFolders;
 
-- (NSString *)calendarRootURL {
-  return [[self userRootURL] stringByAppendingString:@"Calendar/"];
-}
+  [self _setupContext];
+  expandedFolders = [moduleSettings objectForKey: @"ExpandedFolders"];
 
-- (NSString *)contactsRootURL {
-  return [[self userRootURL] stringByAppendingString:@"Contacts/"];
+  return [self responseWithStatus: 200 andString: expandedFolders];
 }
 
-/* error handling */
-
-- (BOOL)hasErrorText {
-  return [[[[self context] request] formValueForKey:@"error"] length] > 0
-    ? YES : NO;
-}
-- (NSString *)errorText {
-  return [[[self context] request] formValueForKey:@"error"];
-}
-
-- (NSString *)errorAlertJavaScript {
-  NSString *errorText;
-  
-  if ([(errorText = [self errorText]) length] == 0)
-    return nil;
-  
-  // TODO: proper JavaScript escaping
-  errorText = [errorText stringByEscapingHTMLString];
-  errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
+- (WOResponse *) saveFoldersStateAction
+{
+  WORequest *request;
+  NSString *expandedFolders;
   
-  return [NSString stringWithFormat:
-                    @"<script language=\"JavaScript\">"
-                    @"alert(\"%@\");"
-                    @"</script>", errorText];
-}
-
-/* FIXME: migrated methods which might not work yet... */
-// #warning check this
-// - (NSString *) mailFolderName
-// {
-//   NSMutableArray *mailboxes;
-//   SOGoMailObject *currentObject;
+  [self _setupContext];
+  request = [context request];
+  expandedFolders = [request formValueForKey: @"expandedFolders"];
 
-//   mailboxes = [NSMutableArray new];
-//   [mailboxes autorelease];
+  [moduleSettings setObject: expandedFolders
+                 forKey: @"ExpandedFolders"];
 
-//   currentObject = [self clientObject];
-//   while (![currentObject isKindOfClass: [SOGoMailAccounts class]])
-//     {
-//       [mailboxes insertObject: [currentObject nameInContainer] atIndex: 0];
-//       currentObject = [currentObject container];
-//     }
-
-//   return [NSString stringWithFormat: @"/%@",
-//                    [mailboxes componentsJoinedByString: @"/"]];
-// }
-
-- (id) composeAction
-{
-  NSArray *c;
-  NSString *inbox, *url, *parameter;
-  NSMutableDictionary *urlParams;
-  id actionResult;
-
-  c = [[self clientObject] toManyRelationshipKeys];
-  if ([c count] > 0)
-    {
-      urlParams = [NSMutableDictionary new];
-      [urlParams autorelease];
-
-      parameter = [self queryParameterForKey: @"mailto"];
-      if (parameter)
-        [urlParams setObject: parameter
-                   forKey: @"mailto"];
-      inbox = [NSString stringWithFormat: @"%@/INBOX",
-                        [c objectAtIndex: 0]];
-      url = [inbox composeURLWithAction: @"compose"
-                   parameters: urlParams
-                   andHash: NO];
-      actionResult = [self redirectToLocation: url];
-    }
-  else
-    actionResult = self;
+  [ud synchronize];
 
-  return actionResult;
+  return [self responseWithStatus: 204];
 }
 
 @end /* UIxMailMainFrame */