atcheck/public/js/custom.js

95 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-12-13 23:28:16 +01:00
$(document).ready(function(){
$('.add-mn-btn').on('click', function () {
2019-12-20 01:11:51 +01:00
$('.card-reader').toggleClass('open');
2019-12-13 23:28:16 +01:00
});
$('.add-subject-btn').on('click', function () {
$('.add-subject').toggleClass('open');
if ($('.add-subject').first().hasClass('open')) {
$(this).addClass('btn-danger');
$(this).html('<i class="fa fa-times"></i> Anuluj');
$(this).attr('title', 'Anuluj');
2019-12-13 23:28:16 +01:00
} else {
$(this).removeClass('btn-danger');
$(this).html('<i class="fa fa-plus"></i> Dodaj nowy przedmiot');
$(this).attr('title', 'Dodaj nowy przedmiot');
2019-12-13 23:28:16 +01:00
}
});
$('.add-attendance-btn').on('click', function () {
$('.add-attendance').toggleClass('open');
if ($('.add-attendance').first().hasClass('open')) {
$(this).addClass('btn-danger');
$(this).html('<i class="fa fa-times"></i> Anuluj');
$(this).attr('title', 'Anuluj');
2019-12-13 23:28:16 +01:00
} else {
$(this).removeClass('btn-danger');
$(this).html('<i class="fa fa-plus"></i> Dodaj nowy wpis');
$(this).attr('title', 'Dodaj nowy wpis');
2019-12-13 23:28:16 +01:00
}
});
$(".modal").on("hidden.bs.modal", function(){
const id = $(this).attr('id').split('-')[1];
const originalText = $(this).find(`#note_content_hidden-${id}`).first().val();
$(this).find(`#note_content-${id}`).first().val(originalText);
});
$('.edit-subject-btn').on('click', function () {
$(this).parents('tr.editable').next().toggleClass('d-none');
$(this).parents('tr.editable').toggleClass('d-none');
});
$('.edit-subject-btn-cancel').on('click', function () {
$(this).parents('tr.edit-subject-tr').prev().toggleClass('d-none');
$(this).parents('tr.edit-subject-tr').toggleClass('d-none');
});
if($('body').find('.invalid-feedback-alert').length > 0) {
if($('.add-subject').find('.invalid-feedback').length > 0) {
$('.add-subject-btn').first().click();
}
if($('.edit-subject-tr').find('.invalid-feedback').length > 0) {
let subject_id = $('#subject_id_redirected').val();
$(`#tr-editable-${subject_id}`).find('.edit-subject-btn').first().click();
}
}
$('#sort-select').on('change', function() {
$(location).attr('href', $(this).val())
});
$('#group-select').on('change', function() {
$(location).attr('href', $(this).val())
});
function setSelectedOptionSortAttendances() {
const orderBy = $('#orderBy-hidden').first().val();
const orderDirection = $('#orderDirection-hidden').first().val();
const pattern = `/${orderBy}/${orderDirection}`;
const options = $('#sort-select').find('option');
options.each(function() {
if($(this).val().search(pattern) !== -1) {
$('#sort-select').val($(this).val());
}
});
}
setSelectedOptionSortAttendances();
function setSelectedOptionGroup() {
const groupBy = $('#groupBy-hidden').first().val();
const pattern = `/${groupBy}`;
const options = $('#group-select').find('option');
options.each(function() {
if($(this).val().search(pattern) !== -1) {
$('#group-select').val($(this).val());
}
});
}
setSelectedOptionGroup();
2019-12-20 15:46:32 +01:00
$('input[type="checkbox"]').on('change', function() {
$('input[type="checkbox"]').not(this).prop('checked', false);
});
2019-12-13 23:28:16 +01:00
});