~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/WEExtensions/JSShiftClick.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/NGObjWeb.h>
 
23
#include "WEClientCapabilities.h"
 
24
 
 
25
/*
 
26
 
 
27
  < scriptName   (obligatory !!!)
 
28
  > identifier
 
29
  > prefix
 
30
 
 
31
  Generates an ShiftClick JavaScript for CheckBoxes.
 
32
 
 
33
  Example:
 
34
 
 
35
  // wod:
 
36
  ShiftClickScript: JSShiftClick {
 
37
    scriptName = scriptName;
 
38
  }
 
39
 
 
40
  Repetition: WORepetition {
 
41
    list = (1, 2, 3, 4, 5, 6, 7, 8, 9);
 
42
    item = index;
 
43
  }
 
44
  CheckBox: WOCheckBox {
 
45
    checked = checked;
 
46
    value   = index;      // = index"              this must be done !!!
 
47
    onClick = scriptCall; // = "scriptName(index)" this must be done !!!
 
48
  }
 
49
 
 
50
  // html:
 
51
 
 
52
  <FORM....>
 
53
  
 
54
    <#ShiftClickScript />
 
55
    <#Repetition>
 
56
      <#CheckBox />
 
57
    </#Repetition>
 
58
 
 
59
  </FORM>
 
60
  
 
61
*/
 
62
 
 
63
@interface JSShiftClick : WODynamicElement
 
64
{
 
65
  WOAssociation *identifier;
 
66
  WOAssociation *prefix;
 
67
  WOAssociation *scriptName;
 
68
}
 
69
@end
 
70
 
 
71
static NSString *JSShiftClick_Script =
 
72
      @"<script language=\"JavaScript\">\n"
 
73
      @"<!--\n"
 
74
      @"var ns = (document.layers) ? true : false;\n"
 
75
      @"var ie = (document.all) ? true : false;\n"
 
76
      @"var last = -1;\n"
 
77
      @"function shiftClick%@SearchElement(el) { \n"
 
78
      @"  for (i = 0; i < document.forms.length; i++) { \n"
 
79
      @"    for (j = 0; j < document.forms[i].elements.length; j++) { \n"
 
80
      @"      if (document.forms[i].elements[j].value == el) { \n"
 
81
      @"        return document.forms[i].elements[j]; \n"
 
82
      @"      } \n"
 
83
      @"    } \n"
 
84
      @"  } \n"
 
85
      @"  return false; \n"
 
86
      @"} \n\n"
 
87
      @"function shiftClick%@(z) {\n"
 
88
      @"  if (ie) {\n"
 
89
      @"    var plusShift = window.event.shiftKey;\n"
 
90
      @"    if (plusShift && last >= 0) {\n"
 
91
      @"      var actEl    = shiftClick%@SearchElement('%@'+last); \n"
 
92
      @"      if (actEl) { \n "
 
93
      @"        var actState = actEl.checked;\n"
 
94
      @"        if (z<last) { var e1 = z; var e2 = last; }\n"
 
95
      @"        else { var e1 = last; var e2 = z; }\n"
 
96
      @"        for (idx = e1; idx<= e2; idx++) {\n"
 
97
      @"          actEl = shiftClick%@SearchElement('%@' + idx); \n"
 
98
      @"          actEl.checked = actState;\n"
 
99
      @"        }\n"
 
100
      @"      } \n"
 
101
      @"    }\n"
 
102
      @"    last = z;\n"
 
103
      @"  }\n"
 
104
      @"}\n"
 
105
      @"//-->\n"
 
106
      @"</script>";
 
107
 
 
108
#include "common.h"
 
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 */