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) ],
$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 {
$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)
$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);
}
}
}
- $self->js->render($self);
+ $self->js
+ ->run(SORTABLE_PICTURE_LIST())
+ ->render($self);
}
sub action_ajax_copy {
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);
}
$self->paste_picture($copied);
}
+sub action_reorder_pictures {
+ my ($self) = @_;
+
+ SL::DB::RequirementSpecPicture->reorder_list(@{ $::form->{picture_id} || [] });
+
+ $self->render(\'', { type => 'json' });
+}
+
#
# filters
#
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 ------------------------------
// --------------------------------------------------------------------------------