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