From e86e30de944c4bbe4b42f43d933e0a28a83408dd Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 12 Mar 2013 10:43:26 +0100 Subject: [PATCH] Pflichtenheftitems und Abschnitte bearbeiten --- SL/Controller/RequirementSpecItem.pm | 93 +++++++++++++------ js/requirement_spec.js | 7 +- templates/webpages/requirement_spec/show.html | 29 ------ .../_function_block_form.html | 4 +- .../requirement_spec_item/_section_form.html | 40 ++++---- .../_section_header.html | 2 +- 6 files changed, 93 insertions(+), 82 deletions(-) diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index b90ec3da9..f3cbd0878 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -112,6 +112,12 @@ sub action_dragged_and_dropped { $self->render($js); } +sub action_ajax_add { + my ($self, %params) = @_; + + die "TODO: add action"; +} + sub action_ajax_edit { my ($self, %params) = @_; @@ -119,39 +125,53 @@ sub action_ajax_edit { my $js = SL::ClientJS->new; - die "TODO: edit section" if $self->item->get_type =~ m/section/; - if (!$self->visible_section || ($self->visible_section->id != $self->item->get_section->id)) { + # 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); $js->html('#column-content', $html); } - if ($self->item->get_type =~ m/function-block/) { - my $create_item = sub { - [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ] - }; - my @dependencies = - map { [ $_->fb_number . ' ' . $_->title, - [ map { ( $create_item->($_), - map { $create_item->($_, '->') } @{ $_->sorted_children }) - } @{ $_->sorted_children } ] ] - } @{ $self->item->requirement_spec->sections }; - - my @selected_dependencies = map { $_->id } @{ $self->item->dependencies }; - - my $html = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies); - my $id_base = $self->item->get_type . '-' . $self->item->id; - my $content_top_id = '#' . $self->item->get_type . '-content-top-' . $self->item->id; - - $js->hide($content_top_id) - ->remove("#edit_${id_base}_form") - ->insertAfter($html, $content_top_id) + if ($self->item->get_type =~ m/section/) { + # Edit the section header, not an item. + my $html = $self->render('requirement_spec_item/_section_form', { output => 0 }); + + $js->hide('#section-header-' . $self->item->id) + ->remove("#edit_section_form") + ->insertAfter($html, '#section-header-' . $self->item->id) ->jstree->select_node('#tree', '#fb-' . $self->item->id) - ->focus("#edit_${id_base}_description") - ->val('#current_content_type', $self->item->get_type) - ->val('#current_content_id', $self->item->id) + ->focus("#edit_section_title") + ->val('#current_content_type', 'section') + ->val('#current_content_id', $self->item->id) ->render($self); + return; } + + # Edit a function block or a sub function block + my $create_item = sub { + [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ] + }; + my @dependencies = + map { [ $_->fb_number . ' ' . $_->title, + [ map { ( $create_item->($_), + map { $create_item->($_, '->') } @{ $_->sorted_children }) + } @{ $_->sorted_children } ] ] + } @{ $self->item->requirement_spec->sections }; + + my @selected_dependencies = map { $_->id } @{ $self->item->dependencies }; + + my $html = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies); + my $id_base = 'edit_function_block_' . $self->item->id; + my $content_top_id = '#' . $self->item->get_type . '-content-top-' . $self->item->id; + + $js->hide($content_top_id) + ->remove("#${id_base}_form") + ->insertAfter($html, $content_top_id) + ->jstree->select_node('#tree', '#fb-' . $self->item->id) + ->focus("#${id_base}_description") + ->val('#current_content_type', $self->item->get_type) + ->val('#current_content_id', $self->item->id) + ->render($self); } sub action_ajax_update { @@ -170,7 +190,26 @@ sub action_ajax_update { $self->item->save; - my $id_prefix = $self->item->get_type eq 'function-block' ? '' : 'sub-'; + my $type = $self->item->get_type; + + if ($type eq 'section') { + # Updated section, now update section header. + + my $html = $self->render('requirement_spec_item/_section_header', { output => 0 }, requirement_spec_item => $self->item); + + return SL::ClientJS->new + ->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)) + ->render($self); + } + + # Updated function block or sub function block. Update (sub) + # function block and potentially the bottom of the parent function + # block. + + my $id_prefix = $type eq 'function-block' ? '' : 'sub-'; my $html_top = $self->render('requirement_spec_item/_function_block_content_top', { output => 0 }, requirement_spec_item => $self->item, id_prefix => $id_prefix); $id_prefix .= 'function-block-content-'; @@ -180,7 +219,7 @@ sub action_ajax_update { ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item)); $self->replace_bottom($js, $self->item, id_prefix => $id_prefix); - $self->replace_bottom($js, $self->item->parent) if $self->item->get_type eq 'sub-function-block'; + $self->replace_bottom($js, $self->item->parent) if $type eq 'sub-function-block'; $js->render($self); } diff --git a/js/requirement_spec.js b/js/requirement_spec.js index 15bec4b5b..da53daa2b 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -221,9 +221,8 @@ function submit_edit_item_form(id_base) { return true; } -function cancel_edit_item_form(form_id_base, hidden_id_base) { - var id = $('#' + form_id_base + '_id').val(); +function cancel_edit_item_form(form_id_base, to_show) { $('#' + form_id_base + '_form').remove(); - if (id) - $('#' + hidden_id_base + '-' + id).show(); + if (to_show) + $(to_show).show(); } diff --git a/templates/webpages/requirement_spec/show.html b/templates/webpages/requirement_spec/show.html index d8221e567..68c021ddf 100644 --- a/templates/webpages/requirement_spec/show.html +++ b/templates/webpages/requirement_spec/show.html @@ -150,34 +150,5 @@ $(function(){ }); }); -function edit_section_header() { - $.post("controller.pl?action=RequirementSpecItem/edit_section&id=" + encodeURIComponent($('#active_section_id').val()), function(data) { - var header = $('#section-header'); - header.data('old-elements', header.children().detach()); - header.html(data); - }); -} - -function submit_section_form() { - $.post("controller.pl?action=RequirementSpecItem/update_section&id=" + $('#section-form form').serialize(), function(data) { - var header = $('#section-header'); - header.removeData('old-elements'); - header.html(data['header_html']); - $('#tree').jstree('rename_node', '#fb-' + data['id'], data['node_name']); - }); -} - -function cancel_section_form() { - var header = $('#section-header'); - header.empty(); - header.append(header.data('old-elements')); - header.removeData('old-elements'); -} - - - - - - --> diff --git a/templates/webpages/requirement_spec_item/_function_block_form.html b/templates/webpages/requirement_spec_item/_function_block_form.html index 5be377ec2..a999c6ba1 100644 --- a/templates/webpages/requirement_spec_item/_function_block_form.html +++ b/templates/webpages/requirement_spec_item/_function_block_form.html @@ -29,12 +29,12 @@
[% LxERP.t8("Description of #1", SELF.item.fb_number) %]:
- [% L.textarea_tag(id_base _ '.description', SELF.item.description, id=id_base _ '_description', rows=8, style="width: 100%") %] + [% L.textarea_tag(id_base _ '.description', SELF.item.description, rows=8, style="width: 100%") %]

[% 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 c2ae0da8b..1b059542d 100644 --- a/templates/webpages/requirement_spec_item/_section_form.html +++ b/templates/webpages/requirement_spec_item/_section_form.html @@ -1,25 +1,27 @@ [%- USE HTML %][%- USE L %][%- USE LxERP %] -[%- SET id_base="section-form" %] -
+[%- DEFAULT id_base="edit_section" %] +[%- SET style="width: 500px" %] +

[%- LxERP.t8("Edit section #1", SELF.item.fb_number) %]

- - [% L.hidden_tag("requirement_spec_id", SELF.item.requirement_spec_id, id=(id_base _ "-requirement-spec-id")) %] - [% L.hidden_tag("id", SELF.item.id, id=(id_base _ "-requirement-spec-item-id")) %] + [% L.hidden_tag(id_base _ '_id', SELF.item.id) %] + [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.item.requirement_spec_id) %] + [% IF insert_after %] + [% L.hidden_tag(id_base _ '.insert_after', insert_after) %] + [% END %] -

- [%- LxERP.t8("Title") %]:
- [% L.input_tag("title", SELF.item.title, id=(id_base _ "-title")) %] -

+

+ [%- LxERP.t8("Title") %]:
+ [% L.input_tag(id_base _ '.title', SELF.item.title, style=style) %] +

-

- [%- LxERP.t8("Description") %]:
- [% L.textarea_tag("description", SELF.item.description, id=(id_base _ "-description"), rows=8, cols=80) %] -

+

+ [%- LxERP.t8("Description") %]:
+ [% L.textarea_tag(id_base _ '.description', SELF.item.description, rows=8, cols=80, style=style) %] +

-

- [% L.button_tag("submit_section_form()", LxERP.t8("Save")) %] - [% LxERP.t8("Cancel") %] -

-
-
+

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

+ diff --git a/templates/webpages/requirement_spec_item/_section_header.html b/templates/webpages/requirement_spec_item/_section_header.html index db3a9983d..268f6cdad 100644 --- a/templates/webpages/requirement_spec_item/_section_header.html +++ b/templates/webpages/requirement_spec_item/_section_header.html @@ -10,7 +10,7 @@ [% END %] -
+
[%- LxERP.t8("Preamble") %]
[% IF requirement_spec_item.description %] [%- L.simple_format(requirement_spec_item.description) -%] -- 2.20.1