X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FRequirementSpecItem.pm;h=1c714ffe48ae75af20990c0998a6b85d09da71c0;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=33ff06710809fcfea301c52656132b56e7cab25c;hpb=e967690da6cc483427d0e930eec1442ed589443e;p=kivitendo-erp.git diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index 33ff06710..1c714ffe4 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -14,15 +14,17 @@ use SL::Controller::Helper::RequirementSpec; use SL::DB::RequirementSpec; use SL::DB::RequirementSpecComplexity; use SL::DB::RequirementSpecItem; +use SL::DB::RequirementSpecPredefinedText; use SL::DB::RequirementSpecRisk; use SL::Helper::Flash; use SL::JSON; use SL::Locale::String; +use SL::Presenter::Text qw(truncate); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(item visible_item visible_section clicked_item sections) ], - 'scalar --get_set_init' => [ qw(complexities risks js) ], + 'scalar --get_set_init' => [ qw(complexities risks predefined_texts) ], ); __PACKAGE__->run_before('check_auth'); @@ -84,28 +86,33 @@ sub action_dragged_and_dropped { my $old_visible_section = $self->visible_section ? $self->visible_section : undef; my $old_parent_id = $self->item->parent_id; my $old_type = $self->item->item_type; + my $new_type = !$dropped_item ? 'section' : $position =~ m/before|after/ ? $dropped_item->item_type : $dropped_item->child_type; - $self->item->db->do_transaction(sub { + $self->item->db->with_transaction(sub { $self->item->remove_from_list; - $self->item->parent_id($position =~ m/before|after/ ? $dropped_item->parent_id : $dropped_item->id); + $self->item->parent_id($position =~ m/before|after/ ? $dropped_item->parent_id : $dropped_item->id) if $dropped_item; + $self->item->item_type($new_type); $self->item->add_to_list(position => $position, reference => $::form->{dropped_id} || undef); }); + return $self->invalidate_version->render if !$old_visible_section || ($new_type eq 'section'); + + # From here on $old_visible_section is definitely set. + $self->item(SL::DB::RequirementSpecItem->new(id => $self->item->id)->load); my $new_section = $self->item->section; - my $new_type = $self->item->item_type; my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->section; - return $self->invalidate_version->render($self) if !$old_visible_section || ($new_type eq 'section'); - - # From here on $old_visible_section is definitely set. - my $old_parent = SL::DB::RequirementSpecItem->new(id => $old_parent_id)->load; my $old_section = $old_parent->section; + # Section debug info: # $::lxdebug->message(0, "old sec ID " . $old_section->id . " new " . $new_section->id . " old visible " . $old_visible_section->id . " new visible " . $new_visible_section->id # . " PARENT: old " . $old_parent->id . " new " . $self->item->parent_id . '/' . $self->item->parent->id); + # Item debug info: + # $::lxdebug->message(0, 'item id: ' . $self->item->id . " new type: $new_type old type: $old_type #old children: " . scalar(@{ $old_parent->children })); + if ($old_visible_section->id != $new_visible_section->id) { # The currently visible item has been dragged to a different section. $self->invalidate_version; @@ -150,6 +157,7 @@ sub action_ajax_add_section { ->hide('#column-content > *') ->appendTo($html, '#column-content') ->focus('#new_section_title') + ->reinit_widgets ->render($self); } @@ -185,27 +193,31 @@ sub action_ajax_create { my $type = $self->item->item_type; if ($type eq 'section') { - my $node = $self->presenter->requirement_spec_item_jstree_data($self->item); + my $node = $self->item->presenter->jstree_data; $self->invalidate_version; - return $self->render_list($self->item) + $self->render_list($self->item) + ->hide('#section-list-empty') ->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#sections', 'last'), $node) - ->jstree->select_node('#tree', '#fb-' . $self->item->id) + ->jstree->select_node('#tree', '#fb-' . $self->item->id); + return $self->add_new_item_form_after_create + ->reinit_widgets ->render($self); } my $template = 'requirement_spec_item/_' . (apply { s/-/_/g; $_ } $type); my $html = $self->render($template, { output => 0 }, requirement_spec_item => $self->item, id_prefix => $type eq 'function-block' ? '' : 'sub-'); - my $node = $self->presenter->requirement_spec_item_jstree_data($self->item); + my $node = $self->item->presenter->jstree_data; $self->js ->replaceWith('#' . $prefix . '_form', $html) ->hide('#section-list-empty') ->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#fb-' . $self->item->parent_id, 'last'), $node) + ->reinit_widgets ->jstree->select_node('#tree', '#fb-' . $self->item->id); $self->replace_bottom($self->item->parent) if $type eq 'sub-function-block'; - $self->add_new_item_form_after_create if $type =~ m/function-block/; + $self->add_new_item_form_after_create; $self->invalidate_version->render($self); } @@ -219,7 +231,8 @@ sub action_ajax_edit { # Show section/item to edit if it is not visible. my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item->section); - $self->js->html('#column-content', $html); + $self->set_function_blocks_tab_menu_class(class => 'section-context-menu') + ->html('#column-content', $html); } if ($self->item->item_type =~ m/section/) { @@ -231,9 +244,10 @@ sub action_ajax_edit { ->remove("#edit_section_form") ->insertAfter($html, '#section-header-' . $self->item->id) ->jstree->select_node('#tree', '#fb-' . $self->item->id) - ->focus("#edit_section_title") ->val('#current_content_type', 'section') ->val('#current_content_id', $self->item->id) + ->reinit_widgets + ->focus("#edit_section_title") ->render($self); return; } @@ -250,10 +264,12 @@ sub action_ajax_edit { ->hide($content_top_id) ->remove("#${id_base}_form") ->insertAfter($html, $content_top_id) + ->run('kivi.requirement_spec.init_function_block_keypress_events', "${id_base}_form") ->jstree->select_node('#tree', '#fb-' . $self->item->id) - ->focus("#${id_base}_description") ->val('#current_content_type', $self->item->item_type) ->val('#current_content_id', $self->item->id) + ->reinit_widgets + ->focus("#${id_base}_description") ->render($self); } @@ -283,7 +299,10 @@ sub action_ajax_update { ->remove('#edit_section_form') ->html('#section-header-' . $self->item->id, $html) ->show('#section-header-' . $self->item->id) - ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item)) + ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $self->item->presenter->tree_node_title) + ->prop('#fb-' . $self->item->id . ' a', 'title', $self->item->content_excerpt) + ->addClass('#fb-' . $self->item->id . ' a', 'tooltip') + ->reinit_widgets ->render($self); } @@ -298,7 +317,10 @@ sub action_ajax_update { $self->js ->remove('#' . $prefix . '_form') ->replaceWith('#' . $id_prefix . 'top-' . $self->item->id, $html_top) - ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item)); + ->prop('#fb-' . $self->item->id . ' a', 'title', $self->item->content_excerpt) + ->addClass('#fb-' . $self->item->id . ' a', 'tooltip') + ->reinit_widgets + ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $self->item->presenter->tree_node_title); $self->replace_bottom($self->item, id_prefix => $id_prefix); $self->replace_bottom($self->item->parent) if $type eq 'sub-function-block'; @@ -322,7 +344,7 @@ sub action_ajax_delete { } else { my $html = $self->render('requirement_spec_item/_no_section', { output => 0 }); - $self->js + $self->set_function_blocks_tab_menu_class(class => 'section-context-menu') ->html('#column-content', $html) ->val('#current_content_type', '') ->val('#current_content_id', '') @@ -418,7 +440,7 @@ sub assign_requirement_spec_id_rec { sub create_and_insert_node_rec { my ($self, $item, $new_parent_id, $insert_after) = @_; - my $node = $self->presenter->requirement_spec_item_jstree_data($item); + my $node = $item->presenter->jstree_data; $self->js->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : $new_parent_id ? ('#fb-' . $new_parent_id, 'last') : ('#sections', 'last'), $node); $self->create_and_insert_node_rec($_, $item->id) for @{ $item->children || [] }; @@ -459,8 +481,9 @@ sub action_ajax_paste { # Pasting the very first section? if (!@{ $self->sections }) { my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item); - $self->js->html('#column-content', $html) - ->jstree->select_node('#tree', '#fb-' . $self->item->id) + $self->set_function_blocks_tab_menu_class(class => 'section-context-menu') + ->html('#column-content', $html) + ->jstree->select_node('#tree', '#fb-' . $self->item->id) } # Update the current view if required. @@ -475,7 +498,7 @@ sub action_ajax_paste { sub check_auth { my ($self) = @_; - $::auth->assert('sales_quotation_edit'); + $::auth->assert('requirement_spec_edit'); } sub load_requirement_spec_item { @@ -507,9 +530,8 @@ sub init_risks { return SL::DB::Manager::RequirementSpecRisk->get_all_sorted; } -sub init_js { - my ($self) = @_; - $self->js(SL::ClientJS->new); +sub init_predefined_texts { + return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted(where => [ useable_for_sections => 1 ]); } sub replace_bottom { @@ -525,7 +547,8 @@ sub render_list { my ($self, $item, $item_to_select) = @_; my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $item); - $self->js->html('#column-content', $html); + $self->set_function_blocks_tab_menu_class(class => 'section-context-menu') + ->html('#column-content', $html); $self->select_node($item_to_select || $item); } @@ -540,7 +563,7 @@ sub select_node { sub create_dependency_item { my $self = shift; - [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ]; + [ $_[0]->id, truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description_as_stripped_html))) ]; } sub create_dependencies { @@ -562,7 +585,7 @@ sub ensure_section_is_shown { my $new_section = $self->item->section; my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $new_section); - return $self->js + return $self->set_function_blocks_tab_menu_class(class => 'section-context-menu') ->html('#column-content', $html) ->val('#current_content_type', 'section') ->val('#current_content_id', $new_section->id) @@ -590,19 +613,63 @@ sub add_new_item_form { return $self->js ->action($params{insert_position}, $html, $params{display_reference}) + ->action_if($self->item->item_type eq 'sub-function-block', 'show', '#sub-function-block-container-' . $self->item->parent_id) + ->run('kivi.requirement_spec.init_function_block_keypress_events', "${id_base}_form") + ->reinit_widgets ->focus("#${id_base}_description"); } sub add_new_item_form_after_create { my ($self, %params) = @_; - my $created_item = $self->item; - $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $created_item->requirement_spec_id, parent_id => $created_item->parent_id, item_type => $created_item->item_type)); + my $created_item = $self->item; + + my ($new_item_type, $new_parent_id, $insert_position, $insert_reference, $display_reference); + if ($created_item->item_type eq 'section') { + # $created_item is section, new one will be function-block + $new_item_type = 'function-block'; + $new_parent_id = $created_item->id; + $insert_position = 'appendTo'; + $display_reference = '#section-list'; + + } elsif (!$::form->{shift_in_out}) { + # $created_item is function-block or sub-function-block, new one will be the same + $new_item_type = $created_item->item_type; + $new_parent_id = $created_item->parent_id; + $insert_position = 'insertAfter'; + $insert_reference = $created_item->id; + $display_reference = '#' . $created_item->item_type . '-' . $created_item->id; + + } elsif ($created_item->item_type eq 'function-block') { + # $created_item is function-block, new one will be sub-function-block + $new_item_type = 'sub-function-block'; + $new_parent_id = $created_item->id; + $insert_position = 'appendTo'; + $display_reference = '#sub-function-block-container-' . $created_item->id; + + } else { + # $created_item is sub-function-block, new one will be function-block + $new_item_type = 'function-block'; + $new_parent_id = $created_item->parent->parent_id; + $insert_position = 'insertAfter'; + $insert_reference = $created_item->parent_id; + $display_reference = '#function-block-' . $created_item->parent_id; + } + + $::lxdebug->message(LXDebug::DEBUG1(), + "OLD item_type " . $created_item->item_type . " ; NEW item_type $new_item_type ; parent_id $new_parent_id ; " . + "insert_position $insert_position ; insert_reference $insert_reference ; display_reference $display_reference"); + + $self->item(SL::DB::RequirementSpecItem->new( + requirement_spec_id => $created_item->requirement_spec_id, + parent_id => $new_parent_id, + item_type => $new_item_type, + )); $self->add_new_item_form( - insert_position => 'insertAfter', - insert_reference => $created_item->id, - display_reference => '#' . $created_item->item_type . '-' . $created_item->id, + insert_reference => $insert_reference, + insert_position => $insert_position, + display_reference => $display_reference, ); } @@ -635,11 +702,10 @@ sub add_function_block { $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}, parent_id => $parent_id, item_type => $new_type)); $self->ensure_section_is_shown; - $self->add_new_item_form(insert_position => $insert_position, insert_reference => $insert_reference, display_reference => $display_reference); - $self->js->show('#sub-function-block-container-' . $parent_id) if $new_type eq 'sub-function-block'; + $self->add_new_item_form(insert_position => $insert_position, insert_reference => $insert_reference, display_reference => $display_reference); - $self->js->render($self); + $self->js->render; } sub is_item_visible {