2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
24 #include <SOGoUI/UIxComponent.h>
26 @interface AnaisUidSelector : UIxComponent
28 NSArray *calendarUIDs;
33 - (NSString *)prettyUid;
34 - (NSString *)userUid;
35 - (NSString *)_colorizedUid:(NSString *)_uid;
36 - (NSString *)showHref;
43 #include <NGObjWeb/SoUser.h>
45 @implementation AnaisUidSelector
55 [self->calendarUIDs release];
57 [self->userUid release];
61 - (void)setCalendarUIDs:(NSArray *)_calendarUIDs {
62 ASSIGN(self->calendarUIDs, _calendarUIDs);
64 - (NSArray *)calendarUIDs {
65 return self->calendarUIDs;
67 - (void)setUid:(NSString *)_uid {
68 ASSIGN(self->uid, _uid);
73 - (NSString *)prettyUid {
74 if([self->calendarUIDs objectAtIndex:0] == self->uid)
75 return [self _colorizedUid:self->uid];
76 return [NSString stringWithFormat:@", %@", [self _colorizedUid:self->uid]];
79 - (NSString *)_colorizedUid:(NSString *)_uid {
80 if([_uid isEqualToString:[self userUid]]) {
81 _uid = [NSString stringWithFormat:@"<span class=\""
82 @"anais_me\">%@</span>",
90 - (NSString *)showHref {
91 return [self completeHrefForMethod:@"show"];
97 - (NSString *)userUid {
101 ASSIGN(self->userUid, [[self user] login]);
102 return self->userUid;
105 - (NSString *)calendarUIDString {
106 return [[self calendarUIDs] componentsJoinedByString:@","];
109 /* this is to determine the initial visibility of the 'addMeToo' button */
110 - (NSString *)meTooStyle {
111 if([[self calendarUIDs] containsObject:userUid])
112 return @"visibility:hidden";
113 return @"visibility:visible";
118 - (NSString *)jsCode {
119 static NSString *script = \
120 @"function clearElementWithId(elemId) {\n"
121 @" var o = document.getElementById(elemId);\n"
122 @" var dst = o.parentNode;\n"
123 @" var n = document.createElement('td');\n"
124 @" n.setAttribute('id', elemId);\n"
125 @" n.setAttribute('align', 'left');\n"
126 @" n.setAttribute('class', 'anais_uids');\n"
127 @" dst.replaceChild(n, o);\n"
129 @"function clearUidList() {\n"
130 @" clearElementWithId('anaisUIDList');\n"
131 @" var e = document.getElementById('anaisUIDString');\n"
132 @" e.setAttribute('value', '');\n"
133 @" var td = document.getElementById('addMeToo');\n"
134 @" td.setAttribute('style', 'visibility:visible');\n"
135 @" td = document.getElementById('clearUidList');\n"
136 @" td.setAttribute('style', 'visibility:hidden');\n"
137 @" td = document.getElementById('showUidList');\n"
138 @" td.setAttribute('style', 'visibility:hidden');\n"
140 @"function addMeToo() {\n"
141 @" addUid('', '', '', '', '%@', '');\n"
142 @" var td = document.getElementById('addMeToo');\n"
143 @" td.setAttribute('style', 'visibility:hidden');\n"
145 @"function addUid(division, cn, dn, email, uid, sn) {\n"
148 @" var e = document.getElementById('anaisUIDString');\n"
149 @" var s = e.getAttribute('value');\n"
151 @" s = s + ',' + uid;\n"
154 @" e.setAttribute('value', s);\n"
155 @" var td = document.getElementById('anaisUIDList');\n"
157 @" if(td.hasChildNodes()) {\n"
158 @" text = document.createTextNode(', ');\n"
159 @" td.appendChild(text);\n"
161 @" text = document.createTextNode(uid);\n"
162 @" if(uid == '%@') {\n"
163 @" var span = document.createElement('span');\n"
164 @" span.setAttribute('class', 'anais_me');\n"
165 @" span.appendChild(text);\n"
166 @" td.appendChild(span);\n"
169 @" td.appendChild(text);\n"
171 @" td = document.getElementById('clearUidList');\n"
172 @" td.setAttribute('style', 'visibility:visible');\n"
173 @" td = document.getElementById('showUidList');\n"
174 @" td.setAttribute('style', 'visibility:visible');\n"
178 return [NSString stringWithFormat:script,
179 [self userUid], [self userUid]];