Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 603481b2

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 603481b2eab49e4e70b43cc9cec269c426fffb9d
  • Vorgänger d90408d8
  • Nachfolger 8e6416fb

Refactoring

Unterschiede anzeigen:

SL/Controller/RequirementSpecTextBlock.pm
17 17
use Rose::Object::MakeMethods::Generic
18 18
(
19 19
  scalar                  => [ qw(text_block) ],
20
  'scalar --get_set_init' => [ qw(predefined_texts) ],
20
  'scalar --get_set_init' => [ qw(predefined_texts js) ],
21 21
);
22 22

  
23 23
__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete ajax_flag dragged_and_dropped ajax_copy)]);
......
42 42

  
43 43
  # $::lxdebug->message(0, "cur $current_where new $new_where");
44 44

  
45
  my $js = SL::ClientJS->new;
46

  
47 45
  if (!defined($current_where) || ($new_where != $current_where)) {
48 46
    my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]);
49 47
    my $html        = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
50 48

  
51
    $js->html('#column-content', $html)
49
    $self->js
50
       ->html('#column-content', $html)
52 51
       ->val('#current_content_type', 'text-blocks-' . (0 == $new_where ? 'front' : 'back'))
53 52
       ->val('#current_content_id',   $::form->{clicked_id});
54 53
  }
55 54

  
56
  $self->render($js);
55
  $self->render($self->js);
57 56
}
58 57

  
59 58
sub action_ajax_add {
60 59
  my ($self) = @_;
61 60

  
62
  my $js            = SL::ClientJS->new;
63

  
64 61
  my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
65 62
  my $new_where     = $self->output_position_from_id($::form->{id})                                                  // $::form->{output_position};
66 63

  
......
68 65
    my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]);
69 66
    my $html        = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
70 67

  
71
    $js->html('#column-content', $html);
68
    $self->js->html('#column-content', $html);
72 69
  }
73 70

  
74 71
  $self->text_block(SL::DB::RequirementSpecTextBlock->new(
......
79 76
  my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
80 77
  my $html    = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $::form->{id});
81 78

  
82
  $self->invalidate_version($js)
79
  $self->invalidate_version
83 80
     ->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'))
84 81
     ->focus('#' . $id_base . '_title')
85 82
     ->render($self);
......
88 85
sub action_ajax_edit {
89 86
  my ($self) = @_;
90 87

  
91
  my $js = SL::ClientJS->new;
92

  
93 88
  my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
94 89
  if ($self->text_block->output_position != $current_where) {
95 90
    my $text_blocks = $self->text_block->get_full_list;
96 91
    my $html        = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $self->text_block->output_position);
97 92

  
98
    $js->html('#column-content', $html)
93
    $self->js
94
       ->html('#column-content', $html)
99 95
       ->val('#current_content_type', 'text-block')
100 96
       ->val('#current_content_id',   $self->text_block->id);
101 97
  }
102 98

  
103 99
  my $html = $self->render('requirement_spec_text_block/_form', { output => 0 });
104 100

  
105
  $js->hide('#text-block-' . $self->text_block->id)
101
  $self->js
102
     ->hide('#text-block-' . $self->text_block->id)
106 103
     ->remove('#edit_text_block_' . $self->text_block->id . '_form')
107 104
     ->insertAfter($html, '#text-block-' . $self->text_block->id)
108 105
     ->jstree->select_node('#tree', '#tb-' . $self->text_block->id)
......
159 156
sub action_ajax_delete {
160 157
  my ($self) = @_;
161 158

  
162
  my $js = SL::ClientJS->new;
163

  
164 159
  my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
165 160
  if ($self->text_block->output_position == $current_where) {
166
    $js->remove('#edit_text_block_' . $self->text_block->id . '_form')
161
    $self->js
162
       ->remove('#edit_text_block_' . $self->text_block->id . '_form')
167 163
       ->remove('#text-block-' . $self->text_block->id);
168 164

  
169
    $js->show('#text-block-list-empty') if 1 == scalar @{ $self->text_block->get_full_list };
165
    $self->js->show('#text-block-list-empty') if 1 == scalar @{ $self->text_block->get_full_list };
170 166
  }
171 167

  
172 168
  $self->text_block->delete;
173 169

  
174
  $self->invalidate_version($js)
170
  $self->invalidate_version
175 171
     ->jstree->delete_node('#tree', '#tb-' . $self->text_block->id)
176 172
     ->render($self);
177 173
}
......
212 208
  my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
213 209
  my $new_where     = $self->text_block->output_position;
214 210
  my $id            = $self->text_block->id;
215
  my $js            = SL::ClientJS->new;
216 211

  
217 212
  # $::lxdebug->message(0, "old $old_where current $current_where new $new_where current_CID " . $::form->{current_content_id} . ' selfid ' . $self->text_block->id);
218 213
  if (($old_where != $new_where) && ($::form->{current_content_id} == $self->text_block->id)) {
......
221 216
    my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where ]);
222 217
    my $html        = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
223 218

  
224
    $js->val('#current_content_type', 'text-blocks-' . ($new_where == 0 ? 'front' : 'back'))
219
    $self->js
220
       ->val('#current_content_type', 'text-blocks-' . ($new_where == 0 ? 'front' : 'back'))
225 221
       ->html('#column-content', $html);
226 222

  
227 223
  } else {
228 224
    if ($old_where == $current_where) {
229
      $js->remove('#text-block-' . $self->text_block->id);
225
      $self->js->remove('#text-block-' . $self->text_block->id);
230 226

  
231 227
      if (0 == scalar(@{ SL::DB::Manager::RequirementSpecTextBlock->get_all(where => [ requirement_spec_id => $self->text_block->requirement_spec_id, output_position => $current_where ]) })) {
232
        $js->show('#text-block-list-empty');
228
        $self->js->show('#text-block-list-empty');
233 229
      }
234 230
    }
235 231

  
236 232
    if ($new_where == $current_where) {
237
      $js->hide('#text-block-list-empty');
233
      $self->js->hide('#text-block-list-empty');
238 234

  
239 235
      my $html             = "" . $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
240 236
      $html                =~ s/^\s+//;
241 237
      my $prior_text_block = $self->text_block->get_previous_in_list;
242 238

  
243 239
      if ($prior_text_block) {
244
        $js->insertAfter($html, '#text-block-' . $prior_text_block->id);
240
        $self->js->insertAfter($html, '#text-block-' . $prior_text_block->id);
245 241
      } else {
246
        $js->prependTo($html, '#text-block-list');
242
        $self->js->prependTo($html, '#text-block-list');
247 243
      }
248 244
    }
249 245
  }
250 246

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

  
......
269 265
      ->render($self);
270 266
  }
271 267

  
272
  my $js                      = SL::ClientJS->new;
273 268
  my $current_output_position = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type});
274 269
  my $new_output_position     = $::form->{id} ? $self->output_position_from_id($::form->{id}) : $::form->{output_position};
275 270
  my $front_back              = 0 == $new_output_position ? 'front' : 'back';
......
280 275

  
281 276
  if ($current_output_position == $new_output_position) {
282 277
    my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
283
    $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'));
278
    $self->js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'));
284 279
  }
285 280

  
286 281
  my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block);
287
  $self->invalidate_version($js)
282
  $self->invalidate_version
288 283
    ->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node)
289 284
    ->render($self);
290 285
}
......
319 314
  return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted;
320 315
}
321 316

  
317
sub init_js {
318
  my ($self) = @_;
319
  $self->js(SL::ClientJS->new);
320
}
321

  
322 322
sub invalidate_version {
323
  my ($self, $js) = @_;
323
  my ($self) = @_;
324 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);
325
  my $html   = $self->render('requirement_spec/_version', { output => 0 },
326
                             requirement_spec => SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id} || $self->text_block->requirement_spec_id)->load);
327
  return $self->js->html('#requirement_spec_version', $html);
329 328
}
330 329

  
331 330
1;

Auch abrufbar als: Unified diff