2020-08-06 02:26:51 +09:00
|
|
|
import { fetchGet } from './fetch';
|
|
|
|
|
2019-02-10 20:48:16 +09:00
|
|
|
(function ($) {
|
|
|
|
$.fn.linkCard = function (options) {
|
2020-06-06 18:01:56 +09:00
|
|
|
const settings = $.extend(
|
|
|
|
{
|
|
|
|
endpoint: '/api/checkin/card',
|
|
|
|
},
|
|
|
|
options
|
|
|
|
);
|
2019-02-10 20:48:16 +09:00
|
|
|
|
|
|
|
return this.each(function () {
|
2020-06-06 16:14:11 +09:00
|
|
|
const $this = $(this);
|
2020-08-06 02:26:51 +09:00
|
|
|
|
|
|
|
const url = $this.find('a').attr('href');
|
|
|
|
if (!url) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchGet(settings.endpoint, { url })
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
const $metaColumn = $this.find('.col-12:last-of-type');
|
|
|
|
const $imageColumn = $this.find('.col-12:first-of-type');
|
|
|
|
const $title = $this.find('.card-title');
|
|
|
|
const $desc = $this.find('.card-text');
|
|
|
|
const $image = $imageColumn.find('img');
|
|
|
|
|
|
|
|
if (data.title === '') {
|
|
|
|
$title.hide();
|
|
|
|
} else {
|
|
|
|
$title.text(data.title);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.description === '') {
|
|
|
|
$desc.hide();
|
|
|
|
} else {
|
|
|
|
$desc.text(data.description);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.image === '') {
|
|
|
|
$imageColumn.hide();
|
|
|
|
$metaColumn.removeClass('col-md-6');
|
|
|
|
} else {
|
|
|
|
$image.attr('src', data.image);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.title !== '' || data.description !== '' || data.image !== '') {
|
|
|
|
$this.removeClass('d-none');
|
|
|
|
}
|
|
|
|
});
|
2019-02-10 20:48:16 +09:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-02-16 23:02:53 +09:00
|
|
|
$.fn.pageSelector = function () {
|
|
|
|
return this.on('change', function () {
|
|
|
|
location.href = $(this).find(':selected').data('href');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-03-05 01:22:49 +09:00
|
|
|
$.fn.deleteCheckinModal = function () {
|
|
|
|
return this.each(function () {
|
2020-06-06 18:01:56 +09:00
|
|
|
$(this)
|
|
|
|
.on('show.bs.modal', function (event) {
|
2020-06-06 19:12:00 +09:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2020-06-06 18:01:56 +09:00
|
|
|
const target = $(event.relatedTarget!);
|
|
|
|
const modal = $(this);
|
|
|
|
modal.find('.modal-body .date-label').text(target.data('date'));
|
|
|
|
modal.data('id', target.data('id'));
|
|
|
|
})
|
|
|
|
.find('.btn-danger')
|
2020-06-06 18:40:49 +09:00
|
|
|
.on('click', function (_event) {
|
2020-06-06 18:01:56 +09:00
|
|
|
const modal = $('#deleteCheckinModal');
|
|
|
|
const form = modal.find('form');
|
|
|
|
form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null);
|
|
|
|
form.submit();
|
|
|
|
});
|
2019-03-05 01:22:49 +09:00
|
|
|
});
|
|
|
|
};
|
2020-06-06 16:14:11 +09:00
|
|
|
})(jQuery);
|