mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FEATURE: allow subclassing of editable form field to update the UDF form editor
This commit is contained in:
parent
53390d6a5d
commit
b1a0026d05
@ -290,6 +290,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
// set the name of the form
|
// set the name of the form
|
||||||
$form = new Form( $this, "Form", $fields, $actions, new RequiredFields( $required ) );
|
$form = new Form( $this, "Form", $fields, $actions, new RequiredFields( $required ) );
|
||||||
$form->loadDataFrom($this->failover);
|
$form->loadDataFrom($this->failover);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,10 @@ class EditableCheckbox extends EditableFormField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getFilterField() {
|
function getFilterField() {
|
||||||
return new OptionsetField( $this->Name,
|
return new OptionsetField( $this->Name, $this->Title,
|
||||||
$this->Title,
|
array( '-1' => '('._t('EditableCheckbox.ANY', 'Any').')',
|
||||||
array( '-1' => '('._t('EditableCheckbox.ANY', 'Any').')',
|
'on' => _t('EditableCheckbox.SELECTED', 'Selected'),
|
||||||
'on' => _t('EditableCheckbox.SELECTED', 'Selected'),
|
'0' => _t('EditableCheckbox.NOTSELECTED', 'Not selected') )
|
||||||
'0' => _t('EditableCheckbox.NOTSELECTED', 'Not selected') )
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ class EditableFormField extends DataObject {
|
|||||||
|
|
||||||
// exit();
|
// exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function Type() {
|
function Type() {
|
||||||
return $this->class;
|
return $this->class;
|
||||||
}
|
}
|
||||||
@ -206,10 +206,5 @@ class EditableFormField extends DataObject {
|
|||||||
function CustomParameter() {
|
function CustomParameter() {
|
||||||
return $this->CustomParameter;
|
return $this->CustomParameter;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
function saveInto( DataObject $record ) {
|
|
||||||
if(
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -48,6 +48,36 @@ class FieldEditor extends FormField {
|
|||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a DataObjectSet of all the addable fields to populate
|
||||||
|
* the add field menu
|
||||||
|
*
|
||||||
|
* @return DataObjectSet
|
||||||
|
*/
|
||||||
|
function CreatableFields() {
|
||||||
|
$fields = ClassInfo::subclassesFor('EditableFormField');
|
||||||
|
|
||||||
|
if($fields) {
|
||||||
|
array_shift($fields); // get rid of subclass 0
|
||||||
|
$output = new DataObjectSet();
|
||||||
|
foreach($fields as $field => $title) {
|
||||||
|
// get the nice title and strip out field
|
||||||
|
$niceTitle = trim(str_ireplace("Field", "", eval("return $title::\$singular_name;")));
|
||||||
|
|
||||||
|
// keep old javascript happy
|
||||||
|
$title = trim(str_ireplace("Editable", "", $title));
|
||||||
|
|
||||||
|
$output->push(new ArrayData(array(
|
||||||
|
'ClassName' => $title,
|
||||||
|
'Title' => "$niceTitle"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function saveInto(DataObject $record) {
|
function saveInto(DataObject $record) {
|
||||||
|
|
||||||
$name = $this->name;
|
$name = $this->name;
|
||||||
@ -113,12 +143,6 @@ class FieldEditor extends FormField {
|
|||||||
$record->processNewFormFields();
|
$record->processNewFormFields();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*function addNewField( $newField ) {
|
|
||||||
$newField->ParentID = $this->ID;
|
|
||||||
$newField->write();
|
|
||||||
return $this->renderWith("FieldEditor");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
function addfield() {
|
function addfield() {
|
||||||
// get the last field in this form editor
|
// get the last field in this form editor
|
||||||
|
@ -1,36 +1,10 @@
|
|||||||
<div class="FieldEditor <% if isReadonly %>readonly<% end_if %>" id="Fields" name="$Name.Attr">
|
<div class="FieldEditor <% if isReadonly %>readonly<% end_if %>" id="Fields" name="$Name.Attr">
|
||||||
<ul class="TopMenu Menu">
|
<ul class="TopMenu Menu">
|
||||||
<li><% _t('ADD', 'Add') %>:</li>
|
<li><% _t('ADD', 'Add') %>:</li>
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('TEXTTITLE', 'Add text field') %>" id="TextField"><% _t('TEXT', 'Text') %></a>
|
<% control CreatableFields %>
|
||||||
</li>
|
<li><a href="#" title="<% _t('ADD', 'Add') %> $Title" id="$ClassName">$Title</a></li>
|
||||||
<li>
|
<% end_control %>
|
||||||
<a href="#" title="<% _t('CHECKBOXTITLE', 'Add checkbox') %>" id="Checkbox"><% _t('CHECKBOX', 'Checkbox') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('DROPDOWNTITLE', 'Add dropdown') %>" id="Dropdown"><% _t('DROPDOWN', 'Dropdown') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('RADIOSETTITLE', 'Add radio button set') %>" id="RadioField"><% _t('RADIOSET', 'Radio') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('EMAILTITLE', 'Add email field') %>" id="EmailField"><% _t('EMAIL', 'Email') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('FORMHEADINGTITLE', 'Add form heading') %>" id="FormHeading"><% _t('FORMHEADING', 'Heading') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('DATETITLE', 'Add date heading') %>" id="DateField"><% _t('DATE', 'Date') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('FILETITLE', 'Add file upload field') %>" id="FileField"><% _t('FILE', 'File') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('CHECKBOXGROUPTITLE', 'Add checkbox group field') %>" id="CheckboxGroupField"><% _t('CHECKBOXGROUP', 'Checkboxes') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('MEMBERTITLE', 'Add member list field') %>" id="MemberListField"><% _t('MEMBER', 'Member List') %></a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<div class="FieldList" id="Fields_fields">
|
<div class="FieldList" id="Fields_fields">
|
||||||
<% control Fields %>
|
<% control Fields %>
|
||||||
@ -43,39 +17,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<ul class="BottomMenu Menu">
|
<ul class="BottomMenu Menu">
|
||||||
<li><% _t('ADD', 'Add') %>:</li>
|
<li><% _t('ADD', 'Add') %>:</li>
|
||||||
<li>
|
<% control CreatableFields %>
|
||||||
<a href="#" title="<% _t('TEXTTITLE', 'Add text field') %>" id="TextField"><% _t('TEXT', 'Text') %></a>
|
<li><a href="#" title="<% _t('ADD', 'Add') %> $Title" id="$ClassName">$Title</a></li>
|
||||||
</li>
|
<% end_control %>
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('CHECKBOXTITLE', 'Add checkbox') %>" id="Checkbox"><% _t('CHECKBOX', 'Checkbox') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('DROPDOWNTITLE', 'Add dropdown') %>" id="Dropdown"><% _t('DROPDOWN', 'Dropdown') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('RADIOSETTITLE', 'Add radio button set') %>" id="RadioField"><% _t('RADIOSET', 'Radio') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('EMAILTITLE', 'Add email field') %>" id="EmailField"><% _t('EMAIL', 'Email') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('FORMHEADINGTITLE', 'Add form heading') %>" id="FormHeading"><% _t('FORMHEADING', 'Heading') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('DATETITLE', 'Add date heading') %>" id="DateField"><% _t('DATE', 'Date') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('FILETITLE', 'Add file upload field') %>" id="FileField"><% _t('FILE', 'File') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('CHECKBOXGROUPTITLE', 'Add checkbox group field') %>" id="CheckboxGroupField"><% _t('CHECKBOXGROUP', 'Checkboxes') %></a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="#" title="<% _t('MEMBERTITLE', 'Add member list field') %>" id="MemberListField"><% _t('MEMBER', 'Member List') %></a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<div class="FormOptions">
|
<div class="FormOptions">
|
||||||
<% control FormOptions %>
|
<% control FormOptions %>
|
||||||
$FieldHolder
|
$FieldHolder
|
||||||
<% end_control %>
|
<% end_control %>
|
||||||
</div></div>
|
</div>
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user