2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Allows an editor to insert a generic heading into a field
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
2012-04-14 08:36:50 +02:00
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-12-07 03:04:20 +01:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableFormHeading extends EditableFormField
|
|
|
|
{
|
|
|
|
|
|
|
|
private static $singular_name = 'Heading';
|
|
|
|
|
|
|
|
private static $plural_name = 'Headings';
|
|
|
|
|
|
|
|
private static $literal = true;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
$fields->removeByName(array('Default', 'Validation', 'RightTitle'));
|
|
|
|
|
|
|
|
$levels = array(
|
|
|
|
'1' => '1',
|
|
|
|
'2' => '2',
|
|
|
|
'3' => '3',
|
|
|
|
'4' => '4',
|
|
|
|
'5' => '5',
|
|
|
|
'6' => '6'
|
|
|
|
);
|
|
|
|
|
|
|
|
$fields->addFieldsToTab('Root.Main', array(
|
|
|
|
DropdownField::create(
|
|
|
|
'Level',
|
|
|
|
_t('EditableFormHeading.LEVEL', 'Select Heading Level'),
|
|
|
|
$levels
|
|
|
|
),
|
|
|
|
CheckboxField::create(
|
|
|
|
'HideFromReports',
|
|
|
|
_t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFormField()
|
|
|
|
{
|
2016-09-23 18:27:15 +02:00
|
|
|
$labelField = HeaderField::create($this->EscapedTitle)
|
2016-09-21 02:26:47 +02:00
|
|
|
->setHeadingLevel($this->Level);
|
2016-07-21 07:53:59 +02:00
|
|
|
$labelField->addExtraClass('FormHeading');
|
|
|
|
$labelField->setAttribute('data-id', $this->Name);
|
|
|
|
$this->doUpdateFormField($labelField);
|
|
|
|
return $labelField;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
if ($this->ExtraClass) {
|
|
|
|
$field->addExtraClass($this->ExtraClass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showInReports()
|
|
|
|
{
|
|
|
|
return !$this->HideFromReports;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldValidationOptions()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSelectorHolder()
|
|
|
|
{
|
|
|
|
return "$(\":header[data-id='{$this->Name}']\")";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLevel()
|
|
|
|
{
|
|
|
|
return $this->getField('Level') ?: 3;
|
|
|
|
}
|
2012-09-10 06:07:52 +02:00
|
|
|
}
|