1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Form_Action_ConditionalSetValue extends Horde_Form_Action {
16:
17: 18: 19: 20: 21:
22: var $_trigger = array('onchange', 'onload');
23:
24: function getActionScript($form, $renderer, $varname)
25: {
26: return 'map(\'' . $renderer->_genID($varname, false) . "', '" . $renderer->_genID($this->getTarget(), false) . '\');';
27: }
28:
29: function setValues(&$vars, $sourceVal, $arrayVal = false)
30: {
31: $map = $this->_params['map'];
32: $target = $this->getTarget();
33:
34: if ($arrayVal) {
35: $i = 0;
36: if (is_array($sourceVal)) {
37: foreach ($sourceVal as $val) {
38: if (!empty($map[$val])) {
39: $vars->set($target, $map[$val], $i);
40: }
41: $i++;
42: }
43: }
44: } else {
45: if (!empty($map[$sourceVal])) {
46: $vars->set($target, $map[$sourceVal]);
47: }
48: }
49: }
50:
51: function printJavaScript()
52: {
53: $this->_printJavaScriptStart();
54: $map = $this->_params['map'];
55: ?>
56:
57: var _map = [<?php
58: $i = 0;
59: foreach ($map as $val) {
60: if ($i > 0) {
61: echo ', ';
62: }
63: echo '"' . $val . '"';
64: $i++;
65: }?>];
66:
67: function map(sourceId, targetId)
68: {
69: var newval;
70: var source = document.getElementById(sourceId);
71: var element = document.getElementById(targetId);
72: if (element) {
73: if (_map[source.selectedIndex]) {
74: newval = _map[source.selectedIndex];
75: replace = true;
76: } else {
77: newval = '';
78: replace = false;
79: for (i = 0; i < _map.length; i++) {
80: if (element.value == _map[i]) {
81: replace = true;
82: break;
83: }
84: }
85: }
86:
87: if (replace) {
88: element.value = newval;
89: }
90: }
91: }<?php
92: $this->_printJavaScriptEnd();
93: }
94:
95: }
96: