`;
+ html += escapedMessage;
+ if (openPopupEvent.input) {
+ html += ``
+ }
+ html += `
`;
const buttonContainer = `
`;
html += buttonContainer;
let id = 0;
@@ -818,12 +821,15 @@ ${escapedMessage}
}, 100);
id = 0;
+ let inputElement : HTMLInputElement;
+ if (openPopupEvent.input) {
+ inputElement = HtmlUtils.getElementByIdOrFail(`popupinput-${openPopupEvent.popupId}`);
+ }
for (const button of openPopupEvent.buttons) {
const button = HtmlUtils.getElementByIdOrFail(`popup-${openPopupEvent.popupId}-${id}`);
const btnId = id;
button.onclick = () => {
- iframeListener.sendButtonClickedEvent(openPopupEvent.popupId, btnId);
- button.disabled = true;
+ iframeListener.sendButtonClickedEvent(openPopupEvent.popupId, btnId, openPopupEvent.input, openPopupEvent.input ? inputElement.value : '');
}
id++;
}
diff --git a/front/src/iframe_api.ts b/front/src/iframe_api.ts
index 06127dcd..290e11c2 100644
--- a/front/src/iframe_api.ts
+++ b/front/src/iframe_api.ts
@@ -5,7 +5,7 @@ import {Subject} from "rxjs";
import {EnterLeaveEvent, isEnterLeaveEvent} from "./Api/Events/EnterLeaveEvent";
import {OpenPopupEvent} from "./Api/Events/OpenPopupEvent";
import {isButtonClickedEvent} from "./Api/Events/ButtonClickedEvent";
-import {ClosePopupEvent} from "./Api/Events/ClosePopupEvent";
+import {ClosePopupEvent, isClosePopupEvent} from "./Api/Events/ClosePopupEvent";
import {OpenTabEvent} from "./Api/Events/OpenTabEvent";
import {GoToPageEvent} from "./Api/Events/GoToPageEvent";
import {OpenCoWebSiteEvent} from "./Api/Events/OpenCoWebSiteEvent";
@@ -13,18 +13,18 @@ import {OpenCoWebSiteEvent} from "./Api/Events/OpenCoWebSiteEvent";
interface WorkAdventureApi {
sendChatMessage(message: string, author: string): void;
onChatMessage(callback: (message: string) => void): void;
- closeChatMessage() : void;
+ closeChatMessage(): void;
onEnterZone(name: string, callback: () => void): void;
onLeaveZone(name: string, callback: () => void): void;
- openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[]): Popup;
- openTab(url : string): void;
- goToPage(url : string): void;
- openCoWebSite(url : string): void;
+ openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[], input: boolean): Popup;
+ openTab(url: string): void;
+ goToPage(url: string): void;
+ openCoWebSite(url: string): void;
closeCoWebSite(): void;
- disablePlayerControl() : void;
- restorePlayerControl() : void;
- displayBubble() : void;
- removeBubble() : void;
+ disablePlayerControl(): void;
+ restorePlayerControl(): void;
+ displayBubble(): void;
+ removeBubble(): void;
}
declare global {
@@ -51,7 +51,7 @@ interface ButtonDescriptor {
/**
* The type of the button. Can be one of "normal", "primary", "success", "warning", "error", "disabled"
*/
- className?: "normal"|"primary"|"success"|"warning"|"error"|"disabled",
+ className?: "normal" | "primary" | "success" | "warning" | "error" | "disabled",
/**
* Callback called if the button is pressed
*/
@@ -59,7 +59,10 @@ interface ButtonDescriptor {
}
class Popup {
+ inputValue: string;
+
constructor(private id: number) {
+ this.inputValue = '';
}
/**
@@ -70,6 +73,7 @@ class Popup {
'type': 'closePopup',
'data': {
'popupId': this.id,
+ 'inputValue': this.inputValue,
} as ClosePopupEvent
}, '*');
}
@@ -89,69 +93,69 @@ window.WA = {
} as ChatEvent
}, '*');
},
- closeChatMessage() : void{
+ closeChatMessage(): void {
window.parent.postMessage({
- "type" : 'closeChatMessage'
- },'*');
+ "type": 'closeChatMessage'
+ }, '*');
},
- disablePlayerControl() : void {
- window.parent.postMessage({'type' : 'disablePlayerControl'},'*');
+ disablePlayerControl(): void {
+ window.parent.postMessage({'type': 'disablePlayerControl'}, '*');
},
- restorePlayerControl() : void {
- window.parent.postMessage({'type' : 'restorePlayerControl'},'*');
+ restorePlayerControl(): void {
+ window.parent.postMessage({'type': 'restorePlayerControl'}, '*');
},
- displayBubble() : void {
- window.parent.postMessage({'type' : 'displayBubble'},'*');
+ displayBubble(): void {
+ window.parent.postMessage({'type': 'displayBubble'}, '*');
},
- removeBubble() : void {
- window.parent.postMessage({'type' : 'removeBubble'},'*');
+ removeBubble(): void {
+ window.parent.postMessage({'type': 'removeBubble'}, '*');
},
- openTab(url : string) : void{
+ openTab(url: string): void {
window.parent.postMessage({
- "type" : 'openTab',
- "data" : {
+ "type": 'openTab',
+ "data": {
url
} as OpenTabEvent
- },'*');
+ }, '*');
},
- goToPage(url : string) : void{
+ goToPage(url: string): void {
window.parent.postMessage({
- "type" : 'goToPage',
- "data" : {
+ "type": 'goToPage',
+ "data": {
url
} as GoToPageEvent
- },'*');
+ }, '*');
},
- openCoWebSite(url : string) : void{
+ openCoWebSite(url: string): void {
window.parent.postMessage({
- "type" : 'openCoWebSite',
- "data" : {
+ "type": 'openCoWebSite',
+ "data": {
url
} as OpenCoWebSiteEvent
- },'*');
+ }, '*');
},
- closeCoWebSite() : void{
+ closeCoWebSite(): void {
window.parent.postMessage({
- "type" : 'closeCoWebSite'
- },'*');
+ "type": 'closeCoWebSite'
+ }, '*');
},
- openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[]): Popup {
+ openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[], input: boolean = false): Popup {
popupId++;
const popup = new Popup(popupId);
const btnMap = new Map void>();
popupCallbacks.set(popupId, btnMap);
let id = 0;
- for (const button of buttons) {
+ for(const button of buttons) {
const callback = button.callback;
- if (callback) {
+ if(callback) {
btnMap.set(id, () => {
callback(popup);
});
@@ -159,6 +163,9 @@ window.WA = {
id++;
}
+ if(input) {
+ this.disablePlayerControl();
+ }
window.parent.postMessage({
'type': 'openPopup',
@@ -171,7 +178,8 @@ window.WA = {
label: button.label,
className: button.className
};
- })
+ }),
+ input: input
} as OpenPopupEvent
}, '*');
@@ -188,7 +196,7 @@ window.WA = {
},
onEnterZone(name: string, callback: () => void): void {
let subject = enterStreams.get(name);
- if (subject === undefined) {
+ if(subject === undefined) {
subject = new Subject();
enterStreams.set(name, subject);
}
@@ -196,7 +204,7 @@ window.WA = {
},
onLeaveZone(name: string, callback: () => void): void {
let subject = leaveStreams.get(name);
- if (subject === undefined) {
+ if(subject === undefined) {
subject = new Subject();
leaveStreams.set(name, subject);
}
@@ -205,7 +213,7 @@ window.WA = {
}
window.addEventListener('message', message => {
- if (message.source !== window.parent) {
+ if(message.source !== window.parent) {
return; // Skip message in this event listener
}
@@ -213,21 +221,22 @@ window.addEventListener('message', message => {
console.log(payload);
- if (isIframeEventWrapper(payload)) {
+ if(isIframeEventWrapper(payload)) {
const payloadData = payload.data;
- if (payload.type === 'userInputChat' && isUserInputChatEvent(payloadData)) {
+ if(payload.type === 'userInputChat' && isUserInputChatEvent(payloadData)) {
userInputChatStream.next(payloadData);
- } else if (payload.type === 'enterEvent' && isEnterLeaveEvent(payloadData)) {
+ } else if(payload.type === 'enterEvent' && isEnterLeaveEvent(payloadData)) {
enterStreams.get(payloadData.name)?.next();
- } else if (payload.type === 'leaveEvent' && isEnterLeaveEvent(payloadData)) {
+ } else if(payload.type === 'leaveEvent' && isEnterLeaveEvent(payloadData)) {
leaveStreams.get(payloadData.name)?.next();
- } else if (payload.type === 'buttonClickedEvent' && isButtonClickedEvent(payloadData)) {
+ } else if(payload.type === 'buttonClickedEvent' && isButtonClickedEvent(payloadData)) {
const callback = popupCallbacks.get(payloadData.popupId)?.get(payloadData.buttonId);
const popup = popups.get(payloadData.popupId);
- if (popup === undefined) {
- throw new Error('Could not find popup with ID "'+payloadData.popupId+'"');
+ if(popup === undefined) {
+ throw new Error('Could not find popup with ID "' + payloadData.popupId + '"');
}
- if (callback) {
+ if(callback) {
+ popup.inputValue = payloadData.inputValue;
callback(popup);
}
}