]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Anais/AnaisUidSelector.m
rewritten the UID selector to display CN's instead of UIDs
[scalable-opengroupware.org] / SOGo / UI / Anais / AnaisUidSelector.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OGo
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
24 #include <SOGoUI/UIxComponent.h>
25
26 /*
27  AnaisUidSelector
28  
29  Modifiable list of uids used to select multiple calendars for viewing at once.
30 */
31
32 @interface AnaisUidSelector : UIxComponent
33 {
34     NSArray *calendarUIDs;
35     NSString *uid;
36     NSString *userUid;
37     NSString *userCN;
38 }
39
40 - (NSString *)prettyUid;
41 - (NSString *)userUid;
42 - (NSString *)userCN;
43 - (NSString *)_colorizedUid:(NSString *)_uid;
44 - (NSString *)showHref;
45
46 - (NSString *)jsCode;
47
48 @end
49
50 #include "common.h"
51 #include <NGObjWeb/SoUser.h>
52 #include <SOGo/AgenorUserManager.h>
53 #include <SOGo/SOGoUser.h>
54 #include <SOGo/WOContext+Agenor.h>
55
56 @implementation AnaisUidSelector
57
58 - (id)init {
59     self = [super init];
60     if(self) {
61     }
62     return self;
63 }
64
65 - (void)dealloc {
66     [self->calendarUIDs release];
67     [self->uid release];
68     [self->userUid release];
69     [super dealloc];
70 }
71
72 - (void)setCalendarUIDs:(NSArray *)_calendarUIDs {
73     ASSIGN(self->calendarUIDs, _calendarUIDs);
74 }
75 - (NSArray *)calendarUIDs {
76     return self->calendarUIDs;
77 }
78 - (void)setUid:(NSString *)_uid {
79     ASSIGN(self->uid, _uid);
80 }
81 - (NSString *)uid {
82     return self->uid;
83 }
84 - (NSString *)prettyUid {
85   AgenorUserManager *um;
86   NSString          *cn;
87
88     if([self->calendarUIDs objectAtIndex:0] == self->uid)
89         return [self _colorizedUid:[self userCN]];
90     
91     um = [AgenorUserManager sharedUserManager];
92     cn = [um getCNForUID:self->uid];
93     return [NSString stringWithFormat:@", %@", [self _colorizedUid:cn]];
94 }
95
96 - (NSString *)_colorizedUid:(NSString *)_uid {
97     if([_uid isEqualToString:[self userCN]]) {
98         _uid = [NSString stringWithFormat:@"<span class=\""
99                                           @"anais_me\">%@</span>",
100             _uid];
101     }
102     return _uid;
103 }
104
105 /* Href */
106
107 - (NSString *)showHref {
108     return [self completeHrefForMethod:@"show"];
109 }
110
111
112 /* Helper */
113
114 - (NSString *)userUid {
115   if(!self->userUid) {
116     ASSIGN(self->userUid, [[self user] login]);
117   }
118   return self->userUid;
119 }
120
121 - (NSString *)userCN {
122   if (!self->userCN) {
123     ASSIGN(self->userCN, [[[self context] activeUser] cn]);
124   }
125   return self->userCN;
126 }
127
128 - (NSString *)calendarUIDString {
129     return [[self calendarUIDs] componentsJoinedByString:@","];
130 }
131
132 /* this is to determine the initial visibility of the 'addMeToo' button */
133 - (NSString *)meTooStyle {
134     if([[self calendarUIDs] containsObject:userUid])
135         return @"visibility:hidden";
136     return @"visibility:visible";
137 }
138
139 /* JavaScript */
140
141 - (NSString *)jsCode {
142     static NSString *script = \
143     @"function clearElementWithId(elemId) {\n"
144     @"  var o = document.getElementById(elemId);\n"
145     @"  var dst = o.parentNode;\n"
146     @"  var n = document.createElement('td');\n"
147     @"  n.setAttribute('id', elemId);\n"
148     @"  n.setAttribute('align', 'left');\n"
149     @"  n.setAttribute('class', 'anais_uids');\n"
150     @"  dst.replaceChild(n, o);\n"
151     @"}\n"
152     @"function clearUidList() {\n"
153     @"  clearElementWithId('anaisUIDList');\n"
154     @"  var e = document.getElementById('anaisUIDString');\n"
155     @"  e.setAttribute('value', '');\n"
156     @"  var td = document.getElementById('addMeToo');\n"
157     @"  td.setAttribute('style', 'visibility:visible');\n"
158     @"  td = document.getElementById('clearUidList');\n"
159     @"  td.setAttribute('style', 'visibility:hidden');\n"
160     @"  td = document.getElementById('showUidList');\n"
161     @"  td.setAttribute('style', 'visibility:hidden');\n"
162     @"}\n"
163     @"function addMeToo() {\n"
164     @"  addUid('', '', '%@', '', '%@', '');\n"
165     @"  var td = document.getElementById('addMeToo');\n"
166     @"  td.setAttribute('style', 'visibility:hidden');\n"
167     @"}\n"
168     @"function clearAllAndAddMe() {\n"
169     @"  clearUidList();\n"
170     @"  addMeToo();\n"
171     @"}\n"
172     @"function addUidFromAnais(type, email, uid, sn, cn, dn) {\n"
173     @"  addUid(type, email, uid, sn, cn, dn); \n"
174     @"}\n"
175     @"function addUid(type, email, uid, sn, cn, dn) {\n"
176     @"  if(!uid)\n"
177     @"    return;\n"
178     @"  var e = document.getElementById('anaisUIDString');\n"
179     @"  var s = e.getAttribute('value');\n"
180     @"  if(s)\n"
181     @"    s = s + ',' + uid;\n"
182     @"  else\n"
183     @"    s = uid;\n"
184     @"  e.setAttribute('value', s);\n"
185     @"  var td = document.getElementById('anaisUIDList');\n"
186     @"  var text;\n"
187     @"  if(td.hasChildNodes()) {\n"
188     @"    text = document.createTextNode(', ');\n"
189     @"    td.appendChild(text);\n"
190     @"  }\n"
191     @"  text = document.createTextNode(cn);\n"
192     @"  if(uid == '%@') {\n"
193     @"    var span = document.createElement('span');\n"
194     @"    span.setAttribute('class', 'anais_me');\n"
195     @"    span.appendChild(text);\n"
196     @"    td.appendChild(span);\n"
197     @"  }\n"
198     @"  else {\n"
199     @"    td.appendChild(text);\n"
200     @"  }\n"
201     @"  td = document.getElementById('clearUidList');\n"
202     @"  td.setAttribute('style', 'visibility:visible');\n"
203     @"  td = document.getElementById('showUidList');\n"
204     @"  td.setAttribute('style', 'visibility:visible');\n"
205     @"}\n"
206     @"";
207     
208     return [NSString stringWithFormat:script,
209                                      [self userUid],
210                                      [self userCN],
211                                      [self userUid]];
212 }
213
214 @end