]> 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 9a6915e457f04719f081d59f63230bd91888dc25..e45d9d3016b36d8a37b3902ed8628b868131d44a 100644 (file)
   02111-1307, USA.
 */
 
-#include <SOGoUI/UIxComponent.h>
+#import <Foundation/NSUserDefaults.h>
 
-@interface UIxMailMainFrame : UIxComponent
-{
-  NSString *title;
-  NSString *rootURL;
-  NSString *userRootURL;
-  id       item;
-  struct {
-    int hideFolderTree:1;
-    int hideFrame:1; /* completely disables all the frame around the comp. */
-    int reserved:30;
-  } mmfFlags;
-}
-
-- (NSString *)rootURL;
-- (NSString *)userRootURL;
-- (NSString *)calendarRootURL;
-
-@end
+#import <NGObjWeb/WOContext.h>
+#import <NGObjWeb/WORequest.h>
+#import <NGObjWeb/WOResponse.h>
+#import <NGObjWeb/SoComponent.h>
+#import <NGExtensions/NSString+misc.h>
 
-@interface UIxMailPanelFrame : UIxMailMainFrame
-@end
+#import <SoObjects/Mailer/SOGoMailObject.h>
+#import <SoObjects/Mailer/SOGoMailAccounts.h>
+#import <SoObjects/SOGo/NSDictionary+URL.h>
+#import <SoObjects/SOGo/NSArray+Utilities.h>
+#import <SoObjects/SOGo/SOGoUser.h>
+#import <SOGoUI/UIxComponent.h>
 
-#include "common.h"
-#include <NGObjWeb/SoComponent.h>
+#import "UIxMailMainFrame.h"
 
 @implementation UIxMailMainFrame
 
-static NSString *treeRootClassName = nil;
-
-+ (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";
-}
-
-- (void)dealloc {
-  [self->item        release];
-  [self->title       release];
-  [self->rootURL     release];
-  [self->userRootURL release];
-  [super dealloc];
+- (void) _setupContext
+{
+  SOGoUser *activeUser;
+  NSString *login, *module;
+  SOGoMailAccounts *clientObject;
+
+  activeUser = [context activeUser];
+  login = [activeUser login];
+  clientObject = [self clientObject];
+
+  module = [clientObject nameInContainer];
+
+  ud = [activeUser userSettings];
+  moduleSettings = [ud objectForKey: module];
+  if (!moduleSettings)
+    {
+      moduleSettings = [NSMutableDictionary new];
+      [moduleSettings autorelease];
+    }
+  [ud setObject: moduleSettings forKey: module];
 }
 
 /* accessors */
+- (NSString *) mailAccounts
+{
+  NSArray *accounts, *accountNames;
 
-- (NSString *)treeRootClassName {
-  return treeRootClassName;
-}
-
-- (void)setHideFolderTree:(BOOL)_flag {
-   self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
-}
-- (BOOL)hideFolderTree {
-  return self->mmfFlags.hideFolderTree ? YES : NO;
-}
-
-- (void)setHideFrame:(BOOL)_flag {
-   self->mmfFlags.hideFrame = _flag ? 1 : 0;
-}
-- (BOOL)hideFrame {
-  return self->mmfFlags.hideFrame ? YES : NO;
-}
-
-- (void)setTitle:(NSString *)_value {
-  ASSIGNCOPY(self->title, _value);
-}
-- (NSString *)title {
-  if ([self->title length] == 0)
-    return @"OpenGroupware.org";
-  
-  return self->title;
-}
+  accounts = [[context activeUser] mailAccounts];
+  accountNames = [accounts objectsForKey: @"name"];
 
-- (void)setItem:(id)_item {
-  ASSIGN(self->item, _item);
-}
-- (id)item {
-  return self->item;
+  return [accountNames jsonRepresentation];
 }
 
-- (NSString *)pageFormURL {
+- (NSString *) pageFormURL
+{
   NSString *u;
   NSRange  r;
   
@@ -149,118 +116,51 @@ static NSString *treeRootClassName = nil;
   return [u hasSuffix:@"/"] ? @"view" : @"#";
 }
 
-- (BOOL)showLinkBanner {
-  return NO;
-}
-- (NSString *)bannerToolbarStyle {
-  return nil;
-}
-- (NSString *)bannerConsumeStyle {
-  return nil;
-}
-
-/* notifications */
-
-- (void)sleep {
-  [self->item release]; self->item = nil;
-  [super sleep];
-}
-
-/* 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;
-
-  if (self->rootURL != nil)
-    return self->rootURL;
-
-  ctx = [self context];
-  traversalObjects = [ctx objectTraversalStack];
-  self->rootURL = [[[traversalObjects objectAtIndex:0]
-                                      rootURLInContext:ctx]
-                                      copy];
-  return self->rootURL;
-}
-
-- (NSString *)userRootURL {
-  WOContext *ctx;
-  NSArray   *traversalObjects;
+- (id <WOActionResults>) composeAction
+{
+  NSArray *accounts;
+  NSString *firstAccount, *newLocation, *parameters;
+  SOGoMailAccounts *co;
+  NSDictionary *formValues;
 
-  if (self->userRootURL)
-    return self->userRootURL;
+  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->userRootURL = [[[[traversalObjects objectAtIndex:1]
-                                           baseURLInContext:ctx]
-                                           stringByAppendingString:@"/"]
-                                           retain];
-  return self->userRootURL;
+  return [self redirectToLocation: newLocation];
 }
 
-- (NSString *)calendarRootURL {
-  return [[self userRootURL] stringByAppendingString:@"Calendar/"];
-}
-- (NSString *)contactsRootURL {
-  return [[self userRootURL] stringByAppendingString:@"Contacts/"];
-}
+- (WOResponse *) getFoldersStateAction
+{
+  NSString *expandedFolders;
 
-/* error handling */
+  [self _setupContext];
+  expandedFolders = [moduleSettings objectForKey: @"ExpandedFolders"];
 
-- (BOOL)hasErrorText {
-  return [[[[self context] request] formValueForKey:@"error"] length] > 0
-    ? YES : NO;
-}
-- (NSString *)errorText {
-  return [[[self context] request] formValueForKey:@"error"];
+  return [self responseWithStatus: 200 andString: expandedFolders];
 }
 
-- (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];
-}
+  [self _setupContext];
+  request = [context request];
+  expandedFolders = [request formValueForKey: @"expandedFolders"];
 
-/* URLs */
+  [moduleSettings setObject: expandedFolders
+                 forKey: @"ExpandedFolders"];
 
-- (NSString *)relativeHomePath {
-  return [self relativePathToUserFolderSubPath:@""];
-}
+  [ud synchronize];
 
-- (NSString *)relativeCalendarPath {
-  return [self relativePathToUserFolderSubPath:@"Calendar/"];
-}
-
-- (NSString *)relativeContactsPath {
-  return [self relativePathToUserFolderSubPath:@"Contacts/"];
-}
-
-- (NSString *)relativeMailPath {
-  return [self relativePathToUserFolderSubPath:@"Mail/"];
+  return [self responseWithStatus: 204];
 }
 
 @end /* UIxMailMainFrame */
-
-@implementation UIxMailPanelFrame
-
-- (BOOL)hideFolderTree {
-  return YES;
-}
-- (BOOL)showLinkBanner {
-  return NO;
-}
-
-@end /* UIxMailPanelFrame */