Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalises the ordering JS #2074

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/dist/css/all.css.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/dist/js/all.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/build/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/css/all.css": "dist/css/all-8b09a6139d.css",
"dist/js/all.js": "dist/js/all-914268da61.js"
"dist/css/all.css": "dist/css/all-9f109896fb.css",
"dist/js/all.js": "dist/js/all-a2296565be.js"
}
59 changes: 17 additions & 42 deletions resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
error: function() {
(new Cachet.Notifier()).notify('Component orders 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');
notifier.notify('Ordering updated.', 'success');
},
error: function() {
(new Cachet.Notifier()).notify('Component groups order could not be updated.', 'error');
notifier.notify('Ordering not updated.', 'error');
}
});
}
});
}
});

// Toggle inline component statuses.
$('form.component-inline').on('click', 'input[type=radio]', function() {
Expand Down
4 changes: 2 additions & 2 deletions resources/views/dashboard/components/groups/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions resources/views/dashboard/components/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down