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

  
templates/webpages/requirement_spec/show.html
1 1
[%- USE JSON -%][%- USE HTML %][%- USE L %][%- USE LxERP %][%- USE P -%]
2 2

  
3
[%- INCLUDE 'common/flash.html' %]
4

  
3 5
<h1>[%- HTML.escape(SELF.requirement_spec.displayable_name('format', 'with_customer')) %]
4 6
  [% LxERP.t8("for") %]
5 7
  [% HTML.escape(SELF.requirement_spec.customer.displayable_name) -%]
templates/webpages/requirement_spec_text_block/_form.html
13 13
 [% L.hidden_tag(id_base _ '_id',                  SELF.text_block.id) %]
14 14
 [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.text_block.requirement_spec_id) %]
15 15
 [% L.hidden_tag(id_base _ '.output_position',     SELF.text_block.output_position) %]
16
 [% IF insert_after %]
17
  [% L.hidden_tag(id_base _ '.insert_after',       insert_after) %]
18
 [% END %]
16 19

  
17 20
 <table>
18 21
  <tr>

Auch abrufbar als: Unified diff