$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) {
$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 {
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)) {
'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',
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 },
$.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 }
}
});
});
[%- DEFAULT id_base="edit_section" %]
[%- SET style="width: 500px" %]
<form id="[% id_base %]_form">
- <h1>[%- LxERP.t8("Edit section #1", SELF.item.fb_number) %]</h1>
+ [%- IF SELF.item.id %]
+ [%- SET hidden = '#section-header-' _ SELF.item.id %]
+ <h1>[%- LxERP.t8("Edit section #1", SELF.item.fb_number) %]</h1>
+
+ [%- ELSE %]
+ [%- SET hidden = '#column-content > *' %]
+ <h1>[%- LxERP.t8("Add section") %]</h1>
+
+ [%- END %]
[% L.hidden_tag(id_base _ '_id', SELF.item.id) %]
[% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.item.requirement_spec_id) %]
<p>
[% L.button_tag('submit_edit_item_form("' _ id_base _ '")', LxERP.t8('Save')) %]
- <a href="#" onclick="cancel_edit_item_form('[% id_base %]', '[% '#section-header-' _ SELF.item.id %]')">[%- LxERP.t8("Cancel") %]</a>
+ <a href="#" onclick="cancel_edit_item_form('[% id_base %]', '[% hidden %]')">[%- LxERP.t8("Cancel") %]</a>
</p>
</form>