From a81e9e42e5c939c466cdfe47eac45d7d594e8c86 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 16 Aug 2013 10:47:46 +0200 Subject: [PATCH] =?utf8?q?Pflichtenheftitems:=20Shift+Return=20=3D=20n?= =?utf8?q?=C3=A4chster=20neuer=20Block=20auf=20anderer=20Ebene?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RequirementSpecItem.pm | 48 ++++++++++++++++++++++++---- js/requirement_spec.js | 8 +++-- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index 0f7d66f22..490f28451 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -601,6 +601,7 @@ 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") ->focus("#${id_base}_description"); } @@ -609,18 +610,53 @@ sub add_new_item_form_after_create { my ($self, %params) = @_; my $created_item = $self->item; - my $is_section = $created_item->item_type eq 'section'; + + 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 => $is_section ? $created_item->id : $created_item->parent_id, - item_type => $is_section ? 'function-block' : $created_item->item_type, + parent_id => $new_parent_id, + item_type => $new_item_type, )); $self->add_new_item_form( - insert_reference => $created_item->id, - insert_position => $is_section ? 'appendTo' : 'insertAfter', - display_reference => $is_section ? '#section-list' : '#' . $created_item->item_type . '-' . $created_item->id, + insert_reference => $insert_reference, + insert_position => $insert_position, + display_reference => $display_reference, ); } diff --git a/js/requirement_spec.js b/js/requirement_spec.js index 11bab3693..ccc452536 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -341,17 +341,21 @@ ns.item_popup_menu_hidden = function(opt) { return ns.handle_item_popup_menu_markings(opt, false); }; -ns.submit_function_block = function(event) { +ns.submit_function_block = function(event, shift_in_out) { event.preventDefault(); var prefix = $(this).attr('id').match("^(?:edit|new)_function_block_[\\d_]+\\d")[0]; - kivi.submit_ajax_form('controller.pl?action=RequirementSpecItem/ajax_update', '#' + prefix + '_form'); + var action = $('#' + prefix + '_id').val() ? 'update' : 'create'; + kivi.submit_ajax_form('controller.pl?action=RequirementSpecItem/ajax_' + action, '#' + prefix + '_form', { shift_in_out: !!shift_in_out }); return false; }; ns.init_function_block_keypress_events = function(form_id) { $("#" + form_id + " INPUT[type=text]").bind("keypress", "return", ns.submit_function_block); + + $('#' + form_id + ' INPUT[type=text],#' + form_id + ' TEXTAREA,#' + form_id + ' INPUT[type=button]') + .bind('keypress', 'shift+return', function(event) { return ns.submit_function_block.apply(this, [ event, true ]); }); }; // ------------------------------------------------------------------------- -- 2.20.1