->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 {
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;
$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') {
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;
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;
# $::lxdebug->message(0, "alright! clicked ID " . $::form->{id} . " type $clicked_type new_type $new_type insert_pos $insert_position ref " . ($insert_reference // '<undef>') . " 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;
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();
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();
}
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 },
[%- 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 %]
<form method="post" id="[% id_base %]_form" class="function-block-form">
[% 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 %]', '[% '#' _ SELF.item.get_type _ '-content-top-' _ SELF.item.id %]')">[%- LxERP.t8("Cancel") %]</a>
+ <a href="#" onclick="cancel_edit_item_form('[% id_base %]', { [% a_options %] })">[%- LxERP.t8("Cancel") %]</a>
</p>
</form>