2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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 #include <NGObjWeb/WODynamicElement.h>
29 <SPAN onDragStart="fnSetInfo($tag,$effectsAllowed)">
35 @interface WEDragContainer : WODynamicElement
39 WOAssociation *effectsAllowed;
40 WOAssociation *elementName;
41 WOAssociation *isDraggable;
43 WOAssociation *object;
44 WOAssociation *droppedObject;
48 @interface WEDragScript : WODynamicElement
49 + (void)appendDragScriptToResponse:(WOResponse *)_response
50 inContext:(WOContext *)_ctx;
53 #include "WEClientCapabilities.h"
54 #include <NGObjWeb/NGObjWeb.h>
55 #include <NGExtensions/NGExtensions.h>
58 //#define DEBUG_TAKEVALUES 1
60 @implementation WEDragContainer
62 static BOOL debugTakeValues = NO;
65 return 0 + [super version];
68 - (id)initWithName:(NSString *)_name
69 associations:(NSDictionary *)_config
70 template:(WOElement *)_t
72 if ((self = [super initWithName:_name associations:_config template:_t])) {
73 self->tag = WOExtGetProperty(_config, @"tag");
74 self->effectsAllowed = WOExtGetProperty(_config, @"effectsAllowed");
75 self->elementName = WOExtGetProperty(_config, @"elementName");
76 self->isDraggable = WOExtGetProperty(_config, @"isDraggable");
78 self->object = WOExtGetProperty(_config, @"object");
79 self->droppedObject = WOExtGetProperty(_config, @"droppedObject");
81 self->template = [_t retain];
87 [self->isDraggable release];
88 [self->object release];
89 [self->droppedObject release];
91 [self->elementName release];
92 [self->effectsAllowed release];
93 [self->template release];
97 /* processing request values */
99 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
102 if ((formValue = [_rq formValueForKey:[_ctx elementID]]) != nil) {
105 if (debugTakeValues) {
107 debugWithFormat:@"WEDragContainer: got value '%@' for id '%@'",
108 formValue, [_ctx elementID]];
111 obj = [self->object valueInComponent:[_ctx component]];
114 NSLog(@"DRAG MATCH => ok, obj is %@",obj);
116 if ([self->droppedObject isValueSettable])
117 [self->droppedObject setValue:obj inComponent:[_ctx component]];
120 [_ctx takeValue:obj forKey:@"WEDragContainer_DropObject"];
123 else if (debugTakeValues) {
125 debugWithFormat:@"WEDragContainer: got no value for id '%@'",
129 [self->template takeValuesFromRequest:_rq inContext:_ctx];
132 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
133 return [self->template invokeActionForRequest:_rq inContext:_ctx];
136 /* generating response */
138 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
143 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
146 if (self->isDraggable)
147 doDnD = [self->isDraggable boolValueInComponent:[_ctx component]];
150 [WEDragScript appendDragScriptToResponse:_response inContext:_ctx];
152 ttag = [self->tag stringValueInComponent:[_ctx component]];
155 NSString *teffect, *tdragContent;
157 teffect = self->effectsAllowed
158 ? [self->effectsAllowed stringValueInComponent:[_ctx component]]
161 tdragContent = @"this.innerHTML";
163 tmp = @"fnSetInfo('%@?%@','%@', %@)";
164 tmp = [NSString stringWithFormat:tmp,
165 [_ctx elementID], ttag,
170 if (self->elementName || doDnD) {
171 /* Note: not using lowercase names since this might break JS? */
172 [_response appendContentString:@"<SPAN "];
173 [_response appendContentString:@"ID=\"span_"];
174 [_response appendContentString:[_ctx elementID]];
175 [_response appendContentString:@"\" "];
179 [_response appendContentString:@" onDragStart=\""];
180 [_response appendContentString:tmp];
181 [_response appendContentString: @"\""];
182 [_response appendContentString:@" onDrag=\"fnDrag()\""];
183 [_response appendContentString:@" onDragEnd=\"fnDragEnd()\""];
186 if (self->elementName || doDnD) {
187 [self appendExtraAttributesToResponse:_response inContext:_ctx];
188 [_response appendContentString:@">"];
192 [self->template appendToResponse:_response inContext:_ctx];
194 /* close container */
195 if (self->elementName || doDnD)
196 [_response appendContentString:@"</SPAN>"];
201 - (WOElement *)template {
202 return self->template;
205 @end /* WEDragContainer */
207 @implementation WEDragScript
209 + (void)appendDragScriptToResponse:(WOResponse *)_response
210 inContext:(WOContext *)_ctx
212 NSString *dragScript;
215 doDnD = [[[_ctx request] clientCapabilities] doesSupportDHTMLDragAndDrop];
217 if (![[_ctx valueForKey: @"WEDragContainerScriptDone"] boolValue] && doDnD) {
219 @"<DIV ID=\"DragDIV\" STYLE=\"position: absolute; visibility: hidden; width: 150;\"></DIV>"
220 @"<SCRIPT LANGUAGE=\"JScript\">\n"
222 @"function fnSetInfo(objData, effects, dragContent) {\n"
223 @" event.dataTransfer.clearData(\"Text\");\n"
224 @" event.dataTransfer.setData(\"Text\", objData);\n"
225 @" event.dataTransfer.effectAllowed = effects;\n "
226 @" DragDIV.innerHTML = dragContent;\n"
227 @" DragDIV.style.visibility = \"visible\";\n "
228 @" DragDIV.style.top =window.event.clientY+document.body.scrollTop;\n"
229 @" DragDIV.style.left =window.event.clientX+document.body.scrollLeft;\n"
230 @" DragDIV.style.zIndex += 20; \n"
232 @"function fnDrag() {\n"
233 @" DragDIV.style.top =window.event.clientY+document.body.scrollTop;\n"
234 @" DragDIV.style.left =window.event.clientX+document.body.scrollLeft;\n"
236 @"function fnDragEnd() {\n"
237 @" DragDIV.innerHTML = \"\";\n"
238 @" DragDIV.style.visibility = \"hidden\";\n"
243 [_response appendContentString: dragScript];
245 [_ctx takeValue: [NSNumber numberWithBool: YES] forKey:
246 @"WEDragContainerScriptDone"];
250 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
251 [[self class] appendDragScriptToResponse:_response inContext:_ctx];
254 @end /* WEDragScript */