import {__, I } from "./globals"; declare const _romhackplaza_script_uploader: any; declare const romhackplaza_modal_submissions: any; export class Reserve_Post_ID { /** * * @param callback - MUST BE FROM A Upload child. */ constructor( callback: () => any ){ if( I.is_edit ) { callback(); return; } if( I.custom_post_type === undefined || I.custom_post_type === "unknown" ){ console.error( "The custom post type is missing" ); return; } this.do_request( callback ); } private do_request( callback: () => any ){ jQuery.ajax({ type: "POST", url: _romhackplaza_script_uploader.submit_url, data: { action: "reserve_post_id", custom_post_type: I.custom_post_type, _wpnonce: _romhackplaza_script_uploader.reserve_nonce }, success: function( response: any ) { if( response.success ) { I.reserved_post_id = response.data.post_id; jQuery( "#reservedPostID" ).val( I.reserved_post_id ); callback(); } else { romhackplaza_manage_modal( romhackplaza_modal_submissions, "block", __( "Submit error", 'romhackplaza' ), __( "Could not reserve a post ID. Please refresh the page.", "romhackplaza" ), "" ); } }, error: function( response: any ) { romhackplaza_manage_modal( romhackplaza_modal_submissions, "block", __( "Submit error", 'romhackplaza' ), __( "Error occurred while reserving a post ID. Please refresh the page.", "romhackplaza" ), "" ); } }); } }