This commit is contained in:
James Brooks 2015-05-26 19:13:46 +01:00
parent e6f6946497
commit 502ae9d2a0
4 changed files with 27 additions and 23 deletions

View File

@ -46,8 +46,9 @@ class ApiController extends AbstractController
*/
public function postUpdateComponentOrder()
{
$componentData = Binput::all();
foreach ($componentData['ids'] as $order => $componentId) {
$componentData = Binput::get('ids');
return $componentData;
foreach ($componentData as $order => $componentId) {
// Ordering should be 1-based, data comes in 0-based
Component::find($componentId)->update(['order' => $order + 1]);
}
@ -62,8 +63,8 @@ class ApiController extends AbstractController
*/
public function postUpdateComponentGroupOrder()
{
$groupData = Binput::all();
foreach ($groupData['ids'] as $order => $groupId) {
$groupData = Binput::get('ids');
foreach ($groupData as $order => $groupId) {
ComponentGroup::find($groupId)->update([
'order' => $order + 1,
]);

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"dist/css/all.css": "dist/css/all-a3ad1e03.css",
"dist/js/all.js": "dist/js/all-c95bf9ff.js"
"dist/js/all.js": "dist/js/all-d0596004.js"
}

View File

@ -1,13 +1,6 @@
$(function() {
// Ajax Setup
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
if (! options.beforeSend) {
options.beforeSend = function(xhr) {
jqXHR.setRequestHeader('Accept', 'application/json; charset=utf-8');
jqXHR.setRequestHeader('Content-Type', 'application/json');
};
}
var token;
if (! options.crossDomain) {
token = $('meta[name="token"]').attr('content');
@ -20,6 +13,10 @@ $(function() {
});
$.ajaxSetup({
beforeSend: function (xhr) {
xhr.setRequestHeader('Accept', 'application/json');
// xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
},
statusCode: {
401: function () {
window.location.href = '/';
@ -157,19 +154,22 @@ $(function() {
group: "omega",
handle: ".drag-handle",
onUpdate: function() {
var orderedComponentIds = $.map(
$('#component-list .striped-list-item'),
function(elem) {
return $(elem).data('component-id');
}
);
var orderedComponentIds = $.map($('#component-list .striped-list-item'), function(elem) {
return $(elem).data('component-id');
});
$.ajax({
async: true,
url: '/dashboard/api/components/order',
type: 'POST',
data: {ids: orderedComponentIds},
data: {
ids: orderedComponentIds
},
success: function() {
(new CachetHQ.Notifier()).notify('Components updated.', 'success');
(new CachetHQ.Notifier()).notify('Component orders updated.', 'success');
},
error: function() {
(new CachetHQ.Notifier()).notify('Component orders not updated.', 'error');
}
});
}
@ -196,6 +196,9 @@ $(function() {
data: {ids: orderedComponentGroupsIds},
success: function() {
(new CachetHQ.Notifier()).notify('Component groups order has been updated.', 'success');
},
error: function() {
(new CachetHQ.Notifier()).notify('Component groups order could not be updated.', 'error');
}
});
}
@ -230,7 +233,6 @@ $(function() {
if (slug) {
$.ajax({
async: true,
dataType: 'json',
data: {
slug: slug
},