annotate Applications/Samples/Web/simple-viewer-single-file.ts @ 319:daa04d15192c am-2

new SimpleViewer sample that has been split in multiple files to be able to scale it
author am@osimis.io
date Thu, 11 Oct 2018 13:16:54 +0200
parents Applications/Samples/Web/simple-viewer.ts@be2660b6e40a
children 612238b3f3e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
1 ///<reference path='../../../Platforms/Wasm/wasm-application-runner.ts'/>
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
diff changeset
2
264
6b98ac45aaee documented how to compile and execute WASM samples
am@osimis.io
parents: 240
diff changeset
3 InitializeWasmApplication("OrthancStoneSimpleViewer", "/orthanc");
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
4
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
5 function SelectTool(toolName: string) {
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
6 var command = {
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
7 command: "selectTool",
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
8 args: {
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
9 toolName: toolName
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
10 }
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
11 };
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
12 SendMessageToStoneApplication(JSON.stringify(command));
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
13
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
14 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
15
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
16 function PerformAction(commandName: string) {
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
17 var command = {
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
18 command: commandName,
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
19 commandType: "simple",
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
20 args: {}
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
21 };
be2660b6e40a wip: commands + status update
am@osimis.io
parents: 287
diff changeset
22 SendMessageToStoneApplication(JSON.stringify(command));
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
23 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
24
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
25 //initializes the buttons
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
26 //-----------------------
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
27 // install "SelectTool" handlers
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
28 document.querySelectorAll("[tool-selector]").forEach((e) => {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
29 console.log(e);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
30 (e as HTMLInputElement).addEventListener("click", () => {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
31 console.log(e);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
32 SelectTool(e.attributes["tool-selector"].value);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
33 });
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
34 });
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
35
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
36 // install "PerformAction" handlers
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
37 document.querySelectorAll("[action-trigger]").forEach((e) => {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
38 (e as HTMLInputElement).addEventListener("click", () => {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
39 PerformAction(e.attributes["action-trigger"].value);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
40 });
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
41 });
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
42
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
43 // this method is called "from the C++ code" when the StoneApplication is updated.
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
44 // it can be used to update the UI of the application
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
45 function UpdateWebApplication(statusUpdateMessage: string) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
46 console.log(statusUpdateMessage);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
47
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
48 if (statusUpdateMessage.startsWith("series-description=")) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
49 document.getElementById("series-description").innerText = statusUpdateMessage.split("=")[1];
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
50 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents: 264
diff changeset
51 }