From: Moritz Bunkus Date: Tue, 12 Mar 2013 14:17:29 +0000 (+0100) Subject: Pflichtenheftitems: Neuanlegen von (Unter)Funktionsblöcken X-Git-Tag: release-3.2.0beta~467^2~218 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=9a71fdb60ef0a0dcc50b858d34b552f937880778;p=kivitendo-erp.git Pflichtenheftitems: Neuanlegen von (Unter)Funktionsblöcken --- diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index 570a8cb37..c2f470aba 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -167,7 +167,18 @@ sub action_ajax_create { ->render($self); } - die 'TODO: create item'; + 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); + + $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) + ->jstree->select_node('#tree', '#fb-' . $self->item->id); + + $self->replace_bottom($js, $self->item->parent) if $type eq 'sub-function-block'; + + $js->render($self); } sub action_ajax_edit { @@ -270,7 +281,8 @@ sub action_ajax_update { sub action_ajax_delete { my ($self) = @_; - my $js = SL::ClientJS->new; + my $js = SL::ClientJS->new; + my $full_list = $self->item->get_full_list; $self->item->delete; @@ -297,7 +309,7 @@ sub action_ajax_delete { $self->replace_bottom($js, $self->item->parent_id) if $type eq 'sub-function-block'; - if (1 == scalar @{ $self->item->get_full_list }) { + if (1 == scalar @{ $full_list }) { if ($type eq 'function-block') { $js->show('#section-list-empty'); } elsif ($type eq 'sub-function-block') { @@ -400,11 +412,13 @@ sub create_dependencies { sub add_function_block { my ($self, $new_type) = @_; - die "Invalid new_type '$new_type'" if $new_type !~ m/^(?:sub-)?function-block$/; - die "Missing parameter 'id'" if !$::form->{id}; - die "Missing parameter 'requirement_spec_id'" if !$::form->{requirement_spec_id}; + my $clicked_id = $::form->{id} || ($self->visible_item ? $self->visible_item->id : undef); - my $clicked_item = SL::DB::RequirementSpecItem->new(id => $::form->{id})->load; + die "Invalid new_type '$new_type'" if $new_type !~ m/^(?:sub-)?function-block$/; + die "Missing parameter 'id' and no visible item" if !$clicked_id; + die "Missing parameter 'requirement_spec_id'" if !$::form->{requirement_spec_id}; + + my $clicked_item = SL::DB::RequirementSpecItem->new(id => $clicked_id)->load; my $clicked_type = $clicked_item->get_type; die "Invalid clicked_type '$clicked_type'" if $clicked_type !~ m/^(?: section | (?:sub-)? function-block )$/x; @@ -430,7 +444,7 @@ sub add_function_block { SELECTED_DEPENDENCIES => [], requirement_spec_item => $self->item, id_base => $id_base, - insert_after => $insert_reference, + insert_after => $insert_position eq 'insertAfter' ? $insert_reference : undef, ); my $js = SL::ClientJS->new; @@ -449,8 +463,11 @@ sub add_function_block { # $::lxdebug->message(0, "alright! clicked ID " . $::form->{id} . " type $clicked_type new_type $new_type insert_pos $insert_position ref " . ($insert_reference // '') . " parent $parent_id display_ref $display_reference"); $js->action($insert_position, $html, $display_reference) - ->focus("#${id_base}_description") - ->render($self); + ->focus("#${id_base}_description"); + + $js->show('#sub-function-block-container-' . $parent_id) if $new_type eq 'sub-function-block'; + + $js->render($self); } 1; diff --git a/js/requirement_spec.js b/js/requirement_spec.js index da53daa2b..896b93ba1 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -209,6 +209,12 @@ function disable_edit_item_commands(key, opt) { return find_item_id(opt.$trigger) == undefined; } +function disable_add_function_block_command(key, opt) { + if (find_item_id(opt.$trigger)) + return false; + return opt.$trigger.attr('id') != "section-list-empty"; +} + function submit_edit_item_form(id_base) { var id = $('#' + id_base + '_id').val(); var url = "controller.pl?" + $('#' + id_base + '_form').serialize(); @@ -221,8 +227,12 @@ function submit_edit_item_form(id_base) { return true; } -function cancel_edit_item_form(form_id_base, to_show) { +function cancel_edit_item_form(form_id_base, options) { $('#' + form_id_base + '_form').remove(); - if (to_show) - $(to_show).show(); + if (!options) + return; + if (options.to_show) + $(options.to_show).show(); + if (options.to_hide_if_empty && (1 == $(options.to_hide_if_empty).children().size())) + $(options.to_hide_if_empty).hide(); } diff --git a/templates/webpages/requirement_spec/show.html b/templates/webpages/requirement_spec/show.html index 31c93bbd0..655fe6577 100644 --- a/templates/webpages/requirement_spec/show.html +++ b/templates/webpages/requirement_spec/show.html @@ -125,7 +125,7 @@ $(function(){ selector: '.section-context-menu', items: { add_section: { name: "[% LxERP.t8('Add section') %]", icon: "add", callback: standard_item_ajax_call }, - add_function_block: { name: "[% LxERP.t8('Add function block') %]", icon: "add", callback: standard_item_ajax_call, disabled: disable_edit_item_commands }, + add_function_block: { name: "[% LxERP.t8('Add function block') %]", icon: "add", callback: standard_item_ajax_call, disabled: disable_add_function_block_command }, sep1: "---------", edit: { name: "[% LxERP.t8('Edit') %]", icon: "edit", callback: standard_item_ajax_call, disabled: disable_edit_item_commands }, delete: { name: "[% LxERP.t8('Delete') %]", icon: "delete", callback: ask_delete_item, disabled: disable_edit_item_commands }, diff --git a/templates/webpages/requirement_spec_item/_function_block_form.html b/templates/webpages/requirement_spec_item/_function_block_form.html index 580dc47dc..5869fc96f 100644 --- a/templates/webpages/requirement_spec_item/_function_block_form.html +++ b/templates/webpages/requirement_spec_item/_function_block_form.html @@ -1,5 +1,13 @@ [%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][%- USE P -%][% SET style="width: 500px" %] [% DEFAULT id_base = 'edit_function_block_' _ SELF.item.id %] +[%- SET a_options = '' %] +[%- IF SELF.item.id %] + [%- SET a_options = "to_show: '#" _ SELF.item.get_type _ "-content-top-" _ SELF.item.id _ "'" %] +[%- END %] +[%- IF SELF.item.get_type == 'sub-function-block' %] + [%- SET a_options = a_options ? a_options _ ', ' : a_options %] + [%- SET a_options = a_options _ "to_hide_if_empty: '#sub-function-block-container-" _ SELF.item.parent_id _ "'" %] +[%- END %]
[% L.hidden_tag(id_base _ '_id', SELF.item.id) %] [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.item.requirement_spec_id) %] @@ -41,6 +49,6 @@

[% L.button_tag('submit_edit_item_form("' _ id_base _ '")', LxERP.t8('Save')) %] - [%- LxERP.t8("Cancel") %] + [%- LxERP.t8("Cancel") %]

diff --git a/templates/webpages/requirement_spec_item/_section_form.html b/templates/webpages/requirement_spec_item/_section_form.html index 0a1fc7fc1..1136fc806 100644 --- a/templates/webpages/requirement_spec_item/_section_form.html +++ b/templates/webpages/requirement_spec_item/_section_form.html @@ -30,6 +30,6 @@

[% L.button_tag('submit_edit_item_form("' _ id_base _ '")', LxERP.t8('Save')) %] - [%- LxERP.t8("Cancel") %] + [%- LxERP.t8("Cancel") %]