Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e86e30de

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID e86e30de944c4bbe4b42f43d933e0a28a83408dd
  • Vorgänger e2a8a58a
  • Nachfolger 0eb8e223

Pflichtenheftitems und Abschnitte bearbeiten

Unterschiede anzeigen:

SL/Controller/RequirementSpecItem.pm
112 112
  $self->render($js);
113 113
}
114 114

  
115
sub action_ajax_add {
116
  my ($self, %params) = @_;
117

  
118
  die "TODO: add action";
119
}
120

  
115 121
sub action_ajax_edit {
116 122
  my ($self, %params) = @_;
117 123

  
......
119 125

  
120 126
  my $js = SL::ClientJS->new;
121 127

  
122
  die "TODO: edit section" if $self->item->get_type =~ m/section/;
123

  
124 128
  if (!$self->visible_section || ($self->visible_section->id != $self->item->get_section->id)) {
129
    # Show section/item to edit if it is not visible.
130

  
125 131
    my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item);
126 132
    $js->html('#column-content', $html);
127 133
  }
128 134

  
129
  if ($self->item->get_type =~ m/function-block/) {
130
    my $create_item = sub {
131
      [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ]
132
    };
133
    my @dependencies =
134
      map { [ $_->fb_number . ' ' . $_->title,
135
              [ map { ( $create_item->($_),
136
                        map { $create_item->($_, '->') } @{ $_->sorted_children })
137
                    } @{ $_->sorted_children } ] ]
138
          } @{ $self->item->requirement_spec->sections };
139

  
140
    my @selected_dependencies = map { $_->id } @{ $self->item->dependencies };
141

  
142
    my $html                  = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies);
143
    my $id_base               = $self->item->get_type . '-' . $self->item->id;
144
    my $content_top_id        = '#' . $self->item->get_type . '-content-top-' . $self->item->id;
145

  
146
    $js->hide($content_top_id)
147
       ->remove("#edit_${id_base}_form")
148
       ->insertAfter($html, $content_top_id)
135
  if ($self->item->get_type =~ m/section/) {
136
    # Edit the section header, not an item.
137
    my $html = $self->render('requirement_spec_item/_section_form', { output => 0 });
138

  
139
    $js->hide('#section-header-' . $self->item->id)
140
       ->remove("#edit_section_form")
141
       ->insertAfter($html, '#section-header-' . $self->item->id)
149 142
       ->jstree->select_node('#tree', '#fb-' . $self->item->id)
150
       ->focus("#edit_${id_base}_description")
151
       ->val('#current_content_type', $self->item->get_type)
152
       ->val('#current_content_id', $self->item->id)
143
       ->focus("#edit_section_title")
144
       ->val('#current_content_type', 'section')
145
       ->val('#current_content_id',   $self->item->id)
153 146
       ->render($self);
147
    return;
154 148
  }
149

  
150
  # Edit a function block or a sub function block
151
  my $create_item = sub {
152
    [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ]
153
  };
154
  my @dependencies =
155
    map { [ $_->fb_number . ' ' . $_->title,
156
            [ map { ( $create_item->($_),
157
                      map { $create_item->($_, '->') } @{ $_->sorted_children })
158
                  } @{ $_->sorted_children } ] ]
159
        } @{ $self->item->requirement_spec->sections };
160

  
161
  my @selected_dependencies = map { $_->id } @{ $self->item->dependencies };
162

  
163
  my $html                  = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies);
164
  my $id_base               = 'edit_function_block_' . $self->item->id;
165
  my $content_top_id        = '#' . $self->item->get_type . '-content-top-' . $self->item->id;
166

  
167
  $js->hide($content_top_id)
168
     ->remove("#${id_base}_form")
169
     ->insertAfter($html, $content_top_id)
170
     ->jstree->select_node('#tree', '#fb-' . $self->item->id)
171
     ->focus("#${id_base}_description")
172
     ->val('#current_content_type', $self->item->get_type)
173
     ->val('#current_content_id', $self->item->id)
174
     ->render($self);
155 175
}
156 176

  
157 177
sub action_ajax_update {
......
170 190

  
171 191
  $self->item->save;
172 192

  
173
  my $id_prefix    = $self->item->get_type eq 'function-block' ? '' : 'sub-';
193
  my $type = $self->item->get_type;
194

  
195
  if ($type eq 'section') {
196
    # Updated section, now update section header.
197

  
198
    my $html = $self->render('requirement_spec_item/_section_header', { output => 0 }, requirement_spec_item => $self->item);
199

  
200
    return SL::ClientJS->new
201
      ->remove('#edit_section_form')
202
      ->html('#section-header-' . $self->item->id, $html)
203
      ->show('#section-header-' . $self->item->id)
204
      ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item))
205
      ->render($self);
206
  }
207

  
208
  # Updated function block or sub function block. Update (sub)
209
  # function block and potentially the bottom of the parent function
210
  # block.
211

  
212
  my $id_prefix    = $type eq 'function-block' ? '' : 'sub-';
174 213
  my $html_top     = $self->render('requirement_spec_item/_function_block_content_top',    { output => 0 }, requirement_spec_item => $self->item, id_prefix => $id_prefix);
175 214
  $id_prefix      .= 'function-block-content-';
176 215

  
......
180 219
    ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item));
181 220

  
182 221
  $self->replace_bottom($js, $self->item, id_prefix => $id_prefix);
183
  $self->replace_bottom($js, $self->item->parent) if $self->item->get_type eq 'sub-function-block';
222
  $self->replace_bottom($js, $self->item->parent) if $type eq 'sub-function-block';
184 223

  
185 224
  $js->render($self);
186 225
}

Auch abrufbar als: Unified diff