]> err.no Git - sope/blob - sope-appserver/WEExtensions/JSShiftClick.m
added strict OSX bundle dependencies
[sope] / sope-appserver / WEExtensions / JSShiftClick.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include <NGObjWeb/WODynamicElement.h>
23
24 /*
25
26   < scriptName   (obligatory !!!)
27   > identifier
28   > prefix
29
30   Generates an ShiftClick JavaScript for CheckBoxes.
31
32   Example:
33
34   // wod:
35   ShiftClickScript: JSShiftClick {
36     scriptName = scriptName;
37   }
38
39   Repetition: WORepetition {
40     list = (1, 2, 3, 4, 5, 6, 7, 8, 9);
41     item = index;
42   }
43   CheckBox: WOCheckBox {
44     checked = checked;
45     value   = index;      // = index"              this must be done !!!
46     onClick = scriptCall; // = "scriptName(index)" this must be done !!!
47   }
48
49   // html:
50
51   <FORM....>
52   
53     <#ShiftClickScript />
54     <#Repetition>
55       <#CheckBox />
56     </#Repetition>
57
58   </FORM>
59   
60 */
61
62 @interface JSShiftClick : WODynamicElement
63 {
64   WOAssociation *identifier;
65   WOAssociation *prefix;
66   WOAssociation *scriptName;
67 }
68 @end
69
70 #include "common.h"
71 #include <NGObjWeb/WEClientCapabilities.h>
72
73 static NSString *JSShiftClick_Script =
74       @"<script language=\"JavaScript\">\n"
75       @"<!--\n"
76       @"var ns = (document.layers) ? true : false;\n"
77       @"var ie = (document.all) ? true : false;\n"
78       @"var last = -1;\n"
79       @"function shiftClick%@SearchElement(el) { \n"
80       @"  for (i = 0; i < document.forms.length; i++) { \n"
81       @"    for (j = 0; j < document.forms[i].elements.length; j++) { \n"
82       @"      if (document.forms[i].elements[j].value == el) { \n"
83       @"        return document.forms[i].elements[j]; \n"
84       @"      } \n"
85       @"    } \n"
86       @"  } \n"
87       @"  return false; \n"
88       @"} \n\n"
89       @"function shiftClick%@(z) {\n"
90       @"  if (ie) {\n"
91       @"    var plusShift = window.event.shiftKey;\n"
92       @"    if (plusShift && last >= 0) {\n"
93       @"      var actEl    = shiftClick%@SearchElement('%@'+last); \n"
94       @"      if (actEl) { \n "
95       @"        var actState = actEl.checked;\n"
96       @"        if (z<last) { var e1 = z; var e2 = last; }\n"
97       @"        else { var e1 = last; var e2 = z; }\n"
98       @"        for (idx = e1; idx<= e2; idx++) {\n"
99       @"          actEl = shiftClick%@SearchElement('%@' + idx); \n"
100       @"          actEl.checked = actState;\n"
101       @"        }\n"
102       @"      } \n"
103       @"    }\n"
104       @"    last = z;\n"
105       @"  }\n"
106       @"}\n"
107       @"//-->\n"
108       @"</script>";
109
110 @implementation JSShiftClick
111
112 - (id)initWithName:(NSString *)_name
113   associations:(NSDictionary *)_config
114   template:(WOElement *)_tmp
115 {
116   if ((self = [super initWithName:_name associations:_config template:_tmp])) {
117     self->identifier = WOExtGetProperty(_config, @"identifier");
118     self->prefix     = WOExtGetProperty(_config, @"prefix");
119     self->scriptName = WOExtGetProperty(_config, @"scriptName");
120   }
121   return self;
122 }
123
124 - (void)dealloc {
125   [self->identifier release];
126   [self->prefix     release];
127   [self->scriptName release];
128   [super dealloc];
129 }
130
131 /* response generation */
132
133 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
134   WEClientCapabilities *ccaps = nil;
135   NSString *eid  = nil;
136   NSString *prfx = nil;
137
138   ccaps = [[_ctx request] clientCapabilities];
139
140   eid = [self->identifier stringValueInComponent:[_ctx component]];
141   eid = (eid) ? eid : [_ctx elementID];
142   eid = [[eid componentsSeparatedByString:@"."]
143               componentsJoinedByString:@"_"];
144   
145   prfx = [self->prefix stringValueInComponent:[_ctx component]];
146   prfx = (prfx) ? prfx : @"";
147
148   if ([ccaps isJavaScriptBrowser]) {
149     NSString *s;
150     
151     s = [[NSString alloc] initWithFormat:JSShiftClick_Script,
152                           eid, eid, eid, prfx, eid, prfx];
153     [_response appendContentString:s];
154     [s release];
155   }
156   if ([self->scriptName isValueSettable]) {
157     NSString *sName = nil;
158
159     sName = [@"shiftClick" stringByAppendingString:eid];
160     [self->scriptName setValue:sName inComponent:[_ctx component]];
161   }
162 #if DEBUG
163   else {
164     NSLog(@"Warning: JSShiftClick: 'scriptName' is not settable!!!");
165   }
166 #endif
167 }
168
169 @end /* JSShiftClick */