]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailMoveToPopUp.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1036 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailMoveToPopUp.m
1 /*
2  Copyright (C) 2000-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 #include <NGObjWeb/WOComponent.h>
23
24 @class NSString, NSMutableArray, NSDictionary;
25
26 @interface UIxMailMoveToPopUp : WOComponent
27 {
28   NSString *identifier;
29   NSString *callback;
30   id       rootNodes;
31   id       item;
32 }
33
34 - (NSString *)itemDisplayString;
35 - (NSString *)itemURL;
36   
37 - (void)_appendEntriesFromNodeDict:(NSDictionary *)_dict
38   toList:(NSMutableArray *)_list
39   withPrefix:(NSString *)_pathPrefix;
40
41 @end
42
43 #include "common.h"
44
45 @implementation UIxMailMoveToPopUp
46
47 - (void)dealloc {
48   [self->identifier release];
49   [self->callback   release];
50   [self->rootNodes  release];
51   [self->item       release];
52   [super dealloc];
53 }
54
55 /* accessors */
56
57 - (void)setIdentifier:(NSString *)_identifier {
58   ASSIGN(self->identifier, _identifier);
59 }
60 - (NSString *)identifier {
61   return self->identifier;
62 }
63
64 - (void)setCallback:(NSString *)_callback {
65   ASSIGN(self->callback, _callback);
66 }
67 - (NSString *)callback {
68   return self->callback;
69 }
70
71 - (void)setRootNodes:(id)_rootNodes {
72   ASSIGN(self->rootNodes, _rootNodes);
73 }
74 - (id)rootNodes {
75   return self->rootNodes;
76 }
77
78 - (void)setItem:(id)_item {
79   ASSIGN(self->item, _item);
80 }
81 - (id)item {
82   return self->item;
83 }
84
85 - (NSArray *)sortedNodes {
86   NSMutableArray *r;
87   NSDictionary *dict;
88
89   r = [NSMutableArray arrayWithCapacity:10];
90   
91   /* INBOX node */
92   dict = [[self->rootNodes objectForKey:@"children"] objectAtIndex:0];
93   [self _appendEntriesFromNodeDict:dict toList:r withPrefix:nil];
94   return r;
95 }
96
97 - (void)_appendEntriesFromNodeDict:(NSDictionary *)_dict
98   toList:(NSMutableArray *)_list
99   withPrefix:(NSString *)_pathPrefix
100 {
101   NSMutableDictionary *e;
102   NSString *title, *link;
103   NSArray  *children;
104   unsigned count, i;
105
106   title = [_dict objectForKey:@"title"];
107   link  = [_dict objectForKey:@"link"];
108   
109   e = [[NSMutableDictionary alloc] initWithCapacity:2];
110   _pathPrefix = (_pathPrefix == nil)
111     ? title
112     : [NSString stringWithFormat:@"%@.%@", _pathPrefix, title];
113   [e setObject:_pathPrefix forKey:@"title"];
114   [e setObject:link        forKey:@"link"];
115   [_list addObject:e];
116   [e release]; e = nil;
117   
118   children = [_dict objectForKey:@"children"];
119   count = [children count];
120   for (i = 0; i < count; i++) {
121     NSDictionary *dict;
122     
123     dict = [children objectAtIndex:i];
124     [self _appendEntriesFromNodeDict:dict
125                               toList:_list
126                           withPrefix:_pathPrefix];
127   }
128 }
129
130 - (NSString *)itemDisplayString {
131   return [self->item objectForKey:@"title"];
132 }
133
134 - (NSString *)itemURL {
135   return [self->item objectForKey:@"link"];
136 }
137
138 - (NSString *)itemDisabledValue {
139   return [[self itemURL] isEqualToString:@"."] ? @" disabled" : @"";
140 }
141
142 /* JavaScript */
143
144 - (NSString *)selectItemJS {
145   static NSString *selectJS = \
146     @"javascript:if(!this.hasAttribute('disabled')) %@('%@');";
147   return [NSString stringWithFormat:selectJS, self->callback, [self itemURL]];
148 }
149
150 @end /* UIxMailMoveToPopUp */