steffen: server/kolab-horde-framework/kolab-horde-framework/Form/Form/Action conditional_enable.php, NONE, 1.1 conditional_setvalue.php, NONE, 1.1 reload.php, NONE, 1.1 submit.php, NONE, 1.1 sum_fields.php, NONE, 1.1 updatefield.php, NONE, 1.1
cvs at intevation.de
cvs at intevation.de
Fri Oct 14 16:33:06 CEST 2005
Author: steffen
Update of /kolabrepository/server/kolab-horde-framework/kolab-horde-framework/Form/Form/Action
In directory doto:/tmp/cvs-serv28903/kolab-horde-framework/kolab-horde-framework/Form/Form/Action
Added Files:
conditional_enable.php conditional_setvalue.php reload.php
submit.php sum_fields.php updatefield.php
Log Message:
Separated Horde Framework from kolab-resource-handlers
--- NEW FILE: conditional_enable.php ---
<?php
/**
* Horde_Form_Action_conditional_enable is a Horde_Form_Action that
* enables or disables an element based on the value of another element
*
* Format of the $params passed to the constructor:
* <pre>
* $params = array(
* 'target' => '[name of element this is conditional on]',
* 'enabled' => 'true' | 'false',
* 'values' => array([target values to check])
* );
* </pre>
*
* So $params = array('foo', 'true', array(1, 2)) will enable the field this
* action is attached to if the value of 'foo' is 1 or 2, and disable it
* otherwise.
*
* Copyright 2002-2004 Matt Kynaston <matt at kynx.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Matt Kynaston <matt at kynx.org>
* @package Horde_Form
*/
class Horde_Form_Action_conditional_enable extends Horde_Form_Action {
var $_trigger = array('onload');
function getActionScript(&$form, $renderer, $varname)
{
Horde::addScriptFile('form_helpers.js', 'horde');
$form_name = $form->getName();
$target = $this->_params['target'];
$enabled = $this->_params['enabled'];
if (!is_string($enabled)) {
$enabled = ($enabled) ? 'true' : 'false';
}
$vals = $this->_params['values'];
$vals = (is_array($vals)) ? $vals : array($vals);
$args = "'$varname', $enabled, '" . join("','", $vals) . "'";
return "if (addEvent(document.$form_name.$target, 'onchange', \"checkEnabled(this, $args);\")) { "
." checkEnabled(document.$form_name.$varname, $args); "
."};";
}
}
--- NEW FILE: conditional_setvalue.php ---
<?php
/**
* Horde_Form_Action_conditional_setvalue is a Horde_Form_Action that
* sets the value of one Horde_Form variable based on the value of the
* variable the action is attached to.
*
* $Horde: framework/Form/Form/Action/conditional_setvalue.php,v 1.18 2004/04/14 15:38:41 chuck Exp $
*
* Copyright 2002-2004 Chuck Hagenbuch <chuck at horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Chuck Hagenbuch <chuck at horde.org>
* @version $Revision: 1.1 $
* @package Horde_Form
*/
class Horde_Form_Action_conditional_setvalue extends Horde_Form_Action {
/**
* Which JS events should trigger this action?
* @var array $_trigger
*/
var $_trigger = array('onchange', 'onload');
function getActionScript($form, $renderer, $varname)
{
return 'map(\'' . $renderer->_genID($varname, false) . "', '" . $renderer->_genID($this->getTarget(), false) . '\');';
}
function setValues(&$vars, $sourceVal, $arrayVal = false)
{
$map = $this->_params['map'];
$target = $this->getTarget();
if ($arrayVal) {
$i = 0;
if (is_array($sourceVal)) {
foreach ($sourceVal as $val) {
if (!empty($map[$val])) {
$vars->set($target, $map[$val], $i);
}
$i++;
}
}
} else {
if (!empty($map[$sourceVal])) {
$vars->set($target, $map[$sourceVal]);
}
}
}
function printJavaScript()
{
$this->_printJavaScriptStart();
$map = $this->_params['map'];
?>
_map = new Array(<?php
$i = 0;
foreach ($map as $val) {
if ($i > 0) {
echo ', ';
}
echo '"' . $val . '"';
$i++;
}?>);
function map(sourceId, targetId)
{
var newval;
var source = document.getElementById(sourceId);
var element = document.getElementById(targetId);
if (element && _map) {
if (_map[source.selectedIndex]) {
newval = _map[source.selectedIndex];
replace = true;
} else {
newval = '';
replace = false;
for (i = 0; i < _map.length; i++) {
if (element.value == _map[i]) {
replace = true;
break;
}
}
}
if (replace) {
element.value = newval;
}
}
}<?php
$this->_printJavaScriptEnd();
}
}
--- NEW FILE: reload.php ---
<?php
/**
* Horde_Form_Action_reload is a Horde_Form Action that reloads the
* form with the current (not the original) value after the form element
* that the action is attached to is modified.
*
* $Horde: framework/Form/Form/Action/reload.php,v 1.6 2004/03/21 18:22:19 eraserhd Exp $
*
* Copyright 2003-2004 Jan Schneider <jan at horde.org>
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsdl.php.
*
* @author Jan Schneider <jan at horde.org>
* @version $Revision: 1.1 $
* @package Horde_Form
*/
class Horde_Form_Action_reload extends Horde_Form_Action {
var $_trigger = array('onchange');
function getActionScript($form, $renderer, $varname)
{
return 'if (this.value) { document.' . $form->getName() . '.formname.value=\'\';' .
'document.' . $form->getName() . '.submit() }';
}
}
--- NEW FILE: submit.php ---
<?php
/**
* Horde_Form_Action_submit is a Horde_Form Action that submits the
* form after the form element that the action is attached to is
* modified.
*
* $Horde: framework/Form/Form/Action/submit.php,v 1.10 2004/03/21 18:22:19 eraserhd Exp $
*
* Copyright 2002-2004 Chuck Hagenbuch <chuck at horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Chuck Hagenbuch <chuck at horde.org>
* @version $Revision: 1.1 $
* @package Horde_Form
*/
class Horde_Form_Action_submit extends Horde_Form_Action {
var $_trigger = array('onchange');
function getActionScript($form, $renderer, $varname)
{
return 'document.' . $form->getName() . '.submit()';
}
}
--- NEW FILE: sum_fields.php ---
<?php
/**
* Horde_Form_Action_sum_fields is a Horde_Form_Action that sets the target
* field to the sum of one or more other numeric fields.
*
* The params array should contain the names of the fields which will be
* summed.
*`
* Copyright 2002-2004 Matt Kynaston <matt at kynx.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Matt Kynaston <matt at kynx.org>
* @package Horde_Form
*/
class Horde_Form_Action_sum_fields extends Horde_Form_Action {
var $_trigger = array('onload');
function getActionScript(&$form, $renderer, $varname)
{
Horde::addScriptFile('form_helpers.js', 'horde');
$form_name = $form->getName();
$fields = "'" . join("','", $this->_params) . "'";
$js = array();
$js[] = sprintf('document.%s.%s.disabled = true;',
$form_name,
$varname);
foreach($this->_params as $field) {
$js[] = sprintf("addEvent(document.%s.%s, 'onchange', \"sumFields(this.form, '%s', %s);\");",
$form_name,
$field,
$varname,
$fields);
}
return join("\n", $js);
}
}
--- NEW FILE: updatefield.php ---
<?php
/**
* Horde_Form_Action_updatefield is a Horde_Form_Action that updates
* the value of one Horde_Form variable as the variable the action is
* attached to is updated.
*
* $Horde: framework/Form/Form/Action/updatefield.php,v 1.5 2004/03/21 18:22:19 eraserhd Exp $
*
* Copyright 2002-2004 Chuck Hagenbuch <chuck at horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Chuck Hagenbuch <chuck at horde.org>
* @version $Revision: 1.1 $
* @package Horde_Form
*/
class Horde_Form_Action_updatefield extends Horde_Form_Action {
var $_trigger = array('onchange', 'onload', 'onkeyup');
function getActionScript(&$form, &$renderer, $varname)
{
return 'updateField' . $this->id() . '();';
}
function setValues(&$vars, $sourceVal, $arrayVal = false)
{
}
function printJavaScript()
{
$this->_printJavaScriptStart();
$pieces = explode('%s', $this->_params['format']);
$fields = $this->_params['fields'];
$val_first = (substr($this->_params['format'], 0, 2) == '%s');
if ($val_first) {
array_shift($pieces);
}
if (substr($this->_params['format'], -2) == '%s') {
array_pop($pieces);
}
$args = array();
if ($val_first) {
$args[] = "document.getElementById('" . array_shift($fields) . "').value";
}
while (count($pieces)) {
$args[] = "'" . array_shift($pieces) . "'";
$args[] = "document.getElementById('" . array_shift($fields) . "').value";
}
?>
// Updater for <?php echo $this->getTarget() ?>.
function updateField<?php echo $this->id() ?>()
{
var target = document.getElementById('<?php echo $this->getTarget() ?>');
if (target) {
target.value = <?php echo implode(' + ', $args) ?>;
}
}<?php
$this->_printJavaScriptEnd();
}
}
More information about the commits
mailing list