silverstripe-framework/forms/InlineFormAction.php
Sam Minnee 1f7fc1f76a FIX Remove instances of lines longer than 120c
The entire framework repo (with the exception of system-generated files) has been amended to respect the 120c line-length limit.  This is in preparation for the enforcement of this rule with PHP_CodeSniffer.
2012-09-30 17:18:13 +13:00

73 lines
2.0 KiB
PHP

<?php
/**
* Render a button that will submit the form its contained in through ajax.
* If you want to add custom behaviour, please set {@link inlcudeDefaultJS()} to FALSE and work with behaviour.js.
*
* @see framework/javascript/InlineFormAction.js
*
* @package forms
* @subpackage actions
*/
class InlineFormAction extends FormField {
protected $includeDefaultJS = true;
/**
* Create a new action button.
* @param action The method to call when the button is clicked
* @param title The label on the button
* @param extraClass A CSS class to apply to the button in addition to 'action'
*/
public function __construct($action, $title = "", $extraClass = '') {
$this->extraClass = ' '.$extraClass;
parent::__construct($action, $title, null, null);
}
public function performReadonlyTransformation() {
return new InlineFormAction_ReadOnly( $this->name, $this->title );
}
public function Field($properties = array()) {
if($this->includeDefaultJS) {
Requirements::javascriptTemplate(FRAMEWORK_DIR . '/javascript/InlineFormAction.js',
array('ID'=>$this->id()));
}
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\""
. " class=\"action{$this->extraClass}\" />";
}
public function Title() {
return false;
}
/**
* Optionally disable the default javascript include (framework/javascript/InlineFormAction.js),
* which routes to an "admin-custom"-URL.
*
* @param $bool boolean
*/
public function includeDefaultJS($bool) {
$this->includeDefaultJS = (bool)$bool;
}
}
/**
* Readonly version of {@link InlineFormAction}.
* @package forms
* @subpackage actions
*/
class InlineFormAction_ReadOnly extends FormField {
protected $readonly = true;
public function Field($properties = array()) {
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\""
. " disabled=\"disabled\" class=\"action disabled$this->extraClass\" />";
}
public function Title() {
return false;
}
}