mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
76b5adc979
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75579 467b73ca-7a2a-4603-9d3b-597d59a354a9
70 lines
1.9 KiB
PHP
Executable File
70 lines
1.9 KiB
PHP
Executable File
<?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 sapphire/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'
|
|
*/
|
|
function __construct($action, $title = "", $extraClass = '') {
|
|
$this->extraClass = ' '.$extraClass;
|
|
parent::__construct($action, $title, null, null);
|
|
}
|
|
|
|
function performReadonlyTransformation() {
|
|
return new InlineFormAction_ReadOnly( $this->name, $this->title );
|
|
}
|
|
|
|
function Field() {
|
|
if($this->includeDefaultJS) {
|
|
Requirements::javascriptTemplate(SAPPHIRE_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}\" />";
|
|
}
|
|
|
|
function Title() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Optionally disable the default javascript include (sapphire/javascript/InlineFormAction.js),
|
|
* which routes to an "admin-custom"-URL.
|
|
*
|
|
* @param $bool boolean
|
|
*/
|
|
function includeDefaultJS($bool) {
|
|
$this->includeDefaultJS = (bool)$bool;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Readonly version of {@link InlineFormAction}.
|
|
* @package forms
|
|
* @subpackage actions
|
|
*/
|
|
class InlineFormAction_ReadOnly extends FormField {
|
|
|
|
protected $readonly = true;
|
|
|
|
function Field() {
|
|
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action disabled$this->extraClass\" />";
|
|
}
|
|
|
|
function Title() {
|
|
return false;
|
|
}
|
|
}
|
|
?>
|