From: Moritz Bunkus Date: Fri, 19 Apr 2013 12:53:16 +0000 (+0200) Subject: Pflichtenhefte: nach Änderung an Textblöcken Version invalidieren X-Git-Tag: release-3.2.0beta~467^2~194 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d90408d8d3aa5db131d333144b5ef7c1bd372b2a;p=kivitendo-erp.git Pflichtenhefte: nach Änderung an Textblöcken Version invalidieren --- diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index 140a104c8..ab0b47ffa 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -16,7 +16,7 @@ use SL::Locale::String; use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(requirement_spec text_block) ], + scalar => [ qw(text_block) ], 'scalar --get_set_init' => [ qw(predefined_texts) ], ); @@ -79,7 +79,8 @@ sub action_ajax_add { my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000); my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $::form->{id}); - $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list')) + $self->invalidate_version($js) + ->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list')) ->focus('#' . $id_base . '_title') ->render($self); } @@ -124,7 +125,7 @@ sub action_ajax_create { my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block); my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block); - SL::ClientJS->new + $self->invalidate_version ->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) @@ -148,7 +149,7 @@ sub action_ajax_update { my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block); - SL::ClientJS->new + $self->invalidate_version ->remove('#' . $prefix . '_form') ->replaceWith('#text-block-' . $self->text_block->id, $html) ->jstree->rename_node('#tree', '#tb-' . $self->text_block->id, $self->text_block->title) @@ -170,7 +171,8 @@ sub action_ajax_delete { $self->text_block->delete; - $js->jstree->delete_node('#tree', '#tb-' . $self->text_block->id) + $self->invalidate_version($js) + ->jstree->delete_node('#tree', '#tb-' . $self->text_block->id) ->render($self); } @@ -205,7 +207,7 @@ sub action_dragged_and_dropped { # $::lxdebug->dump(0, "form", $::form); - return $self->render(\'', { type => 'json' }) if $::form->{current_content_type} !~ m/^text-block/; + return $self->invalidate_version->render($self) if $::form->{current_content_type} !~ m/^text-block/; my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; my $new_where = $self->text_block->output_position; @@ -246,7 +248,8 @@ sub action_dragged_and_dropped { } } - $self->render($js); + $self->invalidate_version($js) + ->render($self); } sub action_ajax_copy { @@ -281,19 +284,15 @@ sub action_ajax_paste { } my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block); - $js->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node) - ->render($self); + $self->invalidate_version($js) + ->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node) + ->render($self); } # # filters # -sub load_requirement_spec { - my ($self) = @_; - $self->requirement_spec(SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id})->load || die "No such requirement spec"); -} - sub load_requirement_spec_text_block { my ($self) = @_; $self->text_block(SL::DB::RequirementSpecTextBlock->new(id => $::form->{id})->load || die "No such requirement spec text block"); @@ -320,4 +319,13 @@ sub init_predefined_texts { return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted; } +sub invalidate_version { + my ($self, $js) = @_; + + $js ||= SL::ClientJS->new; + my $html = $self->render('requirement_spec/_version', { output => 0 }, + requirement_spec => SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id} || $self->text_block->requirement_spec_id)->load); + return $js->html('#requirement_spec_version', $html); +} + 1; diff --git a/SL/DB/RequirementSpec.pm b/SL/DB/RequirementSpec.pm index e2ac8b10f..c25c289d9 100644 --- a/SL/DB/RequirementSpec.pm +++ b/SL/DB/RequirementSpec.pm @@ -173,4 +173,14 @@ sub create_version { return $ok ? ($copy, $version) : (); } +sub invalidate_version { + my ($self, %params) = @_; + + $::lxdebug->message(0, "Invalidate version called for id " . $self->id . " version " . $self->version_id); + $::lxdebug->show_backtrace(1); + + return if !$self->id || !$self->version_id; + $self->update_attributes(version_id => undef); +} + 1; diff --git a/SL/DB/RequirementSpecTextBlock.pm b/SL/DB/RequirementSpecTextBlock.pm index 1db862313..50851ad78 100644 --- a/SL/DB/RequirementSpecTextBlock.pm +++ b/SL/DB/RequirementSpecTextBlock.pm @@ -2,6 +2,10 @@ package SL::DB::RequirementSpecTextBlock; use strict; +use List::MoreUtils qw(any); +use Rose::DB::Object::Helpers; +use Rose::DB::Object::Util; + use SL::DB::MetaSetup::RequirementSpecTextBlock; use SL::DB::Manager::RequirementSpecTextBlock; use SL::DB::Helper::ActsAsList; @@ -11,6 +15,9 @@ __PACKAGE__->meta->initialize; __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id output_position)]); +__PACKAGE__->before_save(\ &_before_save_invalidate_requirement_spec_version); +__PACKAGE__->before_delete(\&_before_delete_invalidate_requirement_spec_version); + sub validate { my ($self) = @_; @@ -20,4 +27,26 @@ sub validate { return @errors; } +sub _before_save_invalidate_requirement_spec_version { + my ($self, %params) = @_; + + + return 1 if !$self->requirement_spec_id; + + my %changed_columns = map { $_ => 1 } (Rose::DB::Object::Helpers::dirty_columns($self)); + + $self->requirement_spec->invalidate_version + if !Rose::DB::Object::Util::is_in_db($self) || any { $changed_columns{$_} } qw(title text position output_position); + + return 1; +} + +sub _before_delete_invalidate_requirement_spec_version { + my ($self, %params) = @_; + + $self->requirement_spec->invalidate_version if $self->requirement_spec_id; + + return 1; +} + 1;