Subversion Repositories Applications.papyrus

Rev

Rev 320 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 443
Line 16... Line 16...
16
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
16
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
17
// |          Alexey Borzov <borz_off@cs.msu.su>                          |
17
// |          Alexey Borzov <borz_off@cs.msu.su>                          |
18
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
18
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
19
// +----------------------------------------------------------------------+
19
// +----------------------------------------------------------------------+
20
//
20
//
21
// $Id: RuleRegistry.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
21
// $Id: RuleRegistry.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
Line 22... Line 22...
22
 
22
 
23
/**
23
/**
24
* Registers rule objects and uses them for validation
24
* Registers rule objects and uses them for validation
25
*
25
*
Line 213... Line 213...
213
    function _getJsValue(&$element, $elementName, $reset = false, $index = null)
213
    function _getJsValue(&$element, $elementName, $reset = false, $index = null)
214
    {
214
    {
215
        $jsIndex = isset($index)? '[' . $index . ']': '';
215
        $jsIndex = isset($index)? '[' . $index . ']': '';
216
        $tmp_reset = $reset? "    var field = frm.elements['$elementName'];\n": '';
216
        $tmp_reset = $reset? "    var field = frm.elements['$elementName'];\n": '';
217
        if (is_a($element, 'html_quickform_group')) {
217
        if (is_a($element, 'html_quickform_group')) {
218
            $value = "  var {$elementName}Elements = '::";
218
            $value = "  _qfGroups['{$elementName}'] = {";
-
 
219
            $elements =& $element->getElements();
219
            for ($i = 0, $count = count($element->_elements); $i < $count; $i++) {
220
            for ($i = 0, $count = count($elements); $i < $count; $i++) {
-
 
221
                $append = ($elements[$i]->getType() == 'select' && $elements[$i]->getMultiple())? '[]': '';
220
                $value .= $element->getElementName($i) . '::';
222
                $value .= "'" . $element->getElementName($i) . $append . "': true" .
-
 
223
                          ($i < $count - 1? ', ': '');
221
            }
224
            }
222
            $value .=
225
            $value .=
223
                "';\n" .
226
                "};\n" .
224
                "  value{$jsIndex} = new Array();\n" .
227
                "  value{$jsIndex} = new Array();\n" .
225
                "  var valueIdx = 0;\n" .
228
                "  var valueIdx = 0;\n" .
226
                "  for (var i = 0; i < frm.elements.length; i++) {\n" .
229
                "  for (var i = 0; i < frm.elements.length; i++) {\n" .
227
                "    var _element = frm.elements[i];\n" .
230
                "    var _element = frm.elements[i];\n" .
228
                "    if ({$elementName}Elements.indexOf('::' + _element.name + '::') >= 0) {\n" . 
231
                "    if (_element.name in _qfGroups['{$elementName}']) {\n" . 
229
                "      switch (_element.type) {\n" .
232
                "      switch (_element.type) {\n" .
230
                "        case 'checkbox':\n" .
233
                "        case 'checkbox':\n" .
231
                "        case 'radio':\n" .
234
                "        case 'radio':\n" .
232
                "          if (_element.checked) {\n" .
235
                "          if (_element.checked) {\n" .
233
                "            value{$jsIndex}[valueIdx++] = _element.value;\n" .
236
                "            value{$jsIndex}[valueIdx++] = _element.value;\n" .
234
                "          }\n" .
237
                "          }\n" .
235
                "          break;\n" .
238
                "          break;\n" .
236
                "        case 'select':\n" .
239
                "        case 'select-one':\n" .
237
                "          if (-1 != _element.selectedIndex) {\n" .
240
                "          if (-1 != _element.selectedIndex) {\n" .
238
                "            value{$jsIndex}[valueIdx++] = _element.options[_element.selectedIndex].value;\n" .
241
                "            value{$jsIndex}[valueIdx++] = _element.options[_element.selectedIndex].value;\n" .
239
                "          }\n" .
242
                "          }\n" .
240
                "          break;\n" .
243
                "          break;\n" .
-
 
244
                "        case 'select-multiple':\n" .
-
 
245
                "          var tmpVal = new Array();\n" .
-
 
246
                "          var tmpIdx = 0;\n" .
-
 
247
                "          for (var j = 0; j < _element.options.length; j++) {\n" .
-
 
248
                "            if (_element.options[j].selected) {\n" .
-
 
249
                "              tmpVal[tmpIdx++] = _element.options[j].value;\n" .
-
 
250
                "            }\n" .
-
 
251
                "          }\n" .
-
 
252
                "          if (tmpIdx > 0) {\n" .
-
 
253
                "            value{$jsIndex}[valueIdx++] = tmpVal;\n" .
-
 
254
                "          }\n" .
-
 
255
                "          break;\n" .
241
                "        default:\n" .
256
                "        default:\n" .
242
                "          value{$jsIndex}[valueIdx++] = _element.value;\n" .
257
                "          value{$jsIndex}[valueIdx++] = _element.value;\n" .
243
                "      }\n" .
258
                "      }\n" .
244
                "    }\n" .
259
                "    }\n" .
245
                "  }\n";
260
                "  }\n";
246
            if ($reset) {
261
            if ($reset) {
247
                $tmp_reset =
262
                $tmp_reset =
248
                    "    for (var i = 0; i < frm.elements.length; i++) {\n" .
263
                    "    for (var i = 0; i < frm.elements.length; i++) {\n" .
249
                    "      var _element = frm.elements[i];\n" .
264
                    "      var _element = frm.elements[i];\n" .
250
                    "      if ({$elementName}Elements.indexOf('::' + _element.name + '::') >= 0) {\n" . 
265
                    "      if (_element.name in _qfGroups['{$elementName}']) {\n" . 
251
                    "        switch (_element.type) {\n" .
266
                    "        switch (_element.type) {\n" .
252
                    "          case 'checkbox':\n" .
267
                    "          case 'checkbox':\n" .
253
                    "          case 'radio':\n" .
268
                    "          case 'radio':\n" .
254
                    "            _element.checked = _element.defaultChecked;\n" .
269
                    "            _element.checked = _element.defaultChecked;\n" .
255
                    "            break;\n" .
270
                    "            break;\n" .
256
                    "          case 'select':\n" .
271
                    "          case 'select-one':\n" .
-
 
272
                    "          case 'select-multiple:\n" .
257
                    "            for (var j = 0; j < _element.options.length; j++) {\n" .
273
                    "            for (var j = 0; j < _element.options.length; j++) {\n" .
258
                    "              _element.options[j].selected = _element.options[j].defaultSelected;\n" .
274
                    "              _element.options[j].selected = _element.options[j].defaultSelected;\n" .
259
                    "            }\n" .
275
                    "            }\n" .
260
                    "            break;\n" .
276
                    "            break;\n" .
261
                    "          default:\n" .
277
                    "          default:\n" .
Line 275... Line 291...
275
                    "    if (frm.elements['{$elementName}'].options[i].selected) {\n" .
291
                    "    if (frm.elements['{$elementName}'].options[i].selected) {\n" .
276
                    "      value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" .
292
                    "      value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" .
277
                    "    }\n" .
293
                    "    }\n" .
278
                    "  }\n";
294
                    "  }\n";
279
            } else {
295
            } else {
280
                $value = "  value{$jsIndex} = frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n";
296
                $value = "  value{$jsIndex} = frm.elements['{$elementName}'].selectedIndex == -1? '': frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n";
281
            }
297
            }
282
            if ($reset) {
298
            if ($reset) {
283
                $tmp_reset .= 
299
                $tmp_reset .= 
284
                    "    for (var i = 0; i < field.options.length; i++) {\n" .
300
                    "    for (var i = 0; i < field.options.length; i++) {\n" .
285
                    "      field.options[i].selected = field.options[i].defaultSelected;\n" .
301
                    "      field.options[i].selected = field.options[i].defaultSelected;\n" .
286
                    "    }\n";
302
                    "    }\n";
287
            }
303
            }
Line 288... Line 304...
288
 
304
 
289
        } elseif ($element->getType() == 'checkbox') {
305
        } elseif ($element->getType() == 'checkbox' && !is_a($element, 'html_quickform_advcheckbox')) {
290
            $value = "  if (frm.elements['$elementName'].checked) {\n" .
306
            $value = "  if (frm.elements['$elementName'].checked) {\n" .
291
                     "    value{$jsIndex} = '1';\n" .
307
                     "    value{$jsIndex} = '1';\n" .
292
                     "  } else {\n" .
308
                     "  } else {\n" .
293
                     "    value{$jsIndex} = '';\n" .
309
                     "    value{$jsIndex} = '';\n" .