File: JSModalWindow.m

package info (click to toggle)
sope 5.12.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,588 kB
  • sloc: objc: 169,223; sh: 3,823; ansic: 3,409; javascript: 446; python: 318; makefile: 185
file content (271 lines) | stat: -rw-r--r-- 9,077 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
  Copyright (C) 2000-2005 SKYRIX Software AG

  This file is part of SOPE.

  SOPE 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.

  SOPE 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 SOPE; see the file COPYING.  If not, write to the
  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  02111-1307, USA.
*/

#include <NGObjWeb/WODynamicElement.h>

@interface JSModalWindow : WODynamicElement
{
  WOAssociation *action;
  WOAssociation *pageName;
  WOAssociation *href;      /* non - WO API */
  
  WOAssociation *height;
  WOAssociation *width;
  WOAssociation *windowName;
  WOAssociation *isResizable;
  WOAssociation *showLocation;
  WOAssociation *showMenuBar;
  WOAssociation *showScrollbars;
  WOAssociation *showStatus;
  WOAssociation *showToolbar;

  /* non - WO API */
  WOAssociation *top;
  WOAssociation *left;
  WOAssociation *isCenter;
  WOAssociation *filename;
  WOAssociation *string;
  WOAssociation *framework;
  
  WOElement     *template;
}

@end

#include "common.h"

@implementation JSModalWindow

- (id)initWithName:(NSString *)_name
  associations:(NSDictionary *)_config
  template:(WOElement *)_subs
{
  if ((self = [super initWithName:_name associations:_config template:_subs])){
    int funcCount;

    self->action             = WOExtGetProperty(_config, @"action");
    self->pageName           = WOExtGetProperty(_config, @"pageName");
    self->href               = WOExtGetProperty(_config, @"href");
    
    self->height             = WOExtGetProperty(_config, @"height");
    self->width              = WOExtGetProperty(_config, @"width");
    self->windowName         = WOExtGetProperty(_config, @"windowName");
    self->isResizable        = WOExtGetProperty(_config, @"isResizable");
    self->showLocation       = WOExtGetProperty(_config, @"showLocation");
    self->showMenuBar        = WOExtGetProperty(_config, @"showMenuBar");
    self->showScrollbars     = WOExtGetProperty(_config, @"showScrollbars");
    self->showStatus         = WOExtGetProperty(_config, @"showStatus");
    self->showToolbar        = WOExtGetProperty(_config, @"showToolbar");

    self->top                = WOExtGetProperty(_config, @"top");
    self->left               = WOExtGetProperty(_config, @"left");
    self->isCenter           = WOExtGetProperty(_config, @"isCenter");
    self->filename           = WOExtGetProperty(_config, @"filename");
    self->string             = WOExtGetProperty(_config, @"string");
    self->framework          = WOExtGetProperty(_config, @"framework");

    funcCount = 0;
    if (self->action)   funcCount++;
    if (self->pageName) funcCount++;
    if (self->href)     funcCount++;

    if (funcCount > 1)
      NSLog(@"WARNING: JSModalWindow: choose only one of "
            @"action | pageName | href");
    if (funcCount < 1)
      NSLog(@"WARNING: JSModalWindow: no function declared - choose one of"
            @"action | pageName | href");

#define SetAssociationValue(_assoc_, _value_)                               \
             if (_assoc_ == nil) {                                          \
               _assoc_ = [WOAssociation associationWithValue:_value_];      \
               [_assoc_ retain];                                            \
             }                                                              \

    SetAssociationValue(self->height,         @"300");
    SetAssociationValue(self->width,          @"300");
    SetAssociationValue(self->isResizable,    @"Yes");
    SetAssociationValue(self->showLocation,   @"Yes");
    SetAssociationValue(self->showMenuBar,    @"Yes");
    SetAssociationValue(self->showScrollbars, @"Yes");
    SetAssociationValue(self->showStatus,     @"Yes");
    SetAssociationValue(self->showToolbar,    @"Yes");
    SetAssociationValue(self->top,            @"500");
    SetAssociationValue(self->left,           @"500");

#undef SetAssociationValue

    self->template = [_subs retain];
  }
  return self;
}

- (void)dealloc {
  [self->action   release];
  [self->pageName release];
  [self->href     release];
  
  [self->height         release];
  [self->width          release];
  [self->windowName     release];
  [self->isResizable    release];
  [self->showLocation   release];
  [self->showMenuBar    release];
  [self->showScrollbars release];
  [self->showStatus     release];
  [self->showToolbar    release];

  [self->top       release];
  [self->left      release];
  [self->isCenter  release];
  [self->filename  release];
  [self->string    release];
  [self->framework release];
  
  [self->template release];
  [super dealloc];
}

/* handling requests */

- (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
  [self->template takeValuesFromRequest:_rq inContext:_ctx];
}

- (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
  if (self->pageName != nil) {
    NSString *name;
    
    name = [self->pageName stringValueInComponent: [_ctx component]];
    return [[_ctx application] pageWithName:name inContext:_ctx];
  }
  
  if (self->action != nil)
    return [self->action valueInComponent:[_ctx component]];

  return [self->template invokeActionForRequest:_rq inContext:_ctx];
}

/* generating response */

- (void)appendToResponse:(WOResponse *)_resp inContext:(WOContext *)_ctx {
  WOComponent *comp;
  NSString    *tmp;
  NSArray     *languages;
  
  if ([_ctx isRenderingDisabled]) {
    [self->template appendToResponse:_resp inContext:_ctx];
    return;
  }
  
  comp = [_ctx component];
  
  // link
  [_resp appendContentString:
             @"<a onclick=\"window.showModalDialog('"];
  if (self->href != nil)
    [_resp appendContentString:[self->href stringValueInComponent:comp]];
  else
    [_resp appendContentString:@"http://sope.opengroupware.org/"];
  
  [_resp appendContentString:@"', 'a short text', '"];

  /* configure modal panel */
  if (self->height != nil) {
    [_resp appendContentString:@" dialogHeight: "];
    [_resp appendContentString:[self->height stringValueInComponent:comp]];
    [_resp appendContentString:@"px;"];
  }
  if (self->width != nil) {
    [_resp appendContentString:@" dialogWidth: "];
    [_resp appendContentString:[self->width stringValueInComponent:comp]];
    [_resp appendContentString:@"px;"];
  }
  if (self->top != nil) {
    [_resp appendContentString:@" dialogTop: "];
    [_resp appendContentString:[self->top stringValueInComponent:comp]];
    [_resp appendContentString:@"px;"];
  }
  if (self->left != nil) {
    [_resp appendContentString:@" dialogLeft: "];
    [_resp appendContentString:[self->left stringValueInComponent:comp]];
    [_resp appendContentString:@"px;"];
  }
  if (self->isResizable != nil) {
    [_resp appendContentString:@" resizable: "];
    [_resp appendContentString:
	     [self->isResizable stringValueInComponent:comp]];
    [_resp appendContentCharacter:';'];
  }
  if (self->showStatus != nil) {
    [_resp appendContentString:@" status: "];
    [_resp appendContentString:[self->showStatus stringValueInComponent:comp]];
    [_resp appendContentCharacter:';'];
  }
  if (self->isCenter != nil) {
    [_resp appendContentString:@" center: "];
    [_resp appendContentString:[self->isCenter stringValueInComponent:comp]];
    [_resp appendContentCharacter:';'];
  }

  [_resp appendContentString:@"')\""];
  
  [_resp appendContentString:@" href=\""];
  [_resp appendContentString:[_ctx componentActionURL]];
  [_resp appendContentString:@"\" "];
  
  [self appendExtraAttributesToResponse:_resp inContext:_ctx];
  [_resp appendContentString:@" >"];

  /* link content */
  if (self->filename != nil) {
    WOResourceManager *rm;
    NSString          *frameworkName;
      
    rm        = [[_ctx application] resourceManager];
    languages = [_ctx resourceLookupLanguages];
    frameworkName = (self->framework != nil)
      ? [self->framework stringValueInComponent:comp] 
      : [comp frameworkName];
    
    tmp = [rm urlForResourceNamed:[self->filename stringValueInComponent:comp]
              inFramework:frameworkName
              languages:languages
              request:[_ctx request]];
    
    [_resp appendContentString:@"<img border=\"0\" src=\""];
    [_resp appendContentString:tmp];
    [_resp appendContentString:@"\" "];
    
    [_resp appendContentString:
	     (_ctx->wcFlags.xmlStyleEmptyElements ? @" />" : @">")];
  }
  
  [self->template appendToResponse:_resp inContext:_ctx];
  
  if (self->string != nil)
    [_resp appendContentString:[self->string stringValueInComponent:comp]];
  
  /* close link */
  [_resp appendContentString:@"</a>"];
}

@end /* JSModalWindow */