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({
|
|
|
|
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');
|
2013-04-27 01:25:56 +02:00
|
|
|
var pageSort=false;
|
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),
|
|
|
|
helper: function(e, ui) {
|
|
|
|
//Maintains width of the columns
|
|
|
|
ui.children().each(function() {
|
|
|
|
$(this).width($(this).width());
|
|
|
|
});
|
|
|
|
|
|
|
|
return ui;
|
|
|
|
},
|
|
|
|
update: function(event, ui) {
|
2013-04-27 01:25:56 +02:00
|
|
|
if(pageSort) {
|
|
|
|
pageSort=false;
|
|
|
|
return;
|
|
|
|
}
|
2015-02-11 13:29:26 +01:00
|
|
|
|
|
|
|
$('.ss-gridfield-item').removeClass('first last odd even');
|
|
|
|
$('.ss-gridfield-item').first().addClass('first');
|
|
|
|
$('.ss-gridfield-item:odd').last().addClass('last');
|
|
|
|
$('.ss-gridfield-item:even').addClass('even');
|
|
|
|
$('.ss-gridfield-item:odd').addClass('odd');
|
2013-04-27 01:25:56 +02:00
|
|
|
|
2012-05-28 16:26:33 +02:00
|
|
|
var dataRows=[];
|
|
|
|
var gridItems=gridField.getItems();
|
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-04-07 00:09:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if(refCheckbox.hasClass('gridfield-sortablerows-noselection')){
|
|
|
|
gridField.find('tbody').disableSelection();
|
|
|
|
}
|
2012-05-28 16:26:33 +02:00
|
|
|
|
|
|
|
gridField.find('.datagrid-pagination .ss-gridfield-previouspage, .datagrid-pagination .ss-gridfield-nextpage').each(function() {
|
|
|
|
$(this).droppable({
|
|
|
|
disabled: $(this).is(':disabled'),
|
|
|
|
accept: 'tr.ss-gridfield-item',
|
|
|
|
activeClass: 'sortablerows-droptarget',
|
|
|
|
tolerance: 'pointer',
|
|
|
|
drop: function(event, ui) {
|
2013-04-27 01:25:56 +02:00
|
|
|
pageSort=true;
|
2012-05-28 16:26:33 +02:00
|
|
|
|
|
|
|
var button=refCheckbox.parent().find('.sortablerows-sorttopage');
|
|
|
|
var itemID=$(ui.draggable).data('id');
|
|
|
|
var target='';
|
|
|
|
|
|
|
|
|
|
|
|
if($(this).hasClass('ss-gridfield-previouspage')) {
|
|
|
|
target='previouspage';
|
|
|
|
}else if($(this).hasClass('ss-gridfield-nextpage')) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
]});
|
2012-05-17 14:56:16 +02:00
|
|
|
}
|
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();
|
|
|
|
var form = gridField.closest('form'),
|
|
|
|
focusedElName = gridField.find(':input:focus').attr('name'); // Save focused element for restoring after refresh
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
});
|
2012-05-15 16:04:40 +02:00
|
|
|
});
|
2012-05-09 19:14:34 +02:00
|
|
|
})(jQuery);
|