Explorar o código

add download/new buttons and hide file picker on upload

Daniel Sheffield hai 1 ano
pai
achega
7766302f43
Modificáronse 3 ficheiros con 17 adicións e 4 borrados
  1. 10 2
      app/rest/pyapi.py
  2. 3 2
      app/rest/templates/file-form.tpl
  3. 4 0
      app/rest/templates/upload.tpl

+ 10 - 2
app/rest/pyapi.py

@@ -187,10 +187,18 @@ def upload():
         
         link = f'{LOCATION}/upload/{_hash}' if _hash else f'{LOCATION}/upload'
         response.content_type = 'text/html; charset=utf-8'
-        form = template('file-form', action='/upload', method='post')
+        disabled = True if _hash else False
+        form = template('file-form', action='/upload', method='post', disabled=disabled)
         svg = get_qr_code(link)
         
-        return template('upload', form=form, svg=svg, link=link, mimetype=mimetype)
+        return template(
+            'upload',
+            form=form,
+            svg=svg,
+            link=link,
+            mimetype=mimetype,
+            disabled=disabled
+        )
 
     if request.method == 'POST':
         if 'paste' not in request.files:

+ 3 - 2
app/rest/templates/file-form.tpl

@@ -1,6 +1,7 @@
 % from app.data.filter import get_query_param
 % content = setdefault("content", "") or ""
-% disabled = (setdefault("disabled", False) and 'readonly="true"') or ""
+% disabled = setdefault("disabled", "") and 'hidden="true"'
 <form id="upload" method="{{ method }}" action="{{ action }}" enctype="multipart/form-data">
-  <input type="file" name="paste" required="true" />
+  <input type="file" name="paste" required="true" {{disabled}} />
 </form>
+<form id="new" method="get" action="{{ action }}"></form>

+ 4 - 0
app/rest/templates/upload.tpl

@@ -1,5 +1,6 @@
 % link = setdefault("link", "") or ""
 % disabled = setdefault("disabled", "") and 'disabled="true"'
+% download_disabled = "" if disabled else 'disabled="true"'
 % mimetype = (setdefault("mimetype", None) is not True and mimetype) or None
 <!DOCTYPE html>
 <html>
@@ -44,7 +45,9 @@ object.text {
       % include('button-style')
       <div class="pure-u-1">
         <div class="pure-button-group" role="action" style="padding: 1em 0 0;">
+          <button class="button-resize pure-button" type="submit" form="new"> New </button>
           <button class="button-resize pure-button" type="submit" form="upload" {{!disabled}}> Upload </button>
+          <button class="button-resize pure-button" type="submit" form="download" {{!download_disabled}}> Download </button>
         </div>
       </div>
       <div class="pure-u-1">
@@ -55,6 +58,7 @@ object.text {
       <div class="pure-u-1">
         <p><details><summary> Show QR code ...</summary>{{!svg}}</details></p>
 {{!form}}
+<form id="download" method="get" action="{{link}}"></form>
         % if mimetype and mimetype.startswith('text'):
         <object class="text" data="{{link}}?download=false&mimetype=text/plain" type={{mimetype}}><p>Unable to display {{mimetype}}</p></object>
         % elif mimetype and mimetype.startswith('image'):