| 1 | {{define "head"}} |
| 2 | {{/* Drag and drop only. Everything the drop zone does, the form below |
| 3 | it already does with scripting off — drop.js fills that same file |
| 4 | input and submits that same form, so there is one route, one CSRF |
| 5 | check and one code path either way. |
| 6 | |
| 7 | This moved here with the form it decorates. It used to sit on the |
| 8 | sheet list, which is where the import form used to be. */}} |
| 9 | <script defer src="{{asset "static/drop.js"}}"></script> |
| 10 | {{/* Google Drive's chooser, only where it is configured: its module, |
| 11 | and with it the page's widened policy (googleimport.go). */}} |
| 12 | {{with .Data.GoogleScript}}<script type="module" src="{{.}}"></script>{{end}} |
| 13 | {{end}} |
| 14 | |
| 15 | {{define "content"}} |
| 16 | <header rst-page-header> |
| 17 | <div rst-page-header-titles> |
| 18 | <h1>Import a spreadsheet</h1> |
| 19 | {{/* The limits are stated BEFORE the import, not discovered after it. |
| 20 | Import reads one worksheet (xlsx.Import), and a workbook with |
| 21 | three of them would otherwise arrive looking whole — the quiet |
| 22 | kind of wrong PRODUCT.md's first principle forbids. |
| 23 | |
| 24 | They are a subhead here rather than a hint under the field |
| 25 | because this page has the room the dropdown they nearly went in |
| 26 | did not, and because drop.js overwrites the hint to speak about |
| 27 | a drop — which would take the file limits down with it. */}} |
| 28 | <p rst-page-header-sub>Excel .xlsx or .xlsm, up to 20 MB. Only the first |
| 29 | worksheet is imported. Values, formulas Sheets can calculate and basic |
| 30 | formatting come across; anything else is listed in an import report when |
| 31 | the import finishes.</p> |
| 32 | </div> |
| 33 | </header> |
| 34 | |
| 35 | {{if .Data.Error}} |
| 36 | {{/* A refusal renders HERE, on the page holding the form, rather than |
| 37 | back on the sheet list. The list is not where the person is and |
| 38 | no longer carries a form to try again with. */}} |
| 39 | <div rst-callout rst-tone="negative"> |
| 40 | <div rst-callout-body> |
| 41 | <p>{{.Data.Error}}</p> |
| 42 | </div> |
| 43 | </div> |
| 44 | {{end}} |
| 45 | |
| 46 | <form rst-form id="import-form" method="post" action="/sheets/import" enctype="multipart/form-data"> |
| 47 | <div data-drop> |
| 48 | <div rst-field-row> |
| 49 | <div rst-field> |
| 50 | <label rst-field-label for="file">Choose a file</label> |
| 51 | <input rst-input id="file" name="file" type="file" accept=".xlsx,.xlsm"> |
| 52 | <p rst-field-hint data-drop-hint>You can also drag a file onto this box.</p> |
| 53 | </div> |
| 54 | <button rst-btn="primary" type="submit">Import</button> |
| 55 | </div> |
| 56 | </div> |
| 57 | </form> |
| 58 | |
| 59 | {{/* After the form it fills: the chooser exports one Google sheet as |
| 60 | XLSX in this browser and submits it through the form above, so it |
| 61 | is the same route, the same checks and the same report. Nothing |
| 62 | renders here when Google import is not configured, and with |
| 63 | scripting off the component says how to download from Google and |
| 64 | use the form instead. */}} |
| 65 | {{if .Data.Google.Enabled}} |
| 66 | <section rst-stack rst-section> |
| 67 | <h2>From Google Drive</h2> |
| 68 | {{template "estilo-google-import" .Data.Google}} |
| 69 | </section> |
| 70 | {{end}} |
| 71 | {{end}} |
| 72 | |