Browse code

"Is there something new ?"

Doug Le Tough authored on 02/12/2017 19:50:42
Showing 5 changed files
... ...
@@ -155,6 +155,12 @@ main > article > ol {
155 155
   text-justify: distribute;
156 156
 }
157 157
 
158
+main > hr {
159
+  border-color: var(--mid-bg);
160
+  border-style: solid;
161
+  border-width: 1px;
162
+}
163
+
158 164
 main > article > img {
159 165
   display:inline-block;
160 166
   border-color: var(--mid-bg);
... ...
@@ -1,14 +1,35 @@
1 1
 {% extends "index.html" %}
2 2
 {% block title %}Ajax{% endblock %}
3 3
       {% block main %}
4
-      <article class='left'>
5
-        <h3>Get HTML response from AJAX</h3>
6
-        <p>Click the refresh button to get the HTML response.</p>
7
-        <p>The response may randomly be a voluntary error so you should try it more than once.</p>
8
-        Refresh: <input type='button' class='refresh' value=' ' onclick='javascript:get_html_from_ajax(document.getElementById("html_container"), "/get_html_from_ajax");'>
9
-      </article>
10
-      <article class='right' id='html_container'>
11
-      </article>
4
+      <section class='inline'>
5
+        <article class='left'>
6
+          <h3>Get HTML response from AJAX</h3>
7
+          <p>Click the refresh button to get the HTML response.</p>
8
+          <p>The response may randomly be a voluntary error so you should try it more than once.</p>
9
+          Refresh: <input type='button' class='refresh' value=' '
10
+                          onclick='javascript:get_html_from_ajax(document.getElementById("html_container"), "/get_html_from_ajax");'>
11
+        </article>
12
+        <article class='right'>
13
+          <h3>Upload files with AJAX</h3>
14
+          <p>Select files to upload</p>
15
+          <p>The response may randomly be a voluntary error so you should try it more than once.</p>
16
+          Upload files: 
17
+          <div class='file_upload'>
18
+            <!--
19
+              Input file is a tricky hack (see tetawebapp.css and tetawebapp.js)
20
+            -->
21
+            <input type='button' id='upload_icon_1' class='upload' title='Upload' value=' '/>
22
+            <input type='file' id='upload_input_1' multiple
23
+                   title='Upload'
24
+                   onchange='javascript:upload_file_from_ajax(this, "/upload", "TETA_ERR");'
25
+                   onmouseover='javascript:lit(document.getElementById("upload_icon_1"));'
26
+                   onmouseout='javascript:unlit(document.getElementById("upload_icon_1"));'/>
27
+          </div>
28
+        </article>
29
+      </section>
30
+      <hr/>
31
+      <article class='right' id='html_container'></article>
32
+      <hr/>
12 33
       <section class='inline'>
13 34
         <article class='left'>
14 35
           <h3>Set value via AJAX</h3>
... ...
@@ -25,17 +46,4 @@
25 25
           <input type='button' value="Try me" onclick='javascript:get_value_from_ajax(document.getElementById("value_receiver"), "/get_value_from_ajax", "TETA_ERR");'>
26 26
         </article>
27 27
       </section>
28
-      <article class='left'>
29
-        <h3>Upload files with AJAX</h3>
30
-        <p>Select files to upload</p>
31
-        <p>The response may randomly be a voluntary error so you should try it more than once.</p>
32
-        Upload files: 
33
-        <div class='file_upload'>
34
-          <!--
35
-            Input file is a tricky hack (see tetawebapp.css and tetawebapp.js)
36
-          -->
37
-          <input type='button' id='upload_icon_1' class='upload' title='Upload' value=' '/>
38
-          <input type='file' id='upload_input_1' multiple title='Upload' value='' onchange='javascript:upload_file_from_ajax(this, "/upload", "TETA_ERR");' onmouseover='javascript:lit(document.getElementById("upload_icon_1"));' onmouseout='javascript:unlit(document.getElementById("upload_icon_1"));'/>
39
-        </div>
40
-      </article>
41 28
       {% endblock %}
... ...
@@ -8,7 +8,7 @@
8 8
   <link rel="stylesheet" type="text/css" href="/static/styles/fonts.css" />
9 9
   <link rel="stylesheet" type="text/css" href="/static/styles/tetawebapp.css" />
10 10
   <link rel="icon" type="image/png" href="/static/images/favicon.png" />
11
-  <script type="text/javascript" src="/static/scripts/tetawebapp.js"></script>
11
+  <script src="/static/scripts/tetawebapp.js"></script>
12 12
 </head>
13 13
 {% block bodyheader %}
14 14
 <body>
... ...
@@ -33,7 +33,11 @@
33 33
         -->
34 34
         <div class='file_upload'>
35 35
           <input type='button' id='upload_icon_1' class='upload' title='Upload' value=' '/>
36
-          <input type='file' id='upload_input_1' name='files' multiple title='Upload' value='' onchange='javascript:upload_file_from_ajax(this, "/upload", "TETA_ERR");' onmouseover='javascript:lit(document.getElementById("upload_icon_1"));' onmouseout='javascript:unlit(document.getElementById("upload_icon_1"));'/>
36
+          <input type='file' id='upload_input_1' name='files' multiple
37
+                 title='Upload'
38
+                 onchange='javascript:upload_file_from_ajax(this, "/upload", "TETA_ERR");'
39
+                 onmouseover='javascript:lit(document.getElementById("upload_icon_1"));'
40
+                 onmouseout='javascript:unlit(document.getElementById("upload_icon_1"));'/>
37 41
         </div>
38 42
         <br/>
39 43
         <pre>
... ...
@@ -253,8 +253,8 @@ def set_value_from_ajax(value):
253 253
 @app.route("/upload", methods=['POST'])
254 254
 @check_session
255 255
 def upload():
256
-  """ Accept a value from an AJAX request
257
-      It may return an error code for testing purpose """
256
+  """ Save a file from AJAX request
257
+      Files are saved in UPLOADED_FILES_DEST (see config.local.py) """
258 258
   err_code = 'TETA_ERR'
259 259
   RND = int(random.random()*10)
260 260
   if RND % 2:
... ...
@@ -267,7 +267,7 @@ def upload():
267 267
   print "Uploaded files:"
268 268
   for f in uploaded_files:
269 269
     print '  [+] %s [%s]' % (f.filename, f.content_type)
270
-    # Befor saving you should:
270
+    # Before saving you should:
271 271
     # - Secure the filename
272 272
     # - Check file size
273 273
     # - Check content type