mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
ENHANCEMENT Moved readonly capabilities to EditableFormFiel from EditableMultipleOptionField - this means you can now set readonly on any form field
BUGFIX Check for readonly when checking edit and delete permissions on FieldEditor BUGFIX Don't just show "None" when the page is in readonly mode and showing the Fields tab, instead show a readonly representation of the field editor
This commit is contained in:
parent
0b10a29345
commit
f6f1085029
@ -35,6 +35,8 @@ class EditableFormField extends DataObject {
|
||||
*/
|
||||
protected $editor;
|
||||
|
||||
protected $readonly;
|
||||
|
||||
/**
|
||||
* Construct a new EditableFormField Object.
|
||||
*
|
||||
@ -54,6 +56,22 @@ class EditableFormField extends DataObject {
|
||||
$this->editor = $editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this formfield to readonly
|
||||
*/
|
||||
public function setReadonly() {
|
||||
$this->readonly = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this multipleoption field readonly to the user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadonly() {
|
||||
return $this->readonly;
|
||||
}
|
||||
|
||||
function EditSegment() {
|
||||
return $this->renderWith('EditableFormField');
|
||||
}
|
||||
@ -156,6 +174,7 @@ class EditableFormField extends DataObject {
|
||||
public function showExtraOptions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Custom Validation fields for this
|
||||
* field for the CMS
|
||||
|
@ -22,8 +22,6 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
"Options" => "EditableOption"
|
||||
);
|
||||
|
||||
protected $readonly;
|
||||
|
||||
/**
|
||||
* Deletes all the options attached to this field before
|
||||
* deleting the field. Keeps stray options from floating
|
||||
@ -94,22 +92,6 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this multipleoptionfield to readonly
|
||||
*/
|
||||
protected function ReadonlyOption() {
|
||||
$this->readonly = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this multipleoption field readonly to the user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadonly() {
|
||||
return $this->readonly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the form field for this object in the front
|
||||
* end form view
|
||||
|
@ -13,14 +13,33 @@ class FieldEditor extends FormField {
|
||||
}
|
||||
|
||||
/**
|
||||
* Can a user edit this field
|
||||
*
|
||||
* @return bool
|
||||
* Can a user edit this field?
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit() {
|
||||
if($this->readonly) return false;
|
||||
return $this->form->getRecord()->canEdit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Can a user delete this field?
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete() {
|
||||
if($this->readonly) return false;
|
||||
return $this->form->getRecord()->canDelete();
|
||||
}
|
||||
|
||||
function performReadonlyTransformation() {
|
||||
$this->readonly = true;
|
||||
$fields = $this->Fields();
|
||||
if($fields) foreach($fields as $field) {
|
||||
$field->setReadonly();
|
||||
}
|
||||
|
||||
return $this->customise(array('Fields' => $fields));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Form Fields for the user forms
|
||||
*
|
||||
@ -33,19 +52,20 @@ class FieldEditor extends FormField {
|
||||
Requirements::javascript("userforms/javascript/UserForm.js");
|
||||
|
||||
$relationName = $this->name;
|
||||
|
||||
$fields = $this->form->getRecord()->$relationName();
|
||||
|
||||
foreach($fields as $field) {
|
||||
if(!$this->canEdit()) {
|
||||
if(is_a($field, 'FormField')) {
|
||||
$fields->remove($field);
|
||||
$fields->push($field->performReadonlyTransformation());
|
||||
if($fields) {
|
||||
foreach($fields as $field) {
|
||||
if(!$this->canEdit()) {
|
||||
if(is_a($field, 'FormField')) {
|
||||
$fields->remove($field);
|
||||
$fields->push($field->performReadonlyTransformation());
|
||||
}
|
||||
}
|
||||
$field->setEditor($this);
|
||||
}
|
||||
|
||||
$field->setEditor($this);
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,8 @@
|
||||
<% end_if %>
|
||||
|
||||
<% if canDelete %>
|
||||
<a class="delete" href="#" title="<% _t('DELETE', 'Delete') %>">
|
||||
<% _t('DELETE', 'Delete') %>
|
||||
</a>
|
||||
<% end_if %>
|
||||
<a class="delete" href="#" title="<% _t('DELETE', 'Delete') %>"><% _t('DELETE', 'Delete') %></a>
|
||||
<% end_if %>
|
||||
</div>
|
||||
|
||||
<% if showExtraOptions %>
|
||||
|
@ -5,11 +5,7 @@
|
||||
<div class="FieldListHold">
|
||||
<ul class="FieldList" id="Fields_fields">
|
||||
<% control Fields %>
|
||||
<% if isReadonly %>
|
||||
$ReadonlyEditSegment
|
||||
<% else %>
|
||||
$EditSegment
|
||||
<% end_if %>
|
||||
$EditSegment
|
||||
<% end_control %>
|
||||
</ul>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user