Overview
Comment: | Throw and retrieve errors using JS |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | stable |
Files: | files | file ages | folders |
SHA3-256: |
5dce1665abec830e895dd07ee8943cd6 |
User & Date: | bohwaz on 2023-04-17 17:17:45 |
Other Links: | manifest | tags |
Context
2023-04-17
| ||
20:09 | Use .search, not .path check-in: 9f0a700070 user: bohwaz tags: trunk, stable | |
17:17 | Throw and retrieve errors using JS check-in: 5dce1665ab user: bohwaz tags: trunk, stable | |
16:59 | Make sure we fallback to form submission if there is an error on the server check-in: 76f4b4d7f8 user: bohwaz tags: trunk | |
Changes
Modified src/www/admin/static/scripts/web_editor.js from [55eadfb606] to [803744c960].
︙ | ︙ | |||
294 295 296 297 298 299 300 | } data.append('save', 1); fetch(t.textarea.form.action + '&js', { method: 'post', body: data, | | > > > > > > > | 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | } data.append('save', 1); fetch(t.textarea.form.action + '&js', { method: 'post', body: data, }).then((response) => { if (!response.ok) { throw Error(response.status); } else { return response.json(); } }) .then(data => callback(data)) .catch(e => { console.log(e); t.textarea.form.querySelector('[type=submit]').click(); }); return true; }; const quicksave = () => { save((data) => { |
︙ | ︙ |
Modified src/www/admin/web/edit.php from [3fbfec5ea2] to [a7e3ffa8ee].
︙ | ︙ | |||
34 35 36 37 38 39 40 | $show_diff = false; $current_content = trim(preg_replace("/\r\n?/", "\n", $page->content)); $new_content = null; $form->runIf('save', function () use ($page, $editing_started, &$show_diff, &$new_content, $current_content) { $new_content = trim(preg_replace("/\r\n?/", "\n", (string)f('content'))); | > | | | | | < | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | $show_diff = false; $current_content = trim(preg_replace("/\r\n?/", "\n", $page->content)); $new_content = null; $form->runIf('save', function () use ($page, $editing_started, &$show_diff, &$new_content, $current_content) { $new_content = trim(preg_replace("/\r\n?/", "\n", (string)f('content'))); try { if ($new_content !== $current_content && $editing_started < $page->modified->getTimestamp()) { $show_diff = true; http_response_code(400); throw new UserException('La page a été modifiée par quelqu\'un d\'autre pendant que vous éditiez le contenu.'); } $page->importForm(); $page->save(); } catch (UserException $e) { if (qg('js') !== null) { http_response_code(400); die(json_encode(['error' => $e->getMessage()])); |
︙ | ︙ |