Debian Codegraph @

examples/flask_app/gui/index.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head lang="en">
4 <meta charset="UTF-8">
5 <style type="text/css">
6 body {
7 color: #333;
8 font-size: 14pt;
9 }
10
11 h1 {
12 font-size: 24pt;
13 }
14
15 </style>
16 </head>
17 <body>
18
19 <h1>My first pywebview application</h1>
20
21 <button onclick="openFolder()">Open folder</button>
22 <button onclick="toggleFullscreen()">Toggle fullscreen</button>
23 <button onclick="doStuff()">Do stuff</button>
24 <div id="open-folder-container"></div>
25 <div id="stuff-container"></div>
26 <div id="json-container"></div>
27
28 <div style="text-align: center; margin-top: 50px;">
29 <a href="http://mbsy.co/gHVfC" target="_blank" style="outline:none;border:none;" onclick="openLink(event)">
30 <img src="https://ambassador-api.s3.amazonaws.com/uploads/marketing/11948/2016_11_29_21_53_43.png" alt="DreamHost" border="0" />
31 </a>
32 </div>
33
34 <script>
35 window.token = '{{ token }}';
36 // Perform background initialization
37 doAjax("/init", "POST");
38
39 function getMethods(obj) {
40 var result = [];
41 for (var id in obj) {
42 try {
43 if (typeof(obj[id]) == "function") {
44 result.push(id + ": " + obj[id].toString());
45 }
46 } catch (err) {
47 result.push(id + ": inaccessible");
48 }
49 }
50 return result;
51 }
52
53 function openFolderHandler() {
54 if (this.responseText) {
55 var response = JSON.parse(this.responseText);
56 document.getElementById("open-folder-container").innerHTML = 'Selected directory: ' + response.directory;
57 }
58 }
59
60 function doStuffHandler(response) {
61 if (this.responseText) {
62 var response = JSON.parse(this.responseText);
63 document.getElementById("stuff-container").innerHTML = response.result;
64 }
65
66 }
67
68 function openFolder() {
69 doAjax("/choose/path", "POST", openFolderHandler);
70 }
71
72 function doStuff() {
73 doAjax("/do/stuff", "POST", doStuffHandler);
74 }
75
76 function toggleFullscreen() {
77 doAjax("/fullscreen", "POST", doStuffHandler);
78 }
79
80 function openLink(e) {
81 e.preventDefault()
82 var request = {url: e.currentTarget.href}
83 doAjax("/open-url", "POST", false, request)
84 }
85
86 // From https://gist.github.com/dharmavir/936328
87 function getHttpRequestObject()
88 {
89 // Define and initialize as false
90 var xmlHttpRequst = false;
91
92 // Mozilla/Safari/Non-IE
93 if (window.XMLHttpRequest)
94 {
95 xmlHttpRequst = new XMLHttpRequest();
96 }
97 // IE
98 else if (window.ActiveXObject)
99 {
100 xmlHttpRequst = new ActiveXObject("Microsoft.XMLHTTP");
101 }
102 return xmlHttpRequst;
103 }
104
105 // Does the AJAX call to URL specific with rest of the parameters
106 function doAjax(url, method, responseHandler, data)
107 {
108 // Set the variables
109 url = url || "";
110 method = method || "GET";
111 async = true;
112 data = data || {};
113 data.token = window.token;
114
115 if(url == "") {
116 alert("URL can not be null/blank");
117 return false;
118 }
119 var xmlHttpRequest = getHttpRequestObject();
120
121 // If AJAX supported
122 if(xmlHttpRequest != false) {
123 xmlHttpRequest.open(method, url, async);
124 // Set request header (optional if GET method is used)
125 if(method == "POST") {
126 xmlHttpRequest.setRequestHeader("Content-Type", "application/json");
127 }
128 // Assign (or define) response-handler/callback when ReadyState is changed.
129 xmlHttpRequest.onreadystatechange = responseHandler;
130 // Send data
131 xmlHttpRequest.send(JSON.stringify(data));
132 }
133 else
134 {
135 alert("Please use browser with Ajax support.!");
136 }
137 }
138 </script>
139 </body>
140 </html>