]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Anais/AnaisUidSelector.m
better visualization according to the functional requirements
[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 @interface AnaisUidSelector : UIxComponent
27 {
28     NSArray *calendarUIDs;
29     NSString *uid;
30     NSString *userUid;
31 }
32
33 - (NSString *)prettyUid;
34 - (NSString *)userUid;
35 - (NSString *)_colorizedUid:(NSString *)_uid;
36 - (NSString *)showHref;
37
38 - (NSString *)jsCode;
39
40 @end
41
42 #include "common.h"
43 #include <NGObjWeb/SoUser.h>
44
45 @implementation AnaisUidSelector
46
47 - (id)init {
48     self = [super init];
49     if(self) {
50     }
51     return self;
52 }
53
54 - (void)dealloc {
55     [self->calendarUIDs release];
56     [self->uid release];
57     [self->userUid release];
58     [super dealloc];
59 }
60
61 - (void)setCalendarUIDs:(NSArray *)_calendarUIDs {
62     ASSIGN(self->calendarUIDs, _calendarUIDs);
63 }
64 - (NSArray *)calendarUIDs {
65     return self->calendarUIDs;
66 }
67 - (void)setUid:(NSString *)_uid {
68     ASSIGN(self->uid, _uid);
69 }
70 - (NSString *)uid {
71     return self->uid;
72 }
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]];
77 }
78
79 - (NSString *)_colorizedUid:(NSString *)_uid {
80     if([_uid isEqualToString:[self userUid]]) {
81         _uid = [NSString stringWithFormat:@"<span class=\""
82                                           @"anais_me\">%@</span>",
83             _uid];
84     }
85     return _uid;
86 }
87
88 /* Href */
89
90 - (NSString *)showHref {
91     return [self completeHrefForMethod:@"show"];
92 }
93
94
95 /* Helper */
96
97 - (NSString *)userUid {
98     if(self->userUid)
99         return self->userUid;
100
101     ASSIGN(self->userUid, [[self user] login]);
102     return self->userUid;
103 }
104
105 - (NSString *)calendarUIDString {
106     return [[self calendarUIDs] componentsJoinedByString:@","];
107 }
108
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";
114 }
115
116 /* JavaScript */
117
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"
128     @"}\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"
139     @"}\n"
140     @"function addMeToo() {\n"
141     @"  addUid('', '', '', '', '%@', '');\n"
142     @"  var td = document.getElementById('addMeToo');\n"
143     @"  td.setAttribute('style', 'visibility:hidden');\n"
144     @"}\n"
145     @"function addUid(division, cn, dn, email, uid, sn) {\n"
146     @"  if(!uid)\n"
147     @"    uid='unknown';\n"
148     @"  var e = document.getElementById('anaisUIDString');\n"
149     @"  var s = e.getAttribute('value');\n"
150     @"  if(s)\n"
151     @"    s = s + ',' + uid;\n"
152     @"  else\n"
153     @"    s = uid;\n"
154     @"  e.setAttribute('value', s);\n"
155     @"  var td = document.getElementById('anaisUIDList');\n"
156     @"  var text;\n"
157     @"  if(td.hasChildNodes()) {\n"
158     @"    text = document.createTextNode(', ');\n"
159     @"    td.appendChild(text);\n"
160     @"  }\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"
167     @"  }\n"
168     @"  else {\n"
169     @"    td.appendChild(text);\n"
170     @"  }\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"
175     @"}\n"
176     @"";
177     
178     return [NSString stringWithFormat:script,
179         [self userUid], [self userUid]];
180 }
181
182 @end