2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 18:00:42 +01:00
|
|
|
* 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
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage actions
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class InlineFormAction extends FormField {
|
|
|
|
|
|
|
|
protected $includeDefaultJS = true;
|
2007-09-15 02:18:21 +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 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);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
function performReadonlyTransformation() {
|
|
|
|
return new InlineFormAction_ReadOnly( $this->name, $this->title );
|
|
|
|
}
|
|
|
|
|
|
|
|
function Field() {
|
|
|
|
if($this->includeDefaultJS) {
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascriptTemplate(SAPPHIRE_DIR . '/javascript/InlineFormAction.js',array('ID'=>$this->id()));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-15 02:18:21 +02:00
|
|
|
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\" class=\"action{$this->extraClass}\" />";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 01:34:18 +01:00
|
|
|
/**
|
|
|
|
* Readonly version of {@link InlineFormAction}.
|
|
|
|
* @package forms
|
|
|
|
* @subpackage actions
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class InlineFormAction_ReadOnly extends FormField {
|
2008-08-12 04:58:48 +02:00
|
|
|
|
|
|
|
protected $readonly = true;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function Field() {
|
2008-10-08 04:03:05 +02:00
|
|
|
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action$this->extraClass\" />";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Title() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|