]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Anais/AnaisUidSelector.m
Adapting to Anais1.11
[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 }
38
39 - (NSString *)prettyUid;
40 - (NSString *)userUid;
41 - (NSString *)_colorizedUid:(NSString *)_uid;
42 - (NSString *)showHref;
43
44 - (NSString *)jsCode;
45
46 @end
47
48 #include "common.h"
49 #include <NGObjWeb/SoUser.h>
50
51 @implementation AnaisUidSelector
52
53 - (id)init {
54     self = [super init];
55     if(self) {
56     }
57     return self;
58 }
59
60 - (void)dealloc {
61     [self->calendarUIDs release];
62     [self->uid release];
63     [self->userUid release];
64     [super dealloc];
65 }
66
67 - (void)setCalendarUIDs:(NSArray *)_calendarUIDs {
68     ASSIGN(self->calendarUIDs, _calendarUIDs);
69 }
70 - (NSArray *)calendarUIDs {
71     return self->calendarUIDs;
72 }
73 - (void)setUid:(NSString *)_uid {
74     ASSIGN(self->uid, _uid);
75 }
76 - (NSString *)uid {
77     return self->uid;
78 }
79 - (NSString *)prettyUid {
80     if([self->calendarUIDs objectAtIndex:0] == self->uid)
81         return [self _colorizedUid:self->uid];
82     return [NSString stringWithFormat:@", %@", [self _colorizedUid:self->uid]];
83 }
84
85 - (NSString *)_colorizedUid:(NSString *)_uid {
86     if([_uid isEqualToString:[self userUid]]) {
87         _uid = [NSString stringWithFormat:@"<span class=\""
88                                           @"anais_me\">%@</span>",
89             _uid];
90     }
91     return _uid;
92 }
93
94 /* Href */
95
96 - (NSString *)showHref {
97     return [self completeHrefForMethod:@"show"];
98 }
99
100
101 /* Helper */
102
103 - (NSString *)userUid {
104     if(self->userUid)
105         return self->userUid;
106
107     ASSIGN(self->userUid, [[self user] login]);
108     return self->userUid;
109 }
110
111 - (NSString *)calendarUIDString {
112     return [[self calendarUIDs] componentsJoinedByString:@","];
113 }
114
115 /* this is to determine the initial visibility of the 'addMeToo' button */
116 - (NSString *)meTooStyle {
117     if([[self calendarUIDs] containsObject:userUid])
118         return @"visibility:hidden";
119     return @"visibility:visible";
120 }
121
122 /* JavaScript */
123
124 - (NSString *)jsCode {
125     static NSString *script = \
126     @"function clearElementWithId(elemId) {\n"
127     @"  var o = document.getElementById(elemId);\n"
128     @"  var dst = o.parentNode;\n"
129     @"  var n = document.createElement('td');\n"
130     @"  n.setAttribute('id', elemId);\n"
131     @"  n.setAttribute('align', 'left');\n"
132     @"  n.setAttribute('class', 'anais_uids');\n"
133     @"  dst.replaceChild(n, o);\n"
134     @"}\n"
135     @"function clearUidList() {\n"
136     @"  clearElementWithId('anaisUIDList');\n"
137     @"  var e = document.getElementById('anaisUIDString');\n"
138     @"  e.setAttribute('value', '');\n"
139     @"  var td = document.getElementById('addMeToo');\n"
140     @"  td.setAttribute('style', 'visibility:visible');\n"
141     @"  td = document.getElementById('clearUidList');\n"
142     @"  td.setAttribute('style', 'visibility:hidden');\n"
143     @"  td = document.getElementById('showUidList');\n"
144     @"  td.setAttribute('style', 'visibility:hidden');\n"
145     @"}\n"
146     @"function addMeToo() {\n"
147     @"  addUid('', '', '', '', '%@', '');\n"
148     @"  var td = document.getElementById('addMeToo');\n"
149     @"  td.setAttribute('style', 'visibility:hidden');\n"
150     @"}\n"
151     @"function addUidFromAnais() {\n"
152     @"  var uid = arguments[2]; \n"
153     @"  alert(uid); \n"
154     @"  addUid('','','','',uid,''); \n"
155     @"}\n"
156     @"function addUid(division, cn, dn, email, uid, sn) {\n"
157     @"  if(!uid)\n"
158     @"    return;\n"
159     @"  var e = document.getElementById('anaisUIDString');\n"
160     @"  var s = e.getAttribute('value');\n"
161     @"  if(s)\n"
162     @"    s = s + ',' + uid;\n"
163     @"  else\n"
164     @"    s = uid;\n"
165     @"  e.setAttribute('value', s);\n"
166     @"  var td = document.getElementById('anaisUIDList');\n"
167     @"  var text;\n"
168     @"  if(td.hasChildNodes()) {\n"
169     @"    text = document.createTextNode(', ');\n"
170     @"    td.appendChild(text);\n"
171     @"  }\n"
172     @"  text = document.createTextNode(uid);\n"
173     @"  if(uid == '%@') {\n"
174     @"    var span = document.createElement('span');\n"
175     @"    span.setAttribute('class', 'anais_me');\n"
176     @"    span.appendChild(text);\n"
177     @"    td.appendChild(span);\n"
178     @"  }\n"
179     @"  else {\n"
180     @"    td.appendChild(text);\n"
181     @"  }\n"
182     @"  td = document.getElementById('clearUidList');\n"
183     @"  td.setAttribute('style', 'visibility:visible');\n"
184     @"  td = document.getElementById('showUidList');\n"
185     @"  td.setAttribute('style', 'visibility:visible');\n"
186     @"}\n"
187     @"";
188     
189     return [NSString stringWithFormat:script,
190         [self userUid], [self userUid]];
191 }
192
193 @end