+ my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]);
+ my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
+
+ $self->js
+ ->html('#column-content', $html)
+ ->val('#current_content_type', 'text-blocks-' . (0 == $new_where ? 'front' : 'back'))
+ ->val('#current_content_id', $::form->{clicked_id});
+ }
+
+ $self->render($self->js);
+}
+
+sub action_ajax_add {
+ my ($self) = @_;
+
+ my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
+ my $new_where = $self->output_position_from_id($::form->{id}) // $::form->{output_position};
+
+ if ($new_where != $current_where) {
+ my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]);
+ my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
+
+ $self->js->html('#column-content', $html);
+ }
+
+ $self->text_block(SL::DB::RequirementSpecTextBlock->new(
+ requirement_spec_id => $::form->{requirement_spec_id},
+ output_position => $::form->{output_position},
+ ));
+
+ my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
+ my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $::form->{id});
+
+ $self->invalidate_version
+ ->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'))
+ ->focus('#' . $id_base . '_title')
+ ->render($self);
+}
+
+sub action_ajax_edit {
+ my ($self) = @_;
+
+ 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);
+
+ $self->js
+ ->html('#column-content', $html)
+ ->val('#current_content_type', 'text-block')
+ ->val('#current_content_id', $self->text_block->id);
+ }
+
+ my $html = $self->render('requirement_spec_text_block/_form', { output => 0 });
+
+ $self->js
+ ->hide('#text-block-' . $self->text_block->id)
+ ->remove('#edit_text_block_' . $self->text_block->id . '_form')
+ ->insertAfter($html, '#text-block-' . $self->text_block->id)
+ ->jstree->select_node('#tree', '#tb-' . $self->text_block->id)
+ ->focus('#edit_text_block_' . $self->text_block->id . '_title')
+ ->render($self);
+}
+
+sub action_ajax_create {
+ my ($self, %params) = @_;
+
+ my $attributes = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
+ my $insert_after = delete $attributes->{insert_after};
+
+ my @errors = $self->text_block(SL::DB::RequirementSpecTextBlock->new(%{ $attributes }))->validate;
+ return SL::ClientJS->new->error(@errors)->render($self) if @errors;