X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FRequirementSpec.pm;h=3acb6b963437ba5806b5fe007917ddbf05c96f2a;hb=5ca41cde212c8c699f835f292849786091c921af;hp=abcfbff1ee04d3feeb514b0ed20597a995c5c096;hpb=9dffe94b2b63322be723ad557ba1e1222185bf1c;p=kivitendo-erp.git diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index abcfbff1e..3acb6b963 100644 --- a/SL/Controller/RequirementSpec.pm +++ b/SL/Controller/RequirementSpec.pm @@ -26,7 +26,7 @@ use SL::Template::LaTeX; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(requirement_spec_item customers types statuses db_args flat_filter visible_item visible_section) ], - 'scalar --get_set_init' => [ qw(requirement_spec complexities risks projects copy_source js) ], + 'scalar --get_set_init' => [ qw(requirement_spec complexities risks projects copy_source js current_text_block_output_position) ], ); __PACKAGE__->run_before('setup'); @@ -83,29 +83,30 @@ sub action_new { $self->requirement_spec->$_($self->copy_source->$_) for qw(type_id status_id customer_id title hourly_rate) } - $self->render('requirement_spec/new', title => $self->requirement_spec->is_template ? t8('Create a new requirement spec section template') : t8('Create a new requirement spec')); + $self->render('requirement_spec/new', title => $self->requirement_spec->is_template ? t8('Create a new requirement spec template') : t8('Create a new requirement spec')); } -sub action_ajax_edit { +sub action_ajax_show_basic_settings { my ($self) = @_; - $self->render('requirement_spec/_form', { layout => 0 }, submit_as => 'ajax'); + $self->render('requirement_spec/_show_basic_settings', { layout => 0 }); } -sub action_ajax_show_time_and_cost_estimate { +sub action_ajax_edit { my ($self) = @_; - $self->render('requirement_spec/_show_time_and_cost_estimate', { layout => 0 }); + 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_cancel_time_and_cost_estimate { +sub action_ajax_show_time_and_cost_estimate { my ($self) = @_; - my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }); - - $self->js - ->replaceWith('#time_cost_estimate', $html) - ->render($self); + $self->render('requirement_spec/_show_time_and_cost_estimate', { layout => 0 }); } sub action_ajax_edit_time_and_cost_estimate { @@ -114,7 +115,9 @@ sub action_ajax_edit_time_and_cost_estimate { my $html = $self->render('requirement_spec/_edit_time_and_cost_estimate', { output => 0 }); $self->js - ->replaceWith('#time_cost_estimate', $html) + ->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') ->render($self); } @@ -134,8 +137,11 @@ sub action_ajax_save_time_and_cost_estimate { 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 }); - $self->js->replaceWith('#time_cost_estimate', $html); + $self->js->replaceWith('#time_cost_estimate', $html) + ->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); @@ -148,10 +154,11 @@ sub action_ajax_save_time_and_cost_estimate { sub action_show { my ($self) = @_; - my $item = $::form->{requirement_spec_item_id} ? SL::DB::RequirementSpecItem->new(id => $::form->{requirement_spec_item_id})->load : @{ $self->requirement_spec->sections }[0]; + 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 }[0]; $self->requirement_spec_item($item); - $self->render('requirement_spec/show', title => t8('Show requirement spec')); + $self->render('requirement_spec/show', title => $title); } sub action_create { @@ -210,6 +217,31 @@ sub action_create_pdf { unlink $result{file_name}; } +sub action_select_template_to_paste { + my ($self) = @_; + + my @templates = grep { @{ $_->sections } || @{ $_->text_blocks } } @{ SL::DB::Manager::RequirementSpec->get_all(where => [ is_template => 1 ], sort_by => 'lower(title)') }; + $self->render('requirement_spec/select_template_to_paste', { layout => 0 }, TEMPLATES => \@templates); +} + +sub action_paste_template { + my ($self, %params) = @_; + + my $template = SL::DB::RequirementSpec->new(id => $::form->{template_id})->load; + my %result = $self->requirement_spec->paste_template($template); + + return $self->js->error($self->requirement_spec->error)->render($self) if !%result; + + $self->render_pasted_text_block($_) for sort { $a->position <=> $b->position } @{ $result{text_blocks} }; + $self->render_pasted_section($_) for sort { $a->position <=> $b->position } @{ $result{sections} }; + + if (@{ $result{sections} } && (($::form->{current_content_type} || 'sections') eq 'sections') && !$::form->{current_content_id}) { + $self->render_first_pasted_section_as_list($result{sections}->[0]); + } + + $self->invalidate_version->render($self); +} + # # filters # @@ -255,6 +287,11 @@ sub init_js { $self->js(SL::ClientJS->new); } +sub init_current_text_block_output_position { + my ($self) = @_; + $self->current_text_block_output_position($::form->{current_content_type} !~ m/^(?:text-blocks|tb)-(front|back)/ ? -1 : $1 eq 'front' ? 0 : 1); +} + sub load_select_options { my ($self) = @_; @@ -277,9 +314,9 @@ sub create_or_update { $self->requirement_spec->assign_attributes(%{ $params }); - my $title = $is_new && $self->requirement_spec->is_template ? t8('Create a new requirement spec section template') + my $title = $is_new && $self->requirement_spec->is_template ? t8('Create a new requirement spec template') : $is_new ? t8('Create a new requirement spec') - : $self->requirement_spec->is_template ? t8('Edit section template') + : $self->requirement_spec->is_template ? t8('Edit requirement spec template') : t8('Edit requirement spec'); my @errors = $self->requirement_spec->validate; @@ -309,12 +346,15 @@ sub create_or_update { return $self->render('requirement_spec/new', title => $title); } - my $info = $self->requirement_spec->is_template ? t8('The section template has been saved.') : t8('The requirement spec has been saved.'); + my $info = $self->requirement_spec->is_template ? t8('The requirement spec template has been saved.') : t8('The requirement spec has been saved.'); if ($::request->is_ajax) { - my $html = $self->render('requirement_spec/_header', { output => 0 }); + my $header_html = $self->render('requirement_spec/_header', { output => 0 }); + my $basics_html = $self->render('requirement_spec/_show_basic_settings', { output => 0 }); return $self->invalidate_version - ->replaceWith('#requirement-spec-header', $html) + ->replaceWith('#requirement-spec-header', $header_html) + ->replaceWith('#basic_settings', $basics_html) + ->remove('#basic_settings_form') ->flash('info', $info) ->render($self); } @@ -381,7 +421,7 @@ sub prepare_report { output_format => 'HTML', raw_top_info_text => $self->render('requirement_spec/report_top', { output => 0 }, is_template => $is_template), raw_bottom_info_text => $self->render('requirement_spec/report_bottom', { output => 0 }), - title => $is_template ? t8('Requirement Spec Section Templates') : t8('Requirement Specs'), + title => $is_template ? t8('Requirement Spec Templates') : t8('Requirement Specs'), allow_pdf_export => 1, allow_csv_export => 1, ); @@ -406,4 +446,43 @@ sub invalidate_version { return $self->js->html('#requirement_spec_version', $html); } +sub render_pasted_text_block { + my ($self, $text_block, %params) = @_; + + if ($self->current_text_block_output_position == $text_block->output_position) { + my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $text_block); + $self->js + ->appendTo($html, '#text-block-list') + ->hide('#text-block-list-empty'); + } + + my $node = $self->presenter->requirement_spec_text_block_jstree_data($text_block); + my $front_back = $text_block->output_position == 0 ? 'front' : 'back'; + $self->js + ->jstree->create_node('#tree', "#tb-${front_back}", 'last', $node) + ->jstree->open_node( '#tree', "#tb-${front_back}"); +} + +sub render_pasted_section { + my ($self, $item, $parent_id) = @_; + + my $node = $self->presenter->requirement_spec_item_jstree_data($item); + $self->js + ->jstree->create_node('#tree', $parent_id ? "#fb-${parent_id}" : '#sections', 'last', $node) + ->jstree->open_node( '#tree', $parent_id ? "#fb-${parent_id}" : '#sections'); + + $self->render_pasted_section($_, $item->id) for @{ $item->children_sorted }; +} + +sub render_first_pasted_section_as_list { + my ($self, $section, %params) = @_; + + my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $section); + $self->js + ->html('#column-content', $html) + ->val( '#current_content_type', $section->item_type) + ->val( '#current_content_id', $section->id) + ->jstree->select_node('#tree', '#fb-' . $section->id); +} + 1;