Pflichtenhefttextblöcke: Anordnung Bilder via Drag&Drop ändern können
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 12 Aug 2013 09:24:41 +0000 (11:24 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:09:11 +0000 (13:09 +0200)
SL/Controller/RequirementSpecTextBlock.pm
js/requirement_spec.js
templates/webpages/requirement_spec_text_block/_text_block.html

index b5d8310..dc3d281 100644 (file)
@@ -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
 #
index 4a66650..f33e52e 100644 (file)
@@ -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 ------------------------------
 // --------------------------------------------------------------------------------
index 8102c57..860b83d 100644 (file)
@@ -12,7 +12,7 @@
   </div>
  [% END %]
 
- <div class="clearfix" id="text-block-[% HTML.escape(text_block.id) %]-pictures"[% UNLESS text_block.pictures.as_list.size %] style="display: none"[% END %]>
+ <div class="clearfix requirement-spec-text-block-picture-list" id="text-block-[% HTML.escape(text_block.id) %]-pictures" [% UNLESS text_block.pictures.as_list.size %] style="display: none"[% END %]>
   [% FOREACH picture = text_block.pictures_sorted %]
    [% INCLUDE 'requirement_spec_text_block/_text_block_picture.html' picture=picture %]
   [% END %]