Start
This commit is contained in:
71
ts/admin/admin-scripts/index.ts
Normal file
71
ts/admin/admin-scripts/index.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
declare const _romhackplaza_admin_scripts: any;
|
||||
|
||||
document.addEventListener( "DOMContentLoaded", ( event ) => {
|
||||
|
||||
let nb_params = 0;
|
||||
function add_arg( e: Event ) {
|
||||
|
||||
nb_params += 1;
|
||||
|
||||
let html_content = document.createElement("div");
|
||||
html_content.id = "arg_" + ( nb_params - 1 ).toString();
|
||||
|
||||
let name_content = document.createElement( "input" );
|
||||
name_content.type = "text";
|
||||
name_content.name = "arg_name_" + ( nb_params - 1 ).toString();
|
||||
name_content.id = "arg_name_" + ( nb_params - 1 ).toString();
|
||||
name_content.setAttribute( 'required', "required" );
|
||||
|
||||
let value_content = document.createElement( "input" );
|
||||
value_content.type = "text";
|
||||
value_content.name = "arg_value_" + ( nb_params - 1 ).toString();
|
||||
value_content.id = "arg_value_" + ( nb_params - 1 ).toString();
|
||||
value_content.setAttribute( 'required', "required" );
|
||||
|
||||
html_content.appendChild( name_content );
|
||||
html_content.appendChild( value_content );
|
||||
html_content.appendChild( document.createElement( "hr" ) )
|
||||
|
||||
document.getElementById( "arguments" )?.appendChild( html_content );
|
||||
|
||||
}
|
||||
|
||||
function _execute_script( e: Event ){
|
||||
|
||||
e.preventDefault();
|
||||
// @ts-ignore
|
||||
let select = document.getElementById( "script_select" ).value ?? "none";
|
||||
if( select == null || select == "none" || select == "" )
|
||||
return;
|
||||
|
||||
const XML: XMLHttpRequest = new XMLHttpRequest();
|
||||
XML.open( 'POST', _romhackplaza_admin_scripts.execute_url );
|
||||
|
||||
let form_data = new FormData();
|
||||
for( let i = 0; i < nb_params; i++ ){
|
||||
|
||||
// @ts-ignore
|
||||
let name = document.getElementById( 'arg_name_' + i.toString() ).value;
|
||||
// @ts-ignore
|
||||
let value = document.getElementById( 'arg_value_' + i.toString()).value;
|
||||
form_data.append( name, value );
|
||||
|
||||
}
|
||||
|
||||
form_data.append( "script", select );
|
||||
form_data.append( "_wpnonce", _romhackplaza_admin_scripts.execute_nonce );
|
||||
form_data.append( "action", "load_admin_script" );
|
||||
|
||||
XML.onreadystatechange = function(){
|
||||
if(XML.readyState === XMLHttpRequest.DONE && XML.status === 200){
|
||||
document.getElementById( 'script-response')!.innerHTML = XML.responseText;
|
||||
}
|
||||
}
|
||||
XML.send( form_data );
|
||||
|
||||
}
|
||||
|
||||
document.getElementById( 'add_args' )?.addEventListener( 'click', add_arg );
|
||||
document.getElementById( 'script-loader' )?.addEventListener( 'submit', _execute_script );
|
||||
|
||||
})
|
||||
113
ts/admin/send-notification/index.ts
Normal file
113
ts/admin/send-notification/index.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
import { format_state_for_select2 } from "../../ajax_requests";
|
||||
declare const _romhackplaza_send_notification: any;
|
||||
declare const romhackplaza_modal_notifications: any;
|
||||
declare function romhackplaza_manage_modal( a: object, b: string|undefined, c: string|undefined, d: string|undefined, e: string|undefined ): void;
|
||||
declare const tinyMCE: any;
|
||||
|
||||
jQuery(document).ready(function( $: any ) {
|
||||
|
||||
$("#recipients").select2({
|
||||
placeholder: "Search an user",
|
||||
ajax: {
|
||||
url: _romhackplaza_send_notification.fetch_url,
|
||||
dataType: "json",
|
||||
delay: 250,
|
||||
data: function (params: any) {
|
||||
return {
|
||||
q: params.term,
|
||||
action: "search_user",
|
||||
_wpnonce: _romhackplaza_send_notification.fetch_nonce
|
||||
};
|
||||
},
|
||||
processResults: function (results: any) {
|
||||
return {
|
||||
results: results
|
||||
}
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
minimumInputLength: 1,
|
||||
templateResult: format_state_for_select2,
|
||||
templateSelection: format_state_for_select2
|
||||
});
|
||||
|
||||
$( "#send-manual-notification" ).on( 'submit', function( e: Event ){
|
||||
|
||||
e.preventDefault();
|
||||
let type: string = $("#type_select").val() || "none";
|
||||
|
||||
if( type === "none" ){
|
||||
romhackplaza_manage_modal( romhackplaza_modal_notifications, "block", "Submit error", "A type is required.", "" );
|
||||
return;
|
||||
}
|
||||
|
||||
let anonymous_sender: string = $( "#anonymous_sender" ).is( ':checked' ) ? "yes" : "no";
|
||||
let all_users: string = $( "#recipients_all" ).is( ':checked' ) ? "yes" : "no";
|
||||
if( all_users !== "yes" ){
|
||||
|
||||
// Defined number of users.
|
||||
let recipients_list: any = $( "#recipients" ).val();
|
||||
if( recipients_list.length <= 0 ){
|
||||
romhackplaza_manage_modal( romhackplaza_modal_notifications, "block", "Submit error", "A user is required.", "" );
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
let recipients_list: any = [];
|
||||
}
|
||||
|
||||
let editor_content: string;
|
||||
if( tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden() ) {
|
||||
// Visual mode.
|
||||
editor_content = tinyMCE.get( 'postContent' ).getContent();
|
||||
} else {
|
||||
// @ts-ignore
|
||||
// Text mode.
|
||||
editor_content = document.getElementById( 'postContent' ).value;
|
||||
}
|
||||
|
||||
if( editor_content === "" ){
|
||||
romhackplaza_manage_modal( romhackplaza_modal_notifications, "block", "Submit error", "Content is required.", "" );
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const form_data: FormData = new FormData( this );
|
||||
form_data.append( "action", "submit_notification" );
|
||||
form_data.append( "content", editor_content );
|
||||
form_data.append( "_wpnonce", _romhackplaza_send_notification.submit_nonce );
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: _romhackplaza_send_notification.fetch_url,
|
||||
data: form_data,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function( response: any ) {
|
||||
|
||||
let real_response: any;
|
||||
|
||||
if( typeof response === "string" ) {
|
||||
try {
|
||||
real_response = JSON.parse(response);
|
||||
} catch( e ) {
|
||||
console.error( e, response );
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
real_response = response;
|
||||
}
|
||||
|
||||
if( real_response != "-1" && real_response?.success === true ) {
|
||||
romhackplaza_manage_modal( romhackplaza_modal_notifications, "block", "Submit successful", "Notification sent.", "" );
|
||||
return;
|
||||
} else {
|
||||
romhackplaza_manage_modal( romhackplaza_modal_notifications, "block", "Submit error", real_response?.message ?? real_response, "" );
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
50
ts/admin/widgets/rhpz-url/class-rhpz-url.ts
Normal file
50
ts/admin/widgets/rhpz-url/class-rhpz-url.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
declare const _romhackplaza_rhpz_url: any;
|
||||
|
||||
export class RhpzUrl {
|
||||
|
||||
container: HTMLElement;
|
||||
form_field_url: HTMLInputElement|null;
|
||||
form: HTMLElement|null;
|
||||
output: HTMLElement|null;
|
||||
|
||||
constructor( selector: any ){
|
||||
|
||||
this.form_field_url = null;
|
||||
this.form = null;
|
||||
this.output = null;
|
||||
|
||||
this.container = document.querySelector( selector );
|
||||
if ( !this.container )
|
||||
return;
|
||||
|
||||
this.form_field_url = this.container.querySelector( '#FormUrl' );
|
||||
this.form = this.container;
|
||||
this.output = this.container.querySelector( '#Create-A-RHPZ-Url-Response' );
|
||||
|
||||
this.events();
|
||||
}
|
||||
|
||||
events() {
|
||||
|
||||
this.form!.onsubmit = ( event ) => this.submit_request( event );
|
||||
|
||||
}
|
||||
|
||||
async submit_request( e: Event ){
|
||||
|
||||
e.preventDefault();
|
||||
let url = this.form_field_url!.value;
|
||||
url = url.replace("https://", "");
|
||||
url = url.replace("http://", "");
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open( 'GET', _romhackplaza_rhpz_url.create_url + url, true );
|
||||
xhr.onload = () => {
|
||||
this.output!.innerHTML = '<a href="' + xhr.responseText + '" target="_blank">' + xhr.responseText + '</a>';
|
||||
}
|
||||
|
||||
xhr.send();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
5
ts/admin/widgets/rhpz-url/index.ts
Normal file
5
ts/admin/widgets/rhpz-url/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { RhpzUrl } from "./class-rhpz-url";
|
||||
|
||||
document.addEventListener( 'DOMContentLoaded', () => {
|
||||
new RhpzUrl( '#Create-A-RHPZ-Url-Form' );
|
||||
})
|
||||
Reference in New Issue
Block a user