2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <NGObjWeb/WODynamicElement.h>
27 DropContainer: WEDropContainer {
32 droppedObject = droppedObject;
35 activeColor = "lightblue";
42 onDragEnter="fnCancelDefault()"
43 onDragOver="fnCancelDefault()"
49 @interface WEDropContainer : WODynamicElement
51 NSDictionary *dExtraAttrs;
53 WOAssociation *elementName;
54 WOAssociation *isAttached; /* bool */
55 WOAssociation *effect;
56 WOAssociation *swapColor; /* swap bgcolor if drag object is over container */
57 WOAssociation *action;
58 WOAssociation *droppedObject;
64 @interface WEDropScript : WODynamicElement
65 + (void)appendDropScriptToResponse:(WOResponse *)_response
66 inContext:(WOContext *)_ctx;
69 #include <NGObjWeb/WEClientCapabilities.h>
72 @implementation WEDropContainer
75 return 0 + [super version];
78 - (id)initWithName:(NSString *)_name
79 associations:(NSDictionary *)_config
80 template:(WOElement *)_subs
82 if ((self = [super initWithName:_name associations:_config template:_subs])) {
83 self->tags = WOExtGetProperty(_config, @"tags");
84 self->elementName = WOExtGetProperty(_config, @"elementName");
85 self->effect = WOExtGetProperty(_config, @"effect");
86 self->action = WOExtGetProperty(_config, @"action");
87 self->droppedObject = WOExtGetProperty(_config, @"droppedObject");
88 self->swapColor = WOExtGetProperty(_config, @"swapColor");
89 self->isAttached = WOExtGetProperty(_config, @"isAttached");
91 self->template = RETAIN(_subs);
97 RELEASE(self->dExtraAttrs);
99 RELEASE(self->swapColor);
100 RELEASE(self->droppedObject);
101 RELEASE(self->action);
102 RELEASE(self->template);
103 RELEASE(self->effect);
105 RELEASE(self->elementName);
106 RELEASE(self->isAttached);
111 - (void)setExtraAttributes:(NSDictionary *)_extras {
112 ASSIGNCOPY(self->dExtraAttrs, _extras);
115 - (void)appendExtraAttributesToResponse:(WOResponse *)_response
116 inContext:(WOContext *)_ctx
118 if (self->dExtraAttrs) {
119 WOComponent *sComponent;
123 sComponent = [_ctx component];
125 keys = [self->dExtraAttrs keyEnumerator];
127 while ((key = [keys nextObject])) {
130 value = [self->dExtraAttrs objectForKey:key];
135 //key = [key lowercaseString];
136 value = [value stringValueInComponent:sComponent];
138 [_response appendContentCharacter:' '];
139 [_response appendContentString:key];
140 [_response appendContentString:@"=\""];
141 [_response appendContentHTMLAttributeValue:value];
142 [_response appendContentCharacter:'"'];
149 - (void)takeValuesFromRequest:(WORequest *)_request
150 inContext:(WOContext *)_ctx
152 [_ctx appendElementIDComponent:@"p"];
153 [self->template takeValuesFromRequest:_request inContext:_ctx];
154 [_ctx deleteLastElementIDComponent];
157 - (id)invokeActionForRequest:(WORequest *)_request
158 inContext:(WOContext *)_ctx
163 op = [[_ctx currentElementID] stringValue];
165 NSLog(@"check DROP ACTION %@ ..", op);
168 if ([op isEqualToString:@"p"]) {
169 /* an action inside of the component */
170 [_ctx consumeElementID]; // consume id
171 [_ctx appendElementIDComponent:@"p"];
172 result = [self->template invokeActionForRequest:_request inContext:_ctx];
173 [_ctx deleteLastElementIDComponent];
175 else if ([op isEqualToString:@"drop"]) {
176 /* an action of *this* component */
177 [_ctx consumeElementID]; // consume id
178 [_ctx appendElementIDComponent:@"drop"];
181 NSLog(@"WILL RUN DROP ACTION ..");
184 if ([self->droppedObject isValueSettable]) {
185 [self->droppedObject setValue:
186 [_ctx valueForKey:@"WEDragContainer_DropObject"]
187 inComponent:[_ctx component]];
190 result = [self->action valueInComponent:[_ctx component]];
192 [_ctx deleteLastElementIDComponent];
195 NSLog(@"invalid element-id: did not expect '%@' id", op);
201 - (void)appendExtraAttributesAsJavaScriptToResponse:(WOResponse *)_response
202 inContext:(WOContext *)_ctx
204 if (self->dExtraAttrs) {
205 WOComponent *sComponent = [_ctx component];
206 NSEnumerator *keyEnum;
209 [_response appendContentString:
211 @"<script language=\"JavaScript\">\n"
214 keyEnum = [self->dExtraAttrs keyEnumerator];
215 while ((key = [keyEnum nextObject])) {
218 value = [self->dExtraAttrs objectForKey:key];
223 if ([[key lowercaseString] isEqualToString:@"width"])
225 else if ([[key lowercaseString] isEqualToString:@"height"])
227 else if ([[key lowercaseString] isEqualToString:@"bgcolor"])
229 else if ([[key lowercaseString] isEqualToString:@"activecolor"])
230 key = @"activeColor";
231 else if ([[key lowercaseString] isEqualToString:@"align"])
233 else if ([[key lowercaseString] isEqualToString:@"valign"])
235 else if ([[key lowercaseString] isEqualToString:@"colspan"])
237 else if ([[key lowercaseString] isEqualToString:@"rowspan"])
239 else if ([[key lowercaseString] isEqualToString:@"nowrap"])
242 value = [value stringValueInComponent:sComponent];
243 [_response appendContentString:
244 [NSString stringWithFormat:@"tmp.%@ = \"%@\";\n", key, value]];
246 [_response appendContentString:
252 - (void)appendToResponse:(WOResponse *)_response
253 inContext:(WOContext *)_ctx
258 NSString *containerID = nil;
259 BOOL doDnD, doSwap, doAttach;
261 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
265 ttag = [[self->tags valueInComponent:[_ctx component]]
266 componentsJoinedByString:@","];
268 teffect = [self->effect stringValueInComponent:[_ctx component]];
269 if (teffect == nil) teffect = @"move";
271 [WEDropScript appendDropScriptToResponse:_response inContext:_ctx];
273 [_ctx appendElementIDComponent:@"drop"];
275 htmlEl = [self->elementName stringValueInComponent:[_ctx component]];
276 doAttach = ([self->isAttached boolValueInComponent:[_ctx component]] &&
277 (self->elementName != nil));
279 if (htmlEl == nil || doAttach) htmlEl = @"span";
281 if ((self->elementName != nil) || doDnD) {
284 [_response appendContentString: @"<"];
285 [_response appendContentString:htmlEl];
288 /* gen unique container id */
290 if ((containerID = [_ctx valueForKey:@"WEDropContainerSequence"])) {
291 containerID = AUTORELEASE([containerID copy]);
292 containerIDc = [containerID intValue];
299 [_response appendContentString:@" id=\"skydrop"];
300 if (doAttach) [_response appendContentString:@"dummy"];
301 [_response appendContentString:containerID];
302 [_response appendContentString:@"\""];
306 [_ctx takeValue:[NSString stringWithFormat:@"%i", containerIDc]
307 forKey:@"WEDropContainerSequence"];
312 NSString *swapOnAction = @"";
313 NSString *swapOffAction = @"";
314 NSString *cancelAction;
315 NSString *infoAction;
318 doSwap = self->swapColor
319 ? [self->swapColor boolValueInComponent:[_ctx component]]
322 cancelAction = [NSString stringWithFormat:@"fnCancelDefault('%@','%@');",
325 swapOnAction = [NSString stringWithFormat:
326 @"dropFieldSwapColor(skydrop%@,true);",
328 swapOffAction = [NSString stringWithFormat:
329 @"dropFieldSwapColor(skydrop%@,false);",
333 infoAction = [NSString stringWithFormat:@"fnGetInfo(this, '%@');",
334 [_ctx componentActionURL]];
337 NSString *tagName = nil;
339 // doAttach==YES -> self->elementName != nil
340 tagName = [self->elementName stringValueInComponent:[_ctx component]];
341 tagName = [tagName uppercaseString];
343 [_response appendContentCharacter:'>'];
345 [_response appendContentString:[NSString stringWithFormat:
347 @"<script language=\"JavaScript\">\n"
349 @" function onDragEnterFunc%@() {\n %@\n %@\n}\n"
350 @" function onDragOverFunc%@() {\n %@\n %@\n}\n"
351 @" function onDragLeaveFunc%@() {\n %@\n }\n"
352 @" function onDropFunc%@() {\n %@\n }\n"
354 @" tmp = document.getElementById(\"%@\");\n"
356 @" while ((tmp.tagName != \"%@\") && (i >= 0)) {\n"
357 @" tmp = tmp.parentNode;\n"
360 @" tmp.ondragover = onDragOverFunc%@;\n"
361 @" tmp.ondragleave = onDragLeaveFunc%@;\n"
362 @" tmp.ondrop = onDropFunc%@;\n"
363 @" tmp.ondragenter = onDragEnterFunc%@;\n"
364 @" tmp.id = \"%@\";\n"
367 containerID, cancelAction, swapOnAction,
368 containerID, cancelAction, swapOnAction,
369 containerID, swapOffAction,
370 containerID, infoAction,
371 [@"skydropdummy" stringByAppendingString:containerID],
377 [@"skydrop" stringByAppendingString:containerID]]];
379 // remove bgColors of TR's sub TD:
380 if ([tagName isEqualToString:@"TR"]) {
381 [_response appendContentString:
383 @"<script language=\"JavaScript\">\n"
385 @"list = tmp.getElementsByTagName(\"TD\");\n"
386 @"cnt = list.length;\n"
387 @"for (i=0; i<cnt; i++) {\n"
388 @" list[i].removeAttribute(\"bgColor\");\n"
394 /* append extra attributes by script */
395 [self appendExtraAttributesAsJavaScriptToResponse:_response
399 [_response appendContentString:@" onDragEnter=\""];
400 [_response appendContentString:cancelAction];
401 [_response appendContentString:swapOnAction];
403 [_response appendContentString:@"\" onDragOver=\""];
404 [_response appendContentString:cancelAction];
405 [_response appendContentString:swapOnAction];
407 [_response appendContentString:@"\" onDragLeave=\""];
408 [_response appendContentString:swapOffAction];
410 [_response appendContentString:@"\" onDrop=\""];
411 [_response appendContentString:infoAction];
412 [_response appendContentCharacter:'"'];
414 [self appendExtraAttributesToResponse:_response inContext:_ctx];
415 [_response appendContentCharacter:'>'];
418 else if (self->elementName != nil) {
419 [self appendExtraAttributesToResponse:_response inContext:_ctx];
420 [_response appendContentCharacter:'>'];
423 [_ctx deleteLastElementIDComponent];
426 [_ctx appendElementIDComponent:@"p"];
427 [self->template appendToResponse:_response inContext:_ctx];
428 [_ctx deleteLastElementIDComponent];
430 /* close container */
431 if ((self->elementName != nil) || doDnD) {
432 [_response appendContentString:@"</"];
433 [_response appendContentString:htmlEl];
434 [_response appendContentCharacter:'>'];
441 return self->template;
444 @end /* WEDropContainer */
447 @implementation WEDropScript
449 + (void)appendDropScriptToResponse:(WOResponse *)_response
450 inContext:(WOContext *)_ctx
454 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
456 if (![[_ctx valueForKey:@"WEDropContainerScriptDone"] boolValue] && doDnD) {
457 NSString *dropScript;
460 #include "WEDropScript.jsm"
463 [_response appendContentString:dropScript];
465 [_ctx takeValue:[NSNumber numberWithBool:YES]
466 forKey:@"WEDropContainerScriptDone"];
470 - (void)appendToResponse:(WOResponse *)_response
471 inContext:(WOContext *)_ctx
473 [[self class] appendDropScriptToResponse:_response inContext:_ctx];
476 @end /* WEDropScript */