]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Contacts/UIxContactSelector.m
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@900 d1b88da0-ebda-0310-925b-ed51d...
[scalable-opengroupware.org] / SOGo / UI / Contacts / UIxContactSelector.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 UIxContactSelector : UIxComponent
27 {
28   NSString *title;
29   NSString *windowId;
30   NSString *callback;
31 }
32
33 - (void)setTitle:(NSString *)_title;
34 - (NSString *)title;
35 - (void)setWindowId:(NSString *)_winId;
36 - (NSString *)windowId;
37 - (void)setCallback:(NSString *)_callback;
38 - (NSString *)callback;
39
40 - (NSString *)relativeContactsPath;
41
42 - (NSString *)jsFunctionName;
43 - (NSString *)jsFunctionHref;
44 - (NSString *)jsCode;
45 @end
46
47 #include "common.h"
48 #include <NGExtensions/NGExtensions.h>
49
50 @implementation UIxContactSelector
51
52 - (id)init {
53   if ((self = [super init])) {
54     [self setTitle:@"UIxContacts"];
55     [self setWindowId:@"UIxContacts"];
56     [self setCallback:@"undefined"];
57   }
58   return self;
59 }
60
61 - (void)dealloc {
62   [self->title    release];
63   [self->windowId release];
64   [self->callback release];
65   [super dealloc];
66 }
67
68 /* accessors */
69
70 - (void)setTitle:(NSString *)_title {
71   ASSIGNCOPY(self->title, _title);
72 }
73 - (NSString *)title {
74   return self->title;
75 }
76
77 - (void)setWindowId:(NSString *)_winId {
78   ASSIGNCOPY(self->windowId, _winId);
79 }
80 - (NSString *)windowId {
81   return self->windowId;
82 }
83
84 - (void)setCallback:(NSString *)_callback {
85   ASSIGNCOPY(self->callback, _callback);
86 }
87 - (NSString *)callback {
88   return self->callback;
89 }
90
91 /* Helper */
92
93 - (NSString *)relativeContactsPath {
94   return [self relativePathToUserFolderSubPath:@"Contacts/select"];
95 }
96
97 /* JavaScript */
98
99 - (NSString *)jsFunctionName {
100   return [NSString stringWithFormat:@"openUIxContactsListViewWindowWithId%@",
101     [self windowId]];
102 }
103
104 - (NSString *)jsFunctionHref {
105   return [NSString stringWithFormat:@"javascript:%@()",
106     [self jsFunctionName]];
107 }
108
109 - (NSString *)jsCode {
110   static NSString *codeFmt = \
111   @"function %@() {\n"
112   @"  var url = '%@?callback=%@';\n"
113   @"  var contactsWindow = window.open(url, '%@', 'width=600, height=400, left=10, top=10, toolbar=no, dependent=yes, menubar=no, location=no, resizable=yes, scrollbars=yes, directories=no, status=no');\n"
114   @"  contactsWindow.focus();\n"
115   @"}";
116   return [NSString stringWithFormat:codeFmt,
117     [self jsFunctionName],
118     [self relativeContactsPath],
119     [self callback],
120     [self windowId]];
121 }
122
123 @end /* UIxContactSelector */