New IDs, finish Submit Translation page and begin BIG TS.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
use RomhackPlaza\Identifiers\Post_Fields;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Discord_Notification extends Abstract_Extender {
|
||||
@@ -12,7 +13,8 @@ class Discord_Notification extends Abstract_Extender {
|
||||
|
||||
protected function extend(): void
|
||||
{
|
||||
$this->add_action( 'RomhackPlaza\\Extenders\\Discord_Notification\\Send_Notification_After_Submission', [ $this, 'send_notification_after_submission' ], 10, 4 );
|
||||
$this->add_action( 'RomhackPlaza\\Extenders\\Discord_Notification\\Send_Notification_After_Submission',
|
||||
[ $this, 'send_notification_after_submission' ], 10, 4 );
|
||||
}
|
||||
|
||||
protected function get_webhook_url( string $type = 'global' ): string {
|
||||
@@ -93,7 +95,7 @@ class Discord_Notification extends Abstract_Extender {
|
||||
if( $webhook == null || $content == null ) return;
|
||||
|
||||
$this->send_to_discord( $webhook, $content );
|
||||
update_post_meta( $post_id, 'discord_noticed', "yes" );
|
||||
update_post_meta( $post_id, Post_Fields::DISCORD_NOTICED->value, "yes" );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ defined( '\ABSPATH' ) || exit;
|
||||
use RomhackPlaza\API\File_Server;
|
||||
use RomhackPlaza\Extenders\Post\Properties;
|
||||
use RomhackPlaza\Format;
|
||||
use RomhackPlaza\Identifiers\Post_Fields;
|
||||
use RomhackPlaza\Identifiers\Taxonomies;
|
||||
use RomhackPlaza\Modal;
|
||||
use RomhackPlaza\Overrides\Roles;
|
||||
use RomhackPlaza\Script;
|
||||
use RomhackPlaza\Script_Type;
|
||||
@@ -213,14 +216,16 @@ class Submissions extends Abstract_Extender {
|
||||
|
||||
$context['terms_language'] = array_merge( $priority_terms, $other_terms );
|
||||
|
||||
$context['value_terms_language'] = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'language', [ 'fields' => 'ids' ] ) |> $this->test_terms_array(...) : [];
|
||||
$context['value_terms_language'] = $context['submission_post_id'] != 0
|
||||
? wp_get_post_terms( $context['submission_post_id'], Taxonomies::LANG->value, [ 'fields' => 'ids' ] ) |> $this->test_terms_array(...)
|
||||
: [];
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function add_and_format_game( &$context ){
|
||||
|
||||
$game_term = $context['submission_post_id'] != 0 ? get_the_terms( $context['submission_post_id'], 'game' ) : 0;
|
||||
$game_term = $context['submission_post_id'] != 0 ? get_the_terms( $context['submission_post_id'], Taxonomies::GAME->value ) : 0;
|
||||
$context['value_game_id'] = $game_term != 0 && !is_wp_error( $game_term ) ? $game_term[0]->term_id : '';
|
||||
$context['value_game_name'] = $game_term != 0 && !is_wp_error( $game_term ) ? $game_term[0]->name : '';
|
||||
|
||||
@@ -231,11 +236,11 @@ class Submissions extends Abstract_Extender {
|
||||
protected function add_and_format_platform( &$context ){
|
||||
|
||||
$context['terms_platform'] = \Timber\Timber::get_terms([
|
||||
'taxonomy' => 'platform',
|
||||
'taxonomy' => Taxonomies::PLATFORM->value,
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
|
||||
$platform_term = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'platform', ['fields' => 'ids'] ) : 0;
|
||||
$platform_term = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], Taxonomies::PLATFORM->value , ['fields' => 'ids'] ) : 0;
|
||||
$context['value_platform_id'] = $platform_term != 0 && !empty( $platform_term ) ? $platform_term[0] : '';
|
||||
|
||||
return $context;
|
||||
@@ -243,18 +248,18 @@ class Submissions extends Abstract_Extender {
|
||||
|
||||
protected function add_and_format_hashes( &$context )
|
||||
{
|
||||
$context['value_hashes'] = $context['submission_post_id'] != 0 ? esc_textarea( get_post_meta( $context['submission_post_id'], 'hashes', true ) ) : '';
|
||||
$context['value_hashes'] = $context['submission_post_id'] != 0 ? esc_textarea( get_post_meta( $context['submission_post_id'], Post_Fields::HASHES->value, true ) ) : '';
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function add_and_format_genre( &$context ){
|
||||
|
||||
$context['terms_genre'] = \Timber\Timber::get_terms([
|
||||
'taxonomy' => 'genre',
|
||||
'taxonomy' => Taxonomies::GENRE->value,
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
|
||||
$genre_term = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'genre', ['fields' => 'ids'] ) : 0;
|
||||
$genre_term = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], Taxonomies::GENRE->value, ['fields' => 'ids'] ) : 0;
|
||||
$context['value_genre_id'] = $genre_term != 0 && !empty( $genre_term ) ? $genre_term[0] : '';
|
||||
|
||||
return $context;
|
||||
@@ -262,11 +267,11 @@ class Submissions extends Abstract_Extender {
|
||||
|
||||
protected function add_and_format_status( &$context ){
|
||||
|
||||
$context['list_status'] = \Timber\Timber::get_terms([
|
||||
'taxonomy' => 'hack-status',
|
||||
$context['terms_status'] = \Timber\Timber::get_terms([
|
||||
'taxonomy' => Taxonomies::STATUS->value,
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
$context['value_terms_status'] = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'hack-status', [ 'fields' => 'ids' ] ) |> $this->test_terms_array(...) : [];
|
||||
$context['value_terms_status'] = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], Taxonomies::STATUS->value, [ 'fields' => 'ids' ] ) |> $this->test_terms_array(...) : [];
|
||||
|
||||
return $context;
|
||||
}
|
||||
@@ -282,7 +287,7 @@ class Submissions extends Abstract_Extender {
|
||||
$context['attachments_settings'] = [
|
||||
'post_id' => $context['submission_post_id'] != 0 ? $context['submission_post_id'] : 'new-post',
|
||||
'fields_groups' => "REPLACED",
|
||||
'fields' => [ 'custom_featured_image', 'my_gallery' ],
|
||||
'fields' => [ Post_Fields::MAIN_IMAGE->value, Post_Fields::GALLERY->value ],
|
||||
'submit_value' => __( 'Add Images', 'romhackplaza' ),
|
||||
'updated_message' => __( "Images added!", 'romhackplaza' ),
|
||||
'form' => false
|
||||
@@ -294,18 +299,25 @@ class Submissions extends Abstract_Extender {
|
||||
|
||||
protected function add_and_format_author( &$context ){
|
||||
|
||||
$context['value_authors'] = $context['submission_post_id'] != 0 ? get_the_terms( $context['submission_post_id'], 'author' ) |> $this->test_terms_array(...) : [];
|
||||
$context['value_authors'] = $context['submission_post_id'] != 0 ? get_the_terms( $context['submission_post_id'], Taxonomies::AUTHORS->value ) |> $this->test_terms_array(...) : [];
|
||||
return $context;
|
||||
|
||||
}
|
||||
|
||||
protected function add_and_format_credits( &$context ){
|
||||
|
||||
$context['value_credits'] = $context['submission_post_id'] != 0 ? esc_textarea( get_post_meta( $context['submission_post_id'], 'staff', true ) ) : '';
|
||||
$context['value_credits'] = $context['submission_post_id'] != 0 ? esc_textarea( get_post_meta( $context['submission_post_id'], Post_Fields::STAFF_CREDITS->value, true ) ) : '';
|
||||
return $context;
|
||||
|
||||
}
|
||||
|
||||
protected function add_and_format_extra_links( &$context ){
|
||||
|
||||
$context['value_release_site'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], Post_Fields::RELEASE_SITE->value, true ) ) : '';
|
||||
$context['value_youtube_video'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], Post_Fields::YOUTUBE_VIDEO->value, true ) ) : '';
|
||||
return $context;
|
||||
}
|
||||
|
||||
public function fill_fields_for_timber( $context ){
|
||||
|
||||
global $post;
|
||||
@@ -362,17 +374,17 @@ class Submissions extends Abstract_Extender {
|
||||
$context['entry_title_field_name'] = __( "Name:", "romhackplaza" );
|
||||
|
||||
// Entry title value.
|
||||
$context['value_entry_title'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], 'entry_title', true ) ) : "";
|
||||
$context['value_entry_title'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], Post_Fields::ENTRY_TITLE->value, true ) ) : "";
|
||||
|
||||
// Patch version label.
|
||||
$context['version_number_field_name'] = __( "Version:", "romhackplaza" );
|
||||
|
||||
// Patch version value
|
||||
$context['value_version_number'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], 'versionNumber', true ) ) : "";
|
||||
$context['value_version_number'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], Post_Fields::VERSION_NUMBER->value, true ) ) : "";
|
||||
|
||||
// Release date value
|
||||
$context['value_release_date'] = "";
|
||||
$release_date = $context['submission_post_id'] != 0 ? get_post_meta( $context['submission_post_id'], 'release_date', true ) : false;
|
||||
$release_date = $context['submission_post_id'] != 0 ? get_post_meta( $context['submission_post_id'], Post_Fields::LAST_UPDATED->value, true ) : false;
|
||||
if( $release_date ) {
|
||||
$date = \DateTime::createFromFormat( 'Ymd', $release_date );
|
||||
if( $date )
|
||||
@@ -394,6 +406,8 @@ class Submissions extends Abstract_Extender {
|
||||
'quicktags' => array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close'),
|
||||
];
|
||||
|
||||
$context['submission_save_as_draft_checkbox'] = $context['submission_post_id'] != 0 && get_post_status($context['submission_post_id']) === 'draft';
|
||||
|
||||
$post_type_rhpz_obj = null;
|
||||
|
||||
if( str_contains( $post->post_name, 'translation' ) ){
|
||||
@@ -411,6 +425,7 @@ class Submissions extends Abstract_Extender {
|
||||
$context = $this->add_and_format_main_image_gallery( $context );
|
||||
$context = $this->add_and_format_author( $context );
|
||||
$context = $this->add_and_format_credits( $context );
|
||||
$context = $this->add_and_format_extra_links( $context );
|
||||
|
||||
}
|
||||
|
||||
@@ -456,6 +471,10 @@ class Submissions extends Abstract_Extender {
|
||||
|
||||
}
|
||||
|
||||
new Modal(
|
||||
'submissions', "", ""
|
||||
)->render();
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ class SubmissionAccordionNode extends Node {
|
||||
case 'team-information':
|
||||
return __('Team Information', 'romhackplaza');
|
||||
break;
|
||||
case 'extra-links':
|
||||
return __( 'Related Links', 'romhackplaza');
|
||||
break;
|
||||
}
|
||||
|
||||
return __( "Unknown", 'romhackplaza' );
|
||||
@@ -51,6 +54,9 @@ class SubmissionAccordionNode extends Node {
|
||||
case 'team-information':
|
||||
return 'fas fa-users';
|
||||
break;
|
||||
case 'extra-links':
|
||||
return 'fas fa-link';
|
||||
break;
|
||||
}
|
||||
|
||||
return 'fas fa-question-circle';
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Identifier {
|
||||
|
||||
const string CAP_EDIT_POSTS = "edit_posts";
|
||||
const string CAP_EDIT_OTHER_POSTS = "edit_others_posts";
|
||||
|
||||
const string CPT_TRANSLATIONS = "translations";
|
||||
const string CPT_ROMHACKS = "romhacks";
|
||||
const string CPT_HOMEBREWS = "homebrew";
|
||||
const string CPT_UTILITIES = "utilities";
|
||||
const string CPT_DOCUMENTS = "documents";
|
||||
const string CPT_LUA_SCRIPTS = "lua-scripts";
|
||||
const string CPT_TUTORIALS = "tutorials";
|
||||
const string CPT_NEWS = "news";
|
||||
const string CPT_REVIEWS = "reviews";
|
||||
|
||||
// ...
|
||||
|
||||
const string TAX_GAME = "game";
|
||||
const string TAX_STATUS = "hack-status";
|
||||
const string TAX_LANG = "language";
|
||||
const string TAX_PLATFORM = "platform";
|
||||
const string TAX_AUTHORS = "author-name";
|
||||
const string TAX_UTILITY_CATEGORY = "utility-category";
|
||||
const string TAX_LEVEL = "experience-level";
|
||||
const string TAX_OS = "utility-os";
|
||||
const string TAX_DOCUMENT_CATEGORY = "document-category";
|
||||
const string TAX_MODIFICATIONS = "modifications";
|
||||
const string TAX_HOMEBREW_TYPE = "homebrew-type";
|
||||
const string TAX_NEWS_CATEGORY = "news-category";
|
||||
const string TAX_GENRE = "genre";
|
||||
const string TAX_TUTORIAL_CATEGORY = "tutorial-category";
|
||||
const string TAX_LUA_MODIFICATIONS = "lua-modifications";
|
||||
|
||||
// ...
|
||||
|
||||
const string ENTRY_GALLERY = "my_gallery";
|
||||
const string ENTRY_MAIN_IMAGE = "custom_featured_image";
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
}
|
||||
13
src/Identifiers/Misc.php
Normal file
13
src/Identifiers/Misc.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Identifiers;
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
enum Misc: string {
|
||||
|
||||
case PS_LOCKED = 'locked';
|
||||
case CAP_EDIT_POSTS = 'edit_posts';
|
||||
case CAP_EDIT_OTHERS_POSTS = 'edit_others_posts';
|
||||
case CAP_MANAGE_OPTIONS = 'manage_options';
|
||||
|
||||
}
|
||||
19
src/Identifiers/Post_Fields.php
Normal file
19
src/Identifiers/Post_Fields.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Identifiers;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
enum Post_Fields: string {
|
||||
|
||||
case DISCORD_NOTICED = 'discord_noticed';
|
||||
case ENTRY_TITLE = 'entry_title';
|
||||
case GALLERY = 'my_gallery';
|
||||
case HASHES = 'hashes';
|
||||
case LAST_UPDATED = 'release_date';
|
||||
case MAIN_IMAGE = 'custom_featured_image';
|
||||
case RELEASE_SITE = 'release_site';
|
||||
case STAFF_CREDITS = 'staff';
|
||||
case VERSION_NUMBER = 'version_number';
|
||||
case YOUTUBE_VIDEO = 'youtube_video';
|
||||
|
||||
}
|
||||
18
src/Identifiers/Post_Types.php
Normal file
18
src/Identifiers/Post_Types.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Identifiers;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
enum Post_Types: string {
|
||||
|
||||
case TRANSLATIONS = 'translations';
|
||||
case ROMHACKS = 'romhacks';
|
||||
case HOMEBREWS = 'homebrew';
|
||||
case UTILITIES = 'utilities';
|
||||
case DOCUMENTS = 'documents';
|
||||
case LUA_SCRIPTS = 'lua-scripts';
|
||||
case TUTORIALS = 'tutorials';
|
||||
case NEWS = 'news';
|
||||
case REVIEWS = 'reviews';
|
||||
|
||||
}
|
||||
24
src/Identifiers/Taxonomies.php
Normal file
24
src/Identifiers/Taxonomies.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Identifiers;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
enum Taxonomies: string {
|
||||
|
||||
case GAME = 'game';
|
||||
case STATUS = 'hack-status';
|
||||
case LANG = 'language';
|
||||
case PLATFORM = 'platform';
|
||||
case AUTHORS = 'author-name';
|
||||
case UTILITY_CATEGORY = 'utility-category';
|
||||
case LEVEL = 'experience-level';
|
||||
case OS = 'utility-os';
|
||||
case DOCUMENT_CATEGORY = 'document-category';
|
||||
case MODIFICATIONS = 'modifications';
|
||||
case HOMEBREW_TYPE = 'homebrew-type';
|
||||
case NEWS_CATEGORY = 'news-category';
|
||||
case GENRE = 'genre';
|
||||
case TUTORIAL_CATEGORY = 'tutorial-category';
|
||||
case LUA_MODIFICATIONS = 'lua-modifications';
|
||||
|
||||
}
|
||||
@@ -131,4 +131,15 @@ class Script {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function enable_i18n(): Script {
|
||||
|
||||
if( $this->type == Script_Type::JS ) {
|
||||
$this->deps[] = 'wp-i18n';
|
||||
wp_set_script_translations($this->handle, 'romhackplaza');
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
3
ts/globals.d.ts
vendored
3
ts/globals.d.ts
vendored
@@ -1,3 +1,6 @@
|
||||
/// <reference types="jquery" />
|
||||
declare const $: any;
|
||||
declare const jQuery: any;
|
||||
|
||||
/// <reference types="romhackplaza" />
|
||||
declare function romhackplaza_manage_modal( a: object, b: string|undefined, c: string|undefined, d: string|undefined, e: string|undefined ): void;
|
||||
73
ts/submissions/class-drop-container.ts
Normal file
73
ts/submissions/class-drop-container.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import {type Can_Upload_Detail, __} from "./globals";
|
||||
|
||||
export class DropContainer {
|
||||
|
||||
element: HTMLElement;
|
||||
text_element: HTMLElement;
|
||||
enabled: boolean;
|
||||
|
||||
constructor(element: HTMLElement, text_element: HTMLElement) {
|
||||
|
||||
this.element = element;
|
||||
this.text_element = text_element;
|
||||
this.enabled = true;
|
||||
|
||||
this.addEvents();
|
||||
|
||||
}
|
||||
|
||||
switch(){
|
||||
|
||||
this.enabled = !this.enabled;
|
||||
if( !this.enabled )
|
||||
this.text_element.innerHTML = __( "Please wait...", 'romhackplaza' );
|
||||
else
|
||||
this.text_element.innerHTML = __( "Drop files here or click to upload the file", 'romhackplaza' );
|
||||
|
||||
}
|
||||
|
||||
private addEvents(): void {
|
||||
|
||||
this.element.addEventListener( 'click', this.submitFile, false );
|
||||
this.element.addEventListener( 'dragover', (e: Event) => e.preventDefault(), false );
|
||||
this.element.addEventListener( 'dragenter', (e: Event) => this.element.classList.add( 'drag-active'), false );
|
||||
this.element.addEventListener( 'dragleave', (e: Event) => this.element.classList.remove( 'drag-active'), false );
|
||||
this.element.addEventListener( 'drop', this.dropElement );
|
||||
}
|
||||
|
||||
submitFile( e: Event ): void {
|
||||
|
||||
if( this.enabled ) {
|
||||
|
||||
let input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.onchange = ( e: Event ) => {
|
||||
// @ts-ignore
|
||||
let files: Array<File> = Array.from( input.files );
|
||||
this.dispatchEvent( files[0] as File );
|
||||
}
|
||||
input.click();
|
||||
}
|
||||
}
|
||||
|
||||
dropElement( e: Event ): void {
|
||||
|
||||
e.preventDefault();
|
||||
this.element.classList.remove( 'drag-active');
|
||||
if( this.enabled )
|
||||
// @ts-ignore
|
||||
this.dispatchEvent( e.dataTransfer.files[0] );
|
||||
}
|
||||
|
||||
dispatchEvent( file: File ) {
|
||||
|
||||
const evt = new CustomEvent<Can_Upload_Detail>( 'can_upload', {
|
||||
detail: {
|
||||
file
|
||||
}
|
||||
});
|
||||
document.dispatchEvent(evt);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
8
ts/submissions/class-file-list.ts
Normal file
8
ts/submissions/class-file-list.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Server_File } from './class-server-file';
|
||||
|
||||
export class FileList {
|
||||
|
||||
list: Server_File[] = [];
|
||||
|
||||
|
||||
}
|
||||
4
ts/submissions/class-server-file.ts
Normal file
4
ts/submissions/class-server-file.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export class Server_File {
|
||||
|
||||
is_dirty: boolean = false;
|
||||
}
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
19
ts/submissions/globals.ts
Normal file
19
ts/submissions/globals.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export declare const _romhackplaza_script_uploader: any;
|
||||
export declare const romhackplaza_modal_submissions: any;
|
||||
declare const wp: any;
|
||||
export const { __, _x, _n, _nx } = wp.i18n;
|
||||
|
||||
|
||||
export const FORBIDDEN_CARS: Array<string> = [
|
||||
"&", "+"
|
||||
];
|
||||
|
||||
export let during_upload = false;
|
||||
export const I: any = {
|
||||
upload: undefined,
|
||||
drop_container: undefined,
|
||||
}
|
||||
|
||||
export interface Can_Upload_Detail {
|
||||
file: File;
|
||||
}
|
||||
20
ts/submissions/index.ts
Normal file
20
ts/submissions/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {type Can_Upload_Detail, during_upload, I} from "./globals";
|
||||
import {Upload} from "./class-upload";
|
||||
import {DropContainer} from "./class-drop-container";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
if( !document.getElementById( 'fileInput' ) ) // Check if exists.
|
||||
|
||||
// @ts-ignore
|
||||
I.drop_container = new DropContainer( document.getElementById( 'file-container' ) as HTMLElement, document.getElementById( 'file-container-text' ) as HTMLElement );
|
||||
|
||||
// @ts-ignore
|
||||
document.addEventListener( 'can_upload', (e: CustomEvent<Can_Upload_Detail> ) => {
|
||||
|
||||
const { file } = e.detail;
|
||||
if( !during_upload ) // @ts-ignore
|
||||
I.upload = new Upload( file );
|
||||
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user