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/NGObjWeb.h>
24 #include "WEClientCapabilities.h"
28 < scriptName (obligatory !!!)
32 Generates an ShiftClick JavaScript for CheckBoxes.
37 ShiftClickScript: JSShiftClick {
38 scriptName = scriptName;
41 Repetition: WORepetition {
42 list = (1, 2, 3, 4, 5, 6, 7, 8, 9);
45 CheckBox: WOCheckBox {
47 value = index; // = index" this must be done !!!
48 onClick = scriptCall; // = "scriptName(index)" this must be done !!!
64 @interface JSShiftClick : WODynamicElement
66 WOAssociation *identifier;
67 WOAssociation *prefix;
68 WOAssociation *scriptName;
72 static NSString *JSShiftClick_Script =
73 @"<script language=\"JavaScript\">\n"
75 @"var ns = (document.layers) ? true : false;\n"
76 @"var ie = (document.all) ? true : false;\n"
78 @"function shiftClick%@SearchElement(el) { \n"
79 @" for (i = 0; i < document.forms.length; i++) { \n"
80 @" for (j = 0; j < document.forms[i].elements.length; j++) { \n"
81 @" if (document.forms[i].elements[j].value == el) { \n"
82 @" return document.forms[i].elements[j]; \n"
88 @"function shiftClick%@(z) {\n"
90 @" var plusShift = window.event.shiftKey;\n"
91 @" if (plusShift && last >= 0) {\n"
92 @" var actEl = shiftClick%@SearchElement('%@'+last); \n"
94 @" var actState = actEl.checked;\n"
95 @" if (z<last) { var e1 = z; var e2 = last; }\n"
96 @" else { var e1 = last; var e2 = z; }\n"
97 @" for (idx = e1; idx<= e2; idx++) {\n"
98 @" actEl = shiftClick%@SearchElement('%@' + idx); \n"
99 @" actEl.checked = actState;\n"
111 @implementation JSShiftClick
113 - (id)initWithName:(NSString *)_name
114 associations:(NSDictionary *)_config
115 template:(WOElement *)_tmp
117 if ((self = [super initWithName:_name associations:_config template:_tmp])) {
118 self->identifier = WOExtGetProperty(_config, @"identifier");
119 self->prefix = WOExtGetProperty(_config, @"prefix");
120 self->scriptName = WOExtGetProperty(_config, @"scriptName");
126 [self->identifier release];
127 [self->prefix release];
128 [self->scriptName release];
132 /* response generation */
134 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
135 WEClientCapabilities *ccaps = nil;
137 NSString *prfx = nil;
139 ccaps = [[_ctx request] clientCapabilities];
141 eid = [self->identifier stringValueInComponent:[_ctx component]];
142 eid = (eid) ? eid : [_ctx elementID];
143 eid = [[eid componentsSeparatedByString:@"."]
144 componentsJoinedByString:@"_"];
146 prfx = [self->prefix stringValueInComponent:[_ctx component]];
147 prfx = (prfx) ? prfx : @"";
149 if ([ccaps isJavaScriptBrowser]) {
152 s = [[NSString alloc] initWithFormat:JSShiftClick_Script,
153 eid, eid, eid, prfx, eid, prfx];
154 [_response appendContentString:s];
157 if ([self->scriptName isValueSettable]) {
158 NSString *sName = nil;
160 sName = [@"shiftClick" stringByAppendingString:eid];
161 [self->scriptName setValue:sName inComponent:[_ctx component]];
165 NSLog(@"Warning: JSShiftClick: 'scriptName' is not settable!!!");
170 @end /* JSShiftClick */