2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Allows an editor to insert a generic heading into a field
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
2012-04-14 18:36:50 +12:00
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2009-12-07 02:04:20 +00:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
class EditableFormHeading extends EditableFormField {
|
2009-04-27 04:01:06 +00:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $singular_name = 'Heading';
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $plural_name = 'Headings';
|
2015-07-24 14:37:48 +12:00
|
|
|
|
2015-08-13 11:31:37 +12:00
|
|
|
private static $literal = true;
|
|
|
|
|
2015-07-24 14:37:48 +12:00
|
|
|
private static $db = array(
|
|
|
|
'Level' => 'Int(3)', // From CustomSettings
|
|
|
|
'HideFromReports' => 'Boolean(0)' // from CustomSettings
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $defaults = array(
|
|
|
|
'Level' => 3,
|
|
|
|
'HideFromReports' => false
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
2015-08-21 15:21:33 +12:00
|
|
|
$fields->removeByName(array('Default', 'Validation', 'RightTitle'));
|
2015-07-24 14:37:48 +12:00
|
|
|
|
2012-04-14 18:36:50 +12:00
|
|
|
$levels = array(
|
|
|
|
'1' => '1',
|
|
|
|
'2' => '2',
|
|
|
|
'3' => '3',
|
|
|
|
'4' => '4',
|
|
|
|
'5' => '5',
|
|
|
|
'6' => '6'
|
|
|
|
);
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2015-07-24 14:37:48 +12:00
|
|
|
$fields->addFieldsToTab('Root.Main', array(
|
|
|
|
DropdownField::create(
|
|
|
|
'Level',
|
|
|
|
_t('EditableFormHeading.LEVEL', 'Select Heading Level'),
|
|
|
|
$levels
|
|
|
|
),
|
|
|
|
CheckboxField::create(
|
|
|
|
'HideFromReports',
|
|
|
|
_t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
|
2012-09-10 16:07:52 +12:00
|
|
|
)
|
2015-07-24 14:37:48 +12:00
|
|
|
));
|
|
|
|
|
|
|
|
return $fields;
|
2009-04-21 03:44:13 +00:00
|
|
|
}
|
2012-09-10 16:07:52 +12:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getFormField() {
|
2016-09-20 19:26:47 -05:00
|
|
|
$labelField = HeaderField::create($this->EscapedTitle)
|
|
|
|
->setHeadingLevel($this->Level);
|
2008-11-01 15:32:36 +00:00
|
|
|
$labelField->addExtraClass('FormHeading');
|
2015-08-13 11:31:37 +12:00
|
|
|
$labelField->setAttribute('data-id', $this->Name);
|
2015-08-10 17:03:36 +12:00
|
|
|
$this->doUpdateFormField($labelField);
|
2008-11-01 15:32:36 +00:00
|
|
|
return $labelField;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
2015-08-10 17:03:36 +12:00
|
|
|
|
|
|
|
protected function updateFormField($field) {
|
|
|
|
// set the right title on this field
|
|
|
|
if($this->RightTitle) {
|
|
|
|
// Since this field expects raw html, safely escape the user data prior
|
|
|
|
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
|
|
|
}
|
|
|
|
// if this field has an extra class
|
2015-08-14 14:51:42 +12:00
|
|
|
if($this->ExtraClass) {
|
|
|
|
$field->addExtraClass($this->ExtraClass);
|
2015-08-10 17:03:36 +12:00
|
|
|
}
|
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function showInReports() {
|
2015-07-24 14:37:48 +12:00
|
|
|
return !$this->HideFromReports;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getFieldValidationOptions() {
|
2009-05-06 03:34:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-13 11:31:37 +12:00
|
|
|
|
|
|
|
public function getSelectorHolder() {
|
|
|
|
return "$(\":header[data-id='{$this->Name}']\")";
|
|
|
|
}
|
2015-08-18 17:30:15 +12:00
|
|
|
|
|
|
|
public function getLevel() {
|
2015-09-11 00:08:13 +12:00
|
|
|
return $this->getField('Level') ?: 3;
|
|
|
|
}
|
2012-09-10 16:07:52 +12:00
|
|
|
}
|