@interface AnaisUidSelector : UIxComponent
{
- NSArray *calendarUIDs;
- NSString *uid;
- NSString *userUid;
- NSString *userCN;
+ NSString *userUID;
+ NSString *userUIDString;
+ NSString *activeUserCN;
+ int userUIDIdx;
}
-- (NSString *)prettyUid;
-- (NSString *)userUid;
-- (NSString *)userCN;
-- (NSString *)_colorizedUid:(NSString *)_uid;
+- (NSString *)prettyCN;
- (NSString *)showHref;
-- (NSString *)jsCode;
-
@end
#include "common.h"
#include <NGObjWeb/SoUser.h>
+#include <NGObjWeb/WOContext+SoObjects.h>
#include <SOGo/AgenorUserManager.h>
#include <SOGo/SOGoUser.h>
-#include <SOGo/WOContext+Agenor.h>
+#include "SoObjects/Appointments/SOGoAppointmentFolder.h"
@implementation AnaisUidSelector
-- (id)init {
- self = [super init];
- if(self) {
- }
- return self;
-}
-
- (void)dealloc {
- [self->calendarUIDs release];
- [self->uid release];
- [self->userUid release];
- [super dealloc];
+ [self->userUID release];
+ [self->userUIDString release];
+ [self->activeUserCN release];
+ [super dealloc];
}
-- (void)setCalendarUIDs:(NSArray *)_calendarUIDs {
- ASSIGN(self->calendarUIDs, _calendarUIDs);
+/* Accessors */
+
+- (void)setUserUID:(NSString *)_userUID {
+ ASSIGN(self->userUID, _userUID);
}
-- (NSArray *)calendarUIDs {
- return self->calendarUIDs;
+- (NSString *)userUID {
+ return self->userUID;
}
-- (void)setUid:(NSString *)_uid {
- ASSIGN(self->uid, _uid);
+- (void)setUserUIDIdx:(int)_userUIDIdx {
+ self->userUIDIdx = _userUIDIdx;
}
-- (NSString *)uid {
- return self->uid;
+- (int)userUIDIdx {
+ return self->userUIDIdx;
+}
+- (BOOL)needsComma {
+ return self->userUIDIdx == 0 ? NO : YES;
}
-- (NSString *)prettyUid {
- AgenorUserManager *um;
- NSString *cn;
- if([self->calendarUIDs objectAtIndex:0] == self->uid)
- return [self _colorizedUid:[self userCN]];
+- (NSString *)userUIDString {
+ if (!self->userUIDString) {
+ NSString *calendarUIDString;
- um = [AgenorUserManager sharedUserManager];
- cn = [um getCNForUID:self->uid];
- return [NSString stringWithFormat:@", %@", [self _colorizedUid:cn]];
+ calendarUIDString = [[[self clientObject] calendarUIDs]
+ componentsJoinedByString:@","];
+ ASSIGN(self->userUIDString, calendarUIDString);
+ }
+ return self->userUIDString;
}
-- (NSString *)_colorizedUid:(NSString *)_uid {
- if([_uid isEqualToString:[self userCN]]) {
- _uid = [NSString stringWithFormat:@"<span class=\""
- @"anais_me\">%@</span>",
- _uid];
- }
- return _uid;
-}
-/* Href */
+/* Helpers */
-- (NSString *)showHref {
- return [self completeHrefForMethod:@"show"];
+- (NSArray *)userUIDs {
+ return [[self userUIDString] componentsSeparatedByString:@","];
}
-
-/* Helper */
-
-- (NSString *)userUid {
- if(!self->userUid) {
- ASSIGN(self->userUid, [[self user] login]);
+- (NSString *)activeUserCN {
+ if (!self->activeUserCN) {
+ activeUserCN = [[[[self context] activeUser] cn] retain];
}
- return self->userUid;
+ return self->activeUserCN;
}
-- (NSString *)userCN {
- if (!self->userCN) {
- ASSIGN(self->userCN, [[[self context] activeUser] cn]);
- }
- return self->userCN;
+- (NSString *)prettyCN {
+ AgenorUserManager *um;
+ NSString *cn;
+ NSString *classPart;
+
+ um = [AgenorUserManager sharedUserManager];
+ cn = [um getCNForUID:[self userUID]];
+ if ([cn isEqualToString:[self activeUserCN]])
+ classPart = @" class=\"anais_me\"";
+ else
+ classPart = @"";
+
+ return [NSString stringWithFormat:@"<span id=\"%@\"%@>%@</span>",
+ [self userUID],
+ classPart,
+ cn];
}
-- (NSString *)calendarUIDString {
- return [[self calendarUIDs] componentsJoinedByString:@","];
+
+/* Href */
+
+- (NSString *)showHref {
+ return [self completeHrefForMethod:@"show"];
}
/* this is to determine the initial visibility of the 'addMeToo' button */
- (NSString *)meTooStyle {
- if([[self calendarUIDs] containsObject:userUid])
- return @"visibility:hidden";
- return @"visibility:visible";
+ if([[self userUIDString] rangeOfString:[[[self context] activeUser]
+ login]].length > 0)
+ return @"visibility:hidden";
+ return @"visibility:visible";
}
-/* JavaScript */
-
-- (NSString *)jsCode {
- static NSString *script = \
- @"function clearElementWithId(elemId) {\n"
- @" var o = document.getElementById(elemId);\n"
- @" var dst = o.parentNode;\n"
- @" var n = document.createElement('td');\n"
- @" n.setAttribute('id', elemId);\n"
- @" n.setAttribute('align', 'left');\n"
- @" n.setAttribute('class', 'anais_uids');\n"
- @" dst.replaceChild(n, o);\n"
- @"}\n"
- @"function clearUidList() {\n"
- @" clearElementWithId('anaisUIDList');\n"
- @" var e = document.getElementById('anaisUIDString');\n"
- @" e.setAttribute('value', '');\n"
- @" var td = document.getElementById('addMeToo');\n"
- @" td.setAttribute('style', 'visibility:visible');\n"
- @" td = document.getElementById('clearUidList');\n"
- @" td.setAttribute('style', 'visibility:hidden');\n"
- @" td = document.getElementById('showUidList');\n"
- @" td.setAttribute('style', 'visibility:hidden');\n"
- @"}\n"
- @"function addMeToo() {\n"
- @" addUid('', '', '%@', '', '%@', '');\n"
- @" var td = document.getElementById('addMeToo');\n"
- @" td.setAttribute('style', 'visibility:hidden');\n"
- @"}\n"
- @"function clearAllAndAddMe() {\n"
- @" clearUidList();\n"
- @" addMeToo();\n"
- @"}\n"
- @"function addUidFromAnais(type, email, uid, sn, cn, dn) {\n"
- @" addUid(type, email, uid, sn, cn, dn); \n"
- @"}\n"
- @"function addUid(type, email, uid, sn, cn, dn) {\n"
- @" if(!uid)\n"
- @" return;\n"
- @" var e = document.getElementById('anaisUIDString');\n"
- @" var s = e.getAttribute('value');\n"
- @" if(s)\n"
- @" s = s + ',' + uid;\n"
- @" else\n"
- @" s = uid;\n"
- @" e.setAttribute('value', s);\n"
- @" var td = document.getElementById('anaisUIDList');\n"
- @" var text;\n"
- @" if(td.hasChildNodes()) {\n"
- @" text = document.createTextNode(', ');\n"
- @" td.appendChild(text);\n"
- @" }\n"
- @" text = document.createTextNode(cn);\n"
- @" if(uid == '%@') {\n"
- @" var span = document.createElement('span');\n"
- @" span.setAttribute('class', 'anais_me');\n"
- @" span.appendChild(text);\n"
- @" td.appendChild(span);\n"
- @" }\n"
- @" else {\n"
- @" td.appendChild(text);\n"
- @" }\n"
- @" td = document.getElementById('clearUidList');\n"
- @" td.setAttribute('style', 'visibility:visible');\n"
- @" td = document.getElementById('showUidList');\n"
- @" td.setAttribute('style', 'visibility:visible');\n"
- @"}\n"
- @"";
-
- return [NSString stringWithFormat:script,
- [self userUid],
- [self userCN],
- [self userUid]];
+/* actions */
+
+- (BOOL)shouldTakeValuesFromRequest:(WORequest *)_rq inContext:(WOContext*)_c {
+ return YES;
}
@end
xmlns:label="OGo:label"
>
<script language="JavaScript">
- <var:string value="jsCode" const:escapeHTML="NO" />
+ function clearElementWithId(elemId) {
+ var o = document.getElementById(elemId);
+ var dst = o.parentNode;
+ var n = document.createElement('td');
+ n.setAttribute('id', elemId);
+ n.setAttribute('align', 'left');
+ n.setAttribute('class', 'anais_uids');
+ dst.replaceChild(n, o);
+ }
+ function clearUidList() {
+ clearElementWithId('userCNs');
+ var e = document.getElementById('userUIDString');
+ e.setAttribute('value', '');
+ var td = document.getElementById('addMeToo');
+ td.setAttribute('style', 'visibility:visible');
+ td = document.getElementById('clearUidList');
+ td.setAttribute('style', 'visibility:hidden');
+ td = document.getElementById('showUidList');
+ td.setAttribute('style', 'visibility:hidden');
+ }
+ function addMeToo() {
+ addUid('', '', '<var:string value="context.activeUser.login" />', '', '<var:string value="context.activeUser.cn" />', '');
+ var td = document.getElementById('addMeToo');
+ td.setAttribute('style', 'visibility:hidden');
+ }
+ function clearAllAndAddMe() {
+ clearUidList();
+ addMeToo();
+ }
+ function addUidFromAnais(type, email, uid, sn, cn, dn) {
+ addUid(type, email, uid, sn, cn, dn);
+ }
+ function addUid(type, email, uid, sn, cn, dn) {
+ if(!uid)
+ return;
+ var e = document.getElementById(uid);
+ if (e)
+ return;
+ e = document.getElementById('userUIDString');
+ var s = e.getAttribute('value');
+ if(s)
+ s = s + ',' + uid;
+ else
+ s = uid;
+ e.setAttribute('value', s);
+
+ // add CN
+ var td = document.getElementById('userCNs');
+ var text;
+ if(td.hasChildNodes()) {
+ text = document.createTextNode(', ');
+ td.appendChild(text);
+ }
+ text = document.createTextNode(cn);
+ var span = document.createElement('span');
+ span.setAttribute('id', uid);
+ if(uid == '<var:string value="context.activeUser.login" />')
+ span.setAttribute('class', 'anais_me');
+ span.appendChild(text);
+ td.appendChild(span);
+
+ td = document.getElementById('clearUidList');
+ td.setAttribute('style', 'visibility:visible');
+ td = document.getElementById('showUidList');
+ td.setAttribute('style', 'visibility:visible');
+ }
</script>
<table cellspacing="2" cellpadding="0" width="100%" border="0">
<var:if condition="isAccessRestricted" const:negate="YES">
<span id="showUidList" class="button_submit_env">
<form var:href="showHref">
<input type="hidden"
- name="anaisUIDString"
- id="anaisUIDString"
- var:value="calendarUIDString"
+ name="userUIDString"
+ id="userUIDString"
+ var:value="userUIDString"
/>
<input type="hidden"
name="previousMethod"
</tr>
</var:if>
<tr valign="top">
- <td id="anaisUIDList"
+ <td id="userCNs"
align="left"
class="anais_uids"
- ><var:foreach list="calendarUIDs"
- item="uid"
- ><var:string value="prettyUid"
+ ><var:foreach list="userUIDs"
+ item="userUID"
+ index="userUIDIdx"
+ ><var:if condition="needsComma">, </var:if>
+ <var:string value="prettyCN"
const:escapeHTML="NO"
/></var:foreach>
</td>