2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #import <NGObjWeb/WODynamicElement.h>
28 DropContainer: WEDropContainer {
33 droppedObject = droppedObject;
36 activeColor = "lightblue";
43 onDragEnter="fnCancelDefault()"
44 onDragOver="fnCancelDefault()"
50 @interface WEDropContainer : WODynamicElement
52 NSDictionary *dExtraAttrs;
54 WOAssociation *elementName;
55 WOAssociation *isAttached; /* bool */
56 WOAssociation *effect;
57 WOAssociation *swapColor; /* swap bgcolor if drag object is over container */
58 WOAssociation *action;
59 WOAssociation *droppedObject;
65 @interface WEDropScript : WODynamicElement
66 + (void)appendDropScriptToResponse:(WOResponse *)_response
67 inContext:(WOContext *)_ctx;
70 #include "WEClientCapabilities.h"
71 #import <NGObjWeb/NGObjWeb.h>
72 #import <NGExtensions/NGExtensions.h>
75 @implementation WEDropContainer
78 return 0 + [super version];
81 - (id)initWithName:(NSString *)_name
82 associations:(NSDictionary *)_config
83 template:(WOElement *)_subs
85 if ((self = [super initWithName:_name associations:_config template:_subs])) {
86 self->tags = WOExtGetProperty(_config, @"tags");
87 self->elementName = WOExtGetProperty(_config, @"elementName");
88 self->effect = WOExtGetProperty(_config, @"effect");
89 self->action = WOExtGetProperty(_config, @"action");
90 self->droppedObject = WOExtGetProperty(_config, @"droppedObject");
91 self->swapColor = WOExtGetProperty(_config, @"swapColor");
92 self->isAttached = WOExtGetProperty(_config, @"isAttached");
94 self->template = RETAIN(_subs);
100 RELEASE(self->dExtraAttrs);
102 RELEASE(self->swapColor);
103 RELEASE(self->droppedObject);
104 RELEASE(self->action);
105 RELEASE(self->template);
106 RELEASE(self->effect);
108 RELEASE(self->elementName);
109 RELEASE(self->isAttached);
114 - (void)setExtraAttributes:(NSDictionary *)_extras {
115 ASSIGNCOPY(self->dExtraAttrs, _extras);
118 - (void)appendExtraAttributesToResponse:(WOResponse *)_response
119 inContext:(WOContext *)_ctx
121 if (self->dExtraAttrs) {
122 WOComponent *sComponent;
126 sComponent = [_ctx component];
128 keys = [self->dExtraAttrs keyEnumerator];
130 while ((key = [keys nextObject])) {
133 value = [self->dExtraAttrs objectForKey:key];
138 //key = [key lowercaseString];
139 value = [value stringValueInComponent:sComponent];
141 [_response appendContentCharacter:' '];
142 [_response appendContentString:key];
143 [_response appendContentString:@"=\""];
144 [_response appendContentHTMLAttributeValue:value];
145 [_response appendContentCharacter:'"'];
152 - (void)takeValuesFromRequest:(WORequest *)_request
153 inContext:(WOContext *)_ctx
155 [_ctx appendElementIDComponent:@"p"];
156 [self->template takeValuesFromRequest:_request inContext:_ctx];
157 [_ctx deleteLastElementIDComponent];
160 - (id)invokeActionForRequest:(WORequest *)_request
161 inContext:(WOContext *)_ctx
166 op = [[_ctx currentElementID] stringValue];
168 NSLog(@"check DROP ACTION %@ ..", op);
171 if ([op isEqualToString:@"p"]) {
172 /* an action inside of the component */
173 [_ctx consumeElementID]; // consume id
174 [_ctx appendElementIDComponent:@"p"];
175 result = [self->template invokeActionForRequest:_request inContext:_ctx];
176 [_ctx deleteLastElementIDComponent];
178 else if ([op isEqualToString:@"drop"]) {
179 /* an action of *this* component */
180 [_ctx consumeElementID]; // consume id
181 [_ctx appendElementIDComponent:@"drop"];
184 NSLog(@"WILL RUN DROP ACTION ..");
187 if ([self->droppedObject isValueSettable]) {
188 [self->droppedObject setValue:
189 [_ctx valueForKey:@"WEDragContainer_DropObject"]
190 inComponent:[_ctx component]];
193 result = [self->action valueInComponent:[_ctx component]];
195 [_ctx deleteLastElementIDComponent];
198 NSLog(@"invalid element-id: did not expect '%@' id", op);
204 - (void)appendExtraAttributesAsJavaScriptToResponse:(WOResponse *)_response
205 inContext:(WOContext *)_ctx
207 if (self->dExtraAttrs) {
208 WOComponent *sComponent = [_ctx component];
209 NSEnumerator *keyEnum;
212 [_response appendContentString:
214 @"<script language=\"JavaScript\">\n"
217 keyEnum = [self->dExtraAttrs keyEnumerator];
218 while ((key = [keyEnum nextObject])) {
221 value = [self->dExtraAttrs objectForKey:key];
226 if ([[key lowercaseString] isEqualToString:@"width"])
228 else if ([[key lowercaseString] isEqualToString:@"height"])
230 else if ([[key lowercaseString] isEqualToString:@"bgcolor"])
232 else if ([[key lowercaseString] isEqualToString:@"activecolor"])
233 key = @"activeColor";
234 else if ([[key lowercaseString] isEqualToString:@"align"])
236 else if ([[key lowercaseString] isEqualToString:@"valign"])
238 else if ([[key lowercaseString] isEqualToString:@"colspan"])
240 else if ([[key lowercaseString] isEqualToString:@"rowspan"])
242 else if ([[key lowercaseString] isEqualToString:@"nowrap"])
245 value = [value stringValueInComponent:sComponent];
246 [_response appendContentString:
247 [NSString stringWithFormat:@"tmp.%@ = \"%@\";\n", key, value]];
249 [_response appendContentString:
255 - (void)appendToResponse:(WOResponse *)_response
256 inContext:(WOContext *)_ctx
261 NSString *containerID = nil;
262 BOOL doDnD, doSwap, doAttach;
264 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
268 ttag = [[self->tags valueInComponent:[_ctx component]]
269 componentsJoinedByString:@","];
271 teffect = [self->effect stringValueInComponent:[_ctx component]];
272 if (teffect == nil) teffect = @"move";
274 [WEDropScript appendDropScriptToResponse:_response inContext:_ctx];
276 [_ctx appendElementIDComponent:@"drop"];
278 htmlEl = [self->elementName stringValueInComponent:[_ctx component]];
279 doAttach = ([self->isAttached boolValueInComponent:[_ctx component]] &&
280 (self->elementName != nil));
282 if (htmlEl == nil || doAttach) htmlEl = @"span";
284 if ((self->elementName != nil) || doDnD) {
287 [_response appendContentString: @"<"];
288 [_response appendContentString:htmlEl];
291 /* gen unique container id */
293 if ((containerID = [_ctx valueForKey:@"WEDropContainerSequence"])) {
294 containerID = AUTORELEASE([containerID copy]);
295 containerIDc = [containerID intValue];
302 [_response appendContentString:@" id=\"skydrop"];
303 if (doAttach) [_response appendContentString:@"dummy"];
304 [_response appendContentString:containerID];
305 [_response appendContentString:@"\""];
309 [_ctx takeValue:[NSString stringWithFormat:@"%i", containerIDc]
310 forKey:@"WEDropContainerSequence"];
315 NSString *swapOnAction = @"";
316 NSString *swapOffAction = @"";
317 NSString *cancelAction;
318 NSString *infoAction;
321 doSwap = self->swapColor
322 ? [self->swapColor boolValueInComponent:[_ctx component]]
325 cancelAction = [NSString stringWithFormat:@"fnCancelDefault('%@','%@');",
328 swapOnAction = [NSString stringWithFormat:
329 @"dropFieldSwapColor(skydrop%@,true);",
331 swapOffAction = [NSString stringWithFormat:
332 @"dropFieldSwapColor(skydrop%@,false);",
336 infoAction = [NSString stringWithFormat:@"fnGetInfo(this, '%@');",
337 [_ctx componentActionURL]];
340 NSString *tagName = nil;
342 // doAttach==YES -> self->elementName != nil
343 tagName = [self->elementName stringValueInComponent:[_ctx component]];
344 tagName = [tagName uppercaseString];
346 [_response appendContentCharacter:'>'];
348 [_response appendContentString:[NSString stringWithFormat:
350 @"<script language=\"JavaScript\">\n"
352 @" function onDragEnterFunc%@() {\n %@\n %@\n}\n"
353 @" function onDragOverFunc%@() {\n %@\n %@\n}\n"
354 @" function onDragLeaveFunc%@() {\n %@\n }\n"
355 @" function onDropFunc%@() {\n %@\n }\n"
357 @" tmp = document.getElementById(\"%@\");\n"
359 @" while ((tmp.tagName != \"%@\") && (i >= 0)) {\n"
360 @" tmp = tmp.parentNode;\n"
363 @" tmp.ondragover = onDragOverFunc%@;\n"
364 @" tmp.ondragleave = onDragLeaveFunc%@;\n"
365 @" tmp.ondrop = onDropFunc%@;\n"
366 @" tmp.ondragenter = onDragEnterFunc%@;\n"
367 @" tmp.id = \"%@\";\n"
370 containerID, cancelAction, swapOnAction,
371 containerID, cancelAction, swapOnAction,
372 containerID, swapOffAction,
373 containerID, infoAction,
374 [@"skydropdummy" stringByAppendingString:containerID],
380 [@"skydrop" stringByAppendingString:containerID]]];
382 // remove bgColors of TR's sub TD:
383 if ([tagName isEqualToString:@"TR"]) {
384 [_response appendContentString:
386 @"<script language=\"JavaScript\">\n"
388 @"list = tmp.getElementsByTagName(\"TD\");\n"
389 @"cnt = list.length;\n"
390 @"for (i=0; i<cnt; i++) {\n"
391 @" list[i].removeAttribute(\"bgColor\");\n"
397 /* append extra attributes by script */
398 [self appendExtraAttributesAsJavaScriptToResponse:_response
402 [_response appendContentString:@" onDragEnter=\""];
403 [_response appendContentString:cancelAction];
404 [_response appendContentString:swapOnAction];
406 [_response appendContentString:@"\" onDragOver=\""];
407 [_response appendContentString:cancelAction];
408 [_response appendContentString:swapOnAction];
410 [_response appendContentString:@"\" onDragLeave=\""];
411 [_response appendContentString:swapOffAction];
413 [_response appendContentString:@"\" onDrop=\""];
414 [_response appendContentString:infoAction];
415 [_response appendContentCharacter:'"'];
417 [self appendExtraAttributesToResponse:_response inContext:_ctx];
418 [_response appendContentCharacter:'>'];
421 else if (self->elementName != nil) {
422 [self appendExtraAttributesToResponse:_response inContext:_ctx];
423 [_response appendContentCharacter:'>'];
426 [_ctx deleteLastElementIDComponent];
429 [_ctx appendElementIDComponent:@"p"];
430 [self->template appendToResponse:_response inContext:_ctx];
431 [_ctx deleteLastElementIDComponent];
433 /* close container */
434 if ((self->elementName != nil) || doDnD) {
435 [_response appendContentString:@"</"];
436 [_response appendContentString:htmlEl];
437 [_response appendContentCharacter:'>'];
443 - (WOElement *)template {
444 return self->template;
447 @end /* WEDropContainer */
449 @implementation WEDropScript
451 + (void)appendDropScriptToResponse:(WOResponse *)_response
452 inContext:(WOContext *)_ctx
456 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
458 if (![[_ctx valueForKey:@"WEDropContainerScriptDone"] boolValue] && doDnD) {
459 NSString *dropScript;
462 #include "WEDropScript.jsm"
465 [_response appendContentString:dropScript];
467 [_ctx takeValue:[NSNumber numberWithBool:YES]
468 forKey:@"WEDropContainerScriptDone"];
472 - (void)appendToResponse:(WOResponse *)_response
473 inContext:(WOContext *)_ctx
475 [[self class] appendDropScriptToResponse:_response inContext:_ctx];
478 @end /* WEDropScript */