2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Single action button.
|
|
|
|
* The action buttons are <input type="submit"> tags.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage actions
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class FormAction extends FormField {
|
2008-08-11 02:14:48 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $extraData;
|
2008-08-11 02:14:48 +02:00
|
|
|
|
2008-08-06 08:54:59 +02:00
|
|
|
protected $action;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-11 02:14:48 +02:00
|
|
|
/**
|
|
|
|
* Enables the use of <button> instead of <input>
|
|
|
|
* in {@link Field()} - for more customizeable styling.
|
|
|
|
*
|
|
|
|
* @var boolean $useButtonTag
|
|
|
|
*/
|
|
|
|
public $useButtonTag = false;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Create a new action button.
|
|
|
|
* @param action The method to call when the button is clicked
|
|
|
|
* @param title The label on the button
|
|
|
|
* @param form The parent form, auto-set when the field is placed inside a form
|
|
|
|
* @param extraData A piece of extra data that can be extracted with $this->extraData. Useful for
|
|
|
|
* calling $form->buttonClicked()->extraData()
|
2007-09-15 01:43:02 +02:00
|
|
|
* @param extraClass A CSS class to apply to the button in addition to 'action'
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-15 01:43:02 +02:00
|
|
|
function __construct($action, $title = "", $form = null, $extraData = null, $extraClass = '') {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->extraData = $extraData;
|
2007-09-15 01:43:02 +02:00
|
|
|
$this->extraClass = ' '.$extraClass;
|
2008-08-06 08:54:59 +02:00
|
|
|
$this->action = "action_$action";
|
|
|
|
parent::__construct($this->action, $title, null, $form);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-10-09 22:27:01 +02:00
|
|
|
|
2007-09-15 01:43:02 +02:00
|
|
|
static function create($action, $title = "", $extraData = null, $extraClass = null) {
|
|
|
|
return new FormAction($action, $title, null, $extraData, $extraClass);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function actionName() {
|
|
|
|
return substr($this->name,7);
|
|
|
|
}
|
2008-08-06 08:54:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the full action name, including action_
|
|
|
|
* This provides an opportunity to replace it with something else
|
|
|
|
*/
|
|
|
|
function setFullAction($fullAction) {
|
|
|
|
$this->action = $fullAction;
|
|
|
|
}
|
2007-10-18 03:44:37 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function extraData() {
|
|
|
|
return $this->extraData;
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:50:13 +02:00
|
|
|
/**
|
|
|
|
* Create a submit input, or button tag
|
2008-10-16 13:50:55 +02:00
|
|
|
* using {@link FormField->createTag()} functionality.
|
2008-10-16 13:50:13 +02:00
|
|
|
*
|
|
|
|
* @return HTML code for the input OR button element
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function Field() {
|
2008-08-11 02:14:48 +02:00
|
|
|
if($this->useButtonTag) {
|
2008-10-16 13:50:13 +02:00
|
|
|
$attributes = array(
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''),
|
2008-10-16 13:50:13 +02:00
|
|
|
'id' => $this->id(),
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => $this->action
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->createTag('button', $attributes, $this->attrTitle());
|
2008-08-11 02:14:48 +02:00
|
|
|
} else {
|
2008-10-16 13:50:13 +02:00
|
|
|
$attributes = array(
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''),
|
2008-10-16 13:50:13 +02:00
|
|
|
'id' => $this->id(),
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => $this->action,
|
2008-11-06 00:21:50 +01:00
|
|
|
'value' => ($this->dontEscape) ? $this->Title() : $this->attrTitle()
|
2008-10-16 13:50:13 +02:00
|
|
|
);
|
|
|
|
|
2008-11-06 00:21:50 +01:00
|
|
|
$attributes['title'] = ($this->description) ? $this->description : ($this->dontEscape) ? $this->Title() : $this->attrTitle();
|
2008-10-16 13:50:13 +02:00
|
|
|
|
|
|
|
return $this->createTag('input', $attributes);
|
2008-08-11 02:14:48 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does not transform to readonly by purpose.
|
|
|
|
* Globally disabled buttons would break the CMS.
|
|
|
|
*/
|
|
|
|
function performReadonlyTransformation() {
|
2008-08-12 04:58:48 +02:00
|
|
|
$this->setDisabled(true);
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
function readonlyField() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 01:34:18 +01:00
|
|
|
/**
|
|
|
|
* @package forms
|
|
|
|
* @subpackage actions
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class FormAction_WithoutLabel extends FormAction {
|
|
|
|
function Title(){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|