Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f10e650c

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID f10e650c26ed930ce04f4ca1bd3f21d0036e5ba4
  • Vorgänger e2f753a4
  • Nachfolger e5ced2fb

Textblöcke anlegen :)

Unterschiede anzeigen:

SL/Controller/RequirementSpecTextBlock.pm
54 54
  $self->render($js);
55 55
}
56 56

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

  
60
  my $js            = SL::ClientJS->new;
61

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

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

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

  
72
  $self->text_block(SL::DB::RequirementSpecTextBlock->new(
73
    requirement_spec_id => $::form->{requirement_spec_id},
74
    output_position     => $::form->{output_position},
75
  ));
76

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

  
80
  $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'))
81
     ->focus('#' . $id_base . '_title')
82
     ->render($self);
83
}
84

  
57 85
sub action_ajax_edit {
58 86
  my ($self) = @_;
59 87

  
......
79 107
     ->render($self);
80 108
}
81 109

  
82
sub action_ajax_update {
110
sub action_ajax_create {
83 111
  my ($self, %params) = @_;
84 112

  
85
  my $prefix     = $::form->{form_prefix} || 'text_block';
86
  my $attributes = $::form->{$prefix}     || {};
113
  my $attributes   = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
114
  my $insert_after = delete $attributes->{insert_after};
87 115

  
88
  foreach (qw(requirement_spec_id output_position)) {
89
    delete $attributes->{$_} if !defined $attributes->{$_};
90
  }
116
  my @errors = $self->text_block(SL::DB::RequirementSpecTextBlock->new(%{ $attributes }))->validate;
117
  return SL::ClientJS->new->error(@errors)->render($self) if @errors;
91 118

  
92
  $self->text_block->update_attributes(%{ $attributes });
119
  $self->text_block->save;
120
  $self->text_block->add_to_list(position => 'after', reference => $insert_after) if $insert_after;
93 121

  
94 122
  my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
123
  my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block);
95 124

  
96 125
  SL::ClientJS->new
97
    ->remove('#' . $prefix . '_form')
98
    ->replaceWith('#text-block-' . $self->text_block->id, $html)
99
    ->jstree->rename_node('#tree', '#tb-' . $self->text_block->id, $self->text_block->title)
126
    ->replaceWith('#' . $::form->{form_prefix} . '_form', $html)
127
    ->jstree->create_node('#tree', $insert_after ? ('#tb-' . $insert_after, 'after') : ('#tb-' . ($attributes->{output_position} == 0 ? 'front' : 'back'), 'last'), $node)
100 128
    ->render($self);
101 129
}
102 130

  
103
sub action_ajax_create {
104
  # TODO: ajax_create
131
sub action_ajax_update {
105 132
  my ($self, %params) = @_;
106 133

  
107 134
  my $prefix     = $::form->{form_prefix} || 'text_block';
108 135
  my $attributes = $::form->{$prefix}     || {};
109 136

  
110
  foreach (qw(requirement_spec_id output_position)) {
137
  foreach (qw(requirement_spec_id output_position position)) {
111 138
    delete $attributes->{$_} if !defined $attributes->{$_};
112 139
  }
113 140

  
114
  $self->text_block->update_attributes(%{ $attributes });
141
  my @errors = $self->text_block->assign_attributes(%{ $attributes })->validate;
142
  return SL::ClientJS->new->error(@errors)->render($self) if @errors;
143

  
144
  $self->text_block->save;
115 145

  
116 146
  my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
117 147

  
......
141 171
     ->render($self);
142 172
}
143 173

  
144
sub action_ajax_add {
145
  my ($self) = @_;
146

  
147
  my $js = SL::ClientJS->new;
148

  
149
  my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
150
  my $new_where     = $self->output_position_from_id($::form->{id})                                                  // $::form->{output_position};
151

  
152
  if ($new_where != $current_where) {
153
    my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]);
154
    my $html        = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
155

  
156
    $js->html('#column-content', $html);
157
  }
158

  
159
  $self->text_block(SL::DB::RequirementSpecTextBlock->new(
160
    requirement_spec_id => $::form->{requirement_spec_id},
161
    output_position     => $::form->{output_position},
162
  ));
163

  
164
  my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
165
  my $html    = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base);
166

  
167
  $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'))
168
     ->focus('#' . $id_base . '_title')
169
     ->render($self);
170
}
171

  
172 174
sub action_dragged_and_dropped {
173 175
  my ($self)       = @_;
174 176

  

Auch abrufbar als: Unified diff