+sub action_ajax_delete {
+ my ($self) = @_;
+
+ my $js = SL::ClientJS->new;
+
+ $self->item->delete;
+
+ if ($self->visible_section && ($self->visible_section->id == $self->item->id)) {
+ # Currently visible section is deleted.
+
+ my $new_section = first { $_->id != $self->item->id } @{ $self->item->requirement_spec->sections };
+ if ($new_section) {
+ $self->render_list($js, $new_section);
+
+ } else {
+ my $html = $self->render('requirement_spec_item/_no_section', { output => 0 });
+ $js->html('#column-content', $html)
+ ->val('#current_content_type', '')
+ ->val('#current_content_id', '')
+ }
+
+ } elsif ($self->visible_section && ($self->visible_section->id == $self->item->get_section->id)) {
+ # Item in currently visible section is deleted.
+
+ my $type = $self->item->get_type;
+ $js->remove('#edit_function_block_' . $self->item->id . '_form')
+ ->remove('#' . $type . '-' . $self->item->id);
+
+ $self->replace_bottom($js, $self->item->parent_id) if $type eq 'sub-function-block';
+
+ if (1 == scalar @{ $self->item->get_full_list }) {
+ if ($type eq 'function-block') {
+ $js->show('#section-list-empty');
+ } elsif ($type eq 'sub-function-block') {
+ $js->hide('#sub-function-block-container-' . $self->item->parent_id);
+ }
+ }
+ }
+
+ $js->jstree->delete_node('#tree', '#fb-' . $self->item->id)
+ ->render($self);
+}
+