Fixed spaces instead of tabs

This commit is contained in:
UndefinedOffset 2012-05-17 09:56:16 -03:00
parent a07118e2d0
commit fb767a6722
2 changed files with 169 additions and 169 deletions

View File

@ -126,8 +126,8 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
if ($actionName == 'savegridrowsort') { if ($actionName == 'savegridrowsort') {
return $this->saveGridRowSort($gridField, $data); return $this->saveGridRowSort($gridField, $data);
} else if ($actionName == 'sorttopage') { } else if ($actionName == 'sorttopage') {
return $this->sortToPage($gridField, $data); return $this->sortToPage($gridField, $data);
} }
} }
/** /**
@ -149,14 +149,14 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
$items = $gridField->getList(); $items = $gridField->getList();
$many_many = ($items instanceof ManyManyList); $many_many = ($items instanceof ManyManyList);
$sortColumn = $this->sortColumn; $sortColumn = $this->sortColumn;
$pageOffset = 0; $pageOffset = 0;
if ($paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) { if ($paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) {
$pageState = $gridField->State->GridFieldPaginator; $pageState = $gridField->State->GridFieldPaginator;
if($pageState->currentPage && $pageState->currentPage>1) { if($pageState->currentPage && $pageState->currentPage>1) {
$pageOffset = $paginator->getItemsPerPage() * ($pageState->currentPage - 1); $pageOffset = $paginator->getItemsPerPage() * ($pageState->currentPage - 1);
} }
} }
if ($many_many) { if ($many_many) {
@ -169,8 +169,8 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
DB::getConn()->transactionStart(); DB::getConn()->transactionStart();
} }
//@TODO Need to optimize this to eliminate some of the resource load could use raw queries to be more efficient //@TODO Need to optimize this to eliminate some of the resource load could use raw queries to be more efficient
$data['Items'] = explode(',', $data['Items']); $data['Items'] = explode(',', $data['Items']);
for($sort = 0;$sort<count($data['Items']);$sort++) { for($sort = 0;$sort<count($data['Items']);$sort++) {
$id = intval($data['Items'][$sort]); $id = intval($data['Items'][$sort]);
@ -197,93 +197,93 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
* @param Array $data Data submitted in the request * @param Array $data Data submitted in the request
*/ */
protected function sortToPage(GridField $gridField, $data) { protected function sortToPage(GridField $gridField, $data) {
if (!$paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) { if (!$paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) {
user_error('Paginator not detected', E_USER_ERROR); user_error('Paginator not detected', E_USER_ERROR);
} }
if (empty($data['ItemID'])) { if (empty($data['ItemID'])) {
user_error('No item to sort', E_USER_ERROR); user_error('No item to sort', E_USER_ERROR);
} }
if (empty($data['Target'])) { if (empty($data['Target'])) {
user_error('No target page', E_USER_ERROR); user_error('No target page', E_USER_ERROR);
} }
$className = $gridField->getModelClass(); $className = $gridField->getModelClass();
$owner = $gridField->Form->getRecord(); $owner = $gridField->Form->getRecord();
$items = $gridField->getList(); $items = $gridField->getList();
$many_many = ($items instanceof ManyManyList); $many_many = ($items instanceof ManyManyList);
$sortColumn = $this->sortColumn; $sortColumn = $this->sortColumn;
$targetItem = $items->byID(intval($data['ItemID'])); $targetItem = $items->byID(intval($data['ItemID']));
if (!$targetItem) { if (!$targetItem) {
user_error('Target item not found', E_USER_ERROR); user_error('Target item not found', E_USER_ERROR);
} }
$sortPosition = $targetItem->$sortColumn; $sortPosition = $targetItem->$sortColumn;
$currentPage = 1; $currentPage = 1;
$pageState = $gridField->State->GridFieldPaginator;
if($pageState->currentPage && $pageState->currentPage>1) {
$currentPage = $pageState->currentPage;
}
$pageState = $gridField->State->GridFieldPaginator;
if($pageState->currentPage && $pageState->currentPage>1) {
$currentPage = $pageState->currentPage;
}
if ($many_many) { if ($many_many) {
list($parentClass, $componentClass, $parentField, $componentField, $table) = $owner->many_many($gridField->getName()); list($parentClass, $componentClass, $parentField, $componentField, $table) = $owner->many_many($gridField->getName());
} }
if ($data['Target'] == 'firstpage') { if ($data['Target'] == 'firstpage') {
$sortPosition = $paginator->getItemsPerPage(); $sortPosition = $paginator->getItemsPerPage();
} else if ($data['Target'] == 'previouspage') { } else if ($data['Target'] == 'previouspage') {
$sortPosition = $paginator->getItemsPerPage() * ($currentPage - 1); $sortPosition = $paginator->getItemsPerPage() * ($currentPage - 1);
} else if ($data['Target'] == 'nextpage') { } else if ($data['Target'] == 'nextpage') {
$sortPosition = ($paginator->getItemsPerPage() * $currentPage) + 1; $sortPosition = ($paginator->getItemsPerPage() * $currentPage) + 1;
} else if ($data['Target'] == 'lastpage') { } else if ($data['Target'] == 'lastpage') {
$sortPosition = ($paginator->getItemsPerPage() * (ceil($items->count() / $paginator->getItemsPerPage()) - 1)) + 1; $sortPosition = ($paginator->getItemsPerPage() * (ceil($items->count() / $paginator->getItemsPerPage()) - 1)) + 1;
} else { } else {
user_error('Not implemented: '.$data['Target'], E_USER_ERROR); user_error('Not implemented: '.$data['Target'], E_USER_ERROR);
} }
if($targetItem->$sortColumn != $sortPosition) { if($targetItem->$sortColumn != $sortPosition) {
//Start transaction if supported //Start transaction if supported
if(DB::getConn()->supportsTransactions()) { if(DB::getConn()->supportsTransactions()) {
DB::getConn()->transactionStart(); DB::getConn()->transactionStart();
} }
//Swap with the item around the target position //Swap with the item around the target position
$swapItem = $items->where('"'.$sortColumn.'" >= '.$sortPosition)->First(); $swapItem = $items->where('"'.$sortColumn.'" >= '.$sortPosition)->First();
if ($many_many) { if ($many_many) {
DB::query('UPDATE "' . $table DB::query('UPDATE "' . $table
. '" SET "' . $sortColumn.'" = ' . $targetItem->$sortColumn . '" SET "' . $sortColumn.'" = ' . $targetItem->$sortColumn
. ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID); . ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
} else { } else {
$swapItem->$sortColumn = $targetItem->$sortColumn; $swapItem->$sortColumn = $targetItem->$sortColumn;
$swapItem->write(); $swapItem->write();
} }
//Update target item position //Update target item position
if ($many_many) { if ($many_many) {
DB::query('UPDATE "' . $table DB::query('UPDATE "' . $table
. '" SET "' . $sortColumn.'" = ' . $sortPosition . '" SET "' . $sortColumn.'" = ' . $sortPosition
. ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID); . ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
} else { } else {
$targetItem->$sortColumn = $sortPosition; $targetItem->$sortColumn = $sortPosition;
$targetItem->write(); $targetItem->write();
} }
//End transaction if supported //End transaction if supported
if(DB::getConn()->supportsTransactions()) { if(DB::getConn()->supportsTransactions()) {
DB::getConn()->transactionEnd(); DB::getConn()->transactionEnd();
} }
} }
} }
} }
?> ?>

View File

@ -1,7 +1,7 @@
(function($) { (function($) {
$('.ss-gridfield .gridfield-sortablerows input').entwine({ $('.ss-gridfield .gridfield-sortablerows input').entwine({
onmatch: function() { onmatch: function() {
var self=this; var self=this;
var refCheckbox=$(this); var refCheckbox=$(this);
var gridField=$(this).getGridField(); var gridField=$(this).getGridField();
@ -13,7 +13,7 @@
} }
gridField.find('tbody').sortable({ gridField.find('tbody').sortable({
opacity: 0.6, opacity: 0.6,
disabled: ($(this).is(':checked')==false), disabled: ($(this).is(':checked')==false),
helper: function(e, ui) { helper: function(e, ui) {
//Maintains width of the columns //Maintains width of the columns
@ -35,63 +35,63 @@
self._makeRequest({data: [ self._makeRequest({data: [
{ {
name: button.attr('name'), name: button.attr('name'),
value: button.val() value: button.val()
}, },
{ {
name: 'Items', name: 'Items',
value: dataRows value: dataRows
} }
]}); ]});
} }
}).disableSelection(); }).disableSelection();
gridField.find('.datagrid-pagination button').each(function() { gridField.find('.datagrid-pagination button').each(function() {
$(this).droppable({ $(this).droppable({
disabled: $(this).is(':disabled'), disabled: $(this).is(':disabled'),
accept: 'tr.ss-gridfield-item', accept: 'tr.ss-gridfield-item',
tolerance: 'pointer', tolerance: 'pointer',
drop: function(event, ui) { drop: function(event, ui) {
gridField.find('tbody').sortable('cancel'); gridField.find('tbody').sortable('cancel');
var button=refCheckbox.parent().find('.sortablerows-sorttopage'); var button=refCheckbox.parent().find('.sortablerows-sorttopage');
var itemID=$(ui.draggable).data('id'); var itemID=$(ui.draggable).data('id');
var target=''; var target='';
if($(this).hasClass('ss-gridfield-firstpage')) { if($(this).hasClass('ss-gridfield-firstpage')) {
target='firstpage'; target='firstpage';
}else if($(this).hasClass('ss-gridfield-previouspage')) { }else if($(this).hasClass('ss-gridfield-previouspage')) {
target='previouspage'; target='previouspage';
}else if($(this).hasClass('ss-gridfield-nextpage')) { }else if($(this).hasClass('ss-gridfield-nextpage')) {
target='nextpage'; target='nextpage';
}else if($(this).hasClass('ss-gridfield-lastpage')) { }else if($(this).hasClass('ss-gridfield-lastpage')) {
target='lastpage'; target='lastpage';
} }
//Move and Reload the grid //Move and Reload the grid
gridField.reload({data: [ gridField.reload({data: [
{ {
name: button.attr('name'), name: button.attr('name'),
value: button.val() value: button.val()
}, },
{ {
name: 'ItemID', name: 'ItemID',
value: itemID value: itemID
}, },
{ {
name: 'Target', name: 'Target',
value: target value: target
} }
]}); ]});
event.stopPropagation(); event.stopPropagation();
event.stopImmediatePropagation(); event.stopImmediatePropagation();
} }
}); });
}); });
}, },
onchange: function(e) { onchange: function(e) {
@ -103,30 +103,30 @@
var button=$(this).parent().find('.sortablerows-disablepagenator'); var button=$(this).parent().find('.sortablerows-disablepagenator');
gridField.reload({data: [{name: button.attr('name'), value: button.val()}]}); gridField.reload({data: [{name: button.attr('name'), value: button.val()}]});
}, },
_makeRequest: function(ajaxOpts, callback) { _makeRequest: function(ajaxOpts, callback) {
var gridField=$(this).getGridField(); var gridField=$(this).getGridField();
var form = gridField.closest('form'), var form = gridField.closest('form'),
focusedElName = gridField.find(':input:focus').attr('name'); // Save focused element for restoring after refresh focusedElName = gridField.find(':input:focus').attr('name'); // Save focused element for restoring after refresh
ajaxOpts.data = ajaxOpts.data.concat(form.find(':input').serializeArray()); 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. // 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. // For example, a list prefiltered through external search criteria might be passed to GridField.
if(window.location.search) { if(window.location.search) {
ajaxOpts.data = window.location.search.replace(/^\?/, '') + '&' + $.param(ajaxOpts.data); ajaxOpts.data = window.location.search.replace(/^\?/, '') + '&' + $.param(ajaxOpts.data);
} }
$.ajax($.extend({}, { $.ajax($.extend({}, {
headers: {"X-Pjax" : 'CurrentField'}, headers: {"X-Pjax" : 'CurrentField'},
type: "POST", type: "POST",
url: gridField.data('url'), url: gridField.data('url'),
dataType: 'html', dataType: 'html',
success: callback, success: callback,
error: function(e) { error: function(e) {
alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION')); alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION'));
} }
}, ajaxOpts)); }, ajaxOpts));
} }
}); });
})(jQuery); })(jQuery);