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.
|
2015-02-16 21:19:53 +01:00
|
|
|
* If you want to add custom behaviour, please set {@link includeDefaultJS()} to FALSE
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-03-24 04:38:57 +01:00
|
|
|
* @see framework/javascript/InlineFormAction.js
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage actions
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class InlineFormAction extends FormField {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
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'
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($action, $title = "", $extraClass = '') {
|
2007-09-15 02:18:21 +02:00
|
|
|
$this->extraClass = ' '.$extraClass;
|
|
|
|
parent::__construct($action, $title, null, null);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performReadonlyTransformation() {
|
2012-12-13 13:51:28 +01:00
|
|
|
return $this->castedCopy('InlineFormAction_ReadOnly');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-06-20 12:11:08 +02:00
|
|
|
/**
|
|
|
|
* @param array $properties
|
|
|
|
* @return HTMLText
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Field($properties = array()) {
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->includeDefaultJS) {
|
2012-09-26 23:34:00 +02:00
|
|
|
Requirements::javascriptTemplate(FRAMEWORK_DIR . '/javascript/InlineFormAction.js',
|
|
|
|
array('ID'=>$this->id()));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-06-20 12:11:08 +02:00
|
|
|
return DBField::create_field(
|
|
|
|
'HTMLText',
|
|
|
|
FormField::create('input', array(
|
|
|
|
'name' => sprintf('action_%s', $this->getName()),
|
|
|
|
'value' => $this->title,
|
|
|
|
'id' => $this->ID(),
|
|
|
|
'class' => sprintf('action%s', $this->extraClass),
|
|
|
|
))
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Title() {
|
2014-08-15 08:53:05 +02:00
|
|
|
return false;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2012-03-24 04:38:57 +01:00
|
|
|
* Optionally disable the default javascript include (framework/javascript/InlineFormAction.js),
|
2007-07-19 12:40:28 +02:00
|
|
|
* which routes to an "admin-custom"-URL.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param $bool boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function includeDefaultJS($bool) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$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 {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-08-12 04:58:48 +02:00
|
|
|
protected $readonly = true;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-06-20 12:11:08 +02:00
|
|
|
/**
|
|
|
|
* @param array $properties
|
|
|
|
* @return HTMLText
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Field($properties = array()) {
|
2015-06-20 12:11:08 +02:00
|
|
|
return DBField::create_field('HTMLText',
|
|
|
|
FormField::create_tag('input', array(
|
|
|
|
'type' => 'submit',
|
|
|
|
'name' => sprintf('action_%s', $this->name),
|
|
|
|
'value' => $this->title,
|
|
|
|
'id' => $this->id(),
|
|
|
|
'disabled' => 'disabled',
|
|
|
|
'class' => 'action disabled ' . $this->extraClass,
|
|
|
|
))
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Title() {
|
2014-08-15 08:53:05 +02:00
|
|
|
return false;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|