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 #include <NGObjWeb/WODynamicElement.h>
28 <SPAN onDragStart="fnSetInfo($tag,$effectsAllowed)">
34 @interface WEDragContainer : WODynamicElement
38 WOAssociation *effectsAllowed;
39 WOAssociation *elementName;
40 WOAssociation *isDraggable;
42 WOAssociation *object;
43 WOAssociation *droppedObject;
47 @interface WEDragScript : WODynamicElement
48 + (void)appendDragScriptToResponse:(WOResponse *)_response
49 inContext:(WOContext *)_ctx;
52 #include <NGObjWeb/WEClientCapabilities.h>
55 //#define DEBUG_TAKEVALUES 1
57 @implementation WEDragContainer
59 static BOOL debugTakeValues = NO;
62 return 0 + [super version];
65 - (id)initWithName:(NSString *)_name
66 associations:(NSDictionary *)_config
67 template:(WOElement *)_t
69 if ((self = [super initWithName:_name associations:_config template:_t])) {
70 self->tag = WOExtGetProperty(_config, @"tag");
71 self->effectsAllowed = WOExtGetProperty(_config, @"effectsAllowed");
72 self->elementName = WOExtGetProperty(_config, @"elementName");
73 self->isDraggable = WOExtGetProperty(_config, @"isDraggable");
75 self->object = WOExtGetProperty(_config, @"object");
76 self->droppedObject = WOExtGetProperty(_config, @"droppedObject");
78 self->template = [_t retain];
84 [self->isDraggable release];
85 [self->object release];
86 [self->droppedObject release];
88 [self->elementName release];
89 [self->effectsAllowed release];
90 [self->template release];
94 /* processing request values */
96 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
99 if ((formValue = [_rq formValueForKey:[_ctx elementID]]) != nil) {
102 if (debugTakeValues) {
104 debugWithFormat:@"WEDragContainer: got value '%@' for id '%@'",
105 formValue, [_ctx elementID]];
108 obj = [self->object valueInComponent:[_ctx component]];
111 NSLog(@"DRAG MATCH => ok, obj is %@",obj);
113 if ([self->droppedObject isValueSettable])
114 [self->droppedObject setValue:obj inComponent:[_ctx component]];
117 [_ctx takeValue:obj forKey:@"WEDragContainer_DropObject"];
120 else if (debugTakeValues) {
122 debugWithFormat:@"WEDragContainer: got no value for id '%@'",
126 [self->template takeValuesFromRequest:_rq inContext:_ctx];
129 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
130 return [self->template invokeActionForRequest:_rq inContext:_ctx];
133 /* generating response */
135 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
140 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
143 if (self->isDraggable)
144 doDnD = [self->isDraggable boolValueInComponent:[_ctx component]];
147 [WEDragScript appendDragScriptToResponse:_response inContext:_ctx];
149 ttag = [self->tag stringValueInComponent:[_ctx component]];
152 NSString *teffect, *tdragContent;
154 teffect = self->effectsAllowed
155 ? [self->effectsAllowed stringValueInComponent:[_ctx component]]
158 tdragContent = @"this.innerHTML";
160 tmp = @"fnSetInfo('%@?%@','%@', %@)";
161 tmp = [NSString stringWithFormat:tmp,
162 [_ctx elementID], ttag,
167 if (self->elementName || doDnD) {
168 /* Note: not using lowercase names since this might break JS? */
169 [_response appendContentString:@"<SPAN "];
170 [_response appendContentString:@"ID=\"span_"];
171 [_response appendContentString:[_ctx elementID]];
172 [_response appendContentString:@"\" "];
176 [_response appendContentString:@" onDragStart=\""];
177 [_response appendContentString:tmp];
178 [_response appendContentString: @"\""];
179 [_response appendContentString:@" onDrag=\"fnDrag()\""];
180 [_response appendContentString:@" onDragEnd=\"fnDragEnd()\""];
183 if (self->elementName || doDnD) {
184 [self appendExtraAttributesToResponse:_response inContext:_ctx];
185 [_response appendContentString:@">"];
189 [self->template appendToResponse:_response inContext:_ctx];
191 /* close container */
192 if (self->elementName || doDnD)
193 [_response appendContentString:@"</SPAN>"];
199 return self->template;
202 @end /* WEDragContainer */
205 @implementation WEDragScript
207 + (void)appendDragScriptToResponse:(WOResponse *)_response
208 inContext:(WOContext *)_ctx
210 NSString *dragScript;
213 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
215 if (![[_ctx valueForKey: @"WEDragContainerScriptDone"] boolValue] && doDnD) {
217 @"<DIV ID=\"DragDIV\" STYLE=\"position: absolute; visibility: hidden; width: 150;\"></DIV>"
218 @"<SCRIPT LANGUAGE=\"JScript\">\n"
220 @"function fnSetInfo(objData, effects, dragContent) {\n"
221 @" event.dataTransfer.clearData(\"Text\");\n"
222 @" event.dataTransfer.setData(\"Text\", objData);\n"
223 @" event.dataTransfer.effectAllowed = effects;\n "
224 @" DragDIV.innerHTML = dragContent;\n"
225 @" DragDIV.style.visibility = \"visible\";\n "
226 @" DragDIV.style.top =window.event.clientY+document.body.scrollTop;\n"
227 @" DragDIV.style.left =window.event.clientX+document.body.scrollLeft;\n"
228 @" DragDIV.style.zIndex += 20; \n"
230 @"function fnDrag() {\n"
231 @" DragDIV.style.top =window.event.clientY+document.body.scrollTop;\n"
232 @" DragDIV.style.left =window.event.clientX+document.body.scrollLeft;\n"
234 @"function fnDragEnd() {\n"
235 @" DragDIV.innerHTML = \"\";\n"
236 @" DragDIV.style.visibility = \"hidden\";\n"
241 [_response appendContentString: dragScript];
243 [_ctx takeValue: [NSNumber numberWithBool: YES] forKey:
244 @"WEDragContainerScriptDone"];
248 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
249 [[self class] appendDragScriptToResponse:_response inContext:_ctx];
252 @end /* WEDragScript */