+
+ my $html = $self->render('requirement_spec/_form', { output => 0 }, submit_as => 'ajax');
+
+ $self->js
+ ->hide('#basic_settings')
+ ->after('#basic_settings', $html)
+ ->render($self);
+}
+
+sub action_ajax_edit_project_link {
+ my ($self) = @_;
+
+ my $html = $self->render('requirement_spec/_project_link_form', { output => 0 }, submit_as => 'ajax');
+
+ $self->js
+ ->hide('#basic_settings')
+ ->after('#basic_settings', $html)
+ ->render($self);
+}
+
+sub action_ajax_show_time_and_cost_estimate {
+ my ($self) = @_;
+
+ $self->render('requirement_spec/_show_time_and_cost_estimate', { layout => 0 });
+}
+
+sub action_ajax_edit_time_and_cost_estimate {
+ my ($self) = @_;
+
+ my $html = $self->render('requirement_spec/_edit_time_and_cost_estimate', { output => 0 });
+ my $first = ($self->requirement_spec->sections_sorted || [])->[0];
+ $first = ($first->children_sorted || [])->[0] if $first;
+
+ $self->js
+ ->hide('#time_cost_estimate')
+ ->after('#time_cost_estimate', $html)
+ ->on('#time_cost_estimate INPUT[type=text]', 'keydown', 'kivi.requirement_spec.time_cost_estimate_input_key_down')
+ ->action_if($first && $first->id, 'focus', '#time_and_cost_estimate_form_complexity_id_' . $first->id)
+ ->render($self);
+}
+
+sub action_ajax_save_time_and_cost_estimate {
+ my ($self) = @_;
+
+ $self->requirement_spec->db->do_transaction(sub {
+ # Make Emacs happy
+ 1;
+ foreach my $attributes (@{ $::form->{requirement_spec_items} || [] }) {
+ SL::DB::RequirementSpecItem
+ ->new(id => delete $attributes->{id})
+ ->load
+ ->update_attributes(%{ $attributes });
+ }
+
+ 1;
+ });
+
+ $self->requirement_spec(SL::DB::RequirementSpec->new(id => $self->requirement_spec->id)->load);
+
+ my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }, initially_hidden => !!$::form->{keep_open});
+ $self->js->replaceWith('#time_cost_estimate', $html);
+
+ return $self->js->render($self) if $::form->{keep_open};
+
+ $self->js->remove('#time_cost_estimate_form_container');
+
+ if ($self->visible_section) {
+ $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->visible_section);
+ $self->js->html('#column-content', $html);
+ }
+
+ $self->js->render($self);
+}
+
+sub action_show {
+ my ($self) = @_;
+
+ my $title = $self->requirement_spec->is_template ? t8('Show requirement spec template') : t8('Show requirement spec');
+ my $item = $::form->{requirement_spec_item_id} ? SL::DB::RequirementSpecItem->new(id => $::form->{requirement_spec_item_id})->load : @{ $self->requirement_spec->sections_sorted }[0];
+ $self->requirement_spec_item($item);
+
+ $self->render('requirement_spec/show', title => $title);