From b0ac485034697396a72f36f9bf48f0171b9b1692 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 12 Mar 2013 13:07:01 +0100 Subject: [PATCH] Pflichtenheftitems: Abschnitte anlegen --- SL/Controller/RequirementSpecItem.pm | 49 +++++++++++++++++-- locale/de/all | 1 + templates/webpages/requirement_spec/show.html | 18 +++---- .../requirement_spec_item/_section_form.html | 12 ++++- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index f3cbd0878..fd20a7765 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -92,8 +92,8 @@ sub action_dragged_and_dropped { $js->hide('#section-list-empty'); my $id_prefix = $new_type eq 'sub-function-block' ? 'sub-' : ''; - my $template = apply { s/-/_/g; $_ } $new_type; - my $html = "" . $self->render('requirement_spec_item/_' . $template, { output => 0 }, requirement_spec_item => $self->item); + my $template = 'requirement_spec_item/_' . (apply { s/-/_/g; $_ } $new_type); + my $html = "" . $self->render($template, { output => 0 }, requirement_spec_item => $self->item); my $next_item = $self->item->get_next_in_list; if ($next_item) { @@ -112,10 +112,49 @@ sub action_dragged_and_dropped { $self->render($js); } -sub action_ajax_add { +sub action_ajax_add_section { my ($self, %params) = @_; - die "TODO: add action"; + die "Missing parameter 'requirement_spec_id'" if !$::form->{requirement_spec_id}; + + $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id})); + + my $insert_after = $::form->{id} ? SL::DB::RequirementSpecItem->new(id => $::form->{id})->load->get_section->id : undef; + my $html = $self->render('requirement_spec_item/_section_form', { output => 0 }, id_base => 'new_section', insert_after => $insert_after); + + SL::ClientJS->new + ->remove('#new_section_form') + ->hide('#column-content > *') + ->appendTo($html, '#column-content') + ->focus('#new_section_title') + ->render($self); +} + +sub action_ajax_create { + my ($self, %params) = @_; + + my $js = SL::ClientJS->new; + my $prefix = $::form->{form_prefix} || die "Missing parameter 'form_prefix'"; + my $attributes = $::form->{$prefix} || die "Missing parameter group '${prefix}'"; + my $insert_after = delete $attributes->{insert_after}; + + my @errors = $self->item(SL::DB::RequirementSpecItem->new(%{ $attributes }))->validate; + return $js->error(@errors)->render($self) if @errors; + + $self->item->save; + $self->item->add_to_list(position => 'after', reference => $insert_after) if $insert_after; + + my $type = $self->item->get_type; + + if ($type eq 'section') { + my $node = $self->presenter->requirement_spec_item_jstree_data($self->item); + return $self->render_list($js, $self->item) + ->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#sections', 'last'), $node) + ->jstree->select_node('#tree', '#fb-' . $self->item->id) + ->render($self); + } + + die 'TODO: create item'; } sub action_ajax_edit { @@ -178,7 +217,7 @@ sub action_ajax_update { my ($self, %params) = @_; my $js = SL::ClientJS->new; - my $prefix = $::form->{form_prefix} || 'function_block'; + my $prefix = $::form->{form_prefix} || die "Missing parameter 'form_prefix'"; my $attributes = $::form->{$prefix} || {}; foreach (qw(requirement_spec_id parent_id position)) { diff --git a/locale/de/all b/locale/de/all index 73c1ef9b4..a3528d95a 100755 --- a/locale/de/all +++ b/locale/de/all @@ -892,6 +892,7 @@ $self->{texts} = { 'Edit requirement spec status' => 'Pflichtenheftstatus bearbeiten', 'Edit requirement spec type' => 'Pflichtenhefttypen bearbeiten', 'Edit risk level' => 'Risikograd bearbeiten', + 'Edit section #1' => 'Abschnitt #1 bearbeiten', 'Edit templates' => 'Vorlagen bearbeiten', 'Edit text block' => 'Textblock bearbeiten', 'Edit text block \'#1\'' => 'Textblock \'#1\' bearbeiten', diff --git a/templates/webpages/requirement_spec/show.html b/templates/webpages/requirement_spec/show.html index 68c021ddf..31c93bbd0 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_text_block_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_edit_item_commands }, 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 }, @@ -138,14 +138,14 @@ $(function(){ $.contextMenu({ selector: '.function-block-context-menu,.sub-function-block-context-menu', items: { - new_item: { name: "[% LxERP.t8('Add function block') %]", icon: "add", callback: standard_item_ajax_call }, - new_sub_item: { name: "[% LxERP.t8('Add sub function block') %]", icon: "add", callback: standard_item_ajax_call }, - 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 }, - sep2: "---------", - copy: { name: "[% LxERP.t8('Copy') %]", icon: "copy", disabled: disable_edit_item_commands }, - paste: { name: "[% LxERP.t8('Paste') %]", icon: "paste", disabled: disable_edit_item_commands } + add_function_block: { name: "[% LxERP.t8('Add function block') %]", icon: "add", callback: standard_item_ajax_call }, + add_sub_function_block: { name: "[% LxERP.t8('Add sub function block') %]", icon: "add", callback: standard_item_ajax_call }, + 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 }, + sep2: "---------", + copy: { name: "[% LxERP.t8('Copy') %]", icon: "copy", disabled: disable_edit_item_commands }, + paste: { name: "[% LxERP.t8('Paste') %]", icon: "paste", disabled: disable_edit_item_commands } } }); }); diff --git a/templates/webpages/requirement_spec_item/_section_form.html b/templates/webpages/requirement_spec_item/_section_form.html index 1b059542d..0a1fc7fc1 100644 --- a/templates/webpages/requirement_spec_item/_section_form.html +++ b/templates/webpages/requirement_spec_item/_section_form.html @@ -2,7 +2,15 @@ [%- DEFAULT id_base="edit_section" %] [%- SET style="width: 500px" %]
-

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

+ [%- IF SELF.item.id %] + [%- SET hidden = '#section-header-' _ SELF.item.id %] +

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

+ + [%- ELSE %] + [%- SET hidden = '#column-content > *' %] +

[%- LxERP.t8("Add section") %]

+ + [%- END %] [% L.hidden_tag(id_base _ '_id', SELF.item.id) %] [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.item.requirement_spec_id) %] @@ -22,6 +30,6 @@

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

-- 2.20.1