/* Copyright (C) 2000-2004 SKYRIX Software AG This file is part of OGo OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #include /* AnaisUidSelector Modifiable list of uids used to select multiple calendars for viewing at once. */ @interface AnaisUidSelector : UIxComponent { NSArray *calendarUIDs; NSString *uid; NSString *userUid; } - (NSString *)prettyUid; - (NSString *)userUid; - (NSString *)_colorizedUid:(NSString *)_uid; - (NSString *)showHref; - (NSString *)jsCode; @end #include "common.h" #include @implementation AnaisUidSelector - (id)init { self = [super init]; if(self) { } return self; } - (void)dealloc { [self->calendarUIDs release]; [self->uid release]; [self->userUid release]; [super dealloc]; } - (void)setCalendarUIDs:(NSArray *)_calendarUIDs { ASSIGN(self->calendarUIDs, _calendarUIDs); } - (NSArray *)calendarUIDs { return self->calendarUIDs; } - (void)setUid:(NSString *)_uid { ASSIGN(self->uid, _uid); } - (NSString *)uid { return self->uid; } - (NSString *)prettyUid { if([self->calendarUIDs objectAtIndex:0] == self->uid) return [self _colorizedUid:self->uid]; return [NSString stringWithFormat:@", %@", [self _colorizedUid:self->uid]]; } - (NSString *)_colorizedUid:(NSString *)_uid { if([_uid isEqualToString:[self userUid]]) { _uid = [NSString stringWithFormat:@"%@", _uid]; } return _uid; } /* Href */ - (NSString *)showHref { return [self completeHrefForMethod:@"show"]; } /* Helper */ - (NSString *)userUid { if(self->userUid) return self->userUid; ASSIGN(self->userUid, [[self user] login]); return self->userUid; } - (NSString *)calendarUIDString { return [[self calendarUIDs] componentsJoinedByString:@","]; } /* this is to determine the initial visibility of the 'addMeToo' button */ - (NSString *)meTooStyle { if([[self calendarUIDs] containsObject:userUid]) 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 addUidFromAnais() {\n" @" var uid = arguments[2]; \n" @" addUid('','','','',uid,''); \n" @"}\n" @"function addUid(division, cn, dn, email, uid, sn) {\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(uid);\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 userUid]]; } @end