Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d90408d8

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID d90408d8d3aa5db131d333144b5ef7c1bd372b2a
  • Vorgänger 51fec310
  • Nachfolger 603481b2

Pflichtenhefte: nach Änderung an Textblöcken Version invalidieren

Unterschiede anzeigen:

SL/Controller/RequirementSpecTextBlock.pm
16 16

  
17 17
use Rose::Object::MakeMethods::Generic
18 18
(
19
  scalar                  => [ qw(requirement_spec text_block) ],
19
  scalar                  => [ qw(text_block) ],
20 20
  'scalar --get_set_init' => [ qw(predefined_texts) ],
21 21
);
22 22

  
......
79 79
  my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
80 80
  my $html    = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $::form->{id});
81 81

  
82
  $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'))
82
  $self->invalidate_version($js)
83
     ->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'))
83 84
     ->focus('#' . $id_base . '_title')
84 85
     ->render($self);
85 86
}
......
124 125
  my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
125 126
  my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block);
126 127

  
127
  SL::ClientJS->new
128
  $self->invalidate_version
128 129
    ->replaceWith('#' . $::form->{form_prefix} . '_form', $html)
129 130
    ->jstree->create_node('#tree', $insert_after ? ('#tb-' . $insert_after, 'after') : ('#tb-' . ($attributes->{output_position} == 0 ? 'front' : 'back'), 'last'), $node)
130 131
    ->jstree->select_node('#tree', '#tb-' . $self->text_block->id)
......
148 149

  
149 150
  my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
150 151

  
151
  SL::ClientJS->new
152
  $self->invalidate_version
152 153
    ->remove('#' . $prefix . '_form')
153 154
    ->replaceWith('#text-block-' . $self->text_block->id, $html)
154 155
    ->jstree->rename_node('#tree', '#tb-' . $self->text_block->id, $self->text_block->title)
......
170 171

  
171 172
  $self->text_block->delete;
172 173

  
173
  $js->jstree->delete_node('#tree', '#tb-' . $self->text_block->id)
174
  $self->invalidate_version($js)
175
     ->jstree->delete_node('#tree', '#tb-' . $self->text_block->id)
174 176
     ->render($self);
175 177
}
176 178

  
......
205 207

  
206 208
  # $::lxdebug->dump(0, "form", $::form);
207 209

  
208
  return $self->render(\'', { type => 'json' }) if $::form->{current_content_type} !~ m/^text-block/;
210
  return $self->invalidate_version->render($self) if $::form->{current_content_type} !~ m/^text-block/;
209 211

  
210 212
  my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
211 213
  my $new_where     = $self->text_block->output_position;
......
246 248
    }
247 249
  }
248 250

  
249
  $self->render($js);
251
  $self->invalidate_version($js)
252
    ->render($self);
250 253
}
251 254

  
252 255
sub action_ajax_copy {
......
281 284
  }
282 285

  
283 286
  my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block);
284
  $js->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node)
285
     ->render($self);
287
  $self->invalidate_version($js)
288
    ->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node)
289
    ->render($self);
286 290
}
287 291

  
288 292
#
289 293
# filters
290 294
#
291 295

  
292
sub load_requirement_spec {
293
  my ($self) = @_;
294
  $self->requirement_spec(SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id})->load || die "No such requirement spec");
295
}
296

  
297 296
sub load_requirement_spec_text_block {
298 297
  my ($self) = @_;
299 298
  $self->text_block(SL::DB::RequirementSpecTextBlock->new(id => $::form->{id})->load || die "No such requirement spec text block");
......
320 319
  return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted;
321 320
}
322 321

  
322
sub invalidate_version {
323
  my ($self, $js) = @_;
324

  
325
  $js           ||= SL::ClientJS->new;
326
  my $html        = $self->render('requirement_spec/_version', { output => 0 },
327
                                  requirement_spec => SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id} || $self->text_block->requirement_spec_id)->load);
328
  return $js->html('#requirement_spec_version', $html);
329
}
330

  
323 331
1;
SL/DB/RequirementSpec.pm
173 173
  return $ok ? ($copy, $version) : ();
174 174
}
175 175

  
176
sub invalidate_version {
177
  my ($self, %params) = @_;
178

  
179
  $::lxdebug->message(0, "Invalidate version called for id " . $self->id . " version " . $self->version_id);
180
  $::lxdebug->show_backtrace(1);
181

  
182
  return if !$self->id || !$self->version_id;
183
  $self->update_attributes(version_id => undef);
184
}
185

  
176 186
1;
SL/DB/RequirementSpecTextBlock.pm
2 2

  
3 3
use strict;
4 4

  
5
use List::MoreUtils qw(any);
6
use Rose::DB::Object::Helpers;
7
use Rose::DB::Object::Util;
8

  
5 9
use SL::DB::MetaSetup::RequirementSpecTextBlock;
6 10
use SL::DB::Manager::RequirementSpecTextBlock;
7 11
use SL::DB::Helper::ActsAsList;
......
11 15

  
12 16
__PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id output_position)]);
13 17

  
18
__PACKAGE__->before_save(\  &_before_save_invalidate_requirement_spec_version);
19
__PACKAGE__->before_delete(\&_before_delete_invalidate_requirement_spec_version);
20

  
14 21
sub validate {
15 22
  my ($self) = @_;
16 23

  
......
20 27
  return @errors;
21 28
}
22 29

  
30
sub _before_save_invalidate_requirement_spec_version {
31
  my ($self, %params) = @_;
32

  
33

  
34
  return 1 if !$self->requirement_spec_id;
35

  
36
  my %changed_columns = map { $_ => 1 } (Rose::DB::Object::Helpers::dirty_columns($self));
37

  
38
  $self->requirement_spec->invalidate_version
39
    if !Rose::DB::Object::Util::is_in_db($self) || any { $changed_columns{$_} } qw(title text position output_position);
40

  
41
  return 1;
42
}
43

  
44
sub _before_delete_invalidate_requirement_spec_version {
45
  my ($self, %params) = @_;
46

  
47
  $self->requirement_spec->invalidate_version if $self->requirement_spec_id;
48

  
49
  return 1;
50
}
51

  
23 52
1;

Auch abrufbar als: Unified diff