[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * Horde_Form_Action_conditional_setvalue is a Horde_Form_Action that 4 * sets the value of one Horde_Form variable based on the value of the 5 * variable the action is attached to. 6 * 7 * $Horde: framework/Form/Form/Action/conditional_setvalue.php,v 1.19.10.5 2006/01/01 21:28:17 jan Exp $ 8 * 9 * Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org> 10 * 11 * See the enclosed file COPYING for license information (LGPL). If you 12 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 13 * 14 * @author Chuck Hagenbuch <chuck@horde.org> 15 * @package Horde_Form 16 */ 17 class Horde_Form_Action_conditional_setvalue extends Horde_Form_Action { 18 19 /** 20 * Which JS events should trigger this action? 21 * 22 * @var array 23 */ 24 var $_trigger = array('onchange', 'onload'); 25 26 function getActionScript($form, $renderer, $varname) 27 { 28 return 'map(\'' . $renderer->_genID($varname, false) . "', '" . $renderer->_genID($this->getTarget(), false) . '\');'; 29 } 30 31 function setValues(&$vars, $sourceVal, $arrayVal = false) 32 { 33 $map = $this->_params['map']; 34 $target = $this->getTarget(); 35 36 if ($arrayVal) { 37 $i = 0; 38 if (is_array($sourceVal)) { 39 foreach ($sourceVal as $val) { 40 if (!empty($map[$val])) { 41 $vars->set($target, $map[$val], $i); 42 } 43 $i++; 44 } 45 } 46 } else { 47 if (!empty($map[$sourceVal])) { 48 $vars->set($target, $map[$sourceVal]); 49 } 50 } 51 } 52 53 function printJavaScript() 54 { 55 $this->_printJavaScriptStart(); 56 $map = $this->_params['map']; 57 ?> 58 59 var _map = new Array(<?php 60 $i = 0; 61 foreach ($map as $val) { 62 if ($i > 0) { 63 echo ', '; 64 } 65 echo '"' . $val . '"'; 66 $i++; 67 }?>); 68 69 function map(sourceId, targetId) 70 { 71 var newval; 72 var source = document.getElementById(sourceId); 73 var element = document.getElementById(targetId); 74 if (element) { 75 if (_map[source.selectedIndex]) { 76 newval = _map[source.selectedIndex]; 77 replace = true; 78 } else { 79 newval = ''; 80 replace = false; 81 for (i = 0; i < _map.length; i++) { 82 if (element.value == _map[i]) { 83 replace = true; 84 break; 85 } 86 } 87 } 88 89 if (replace) { 90 element.value = newval; 91 } 92 } 93 }<?php 94 $this->_printJavaScriptEnd(); 95 } 96 97 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |