2022-09-03 07:19:00 -07:00
|
|
|
import { post } from '@rails/request.js';
|
2022-01-03 13:22:17 -08:00
|
|
|
import { showErrorNotification, showNotification } from 'utilities/notifications';
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2022-01-03 13:22:17 -08:00
|
|
|
|
|
|
|
export function questionboxAllHandler(event: Event): void {
|
|
|
|
const button = event.target as HTMLButtonElement;
|
|
|
|
|
|
|
|
button.disabled = true;
|
|
|
|
document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').readOnly = true;
|
|
|
|
|
2022-09-03 07:19:00 -07:00
|
|
|
post('/ajax/ask', {
|
|
|
|
body: {
|
2022-01-03 13:22:17 -08:00
|
|
|
rcpt: 'followers',
|
|
|
|
question: document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').value,
|
2022-10-11 13:08:59 -07:00
|
|
|
anonymousQuestion: 'false'
|
2022-09-03 07:19:00 -07:00
|
|
|
},
|
|
|
|
contentType: 'application/json'
|
|
|
|
})
|
|
|
|
.then(async response => {
|
|
|
|
const data = await response.json;
|
|
|
|
|
2022-01-03 13:22:17 -08:00
|
|
|
if (data.success) {
|
|
|
|
document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').value = '';
|
|
|
|
window['$']('#modal-ask-followers').modal('hide');
|
2022-10-31 13:23:22 -07:00
|
|
|
|
|
|
|
// FIXME: also solve this using a Stimulus controller
|
|
|
|
const characterCount = document.querySelector<HTMLElement>('#modal-ask-followers [data-character-count-max-value]').dataset.characterCountMaxValue;
|
|
|
|
document.querySelector<HTMLElement>('#modal-ask-followers [data-character-count-target="counter"]').innerHTML = characterCount;
|
2022-01-03 13:22:17 -08:00
|
|
|
}
|
2022-10-11 13:08:59 -07:00
|
|
|
|
2022-01-03 13:22:17 -08:00
|
|
|
showNotification(data.message, data.success);
|
2022-09-03 07:19:00 -07:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
2022-01-03 13:22:17 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
2022-09-03 07:19:00 -07:00
|
|
|
})
|
|
|
|
.finally(() => {
|
2022-01-03 13:22:17 -08:00
|
|
|
button.disabled = false;
|
|
|
|
document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').readOnly = false;
|
2022-09-03 07:19:00 -07:00
|
|
|
});
|
2022-01-03 13:22:17 -08:00
|
|
|
}
|
|
|
|
|
2022-01-03 13:29:09 -08:00
|
|
|
export function questionboxAllInputHandler(event: KeyboardEvent): void {
|
2022-01-03 13:22:17 -08:00
|
|
|
if (event.keyCode == 13 && (event.ctrlKey || event.metaKey)) {
|
|
|
|
document.querySelector<HTMLButtonElement>(`button[name=qb-all-ask]`).click();
|
|
|
|
}
|
2022-10-11 13:08:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function questionboxAllModalAutofocus(): void {
|
|
|
|
document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').focus();
|
|
|
|
}
|