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') {
return $this->saveGridRowSort($gridField, $data);
} 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();
$many_many = ($items instanceof ManyManyList);
$sortColumn = $this->sortColumn;
$pageOffset = 0;
if ($paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) {
$pageState = $gridField->State->GridFieldPaginator;
if($pageState->currentPage && $pageState->currentPage>1) {
$pageOffset = $paginator->getItemsPerPage() * ($pageState->currentPage - 1);
}
}
$pageOffset = 0;
if ($paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) {
$pageState = $gridField->State->GridFieldPaginator;
if($pageState->currentPage && $pageState->currentPage>1) {
$pageOffset = $paginator->getItemsPerPage() * ($pageState->currentPage - 1);
}
}
if ($many_many) {
@ -169,8 +169,8 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP
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']);
for($sort = 0;$sort<count($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
*/
protected function sortToPage(GridField $gridField, $data) {
if (!$paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) {
user_error('Paginator not detected', E_USER_ERROR);
}
if (empty($data['ItemID'])) {
if (!$paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) {
user_error('Paginator not detected', E_USER_ERROR);
}
if (empty($data['ItemID'])) {
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);
}
$className = $gridField->getModelClass();
$className = $gridField->getModelClass();
$owner = $gridField->Form->getRecord();
$items = $gridField->getList();
$many_many = ($items instanceof ManyManyList);
$sortColumn = $this->sortColumn;
$targetItem = $items->byID(intval($data['ItemID']));
if (!$targetItem) {
user_error('Target item not found', E_USER_ERROR);
}
$sortPosition = $targetItem->$sortColumn;
$currentPage = 1;
$targetItem = $items->byID(intval($data['ItemID']));
if (!$targetItem) {
user_error('Target item not found', E_USER_ERROR);
}
$sortPosition = $targetItem->$sortColumn;
$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) {
list($parentClass, $componentClass, $parentField, $componentField, $table) = $owner->many_many($gridField->getName());
}
if ($data['Target'] == 'firstpage') {
$sortPosition = $paginator->getItemsPerPage();
} else if ($data['Target'] == 'previouspage') {
$sortPosition = $paginator->getItemsPerPage() * ($currentPage - 1);
} else if ($data['Target'] == 'nextpage') {
$sortPosition = ($paginator->getItemsPerPage() * $currentPage) + 1;
} else if ($data['Target'] == 'lastpage') {
$sortPosition = ($paginator->getItemsPerPage() * (ceil($items->count() / $paginator->getItemsPerPage()) - 1)) + 1;
} else {
user_error('Not implemented: '.$data['Target'], E_USER_ERROR);
}
if($targetItem->$sortColumn != $sortPosition) {
//Start transaction if supported
if(DB::getConn()->supportsTransactions()) {
DB::getConn()->transactionStart();
}
//Swap with the item around the target position
$swapItem = $items->where('"'.$sortColumn.'" >= '.$sortPosition)->First();
if ($many_many) {
DB::query('UPDATE "' . $table
. '" SET "' . $sortColumn.'" = ' . $targetItem->$sortColumn
. ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
} else {
$swapItem->$sortColumn = $targetItem->$sortColumn;
$swapItem->write();
}
//Update target item position
if ($many_many) {
DB::query('UPDATE "' . $table
. '" SET "' . $sortColumn.'" = ' . $sortPosition
. ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
} else {
$targetItem->$sortColumn = $sortPosition;
$targetItem->write();
}
//End transaction if supported
if(DB::getConn()->supportsTransactions()) {
DB::getConn()->transactionEnd();
}
}
}
if ($data['Target'] == 'firstpage') {
$sortPosition = $paginator->getItemsPerPage();
} else if ($data['Target'] == 'previouspage') {
$sortPosition = $paginator->getItemsPerPage() * ($currentPage - 1);
} else if ($data['Target'] == 'nextpage') {
$sortPosition = ($paginator->getItemsPerPage() * $currentPage) + 1;
} else if ($data['Target'] == 'lastpage') {
$sortPosition = ($paginator->getItemsPerPage() * (ceil($items->count() / $paginator->getItemsPerPage()) - 1)) + 1;
} else {
user_error('Not implemented: '.$data['Target'], E_USER_ERROR);
}
if($targetItem->$sortColumn != $sortPosition) {
//Start transaction if supported
if(DB::getConn()->supportsTransactions()) {
DB::getConn()->transactionStart();
}
//Swap with the item around the target position
$swapItem = $items->where('"'.$sortColumn.'" >= '.$sortPosition)->First();
if ($many_many) {
DB::query('UPDATE "' . $table
. '" SET "' . $sortColumn.'" = ' . $targetItem->$sortColumn
. ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
} else {
$swapItem->$sortColumn = $targetItem->$sortColumn;
$swapItem->write();
}
//Update target item position
if ($many_many) {
DB::query('UPDATE "' . $table
. '" SET "' . $sortColumn.'" = ' . $sortPosition
. ' WHERE "' . $componentField . '" = ' . $targetItem->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
} else {
$targetItem->$sortColumn = $sortPosition;
$targetItem->write();
}
//End transaction if supported
if(DB::getConn()->supportsTransactions()) {
DB::getConn()->transactionEnd();
}
}
}
}
?>

View File

@ -1,7 +1,7 @@
(function($) {
$('.ss-gridfield .gridfield-sortablerows input').entwine({
onmatch: function() {
var self=this;
var self=this;
var refCheckbox=$(this);
var gridField=$(this).getGridField();
@ -13,7 +13,7 @@
}
gridField.find('tbody').sortable({
opacity: 0.6,
opacity: 0.6,
disabled: ($(this).is(':checked')==false),
helper: function(e, ui) {
//Maintains width of the columns
@ -35,63 +35,63 @@
self._makeRequest({data: [
{
name: button.attr('name'),
value: button.val()
},
{
name: 'Items',
value: dataRows
}
]});
{
name: button.attr('name'),
value: button.val()
},
{
name: 'Items',
value: dataRows
}
]});
}
}).disableSelection();
gridField.find('.datagrid-pagination button').each(function() {
$(this).droppable({
disabled: $(this).is(':disabled'),
accept: 'tr.ss-gridfield-item',
tolerance: 'pointer',
drop: function(event, ui) {
gridField.find('tbody').sortable('cancel');
var button=refCheckbox.parent().find('.sortablerows-sorttopage');
var itemID=$(ui.draggable).data('id');
var target='';
if($(this).hasClass('ss-gridfield-firstpage')) {
target='firstpage';
}else if($(this).hasClass('ss-gridfield-previouspage')) {
target='previouspage';
}else if($(this).hasClass('ss-gridfield-nextpage')) {
target='nextpage';
}else if($(this).hasClass('ss-gridfield-lastpage')) {
target='lastpage';
}
//Move and Reload the grid
gridField.reload({data: [
{
name: button.attr('name'),
value: button.val()
},
{
name: 'ItemID',
value: itemID
},
{
name: 'Target',
value: target
}
]});
event.stopPropagation();
event.stopImmediatePropagation();
}
});
});
gridField.find('.datagrid-pagination button').each(function() {
$(this).droppable({
disabled: $(this).is(':disabled'),
accept: 'tr.ss-gridfield-item',
tolerance: 'pointer',
drop: function(event, ui) {
gridField.find('tbody').sortable('cancel');
var button=refCheckbox.parent().find('.sortablerows-sorttopage');
var itemID=$(ui.draggable).data('id');
var target='';
if($(this).hasClass('ss-gridfield-firstpage')) {
target='firstpage';
}else if($(this).hasClass('ss-gridfield-previouspage')) {
target='previouspage';
}else if($(this).hasClass('ss-gridfield-nextpage')) {
target='nextpage';
}else if($(this).hasClass('ss-gridfield-lastpage')) {
target='lastpage';
}
//Move and Reload the grid
gridField.reload({data: [
{
name: button.attr('name'),
value: button.val()
},
{
name: 'ItemID',
value: itemID
},
{
name: 'Target',
value: target
}
]});
event.stopPropagation();
event.stopImmediatePropagation();
}
});
});
},
onchange: function(e) {
@ -103,30 +103,30 @@
var button=$(this).parent().find('.sortablerows-disablepagenator');
gridField.reload({data: [{name: button.attr('name'), value: button.val()}]});
},
_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
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);
}
$.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));
}
_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
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);
}
$.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));
}
});
})(jQuery);