()
| 114 | } |
| 115 | |
| 116 | async submitImage () { |
| 117 | if (!isValidSignatureCanvas(this.pad.toData())) { |
| 118 | alert('Signature is too small or simple. Please redraw.') |
| 119 | |
| 120 | return Promise.reject(new Error('Image too small or simple')) |
| 121 | } |
| 122 | |
| 123 | return cropCanvasAndExportToPNG(this.canvas).then(async (blob) => { |
| 124 | const file = new File([blob], 'signature.png', { type: 'image/png' }) |
| 125 | |
| 126 | const formData = new FormData() |
| 127 | |
| 128 | formData.append('file', file) |
| 129 | formData.append('submitter_slug', this.dataset.slug) |
| 130 | formData.append('name', 'attachments') |
| 131 | formData.append('remember_signature', 'true') |
| 132 | |
| 133 | return fetch('/api/attachments', { |
| 134 | method: 'POST', |
| 135 | body: formData |
| 136 | }).then(resp => resp.json()) |
| 137 | }) |
| 138 | } |
| 139 | |
| 140 | get submitButton () { |
| 141 | return this.querySelector('button[type="submit"]') |
no test coverage detected