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;
return [u hasSuffix:@"/"] ? @"view" : @"#";
}
-- (BOOL)showLinkBanner {
- if ([self hideFolderTree]) return NO;
- return YES;
-}
-- (NSString *)bannerToolbarStyle {
-#if 0 // 32x32
- return [self showLinkBanner] ? @"top: 58px;" : nil /* fallback to CSS */;
-#else // 24x24
- return [self showLinkBanner] ? @"top: 58px;" : nil /* fallback to CSS */;
-#endif
-}
-- (NSString *)bannerConsumeStyle {
-#if 0 // 32x32
- return [self showLinkBanner] ? @"height: 116px;" : nil /* fallback to CSS */;
-#else // 24x24
- return [self showLinkBanner] ? @"height: 110px;" : nil /* fallback to CSS */;
-#endif
-}
-
-/* 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 */