Skip to content

Commit

Permalink
f js
Browse files Browse the repository at this point in the history
  • Loading branch information
just806me committed Feb 5, 2024
1 parent 614a433 commit e1fc53e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/assets/javascripts/rails_admin/custom/grade-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ $('[data-component="grade-groups"]').each(function () {
newGroupOption.value = grades.join(',');
newGroupOption.text = options.map(o => o.text).join(', ');
groupSelect.appendChild(newGroupOption);
options.forEach(o => o.remove());
});

$('button[data-action="move-to-grades"]').on('click', function () {
const options = Array.from(groupSelect.selectedOptions);
const groups = options.map(o => o.value.split(',').map(grade => parseInt(grade)));
const texts = options.map(o => o.text.split(','));
const newValue = value.filter(a => !groups.some(b => arrayEq(a, b)));
setValue(newValue);
options.forEach(o => o.remove());
groups.forEach((grades, i) => {
grades.forEach((grade, j) => {
const newGradeOption = document.createElement('option');
newGradeOption.value = grade;
newGradeOption.text = texts[i][j];
gradeSelect.appendChild(newGradeOption);
});
});
});
});

0 comments on commit e1fc53e

Please sign in to comment.