2012-05-09 19:14:34 +02:00
|
|
|
(function($) {
|
2012-05-28 16:26:33 +02:00
|
|
|
$.entwine('ss', function($) {
|
|
|
|
$('.ss-gridfield .gridfield-sortablerows input').entwine({
|
2015-09-07 01:45:00 +02:00
|
|
|
PageSort: false,
|
|
|
|
|
2012-05-28 16:26:33 +02:00
|
|
|
onmatch: function() {
|
|
|
|
var self=this;
|
|
|
|
var refCheckbox=$(this);
|
|
|
|
var gridField=this.getGridField();
|
2013-05-26 01:40:14 +02:00
|
|
|
var form=gridField.closest('form');
|
2015-09-07 01:45:00 +02:00
|
|
|
var pageArrows=gridField.find('.gridfield-sortablerows-movepage .sortablerows-psort-arrow');
|
2012-05-28 16:26:33 +02:00
|
|
|
|
|
|
|
if($(this).is(':checked')) {
|
|
|
|
gridField.find('table').addClass('dragSorting');
|
|
|
|
}else {
|
|
|
|
gridField.find('table').removeClass('dragSorting');
|
|
|
|
}
|
|
|
|
|
|
|
|
gridField.find('tbody').sortable({
|
|
|
|
opacity: 0.6,
|
|
|
|
disabled: ($(this).is(':checked')==false),
|
2015-09-07 01:45:00 +02:00
|
|
|
start: function(event, ui) {
|
2015-09-07 01:48:10 +02:00
|
|
|
pageArrows.show();
|
2015-09-08 14:56:21 +02:00
|
|
|
pageArrows.redraw();
|
2015-09-07 01:45:00 +02:00
|
|
|
pageArrows.startMoveTracking();
|
|
|
|
},
|
|
|
|
stop: function(event, ui) {
|
|
|
|
pageArrows.stopMoveTracking();
|
|
|
|
pageArrows.hide();
|
|
|
|
},
|
|
|
|
sort: function(event, ui) {
|
2015-09-07 01:48:10 +02:00
|
|
|
pageArrows.moveTracking(event, ui);
|
2015-09-07 01:45:00 +02:00
|
|
|
},
|
2012-05-28 16:26:33 +02:00
|
|
|
update: function(event, ui) {
|
2015-09-07 01:45:00 +02:00
|
|
|
if(self.getPageSort()) {
|
|
|
|
self.setPageSort(false);
|
2013-04-27 01:25:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-28 16:26:33 +02:00
|
|
|
var gridItems=gridField.getItems();
|
2015-08-29 19:54:46 +02:00
|
|
|
|
|
|
|
gridItems.removeClass('first last odd even');
|
|
|
|
gridItems.first().addClass('first');
|
|
|
|
gridItems.last().addClass('last');
|
|
|
|
gridItems.filter(':even').addClass('odd');
|
|
|
|
gridItems.filter(':odd').addClass('even');
|
|
|
|
|
|
|
|
var dataRows=[];
|
2013-07-19 01:54:33 +02:00
|
|
|
var button=refCheckbox.parent().find('.sortablerows-savesort');
|
2012-05-28 16:26:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
for(var i=0;i<gridItems.length;i++) {
|
|
|
|
dataRows[i]=$(gridItems[i]).data('id');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self._makeRequest({data: [
|
|
|
|
{
|
|
|
|
name: button.attr('name'),
|
|
|
|
value: button.val()
|
|
|
|
},
|
|
|
|
{
|
2012-09-10 05:38:00 +02:00
|
|
|
name: 'ItemIDs',
|
2012-05-28 16:26:33 +02:00
|
|
|
value: dataRows
|
|
|
|
}
|
2013-05-26 01:40:14 +02:00
|
|
|
]},function() {
|
|
|
|
form.removeClass('loading');
|
|
|
|
});
|
2012-05-15 17:46:03 +02:00
|
|
|
}
|
2015-11-30 20:53:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if(refCheckbox.hasClass('gridfield-sortablerows-noselection') || $(this).is(':checked')) {
|
|
|
|
gridField.find('tbody').disableSelection();
|
|
|
|
}
|
2012-05-28 16:26:33 +02:00
|
|
|
},
|
2012-05-17 14:56:16 +02:00
|
|
|
|
2012-05-28 16:26:33 +02:00
|
|
|
onchange: function(e) {
|
|
|
|
var gridField=this.getGridField();
|
|
|
|
gridField.find('tbody').sortable('option', 'disabled', ($(this).is(':checked')==false));
|
|
|
|
gridField.setState('GridFieldSortableRows', {sortableToggle: $(this).is(':checked')});
|
|
|
|
|
|
|
|
|
2013-07-19 01:54:33 +02:00
|
|
|
var button=$(this).parent().find('.sortablerows-toggle');
|
2012-05-28 16:26:33 +02:00
|
|
|
gridField.reload({data: [{name: button.attr('name'), value: button.val()}]});
|
|
|
|
},
|
2012-05-17 14:56:16 +02:00
|
|
|
|
2012-05-28 16:26:33 +02:00
|
|
|
_makeRequest: function(ajaxOpts, callback) {
|
|
|
|
var gridField=this.getGridField();
|
2015-09-07 01:45:00 +02:00
|
|
|
var form = gridField.closest('form');
|
2012-05-28 16:26:33 +02:00
|
|
|
|
2013-05-26 01:40:14 +02:00
|
|
|
form.addClass('loading');
|
|
|
|
|
2012-05-28 16:26:33 +02:00
|
|
|
ajaxOpts.data = ajaxOpts.data.concat(form.find(':input').serializeArray());
|
|
|
|
|
|
|
|
// Include any GET parameters from the current URL, as the view state might depend on it.
|
|
|
|
// For example, a list prefiltered through external search criteria might be passed to GridField.
|
|
|
|
if(window.location.search) {
|
|
|
|
ajaxOpts.data = window.location.search.replace(/^\?/, '') + '&' + $.param(ajaxOpts.data);
|
2012-05-17 14:56:16 +02:00
|
|
|
}
|
2012-05-28 16:26:33 +02:00
|
|
|
|
|
|
|
$.ajax($.extend({}, {
|
|
|
|
headers: {"X-Pjax" : 'CurrentField'},
|
|
|
|
type: "POST",
|
|
|
|
url: gridField.data('url'),
|
|
|
|
dataType: 'html',
|
|
|
|
success: callback,
|
|
|
|
error: function(e) {
|
|
|
|
alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION'));
|
|
|
|
}
|
|
|
|
}, ajaxOpts));
|
|
|
|
}
|
|
|
|
});
|
2015-09-07 01:45:00 +02:00
|
|
|
|
|
|
|
$('.ss-gridfield .gridfield-sortablerows-movepage .sortablerows-psort-arrow').entwine({
|
|
|
|
ArrowIcon: null,
|
|
|
|
|
|
|
|
onmatch: function() {
|
|
|
|
var gridField=this.getGridField();
|
|
|
|
var sortableCheckbox=gridField.find('.gridfield-sortablerows input');
|
|
|
|
var self=$(this);
|
|
|
|
|
2015-10-09 15:20:23 +02:00
|
|
|
if($(this).hasClass('sortablerows-prev-page') && (gridField.find('.ss-gridfield-previouspage').length==0 || gridField.find('.ss-gridfield-previouspage').is(':disabled'))) {
|
2015-09-07 01:45:00 +02:00
|
|
|
$(this).remove();
|
|
|
|
return;
|
2015-10-09 15:20:23 +02:00
|
|
|
}else if($(this).hasClass('sortablerows-next-page') && (gridField.find('.ss-gridfield-nextpage').length==0 || gridField.find('.ss-gridfield-nextpage').is(':disabled'))) {
|
2015-09-07 01:45:00 +02:00
|
|
|
$(this).remove();
|
|
|
|
return;
|
2015-09-07 01:48:10 +02:00
|
|
|
}
|
2015-09-07 01:45:00 +02:00
|
|
|
|
|
|
|
$(this).droppable({
|
|
|
|
disabled: $(this).is(':disabled'),
|
|
|
|
accept: 'tr.ss-gridfield-item',
|
|
|
|
activeClass: 'sortablerows-droptarget',
|
|
|
|
tolerance: 'pointer',
|
|
|
|
drop: function(event, ui) {
|
|
|
|
self.stopMoveTracking();
|
|
|
|
|
|
|
|
sortableCheckbox.setPageSort(true);
|
|
|
|
|
|
|
|
var button=gridField.find('.gridfield-sortablerows .sortablerows-sorttopage');
|
|
|
|
var itemID=$(ui.draggable).data('id');
|
|
|
|
var target='';
|
|
|
|
|
|
|
|
if($(this).hasClass('sortablerows-prev-page')) {
|
|
|
|
target='previouspage';
|
|
|
|
}else if($(this).hasClass('sortablerows-next-page')) {
|
|
|
|
target='nextpage';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Move and Reload the grid
|
|
|
|
gridField.reload({data: [
|
|
|
|
{
|
|
|
|
name: button.attr('name'),
|
|
|
|
value: button.val()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ItemID',
|
|
|
|
value: itemID
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Target',
|
|
|
|
value: target
|
|
|
|
}
|
|
|
|
]});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.redraw();
|
|
|
|
},
|
|
|
|
redraw: function() {
|
|
|
|
var gridField=this.getGridField();
|
|
|
|
var tbody=gridField.find('tbody');
|
|
|
|
var tbodyPos=tbody.position();
|
|
|
|
|
|
|
|
$(this).css('top', tbodyPos.top+'px').height(tbody.height());
|
|
|
|
},
|
|
|
|
startMoveTracking: function() {
|
|
|
|
var self=$(this);
|
|
|
|
self.setArrowIcon(self.find('i'));
|
|
|
|
},
|
|
|
|
stopMoveTracking: function() {
|
2015-09-07 01:48:10 +02:00
|
|
|
$(this).setArrowIcon(null);
|
2015-09-07 01:45:00 +02:00
|
|
|
},
|
|
|
|
moveTracking: function(e, ui) {
|
2015-09-07 01:48:10 +02:00
|
|
|
var self=$(this);
|
2015-09-07 01:45:00 +02:00
|
|
|
var arrowIcon=self.getArrowIcon();
|
|
|
|
if(arrowIcon) {
|
2015-09-07 01:48:10 +02:00
|
|
|
var selfOffset=self.offset().top;
|
|
|
|
var arrowIconHeight=arrowIcon.width()+10;
|
|
|
|
var railHeight=self.height()-arrowIconHeight;
|
|
|
|
var helperPos=ui.helper.offset().top;
|
|
|
|
|
|
|
|
if(helperPos>selfOffset+10 && helperPos<selfOffset+railHeight) {
|
|
|
|
arrowIcon.css('top', ((helperPos-selfOffset)+arrowIconHeight/2)+'px');
|
|
|
|
}
|
2015-09-07 01:45:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-05-15 16:04:40 +02:00
|
|
|
});
|
2015-09-07 01:45:00 +02:00
|
|
|
|
2015-09-18 20:59:03 +02:00
|
|
|
})(jQuery);
|