Files
Romhack-Plaza---WordPress-P…/ts/submissions/class-upload.ts

87 lines
2.5 KiB
TypeScript

import {__, FORBIDDEN_CARS, I } from "./globals";
import {DropContainer} from "./class-drop-container";
declare const _romhackplaza_script_uploader: any;
declare const romhackplaza_modal_submissions: any;
export class Upload {
file: File;
progress_bar: HTMLElement|undefined;
constructor( file: File ){
this.file = file;
this.beginUpload();
}
private beginUpload(){
if( this.checkForbiddenCars() ){
romhackplaza_manage_modal( romhackplaza_modal_submissions, "block", __( "Submit error", 'romhackplaza' ), __( "There is a forbidden character in the file name, please change it.", 'romhackplaza' ), "" );
return;
}
if( !this.file ) {
console.error("WTF at beginUpload method.");
return;
}
this.switchDuringUpload();
if( typeof I.drop_container !== 'undefined' && I.drop_container instanceof DropContainer )
I.drop_container.switch();
let progress = document.getElementById( 'progress' );
if( progress !== null ) {
progress.style.display = 'block';
this.progress_bar = progress.querySelector('.bar') as HTMLElement;
}
if( I.reserved_post_id === undefined || I.reserved_post_id === null )
console.log( "ok" );
}
checkForbiddenCars() :boolean {
// @ts-ignore
for( let char: string of FORBIDDEN_CARS ){
if( this.file.name.includes(char) )
return true;
}
return false;
}
private switchDuringUpload(): void {
// @ts-ignore
I.during_upload = !I.during_upload;
this.changeStatus( __( "Preparing upload...", 'romhackplaza' ) );
this.switchSubmissionButton();
}
private changeStatus( str: string ){
let sts: HTMLElement|null = document.getElementById( 'status' );
if( sts !== null )
sts.textContent = str;
}
private switchSubmissionButton(): void {
let btn: HTMLElement|null = document.getElementById( 'submitTranslationButton' );
if( btn !== null ){
let conv_btn = btn as HTMLButtonElement;
if( conv_btn.disabled ){
conv_btn.disabled = false;
conv_btn.innerText = __( 'Submit Entry', 'romhackplaza' );
} else {
conv_btn.disabled = true;
conv_btn.innerText = __( 'Wait for upload...', 'romhackplaza' );
}
}
}
}