Pflichtenheftitems: Drag&Drop vom aktuell Ausgewählten fixen
[kivitendo-erp.git] / SL / Controller / RequirementSpecTextBlock.pm
index 7d339a8..c4f37de 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
@@ -126,6 +126,7 @@ sub action_ajax_create {
   SL::ClientJS->new
     ->replaceWith('#' . $::form->{form_prefix} . '_form', $html)
     ->jstree->create_node('#tree', $insert_after ? ('#tb-' . $insert_after, 'after') : ('#tb-' . ($attributes->{output_position} == 0 ? 'front' : 'back'), 'last'), $node)
+    ->jstree->select_node('#tree', '#tb-' . $self->text_block->id)
     ->render($self);
 }
 
@@ -172,6 +173,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)       = @_;
 
@@ -260,7 +274,7 @@ sub output_position_from_id {
     return undef                 if $type !~ m/text-block/;
   }
 
-  my $text_block = SL::DB::Manager::RequirementSpecTextBlock->find_by(id => $id);
+  my $text_block = $id ? SL::DB::Manager::RequirementSpecTextBlock->find_by(id => $id) : undef;
 
   return $text_block ? $text_block->output_position : undef;
 }