Order exercises in request body according to manual sort order in UI
This commit is contained in:
@ -127,8 +127,22 @@ $(function() {
|
|||||||
.attr("class", "line maximum-working-time")
|
.attr("class", "line maximum-working-time")
|
||||||
.attr("d", maxWorkingTime);
|
.attr("d", maxWorkingTime);
|
||||||
} else if (exerciseList.isPresent()) {
|
} else if (exerciseList.isPresent()) {
|
||||||
|
var exerciseSelect = $('#exercise-select');
|
||||||
var list = $("#sortable");
|
var list = $("#sortable");
|
||||||
list.sortable();
|
|
||||||
|
var updateExerciseList = function () {
|
||||||
|
// remove all options from the hidden select and add all selected exercises in the new order
|
||||||
|
exerciseSelect.find('option').remove();
|
||||||
|
var exerciseIdsInSortedOrder = list.sortable('toArray', {attribute: 'data-id'});
|
||||||
|
for (var i = 0; i < exerciseIdsInSortedOrder.length; i += 1) {
|
||||||
|
exerciseSelect.append('<option value="' + exerciseIdsInSortedOrder[i] + '" selected></option>')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list.sortable({
|
||||||
|
items: 'tr',
|
||||||
|
update: updateExerciseList
|
||||||
|
});
|
||||||
list.disableSelection();
|
list.disableSelection();
|
||||||
|
|
||||||
var addExercisesForm = $('#exercise-selection');
|
var addExercisesForm = $('#exercise-selection');
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
a.remove-exercise href='#' = t('shared.destroy')
|
a.remove-exercise href='#' = t('shared.destroy')
|
||||||
button.btn.btn-primary type='button' data-toggle='modal' data-target='#add-exercise-modal' = t('exercise_collections.form.add_exercises')
|
button.btn.btn-primary type='button' data-toggle='modal' data-target='#add-exercise-modal' = t('exercise_collections.form.add_exercises')
|
||||||
.hidden
|
.hidden
|
||||||
= f.collection_select(:exercise_ids, Exercise.all, :id, :title, {}, {class: 'form-control', multiple: true})
|
= f.collection_select(:exercise_ids, Exercise.all, :id, :title, {}, {id: 'exercise-select', class: 'form-control', multiple: true})
|
||||||
|
|
||||||
.actions = render('shared/submit_button', f: f, object: @exercise_collection)
|
.actions = render('shared/submit_button', f: f, object: @exercise_collection)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user