-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from wearejust/feature/enable_drag_n_drop
Feature: Enable drag ’n drop feature
- Loading branch information
Showing
6 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
$(function() { | ||
$('.sonata-ba-list tbody').draggableTable(); | ||
}); | ||
|
||
$.fn.draggableTable = function (settings) { | ||
$(this).each(function (index, item) { | ||
item = $(item); | ||
var instance = item.data('DraggableTable'); | ||
if (!instance) { | ||
item.data('DraggableTable', new DraggableTable(this, settings)); | ||
} | ||
}); | ||
}; | ||
|
||
var DraggableTable = function () { | ||
this.init.apply(this, arguments); | ||
}; | ||
|
||
DraggableTable.prototype.init = function (node, settings) { | ||
$(node).sortable({ | ||
'handle': '.js-sortable-move', | ||
'axis': 'y', | ||
'cancel': 'input,textarea,select,option,button:not(.js-sortable-move)', | ||
'tolerance': 'pointer', | ||
'revert': 100, | ||
'cursor': 'move', | ||
'zIndex': 1, | ||
'helper': function(e, ui) { | ||
ui.css('width','100%'); | ||
ui.children().each(function() { | ||
var item = $(this); | ||
item.width(item.width()); | ||
}); | ||
return ui; | ||
}, | ||
'update': function(event, ui) { | ||
var moved = $(ui.item).find('.js-sortable-move'); | ||
var newPosition = ui.item.index(); | ||
|
||
$.ajax({ | ||
'type': 'GET', | ||
'url': moved.data('url').replace('NEW_POSITION', newPosition), | ||
'dataType': 'json', | ||
'success': function(data) { | ||
$(document).trigger("pixSortableBehaviorBundle.success", [data]); | ||
}, | ||
'error': function(data) { | ||
$(document).trigger("pixSortableBehaviorBundle.error",[data]); | ||
} | ||
}); | ||
|
||
} | ||
}).disableSelection(); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% if admin.isGranted('EDIT', object) and admin.hasRoute('edit') %} | ||
{% set current_position = currentObjectPosition(object) %} | ||
{% set last_position = lastPosition(object) %} | ||
{% set enable_top_bottom_buttons = field_description.options.actions.move.enable_top_bottom_buttons ?? true %} | ||
|
||
|
||
<span class="btn btn-sm btn-default js-sortable-move" data-url="{{ admin.generateObjectUrl('move', object, {'position': 'NEW_POSITION'}) }}"> | ||
<i class="fa fa-arrows"></i> | ||
</span> | ||
|
||
{% if enable_top_bottom_buttons and current_position < last_position %} | ||
<a class="btn btn-sm btn-default" href="{{ admin.generateObjectUrl('move', object, {'position': 'bottom'}) }}" title="{{ 'move_to_bottom'|trans }}"> | ||
<i class="fa fa-angle-double-down"></i> | ||
</a> | ||
{% endif %} | ||
|
||
{% if enable_top_bottom_buttons and current_position > 0 %} | ||
<a class="btn btn-sm btn-default" href="{{ admin.generateObjectUrl('move', object, {'position': 'top'}) }}" title="{{ 'move_to_top'|trans }}"> | ||
<i class="fa fa-angle-double-up"></i> | ||
</a> | ||
{% endif %} | ||
|
||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters