From 050a08313581b3185de2fce3ec18aafb787bcf88 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sun, 14 Dec 2014 15:02:22 +0200 Subject: [PATCH] unify usage of TableDnD --- ipf/admin/assets/js/admin.js | 29 +++++++++++++++++++ .../js => assets/vendor}/jquery.tablednd.js | 0 ipf/admin/form/widgets/orderedsettable.php | 26 ----------------- ipf/admin/templates/admin/items.html | 24 +-------------- 4 files changed, 30 insertions(+), 49 deletions(-) rename ipf/admin/{static/admin/js => assets/vendor}/jquery.tablednd.js (100%) diff --git a/ipf/admin/assets/js/admin.js b/ipf/admin/assets/js/admin.js index 01b0a77..9a26057 100644 --- a/ipf/admin/assets/js/admin.js +++ b/ipf/admin/assets/js/admin.js @@ -1,6 +1,7 @@ //= require ../vendor/jquery.js //= require ../vendor/jquery-ui/jquery-ui.custom.js //= require ../vendor/timepicker/jquery-ui-timepicker-addon.js +//= require ../vendor/jquery.tablednd.js $(function(){ $('.toggle-sidebar').on('change', function() { @@ -8,6 +9,34 @@ $(function(){ return false; }); + // reorder items + $('#items-grid.reorderable').tableDnD({ + onDragClass: "ItemsDragClass", + onDrop: function(table, row) { + var ids = []; + $('#items-grid .trsort').each(function(){ + ids.push(this.id); + }); + $.post('reorder/', { 'ids[]': ids }, function(data){}); + } + }); + + // reorder inlines + $('.orderable-set-table').each(function(){ + var $table = $(this), $form = $table.closest("form"), reorder = $table.data("reorder"); + $table.tableDnD({ + onDragClass: "ItemsDragClass", + onDrop: function(table, row) { + var i; + $form.find("[name='"+reorder+"[]']").remove(); + $table.find('tr[data-id]').each(function(){ + i = $("").attr("type", "hidden").attr("name", reorder+"[]").attr("value", $(this).data('id')); + $form.append(i); + }); + } + }); + }); + $('.dateinput').each(function(){ var opts = { dateFormat: $(this).data('format') || 'yy-mm-dd' diff --git a/ipf/admin/static/admin/js/jquery.tablednd.js b/ipf/admin/assets/vendor/jquery.tablednd.js similarity index 100% rename from ipf/admin/static/admin/js/jquery.tablednd.js rename to ipf/admin/assets/vendor/jquery.tablednd.js diff --git a/ipf/admin/form/widgets/orderedsettable.php b/ipf/admin/form/widgets/orderedsettable.php index 1bbd432..d448e82 100644 --- a/ipf/admin/form/widgets/orderedsettable.php +++ b/ipf/admin/form/widgets/orderedsettable.php @@ -36,32 +36,6 @@ class IPF_Admin_Form_Widget_OrderedSetTable extends IPF_Form_Widget_SetTable return $tr; } - public function extra_js() - { - $js = parent::extra_js(); - - $js[] = ''; - $js[] = ''; - return $js; - } - public function valueFromFormData($name, $data) { if (!isset($data[$name])) diff --git a/ipf/admin/templates/admin/items.html b/ipf/admin/templates/admin/items.html index cf50165..2e3247e 100644 --- a/ipf/admin/templates/admin/items.html +++ b/ipf/admin/templates/admin/items.html @@ -47,7 +47,7 @@
{block table} - +
{foreach $header as $h} @@ -88,25 +88,3 @@ {/block} -{block scripts} -{if $orderable} - - -{/if} -{/block} - -- 2.49.0