utilise a more generic sortable list system

This commit is contained in:
Connor S. Parks
2016-08-20 11:12:04 +01:00
parent dbb87782e3
commit 486642df03
8 changed files with 38 additions and 63 deletions

View File

@@ -161,63 +161,38 @@ $(function() {
}
});
// Sortable components.
var componentList = document.getElementById("component-list");
if (componentList) {
new Sortable(componentList, {
group: "omega",
handle: ".drag-handle",
// Sortable models.
var orderableLists = document.querySelectorAll('[data-orderable-list]');
$.each(orderableLists, function (k, list) {
var url = $(list).data('orderableList');
var notifier = new Cachet.Notifier();
new Sortable(list, {
group: 'omega',
handle: '.drag-handle',
onUpdate: function() {
var orderedComponentIds = $.map($('#component-list .striped-list-item'), function(elem) {
return $(elem).data('component-id');
var orderedIds = $.map(list.querySelectorAll('[data-orderable-id]'), function(elem) {
return $(elem).data('orderable-id');
});
$.ajax({
async: true,
url: '/dashboard/api/components/order',
url: url,
type: 'POST',
data: {
ids: orderedComponentIds
ids: orderedIds
},
success: function() {
(new Cachet.Notifier()).notify('Component orders updated.', 'success');
notifier.notify('Ordering updated.', 'success');
},
error: function() {
(new Cachet.Notifier()).notify('Component orders not updated.', 'error');
notifier.notify('Ordering not updated.', 'error');
}
});
}
});
}
// Sortable Component Groups
var componentGroupList = document.getElementById("component-group-list");
if (componentGroupList) {
new Sortable(componentGroupList, {
group: "omega",
handle: ".drag-handle",
onUpdate: function() {
var orderedComponentGroupsIds = $.map(
$('#component-group-list .striped-list-item'),
function(elem) {
return $(elem).data('group-id');
}
);
$.ajax({
async: true,
url: '/dashboard/api/components/groups/order',
type: 'POST',
data: {ids: orderedComponentGroupsIds},
success: function() {
(new Cachet.Notifier()).notify('Component groups order has been updated.', 'success');
},
error: function() {
(new Cachet.Notifier()).notify('Component groups order could not be updated.', 'error');
}
});
}
});
}
});
// Toggle inline component statuses.
$('form.component-inline').on('click', 'input[type=radio]', function() {

View File

@@ -17,9 +17,9 @@
</div>
@include('dashboard.partials.errors')
<div class="row">
<div class="col-sm-12 striped-list" id="component-group-list">
<div class="col-sm-12 striped-list" data-orderable-list="/dashboard/api/components/groups/order">
@forelse($groups as $group)
<div class="row striped-list-item" data-group-id="{{ $group->id }}">
<div class="row striped-list-item" data-orderable-id="{{ $group->id }}">
<div class="col-xs-6">
<h4>
@if($groups->count() > 1)

View File

@@ -17,9 +17,9 @@
</div>
@include('dashboard.partials.errors')
<div class="row">
<div class="col-sm-12 striped-list" id="component-list">
<div class="col-sm-12 striped-list" data-orderable-list="/dashboard/api/components/order">
@forelse($components as $component)
<div class="row striped-list-item {{ !$component->enabled ? 'bg-warning' : null }}" data-component-id="{{ $component->id }}">
<div class="row striped-list-item {{ !$component->enabled ? 'bg-warning' : null }}" data-orderable-id="{{ $component->id }}">
<div class="col-xs-6">
<h4>
@if($components->count() > 1)