Overview
Comment:Make sure we fallback to form submission if there is an error on the server
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 76f4b4d7f87081b83cc44be31f064f7b9e75ef53b589fa72ba2d1f21c905bd6a
User & Date: bohwaz on 2023-04-17 16:59:29
Other Links: manifest | tags
Context
2023-04-17
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
16:52
Ignore trimmed spaces check-in: 56f9dc306d user: bohwaz tags: trunk, stable
Changes

Modified src/www/admin/static/scripts/web_editor.js from [dc2cacd128] to [55eadfb606].

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
			data.append('save', 1);

			fetch(t.textarea.form.action + '&js', {
				method: 'post',
				body: data,
			}).then((response) => response.json())
			.then(data => callback(data))
			.catch(e => { console.log(e); });
			return true;
		};

		const quicksave = () => {
			save((data) => {
				showSaved();
				t.textarea.defaultValue = t.textarea.value;







|







296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
			data.append('save', 1);

			fetch(t.textarea.form.action + '&js', {
				method: 'post',
				body: data,
			}).then((response) => response.json())
			.then(data => callback(data))
			.catch(e => { console.log(e); t.textarea.form.querySelector('[type=submit]').click(); });
			return true;
		};

		const quicksave = () => {
			save((data) => {
				showSaved();
				t.textarea.defaultValue = t.textarea.value;

Modified src/www/admin/web/edit.php from [637ac3fd96] to [3fbfec5ea2].

1
2
3
4

5
6
7
8
9
10
11
<?php

namespace Garradin;


use Garradin\Web\Web;
use Garradin\Web\Render\Render;
use Garradin\Entities\Web\Page;
use Garradin\Entities\Files\File;
use KD2\SimpleDiff;

require_once __DIR__ . '/_inc.php';




>







1
2
3
4
5
6
7
8
9
10
11
12
<?php

namespace Garradin;

use Garradin\UserException;
use Garradin\Web\Web;
use Garradin\Web\Render\Render;
use Garradin\Entities\Web\Page;
use Garradin\Entities\Files\File;
use KD2\SimpleDiff;

require_once __DIR__ . '/_inc.php';
39
40
41
42
43
44
45

46
47









48
49
50
51
52
53
54

	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();










	if (qg('js') !== null) {
		$url = Utils::getLocalURL('!web/page.php?p=' . $page->path);
		die(json_encode(['success' => true, 'modified' => $page->modified->getTimestamp(), 'redirect' => $url]));
	}

	Utils::redirect('!web/page.php?p=' . $page->path);







>
|
|
>
>
>
>
>
>
>
>
>







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

	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.');
	}

	try {
		$page->importForm();
		$page->save();
	}
	catch (UserException $e) {
		if (qg('js') !== null) {
			http_response_code(400);
			die(json_encode(['error' => $e->getMessage()]));
		}

		throw $e;
	}

	if (qg('js') !== null) {
		$url = Utils::getLocalURL('!web/page.php?p=' . $page->path);
		die(json_encode(['success' => true, 'modified' => $page->modified->getTimestamp(), 'redirect' => $url]));
	}

	Utils::redirect('!web/page.php?p=' . $page->path);