]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Anais/AnaisSelector.m
Contacts imported from Anais now got CN set from LDAP
[scalable-opengroupware.org] / SOGo / UI / Anais / AnaisSelector.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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 #include <SOGoUI/UIxComponent.h>
24
25 /*
26  AnaisSelector
27  
28  Open a satellite window providing access to Anais.
29  
30  Bindings:
31  title           - button title to display to user
32  windowId        - string to be used for uniquing this window to a particular
33                    purpose (i.e. for adding participants)
34  division        - Anais division
35  callback        - name of JavaScript callback function to use in caller's page
36  extraAttributes - extra attributes to add as paramaters to the callback
37  
38  Sample:
39  <var:component className="AnaisSelector"
40                 const:windowId="ParticipantSelection"
41                 const:division="CC"
42                 const:callback="addParticipant"
43                 const:extraAttributes="givenName,initials"
44  />
45  */
46
47 @interface AnaisSelector : UIxComponent
48 {
49     NSString *title;
50     NSString *windowId;
51     NSString *division;
52     NSString *callback;
53     NSString *extraAttributes;
54 }
55
56 - (void)setTitle:(NSString *)_title;
57 - (NSString *)title;
58 - (void)setWindowId:(NSString *)_winId;
59 - (NSString *)windowId;
60 - (void)setDivision:(NSString *)_division;
61 - (NSString *)division;
62 - (void)setCallback:(NSString *)_callback;
63 - (NSString *)callback;
64
65 - (NSString *)jsFunctionName;
66 - (NSString *)jsFunctionHref;
67 - (NSString *)jsCode;
68 @end
69
70 #include "common.h"
71
72 @implementation AnaisSelector
73
74 - (id)init {
75   if ((self = [super init])) {
76     [self setTitle:@"Anais"];
77     [self setWindowId:@"Anais"];
78     [self setCallback:@"undefined"];
79   }
80   return self;
81 }
82
83 - (void)dealloc {
84   [self->title           release];
85   [self->windowId        release];
86   [self->division        release];
87   [self->callback        release];
88   [self->extraAttributes release];
89   [super dealloc];
90 }
91
92 /* accessors */
93
94 - (void)setTitle:(NSString *)_title {
95   ASSIGNCOPY(self->title, _title);
96 }
97 - (NSString *)title {
98   return self->title;
99 }
100
101 - (void)setWindowId:(NSString *)_winId {
102   ASSIGNCOPY(self->windowId, _winId);
103 }
104 - (NSString *)windowId {
105   return self->windowId;
106 }
107
108 - (void)setDivision:(NSString *)_division {
109   ASSIGNCOPY(self->division, _division);
110 }
111 - (NSString *)division {
112   return self->division;
113 }
114
115 - (void)setCallback:(NSString *)_callback {
116   ASSIGNCOPY(self->callback, _callback);
117 }
118 - (NSString *)callback {
119   return self->callback;
120 }
121
122 - (void)setExtraAttributes:(NSString *)_extraAttributes {
123   ASSIGN(self->extraAttributes, _extraAttributes);
124 }
125 - (NSString *)extraAttributes {
126   return self->extraAttributes;
127 }
128
129 /* JavaScript */
130
131 - (NSString *)jsFunctionName {
132   return [NSString stringWithFormat:@"openAnaisWindowWithId%@",
133         [self windowId]];
134 }
135
136 - (NSString *)jsFunctionHref {
137   return [NSString stringWithFormat:@"javascript:%@()",
138         [self jsFunctionName]];
139 }
140
141 - (NSString *)jsCode {
142   static NSString *codeFmt = \
143     @"function %@() {\n"
144     @"  var url = '/anais/Admin/Autres/aideFonc.php?m_fonc=%@&m_data=data1&m_type=Pour&m_nom=,%@&m_champ=mail,uid,sn%@&m_nature=BALI&m_agenda0#mon_etiquette';\n"
145     @"  var anaisWindow = window.open(url, '%@', 'width=350, height=600, left=10, top=10, toolbar=no, dependent=yes, menubar=no, location=no, resizable=yes, scrollbars=yes, directories=no, status=no');\n"
146     @"  anaisWindow.focus();\n"
147     @"}";
148   static NSString *divFmt = @"&m_type=%@";
149   NSString *fmt, *exAttrFmt;
150   
151   if([self division])
152     fmt = [NSString stringWithFormat:divFmt, [self division]];
153   else
154     fmt = @"";
155   
156   if([self extraAttributes])
157     exAttrFmt = [NSString stringWithFormat:@",%@", [self extraAttributes]];
158   else
159     exAttrFmt = @"";
160
161     return [NSString stringWithFormat:codeFmt,
162       [self jsFunctionName],
163       [self callback],
164       fmt,
165       exAttrFmt,
166       [self windowId]];
167 }
168
169 @end /* AnaisSelector */