+sub action_ajax_edit {
+ my ($self) = @_;
+
+ my $js = SL::ClientJS->new;
+
+ my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
+ if ($self->text_block->output_position != $current_where) {
+ my $text_blocks = $self->text_block->get_full_list;
+ my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $self->text_block->output_position);
+
+ $js->html('#column-content', $html)
+ ->val('#current_content_type', 'text-block')
+ ->val('#current_content_id', $self->text_block->id);
+ }
+
+ my $predefined_texts = SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted;
+ my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, PREDEFINED_TEXTS => $predefined_texts);
+
+ $js->hide('#text-block-' . $self->text_block->id)
+ ->insertAfter($html, '#text-block-' . $self->text_block->id)
+ ->jstree->select_node('#tree', '#tb-' . $self->text_block->id)
+ ->render($self);
+}
+
+sub action_update {
+ my ($self, %params) = @_;
+
+ my $prefix = $::form->{form_prefix} || 'text_block';
+ my $attributes = $::form->{$prefix} || {};
+
+ foreach (qw(requirement_spec_id output_position)) {
+ delete $attributes->{$_} if !defined $attributes->{$_};
+ }
+
+ $self->text_block->update_attributes(%{ $attributes });
+
+ my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
+
+ SL::ClientJS->new
+ ->remove('#' . $prefix . '_form')
+ ->replaceWith('#text-block-' . $self->text_block->id, $html)
+ ->jstree->rename_node('#tree', '#tb-' . $self->text_block->id, $self->text_block->title)
+ ->render($self);
+}
+
+