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
+5 -4
View File
@@ -46,8 +46,9 @@ class ApiController extends AbstractController
*/ */
public function postUpdateComponentOrder() public function postUpdateComponentOrder()
{ {
$componentData = Binput::all(); $componentData = Binput::get('ids');
foreach ($componentData['ids'] as $order => $componentId) { return $componentData;
foreach ($componentData as $order => $componentId) {
// Ordering should be 1-based, data comes in 0-based // Ordering should be 1-based, data comes in 0-based
Component::find($componentId)->update(['order' => $order + 1]); Component::find($componentId)->update(['order' => $order + 1]);
} }
@@ -62,8 +63,8 @@ class ApiController extends AbstractController
*/ */
public function postUpdateComponentGroupOrder() public function postUpdateComponentGroupOrder()
{ {
$groupData = Binput::all(); $groupData = Binput::get('ids');
foreach ($groupData['ids'] as $order => $groupId) { foreach ($groupData as $order => $groupId) {
ComponentGroup::find($groupId)->update([ ComponentGroup::find($groupId)->update([
'order' => $order + 1, 'order' => $order + 1,
]); ]);
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,4 +1,4 @@
{ {
"dist/css/all.css": "dist/css/all-a3ad1e03.css", "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"
} }
+18 -16
View File
@@ -1,13 +1,6 @@
$(function() { $(function() {
// Ajax Setup // Ajax Setup
$.ajaxPrefilter(function(options, originalOptions, jqXHR) { $.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; var token;
if (! options.crossDomain) { if (! options.crossDomain) {
token = $('meta[name="token"]').attr('content'); token = $('meta[name="token"]').attr('content');
@@ -20,6 +13,10 @@ $(function() {
}); });
$.ajaxSetup({ $.ajaxSetup({
beforeSend: function (xhr) {
xhr.setRequestHeader('Accept', 'application/json');
// xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
},
statusCode: { statusCode: {
401: function () { 401: function () {
window.location.href = '/'; window.location.href = '/';
@@ -157,19 +154,22 @@ $(function() {
group: "omega", group: "omega",
handle: ".drag-handle", handle: ".drag-handle",
onUpdate: function() { onUpdate: function() {
var orderedComponentIds = $.map( var orderedComponentIds = $.map($('#component-list .striped-list-item'), function(elem) {
$('#component-list .striped-list-item'), return $(elem).data('component-id');
function(elem) { });
return $(elem).data('component-id');
}
);
$.ajax({ $.ajax({
async: true, async: true,
url: '/dashboard/api/components/order', url: '/dashboard/api/components/order',
type: 'POST', type: 'POST',
data: {ids: orderedComponentIds}, data: {
ids: orderedComponentIds
},
success: function() { 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}, data: {ids: orderedComponentGroupsIds},
success: function() { success: function() {
(new CachetHQ.Notifier()).notify('Component groups order has been updated.', 'success'); (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) { if (slug) {
$.ajax({ $.ajax({
async: true, async: true,
dataType: 'json',
data: { data: {
slug: slug slug: slug
}, },