2022-12-13 15:22:18 +01:00
|
|
|
import { ApplicationController } from './application_controller';
|
|
|
|
import { show } from '@utils';
|
|
|
|
|
|
|
|
export class ReplaceAttachmentController extends ApplicationController {
|
|
|
|
static targets = ['input'];
|
|
|
|
|
|
|
|
declare readonly inputTarget: HTMLInputElement;
|
|
|
|
|
2022-12-13 16:13:31 +01:00
|
|
|
open(event: Event) {
|
2022-12-13 15:22:18 +01:00
|
|
|
show(this.inputTarget);
|
|
|
|
this.inputTarget.click(); // opens input prompt
|
2022-12-13 16:13:31 +01:00
|
|
|
|
|
|
|
const target = event.currentTarget as HTMLButtonElement;
|
|
|
|
|
|
|
|
if (target.dataset.autoAttachUrl) {
|
|
|
|
// set the auto attach url specific to this button to replace the related attachment
|
|
|
|
this.inputTarget.dataset.originalAutoAttachUrl =
|
|
|
|
this.inputTarget.dataset.autoAttachUrl;
|
|
|
|
|
|
|
|
this.inputTarget.dataset.autoAttachUrl = target.dataset.autoAttachUrl;
|
|
|
|
|
|
|
|
// reset autoAttachUrl which would add an attachment
|
|
|
|
// when replace is not finalized
|
|
|
|
this.inputTarget.addEventListener('cancel', () => {
|
|
|
|
this.inputTarget.dataset.autoAttachUrl =
|
|
|
|
this.inputTarget.dataset.originalAutoAttachUrl;
|
|
|
|
});
|
|
|
|
}
|
2022-12-13 15:22:18 +01:00
|
|
|
}
|
|
|
|
}
|