scalar => [ qw(requirement_spec text_block) ],
);
-__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit update dragged_and_dropped)]);
+__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete dragged_and_dropped)]);
#
# actions
my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, PREDEFINED_TEXTS => $predefined_texts);
$js->hide('#text-block-' . $self->text_block->id)
+ ->remove('#edit_text_block_' . $self->text_block->id . '_form')
->insertAfter($html, '#text-block-' . $self->text_block->id)
->jstree->select_node('#tree', '#tb-' . $self->text_block->id)
->render($self);
}
-sub action_update {
+sub action_ajax_update {
my ($self, %params) = @_;
my $prefix = $::form->{form_prefix} || 'text_block';
->render($self);
}
+sub action_ajax_delete {
+ my ($self) = @_;
+
+ my $js = SL::ClientJS->new;
+
+ my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
+ if ($self->text_block->output_position == $current_where) {
+ $js->remove('#edit_text_block_' . $self->text_block->id . '_form')
+ ->remove('#text-block-' . $self->text_block->id);
+
+ $js->show('#text-block-list-empty') if 1 == scalar @{ $self->text_block->get_full_list };
+ }
+
+ $self->text_block->delete;
+
+ $js->jstree->delete_node('#tree', '#tb-' . $self->text_block->id)
+ ->render($self);
+}
sub action_dragged_and_dropped {
my ($self) = @_;
}
}
- $::lxdebug->message(0, "old $old_where current $current_where new $new_where");
-
- $::lxdebug->dump(0, "actions", $js);
-
$self->render($js);
}
function submit_edit_text_block_form(id_base) {
var url = "controller.pl?" + $('#' + id_base + '_form').serialize();
var data = {
- action: 'RequirementSpecTextBlock/update.js',
+ action: 'RequirementSpecTextBlock/ajax_update',
id: $('#' + id_base + '_id').val(),
form_prefix: id_base
};
[% L.hidden_tag('current_content_id', SELF.requirement_spec_item.id) %]
<div id="column-content">
- [%- IF SELF.requirement_spec_item && SELF.requirement_spec_item.id -%]
+ [%- IF SELF.requirement_spec_item -%]
[%- INCLUDE 'requirement_spec_item/_single_section.html' requirement_spec_item=SELF.requirement_spec_item -%]
[%- ELSE -%]
no section
plugins: [ "themes", "json_data", "ui", "crrm", "dnd" ]
})
.bind("move_node.jstree", requirement_spec_tree_node_moved)
- .bind("click.jstree", requirement_spec_tree_node_clicked)
+ .bind("click.jstree", requirement_spec_tree_node_clicked);
+[%- IF SELF.requirement_spec_item -%]
+ $.jstree._reference("#tree").select_node('fb-[% SELF.requirement_spec_item.id %]', true);
+[%- END -%]
});
function ask_delete_text_block(key, opt) {