my $new_type = $self->item->item_type;
my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->section;
- return $self->render($self->js) if !$old_visible_section || ($new_type eq 'section');
+ return $self->invalidate_version->render($self) if !$old_visible_section || ($new_type eq 'section');
# From here on $old_visible_section is definitely set.
if ($old_visible_section->id != $new_visible_section->id) {
# The currently visible item has been dragged to a different section.
+ $self->invalidate_version;
return $self->render_list($new_section, $self->item)
->render($self);
}
# $::lxdebug->dump(0, "js", $self->js->to_array);
- $self->render($self->js);
+ $self->invalidate_version->render($self);
}
sub action_ajax_add_section {
if ($type eq 'section') {
my $node = $self->presenter->requirement_spec_item_jstree_data($self->item);
+ $self->invalidate_version;
return $self->render_list($self->item)
->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#sections', 'last'), $node)
->jstree->select_node('#tree', '#fb-' . $self->item->id)
$self->replace_bottom($self->item->parent) if $type eq 'sub-function-block';
- $self->js->render($self);
+ $self->invalidate_version->render($self);
}
sub action_ajax_edit {
my $html = $self->render('requirement_spec_item/_section_header', { output => 0 }, requirement_spec_item => $self->item);
- return $self->js
+ return $self->invalidate_version
->remove('#edit_section_form')
->html('#section-header-' . $self->item->id, $html)
->show('#section-header-' . $self->item->id)
$self->replace_bottom($self->item, id_prefix => $id_prefix);
$self->replace_bottom($self->item->parent) if $type eq 'sub-function-block';
- $self->js->render($self);
+ $self->invalidate_version->render($self);
}
sub action_ajax_delete {
}
}
- $self->js->jstree->delete_node('#tree', '#fb-' . $self->item->id)
- ->render($self);
+ $self->invalidate_version
+ ->jstree->delete_node('#tree', '#fb-' . $self->item->id)
+ ->render($self);
}
sub action_ajax_flag {
# Update the current view if required.
$self->insert_new_item_in_section_view($self->js) if $self->is_item_visible;
- $self->js->render($self);
+ $self->invalidate_version->render($self);
}
#
$::auth->assert('sales_quotation_edit');
}
-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_item {
my ($self) = @_;
- $self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load || die "No such requirement spec item");
+ $self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load);
}
#
return $self->visible_section && ($self->visible_section->id == $item->section->id);
}
+sub invalidate_version {
+ my ($self) = @_;
+
+ my $html = $self->render('requirement_spec/_version', { output => 0 },
+ requirement_spec => SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id} || $self->item->requirement_spec_id)->load);
+ return $self->js->html('#requirement_spec_version', $html);
+}
+
1;
use strict;
use Carp;
+use List::MoreUtils qw(any);
+use Rose::DB::Object::Helpers;
+use Rose::DB::Object::Util;
use SL::DB::MetaSetup::RequirementSpecItem;
use SL::DB::Manager::RequirementSpecItem;
__PACKAGE__->attr_duration(qw(time_estimation));
__PACKAGE__->before_save(\&_before_save_create_fb_number);
+__PACKAGE__->before_save(\ &_before_save_invalidate_requirement_spec_version);
__PACKAGE__->before_delete(\&_before_delete_delete_children);
+__PACKAGE__->before_delete(\&_before_delete_invalidate_requirement_spec_version);
sub _before_delete_delete_children {
my ($self) = @_;
return 1;
}
+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));
+ my $has_changed = !Rose::DB::Object::Util::is_in_db($self);
+ $has_changed ||= any { $changed_columns{$_} } qw(requirement_spec_id parent_id position fb_number title description);
+
+ if (!$has_changed && $self->id) {
+ my $old_item = SL::DB::RequirementSpecItem->new(id => $self->id)->load;
+ $has_changed = join(':', sort map { $_->id } @{ $self->dependencies }) ne join(':', sort map { $_->id } @{ $old_item->dependencies });
+ }
+
+ $self->requirement_spec->invalidate_version if $has_changed;
+
+ return 1;
+}
+
+sub _before_delete_invalidate_requirement_spec_version {
+ my ($self, %params) = @_;
+
+ $self->requirement_spec->invalidate_version if $self->requirement_spec_id;
+
+ return 1;
+}
+
sub validate {
my ($self) = @_;