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
|
2023-01-12 18:51:32 +01:00
|
|
|
this.on(this.inputTarget, 'cancel', () => {
|
2022-12-13 16:13:31 +01:00
|
|
|
this.inputTarget.dataset.autoAttachUrl =
|
|
|
|
this.inputTarget.dataset.originalAutoAttachUrl;
|
|
|
|
});
|
|
|
|
}
|
2022-12-13 15:22:18 +01:00
|
|
|
}
|
|
|
|
}
|