Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/WebApplication/app.js @ 1696:572652803929
bootstrapping the Stone Web viewer configuration file
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Nov 2020 09:34:02 +0100 |
parents | eafb10992e73 |
children | c2802561d7f9 |
comparison
equal
deleted
inserted
replaced
1695:a691ab50d416 | 1696:572652803929 |
---|---|
17 * You should have received a copy of the GNU Affero General Public License | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 var CONFIGURATION_SOURCE = 'configuration.json'; | |
23 var WASM_SOURCE = 'StoneWebViewer.js'; | |
24 | |
22 var COLORS = [ 'blue', 'red', 'green', 'yellow', 'violet' ]; | 25 var COLORS = [ 'blue', 'red', 'green', 'yellow', 'violet' ]; |
23 var SERIES_INSTANCE_UID = '0020,000e'; | 26 var SERIES_INSTANCE_UID = '0020,000e'; |
24 var STUDY_INSTANCE_UID = '0020,000d'; | 27 var STUDY_INSTANCE_UID = '0020,000d'; |
25 var STUDY_DESCRIPTION = '0008,1030'; | 28 var STUDY_DESCRIPTION = '0008,1030'; |
26 var STUDY_DATE = '0008,0020'; | 29 var STUDY_DATE = '0008,0020'; |
27 | 30 |
28 // Registry of the PDF series for which the instance metadata is still waiting | 31 // Registry of the PDF series for which the instance metadata is still waiting |
29 var pendingSeriesPdf_ = {}; | 32 var pendingSeriesPdf_ = {}; |
33 | |
34 var globalConfiguration_ = {}; | |
30 | 35 |
31 | 36 |
32 function getParameterFromUrl(key) { | 37 function getParameterFromUrl(key) { |
33 var url = window.location.search.substring(1); | 38 var url = window.location.search.substring(1); |
34 var args = url.split('&'); | 39 var args = url.split('&'); |
807 }); | 812 }); |
808 | 813 |
809 | 814 |
810 | 815 |
811 | 816 |
817 function ParseJsonWithComments(json) | |
818 { | |
819 if (typeof(json) == 'string') { | |
820 // https://stackoverflow.com/a/62945875/881731 | |
821 return JSON.parse(json.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, | |
822 (m, g) => g ? "" : m)); | |
823 } else { | |
824 return json; | |
825 } | |
826 } | |
812 | 827 |
813 | 828 |
814 $(document).ready(function() { | 829 $(document).ready(function() { |
815 // Enable support for tooltips in Bootstrap | 830 // Enable support for tooltips in Bootstrap |
816 $('[data-toggle="tooltip"]').tooltip({ | 831 $('[data-toggle="tooltip"]').tooltip({ |
819 trigger: 'hover' | 834 trigger: 'hover' |
820 }); | 835 }); |
821 | 836 |
822 //app.modalWarning = true; | 837 //app.modalWarning = true; |
823 | 838 |
824 | 839 axios.get(CONFIGURATION_SOURCE) |
825 var wasmSource = 'StoneWebViewer.js'; | 840 .then(function(response) { |
826 | 841 globalConfiguration_ = ParseJsonWithComments(response.data); |
827 // Option 1: Loading script using plain HTML | 842 |
828 | 843 // Option 1: Loading script using plain HTML |
829 /* | 844 |
830 var script = document.createElement('script'); | 845 /* |
831 script.src = wasmSource; | 846 var script = document.createElement('script'); |
832 script.type = 'text/javascript'; | 847 script.src = WASM_SOURCE; |
833 document.body.appendChild(script); | 848 script.type = 'text/javascript'; |
834 */ | 849 document.body.appendChild(script); |
835 | 850 */ |
836 // Option 2: Loading script using AJAX (gives the opportunity to | 851 |
837 // report explicit errors) | 852 // Option 2: Loading script using AJAX (gives the opportunity to |
838 | 853 // explicitly report errors) |
839 axios.get(wasmSource) | 854 |
840 .then(function (response) { | 855 axios.get(WASM_SOURCE) |
841 var script = document.createElement('script'); | 856 .then(function (response) { |
842 script.innerHTML = response.data; | 857 var script = document.createElement('script'); |
843 script.type = 'text/javascript'; | 858 script.innerHTML = response.data; |
844 document.body.appendChild(script); | 859 script.type = 'text/javascript'; |
860 document.body.appendChild(script); | |
861 }) | |
862 .catch(function (error) { | |
863 alert('Cannot load the WebAssembly framework'); | |
864 }); | |
845 }) | 865 }) |
846 .catch(function (error) { | 866 .catch(function (error) { |
847 alert('Cannot load the WebAssembly framework'); | 867 alert('Cannot load the configuration file'); |
848 }); | 868 }); |
849 }); | 869 }); |
850 | 870 |
851 | 871 |
852 // "Prevent Bootstrap dropdown from closing on clicks" for the list of | 872 // "Prevent Bootstrap dropdown from closing on clicks" for the list of |
853 // studies: https://stackoverflow.com/questions/26639346 | 873 // studies: https://stackoverflow.com/questions/26639346 |
858 | 878 |
859 // Disable the selection of text using the mouse | 879 // Disable the selection of text using the mouse |
860 document.onselectstart = new Function ('return false'); | 880 document.onselectstart = new Function ('return false'); |
861 | 881 |
862 | 882 |
863 | |
864 | |
865 | |
866 | |
867 | |
868 //var expectedOrigin = 'http://localhost:8042'; | |
869 var expectedOrigin = ''; // TODO - INSECURE - CONFIGURATION | |
870 | |
871 window.addEventListener('message', function(e) { | 883 window.addEventListener('message', function(e) { |
872 if ('type' in e.data) { | 884 if ('type' in e.data) { |
873 if (expectedOrigin != '' && | 885 var expectedOrigin = globalConfiguration_['ExpectedMessageOrigin']; |
874 e.origin !== expectedOrigin) { | |
875 alert('Bad origin for the message'); | |
876 return; | |
877 } | |
878 | 886 |
879 if (e.data.type == 'show-osirix-annotations') { | 887 if (expectedOrigin === undefined) { |
888 alert('Dynamic actions are disabled in the Stone Web viewer, ' + | |
889 'set the configuration option "ExpectedMessageOrigin".'); | |
890 } | |
891 else if (expectedOrigin != '*' && | |
892 e.origin !== expectedOrigin) { | |
893 alert('Bad origin for a dynamic action in the Stone Web viewer: "' + e.origin + | |
894 '", whereas the message must have origin: "' + expectedOrigin + '"'); | |
895 } | |
896 else if (e.data.type == 'show-osirix-annotations') { | |
880 var clear = true; // Whether to clear previous annotations | 897 var clear = true; // Whether to clear previous annotations |
881 if ('clear' in e.data) { | 898 if ('clear' in e.data) { |
882 clear = e.data.clear; | 899 clear = e.data.clear; |
883 } | 900 } |
884 | 901 |
885 app.LoadOsiriXAnnotations(e.data.xml, clear); | 902 app.LoadOsiriXAnnotations(e.data.xml, clear); |
886 } else { | 903 } |
887 console.log('Unknown message type: ' + e.data.type); | 904 else { |
905 alert('Unknown type of dynamic action in the Stone Web viewer: ' + e.data.type); | |
888 } | 906 } |
889 } | 907 } |
890 }); | 908 }); |
891 | |
892 | |
893 function Test() | |
894 { | |
895 var s = [ 'length.xml', 'arrow.xml', 'text.xml', 'angle.xml' ]; | |
896 | |
897 for (var i = 0; i < s.length; i++) { | |
898 axios.get(s[i]) | |
899 .then(function (response) { | |
900 //var targetOrigin = 'http://localhost:8000'; | |
901 var targetOrigin = '*'; // TODO - INSECURE | |
902 | |
903 window.postMessage({ | |
904 'type': 'show-osirix-annotations', | |
905 'xml': response.data, | |
906 'clear': false | |
907 }, targetOrigin); | |
908 }); | |
909 } | |
910 } |