Pflichtenhefte: Textblöcke, Abschnitte und Funktionsblöcke markieren können
[kivitendo-erp.git] / SL / Controller / RequirementSpecTextBlock.pm
index fb1f364..eaf8b6f 100644 (file)
@@ -19,7 +19,7 @@ use Rose::Object::MakeMethods::Generic
   'scalar --get_set_init' => [ qw(predefined_texts) ],
 );
 
-__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete dragged_and_dropped)]);
+__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete ajax_flag dragged_and_dropped)]);
 
 #
 # actions
@@ -48,6 +48,8 @@ sub action_ajax_list {
     my $html        = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
 
     $js->html('#column-content', $html)
+       ->val('#current_content_type', 'text-blocks-' . (0 == $new_where ? 'front' : 'back'))
+       ->val('#current_content_id',   $::form->{clicked_id});
   }
 
   $self->render($js);
@@ -170,6 +172,19 @@ sub action_ajax_delete {
      ->render($self);
 }
 
+sub action_ajax_flag {
+  my ($self) = @_;
+
+  $self->text_block->update_attributes(is_flagged => !$self->text_block->is_flagged);
+
+  my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type});
+
+  SL::ClientJS->new
+   ->action_if($current_where == $self->text_block->output_position, 'toggleClass', '#text-block-' . $self->text_block->id, 'flagged')
+   ->toggleClass('#tb-' . $self->text_block->id, 'flagged')
+   ->render($self);
+}
+
 sub action_dragged_and_dropped {
   my ($self)       = @_;
 
@@ -224,7 +239,7 @@ sub action_dragged_and_dropped {
       if ($prior_text_block) {
         $js->insertAfter($html, '#text-block-' . $prior_text_block->id);
       } else {
-        $js->appendTo($html, '#text-block-list');
+        $js->prependTo($html, '#text-block-list');
       }
     }
   }