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