Add UI for adding exercises to collection
This commit is contained in:
@ -130,6 +130,31 @@ $(function() {
|
|||||||
var list = $("#sortable");
|
var list = $("#sortable");
|
||||||
list.sortable();
|
list.sortable();
|
||||||
list.disableSelection();
|
list.disableSelection();
|
||||||
|
|
||||||
|
var addExercisesForm = $('#exercise-selection');
|
||||||
|
var addExercisesButton = $('#add-exercises');
|
||||||
|
|
||||||
|
var collectContainedExercises = function () {
|
||||||
|
return exerciseList.find('tbody > tr').toArray().map(function (item) {return $(item).data('id')});
|
||||||
|
}
|
||||||
|
|
||||||
|
addExercisesButton.on('click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var collectionExercises = collectContainedExercises();
|
||||||
|
var selectedExercises = addExercisesForm.find('select')[0].selectedOptions;
|
||||||
|
for (var i = 0; i < selectedExercises.length; i++) {
|
||||||
|
var exercise = {id: selectedExercises[i].value, title: selectedExercises[i].label}
|
||||||
|
if (collectionExercises.indexOf(exercise.id) === -1) {
|
||||||
|
// only add exercises that are not already contained in the collection
|
||||||
|
var template = '<tr data-id="' + exercise.id + '">' +
|
||||||
|
'<td><span class="fa fa-bars"></span></td>' +
|
||||||
|
'<td>' + exercise.title + '</td>' +
|
||||||
|
'<td><a href="/exercises/' + exercise.id + '"><%= I18n.t('shared.show') %></td>' +
|
||||||
|
'<td><a class="remove-exercise" href="#"><%= I18n.t('shared.destroy') %></td></tr>';
|
||||||
|
exerciseList.find('tbody').append(template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -67,3 +67,7 @@ rect.value-bar {
|
|||||||
padding: 14px;
|
padding: 14px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#exercise-list {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
8
app/views/exercise_collections/_add_exercise_modal.slim
Normal file
8
app/views/exercise_collections/_add_exercise_modal.slim
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
- exercises = Exercise.order(:title)
|
||||||
|
|
||||||
|
form#exercise-selection
|
||||||
|
.form-group
|
||||||
|
span.label = t('activerecord.attributes.exercise_collections.exercises')
|
||||||
|
= collection_select({}, :exercise_ids, exercises, :id, :title, {}, {class: 'form-control', multiple: true})
|
||||||
|
|
||||||
|
button.btn.btn-primary#add-exercises = t('exercise_collections.form.add_exercises')
|
@ -1,4 +1,3 @@
|
|||||||
- exercises = Exercise.order(:title)
|
|
||||||
- users = InternalUser.order(:name)
|
- users = InternalUser.order(:name)
|
||||||
|
|
||||||
= form_for(@exercise_collection, multipart: true) do |f|
|
= form_for(@exercise_collection, multipart: true) do |f|
|
||||||
@ -12,9 +11,6 @@
|
|||||||
.form-group
|
.form-group
|
||||||
= f.label(t('activerecord.attributes.exercise_collections.user'))
|
= f.label(t('activerecord.attributes.exercise_collections.user'))
|
||||||
= f.collection_select(:user_id, users, :id, :name, {}, {class: 'form-control'})
|
= f.collection_select(:user_id, users, :id, :name, {}, {class: 'form-control'})
|
||||||
.form-group
|
|
||||||
= f.label(t('activerecord.attributes.exercise_collections.exercises'))
|
|
||||||
= f.collection_select(:exercise_ids, exercises, :id, :title, {}, {class: 'form-control', multiple: true})
|
|
||||||
|
|
||||||
.table-responsive#exercise-list
|
.table-responsive#exercise-list
|
||||||
table.table
|
table.table
|
||||||
@ -22,17 +18,18 @@
|
|||||||
tr
|
tr
|
||||||
th
|
th
|
||||||
th = t('activerecord.attributes.exercise_collection_item.exercise')
|
th = t('activerecord.attributes.exercise_collection_item.exercise')
|
||||||
th = t('activerecord.attributes.exercise.user')
|
|
||||||
th colspan=2 = t('shared.actions')
|
th colspan=2 = t('shared.actions')
|
||||||
tbody#sortable
|
tbody#sortable
|
||||||
- @exercise_collection.items.order(:position).each do |item|
|
- @exercise_collection.items.order(:position).each do |item|
|
||||||
tr
|
tr data-id=item.exercise.id
|
||||||
td
|
td
|
||||||
span.fa.fa-bars
|
span.fa.fa-bars
|
||||||
td = item.exercise.title
|
td = item.exercise.title
|
||||||
td = item.exercise.author
|
|
||||||
td = link_to(t('shared.show'), item.exercise)
|
td = link_to(t('shared.show'), item.exercise)
|
||||||
td
|
td
|
||||||
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')
|
||||||
|
|
||||||
.actions = render('shared/submit_button', f: f, object: @exercise_collection)
|
.actions = render('shared/submit_button', f: f, object: @exercise_collection)
|
||||||
|
|
||||||
|
= render('shared/modal', id: 'add-exercise-modal', title: t('.add_exercises'), template: 'exercise_collections/_add_exercise_modal')
|
||||||
|
@ -784,3 +784,6 @@ de:
|
|||||||
files: "Dateien"
|
files: "Dateien"
|
||||||
users: "Benutzer"
|
users: "Benutzer"
|
||||||
integrations: "Integrationen"
|
integrations: "Integrationen"
|
||||||
|
exercise_collections:
|
||||||
|
form:
|
||||||
|
add_exercises: "Add Exercises"
|
||||||
|
@ -784,3 +784,6 @@ en:
|
|||||||
files: "Files"
|
files: "Files"
|
||||||
users: "Users"
|
users: "Users"
|
||||||
integrations: "Integrations"
|
integrations: "Integrations"
|
||||||
|
exercise_collections:
|
||||||
|
form:
|
||||||
|
add_exercises: "Aufgaben hinzufügen"
|
||||||
|
Reference in New Issue
Block a user