From: Moritz Bunkus Date: Thu, 7 Mar 2013 12:10:00 +0000 (+0100) Subject: Textblöcke anlegen :) X-Git-Tag: release-3.2.0beta~467^2~239 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f10e650c26ed930ce04f4ca1bd3f21d0036e5ba4;p=kivitendo-erp.git Textblöcke anlegen :) --- diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index 4b42841cf..e7964a6a1 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -54,6 +54,34 @@ sub action_ajax_list { $self->render($js); } +sub action_ajax_add { + my ($self) = @_; + + my $js = SL::ClientJS->new; + + my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; + my $new_where = $self->output_position_from_id($::form->{id}) // $::form->{output_position}; + + if ($new_where != $current_where) { + my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]); + my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where); + + $js->html('#column-content', $html); + } + + $self->text_block(SL::DB::RequirementSpecTextBlock->new( + requirement_spec_id => $::form->{requirement_spec_id}, + output_position => $::form->{output_position}, + )); + + my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000); + my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $::form->{id}); + + $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list')) + ->focus('#' . $id_base . '_title') + ->render($self); +} + sub action_ajax_edit { my ($self) = @_; @@ -79,39 +107,41 @@ sub action_ajax_edit { ->render($self); } -sub action_ajax_update { +sub action_ajax_create { my ($self, %params) = @_; - my $prefix = $::form->{form_prefix} || 'text_block'; - my $attributes = $::form->{$prefix} || {}; + my $attributes = $::form->{ $::form->{form_prefix} } || die "Missing attributes"; + my $insert_after = delete $attributes->{insert_after}; - foreach (qw(requirement_spec_id output_position)) { - delete $attributes->{$_} if !defined $attributes->{$_}; - } + my @errors = $self->text_block(SL::DB::RequirementSpecTextBlock->new(%{ $attributes }))->validate; + return SL::ClientJS->new->error(@errors)->render($self) if @errors; - $self->text_block->update_attributes(%{ $attributes }); + $self->text_block->save; + $self->text_block->add_to_list(position => 'after', reference => $insert_after) if $insert_after; my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block); + my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block); SL::ClientJS->new - ->remove('#' . $prefix . '_form') - ->replaceWith('#text-block-' . $self->text_block->id, $html) - ->jstree->rename_node('#tree', '#tb-' . $self->text_block->id, $self->text_block->title) + ->replaceWith('#' . $::form->{form_prefix} . '_form', $html) + ->jstree->create_node('#tree', $insert_after ? ('#tb-' . $insert_after, 'after') : ('#tb-' . ($attributes->{output_position} == 0 ? 'front' : 'back'), 'last'), $node) ->render($self); } -sub action_ajax_create { - # TODO: ajax_create +sub action_ajax_update { my ($self, %params) = @_; my $prefix = $::form->{form_prefix} || 'text_block'; my $attributes = $::form->{$prefix} || {}; - foreach (qw(requirement_spec_id output_position)) { + foreach (qw(requirement_spec_id output_position position)) { delete $attributes->{$_} if !defined $attributes->{$_}; } - $self->text_block->update_attributes(%{ $attributes }); + my @errors = $self->text_block->assign_attributes(%{ $attributes })->validate; + return SL::ClientJS->new->error(@errors)->render($self) if @errors; + + $self->text_block->save; my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block); @@ -141,34 +171,6 @@ sub action_ajax_delete { ->render($self); } -sub action_ajax_add { - my ($self) = @_; - - my $js = SL::ClientJS->new; - - my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; - my $new_where = $self->output_position_from_id($::form->{id}) // $::form->{output_position}; - - if ($new_where != $current_where) { - my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]); - my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where); - - $js->html('#column-content', $html); - } - - $self->text_block(SL::DB::RequirementSpecTextBlock->new( - requirement_spec_id => $::form->{requirement_spec_id}, - output_position => $::form->{output_position}, - )); - - my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000); - my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base); - - $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list')) - ->focus('#' . $id_base . '_title') - ->render($self); -} - sub action_dragged_and_dropped { my ($self) = @_; diff --git a/templates/webpages/requirement_spec/show.html b/templates/webpages/requirement_spec/show.html index 759add13f..53fb52d0f 100644 --- a/templates/webpages/requirement_spec/show.html +++ b/templates/webpages/requirement_spec/show.html @@ -1,5 +1,7 @@ [%- USE JSON -%][%- USE HTML %][%- USE L %][%- USE LxERP %][%- USE P -%] +[%- INCLUDE 'common/flash.html' %] +

[%- HTML.escape(SELF.requirement_spec.displayable_name('format', 'with_customer')) %] [% LxERP.t8("for") %] [% HTML.escape(SELF.requirement_spec.customer.displayable_name) -%] diff --git a/templates/webpages/requirement_spec_text_block/_form.html b/templates/webpages/requirement_spec_text_block/_form.html index 40f430721..5637b2f97 100644 --- a/templates/webpages/requirement_spec_text_block/_form.html +++ b/templates/webpages/requirement_spec_text_block/_form.html @@ -13,6 +13,9 @@ [% L.hidden_tag(id_base _ '_id', SELF.text_block.id) %] [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.text_block.requirement_spec_id) %] [% L.hidden_tag(id_base _ '.output_position', SELF.text_block.output_position) %] + [% IF insert_after %] + [% L.hidden_tag(id_base _ '.insert_after', insert_after) %] + [% END %]