New IDs, finish Submit Translation page and begin BIG TS.
This commit is contained in:
65
ts/submissions/class-upload.ts
Normal file
65
ts/submissions/class-upload.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import {__, FORBIDDEN_CARS, romhackplaza_modal_submissions, during_upload, I } from "./globals";
|
||||
import {DropContainer} from "./class-drop-container";
|
||||
|
||||
export class Upload {
|
||||
|
||||
file: File;
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
during_upload = !during_upload;
|
||||
this.switchSubmissionButton();
|
||||
|
||||
}
|
||||
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user