From e4a28a8d400a4dd07982fe827a47924bfada3947 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 12 Aug 2013 11:24:41 +0200 Subject: [PATCH] =?utf8?q?Pflichtenhefttextbl=C3=B6cke:=20Anordnung=20Bild?= =?utf8?q?er=20via=20Drag&Drop=20=C3=A4ndern=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RequirementSpecTextBlock.pm | 21 +++++++++++++++++-- js/requirement_spec.js | 14 +++++++++++++ .../_text_block.html | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index b5d831044..dc3d281c8 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -18,6 +18,8 @@ use SL::DB::RequirementSpecTextBlock; use SL::Helper::Flash; use SL::Locale::String; +use constant SORTABLE_PICTURE_LIST => 'kivi.requirement_spec.make_text_block_picture_lists_sortable'; + use Rose::Object::MakeMethods::Generic ( scalar => [ qw(text_block) ], @@ -48,7 +50,9 @@ sub action_ajax_list { $self->show_list(output_position => $new_where, id => $::form->{clicked_id}, set_type => 1) if ($new_where != ($current_where // -1)); - $self->render($self->js); + $self->js + ->run(SORTABLE_PICTURE_LIST()) + ->render($self); } sub action_ajax_add { @@ -102,6 +106,7 @@ sub action_ajax_create { $self->invalidate_version ->hide('#text-block-list-empty') ->replaceWith('#' . $::form->{form_prefix} . '_form', $html) + ->run(SORTABLE_PICTURE_LIST()) ->jstree->create_node('#tree', $insert_after ? ('#tb-' . $insert_after, 'after') : ('#tb-' . ($attributes->{output_position} == 0 ? 'front' : 'back'), 'last'), $node) ->jstree->select_node('#tree', '#tb-' . $self->text_block->id); $self->add_new_text_block_form(output_position => $self->text_block->output_position, insert_after_id => $self->text_block->id, requirement_spec_id => $self->text_block->requirement_spec_id) @@ -128,6 +133,7 @@ sub action_ajax_update { $self->invalidate_version ->remove('#' . $prefix . '_form') ->replaceWith('#text-block-' . $self->text_block->id, $html) + ->run(SORTABLE_PICTURE_LIST()) ->jstree->rename_node('#tree', '#tb-' . $self->text_block->id, $self->text_block->title) ->render($self); } @@ -221,7 +227,9 @@ sub action_dragged_and_dropped { } } - $self->js->render($self); + $self->js + ->run(SORTABLE_PICTURE_LIST()) + ->render($self); } sub action_ajax_copy { @@ -261,6 +269,7 @@ sub action_ajax_paste { my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block); $self->invalidate_version + ->run(SORTABLE_PICTURE_LIST()) ->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node) ->render($self); } @@ -372,6 +381,14 @@ sub action_ajax_paste_picture { $self->paste_picture($copied); } +sub action_reorder_pictures { + my ($self) = @_; + + SL::DB::RequirementSpecPicture->reorder_list(@{ $::form->{picture_id} || [] }); + + $self->render(\'', { type => 'json' }); +} + # # filters # diff --git a/js/requirement_spec.js b/js/requirement_spec.js index 4a6665050..f33e52e5a 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -243,6 +243,20 @@ ns.text_block_picture_popup_menu_hidden = function(opt) { return ns.handle_text_block_picture_popup_menu_markings(opt, false); }; +ns.make_text_block_picture_lists_sortable = function() { + kivi.run_once_for(".requirement-spec-text-block-picture-list", 'make-text-block-picture-list-sortable', function($elt) { + $elt.sortable({ + stop: function(event, ui) { + $.post('controller.pl?action=RequirementSpecTextBlock/reorder_pictures', { + 'picture_id[]': $($elt.sortable('toArray')).map(function(idx, str) { return str.replace('text-block-picture-', ''); }).toArray() + }); + return ui; + } + , distance: 5 + }); + }); +}; + // -------------------------------------------------------------------------------- // ------------------------------ sections and items ------------------------------ // -------------------------------------------------------------------------------- diff --git a/templates/webpages/requirement_spec_text_block/_text_block.html b/templates/webpages/requirement_spec_text_block/_text_block.html index 8102c57e4..860b83da5 100644 --- a/templates/webpages/requirement_spec_text_block/_text_block.html +++ b/templates/webpages/requirement_spec_text_block/_text_block.html @@ -12,7 +12,7 @@ [% END %] -