Löschen von Textblöcken
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 6 Mar 2013 16:05:25 +0000 (17:05 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:02:25 +0000 (13:02 +0200)
SL/Controller/RequirementSpecTextBlock.pm
js/requirement_spec.js
templates/webpages/requirement_spec/show.html

index 21cf29e..e0529da 100644 (file)
@@ -17,7 +17,7 @@ use Rose::Object::MakeMethods::Generic
  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
@@ -70,12 +70,13 @@ sub action_ajax_edit {
   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';
@@ -96,6 +97,24 @@ sub action_update {
     ->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)       = @_;
@@ -154,10 +173,6 @@ sub action_dragged_and_dropped {
     }
   }
 
-  $::lxdebug->message(0, "old $old_where current $current_where new $new_where");
-
-  $::lxdebug->dump(0, "actions", $js);
-
   $self->render($js);
 }
 
index a9e19e2..f7b52e6 100644 (file)
@@ -205,7 +205,7 @@ function delete_text_block(key, opt) {
 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
   };
index 8df8c00..cb5cda9 100644 (file)
@@ -28,7 +28,7 @@
   [% 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) {