Skip to content
Snippets Groups Projects
Commit afc19371 authored by Peter Rotich's avatar Peter Rotich Committed by Peter Rotich
Browse files

forms: Add ability to delete properties form

This adds ability to delete properties on list deletion
parent 60300f09
No related branches found
No related tags found
No related merge requests found
...@@ -189,9 +189,11 @@ class DynamicForm extends VerySimpleModel { ...@@ -189,9 +189,11 @@ class DynamicForm extends VerySimpleModel {
} }
function delete() { function delete() {
if (!$this->isDeletable()) if (!$this->isDeletable())
return false; return false;
// Soft Delete: Mark the form as deleted.
$this->setFlag(self::FLAG_DELETED); $this->setFlag(self::FLAG_DELETED);
return $this->save(); return $this->save();
} }
......
...@@ -355,11 +355,20 @@ class DynamicList extends VerySimpleModel implements CustomList { ...@@ -355,11 +355,20 @@ class DynamicList extends VerySimpleModel implements CustomList {
function delete() { function delete() {
$fields = DynamicFormField::objects()->filter(array( $fields = DynamicFormField::objects()->filter(array(
'type'=>'list-'.$this->id))->count(); 'type'=>'list-'.$this->id))->count();
if ($fields == 0)
return parent::delete(); // Refuse to delete lists that are in use by fields
else if ($fields != 0)
// Refuse to delete lists that are in use by fields return false;
if (!parent::delete())
return false; return false;
if (($form = $this->getForm(false))) {
$form->delete(false);
$form->fields->delete();
}
return true;
} }
private function createForm() { private function createForm() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment