Remove legacy list TypeScript

This commit is contained in:
Andreas Nedbal 2022-12-05 23:08:45 +01:00
parent f76f575991
commit d1eb731304
5 changed files with 0 additions and 138 deletions

View file

@ -8,7 +8,6 @@ import initAnswerbox from 'retrospring/features/answerbox/index';
import initInbox from 'retrospring/features/inbox/index'; import initInbox from 'retrospring/features/inbox/index';
import initUser from 'retrospring/features/user'; import initUser from 'retrospring/features/user';
import initSettings from 'retrospring/features/settings/index'; import initSettings from 'retrospring/features/settings/index';
import initLists from 'retrospring/features/lists';
import initQuestionbox from 'retrospring/features/questionbox'; import initQuestionbox from 'retrospring/features/questionbox';
import initQuestion from 'retrospring/features/question'; import initQuestion from 'retrospring/features/question';
import initModeration from 'retrospring/features/moderation'; import initModeration from 'retrospring/features/moderation';
@ -21,7 +20,6 @@ document.addEventListener('DOMContentLoaded', initAnswerbox);
document.addEventListener('DOMContentLoaded', initInbox); document.addEventListener('DOMContentLoaded', initInbox);
document.addEventListener('DOMContentLoaded', initUser); document.addEventListener('DOMContentLoaded', initUser);
document.addEventListener('turbo:load', initSettings); document.addEventListener('turbo:load', initSettings);
document.addEventListener('DOMContentLoaded', initLists);
document.addEventListener('turbo:load', initQuestionbox); document.addEventListener('turbo:load', initQuestionbox);
document.addEventListener('DOMContentLoaded', initQuestion); document.addEventListener('DOMContentLoaded', initQuestion);
document.addEventListener('DOMContentLoaded', initModeration); document.addEventListener('DOMContentLoaded', initModeration);

View file

@ -1,37 +0,0 @@
import { post } from '@rails/request.js';
import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from 'retrospring/i18n';
export function createListHandler(event: Event): void {
const button = event.target as HTMLButtonElement;
const input = document.querySelector<HTMLInputElement>('input#new-list-name');
post('/ajax/create_list', {
body: {
name: input.value,
user: button.dataset.user
},
contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
if (data.success) {
document.querySelector('#lists-list ul.list-group').insertAdjacentHTML('beforeend', data.render);
}
showNotification(data.message, data.success);
})
.catch(err => {
console.log(err);
showErrorNotification(I18n.translate('frontend.error.message'));
});
}
export function createListInputHandler(event: KeyboardEvent): void {
// Return key
if (event.which === 13) {
event.preventDefault();
document.querySelector<HTMLButtonElement>('button#create-list').click();
}
}

View file

@ -1,45 +0,0 @@
import { post } from '@rails/request.js';
import swal from 'sweetalert';
import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from 'retrospring/i18n';
export function destroyListHandler(event: Event): void {
event.preventDefault();
const button = event.target as HTMLButtonElement;
const list = button.dataset.list;
swal({
title: I18n.translate('frontend.list.confirm.title'),
text: I18n.translate('frontend.list.confirm.text'),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: I18n.translate('voc.delete'),
cancelButtonText: I18n.translate('voc.cancel'),
closeOnConfirm: true
}, () => {
post('/ajax/destroy_list', {
body: {
list: list
},
contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
if (data.success) {
const element = document.querySelector(`li.list-group-item#list-${list}`);
if (element) {
element.remove();
}
}
showNotification(data.message, data.success);
})
.catch(err => {
console.log(err);
showErrorNotification(I18n.translate('frontend.error.message'));
});
});
}

View file

@ -1,13 +0,0 @@
import registerEvents from 'retrospring/utilities/registerEvents';
import { createListHandler, createListInputHandler } from './create';
import { destroyListHandler } from './destroy';
import { listMembershipHandler } from './membership';
export default (): void => {
registerEvents([
{ type: 'click', target: 'input[type=checkbox][name=gm-list-check]', handler: listMembershipHandler, global: true },
{ type: 'click', target: 'button#create-list', handler: createListHandler, global: true },
{ type: 'click', target: 'a#delete-list', handler: destroyListHandler, global: true },
{ type: 'click', target: 'input#new-list-name', handler: createListInputHandler, global: true },
]);
}

View file

@ -1,41 +0,0 @@
import { post } from '@rails/request.js';
import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from 'retrospring/i18n';
export function listMembershipHandler(event: Event): void {
const checkbox = event.target as HTMLInputElement;
const list = checkbox.dataset.list;
const memberCountElement: HTMLElement = document.querySelector(`span#${list}-members`);
let memberCount = Number(memberCountElement.dataset.count);
checkbox.setAttribute('disabled', 'disabled');
memberCount += checkbox.checked ? 1 : -1;
post('/ajax/list_membership', {
body: {
list: list,
user: checkbox.dataset.user,
add: String(checkbox.checked)
},
contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
if (data.success) {
checkbox.checked = data.checked;
memberCountElement.innerHTML = I18n.t('frontend.list.item.members', { count: memberCount });
memberCountElement.dataset.count = memberCount.toString();
}
showNotification(data.message, data.success);
})
.catch(err => {
console.log(err);
showErrorNotification(I18n.translate('frontend.error.message'));
})
.finally(() => {
checkbox.removeAttribute('disabled');
});
}