2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Single action button.
|
|
|
|
* The action buttons are <input type="submit"> tags.
|
2010-10-15 05:55:22 +02:00
|
|
|
*
|
|
|
|
* <b>Usage</b>
|
|
|
|
*
|
|
|
|
* Upon clicking the button below will redirect the user to doAction under the current controller.
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* new FormAction (
|
|
|
|
* // doAction has to be a defined controller member
|
|
|
|
* $action = "doAction",
|
|
|
|
* $title = "Submit button"
|
|
|
|
* )
|
|
|
|
* </code>
|
|
|
|
*
|
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
|
|
|
|
2011-12-21 17:35:42 +01:00
|
|
|
protected $template = 'FormAction';
|
|
|
|
|
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;
|
|
|
|
|
2009-07-02 00:27:18 +02:00
|
|
|
private $buttonContent = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add content inside a button field.
|
|
|
|
*/
|
|
|
|
function setButtonContent($content) {
|
|
|
|
$this->buttonContent = (string) $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2012-01-02 16:58:46 +01:00
|
|
|
function __construct($action, $title = "", $form = null) {
|
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
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-01-02 16:58:46 +01:00
|
|
|
static function create($action, $title = "") {
|
|
|
|
return new FormAction($action, $title);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function actionName() {
|
2011-03-23 05:12:25 +01:00
|
|
|
return substr($this->name, 7);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
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
|
|
|
|
2011-03-23 05:12:25 +01:00
|
|
|
function Field($properties = array()) {
|
|
|
|
$properties = array_merge(
|
|
|
|
$properties,
|
|
|
|
array(
|
|
|
|
'Name' => $this->action,
|
|
|
|
'Title' => ($this->description) ? $this->description : $this->Title(),
|
|
|
|
'UseButtonTag' => $this->useButtonTag
|
|
|
|
)
|
|
|
|
);
|
2011-12-21 17:35:42 +01:00
|
|
|
return $this->customise($properties)->renderWith($this->getTemplate());
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
|
|
|
public function Type() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return 'action';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAttributes() {
|
|
|
|
return array_merge(
|
|
|
|
parent::getAttributes(),
|
|
|
|
array(
|
|
|
|
'disabled' => ($this->isReadonly() || $this->isDisabled()),
|
|
|
|
'value' => $this->Title(),
|
|
|
|
'type' => ($this->useButtonTag) ? null : 'submit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function extraClass() {
|
|
|
|
return 'action ' . parent::extraClass();
|
2011-03-23 05:12:25 +01: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-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
$clone->setReadonly(true);
|
|
|
|
return $clone;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2011-03-23 05:12:25 +01:00
|
|
|
}
|