Improved FieldEditor to dynamically get the class for EditableOptions

This commit is contained in:
James Ayers 2014-08-06 15:13:52 +12:00
parent 42932ea47f
commit 0f90ce9596
2 changed files with 6 additions and 3 deletions

View File

@ -268,6 +268,9 @@ class FieldEditor extends FormField {
if($parent) {
$sql_parent = (int)$parent;
$parentObj = EditableFormField::get()->byID($parent);
$optionClass = ($parentObj && $parentObj->exists()) ? $parentObj->getRelationClass('Options') : 'EditableOption';
$sqlQuery = new SQLQuery();
$sqlQuery = $sqlQuery
->setSelect("MAX(\"Sort\")")
@ -277,7 +280,7 @@ class FieldEditor extends FormField {
$sort = $sqlQuery->execute()->value() + 1;
if($parent) {
$object = new EditableOption();
$object = Injector::inst()->create($optionClass);
$object->write();
$object->ParentID = $parent;
$object->Sort = $sort;

View File

@ -270,8 +270,8 @@
e.preventDefault();
// pass the deleted status onto the element
$(this).parent("li").children("[type=text]").attr("value", "field-node-deleted");
$(this).parent("li").hide();
$(this).parents("li:first").find("[type=text]:first").attr("value", "field-node-deleted");
$(this).parents("li:first").hide();
// Give the user some feedback
statusMessage(userforms.message('REMOVED_OPTION'));