]> git.ipfire.org Git - thirdparty/patchwork.git/commit
static: add rest.js to handle PATCH requests & respective responses
authorRaxel Gutierrez <raxel@google.com>
Thu, 19 Aug 2021 04:20:23 +0000 (04:20 +0000)
committerStephen Finucane <stephen@that.guru>
Thu, 19 Aug 2021 17:52:11 +0000 (18:52 +0100)
commit8a6304b51879115d15bff9723e59ba6a51958151
tree183613cf01484b4125fb9e30f6869bc5ad5284af
parent5de787cb4373221fc5e322002b5e77c3c0aee493
static: add rest.js to handle PATCH requests & respective responses

Add `rest.js` file to have a utilities JavaScript module that can be
reused by any Patchwork JS files that make requests to the REST API. The
comments for each function follow the Google JS Style guide [1] which is
something that would be nice to have for better documented frontend code,
especially for JS modules that export functions like rest.js. In
particular, this patch provides the following function:

 - `updateProperty`: make PATCH requests that partially update the
   fields of an object given it's REST API endpoint specified by the
   caller. Also, the caller can specify the field(s) to modify and the
   associated content for update messages in the case of both failed
   successful requests that render to the current webpage. The caller
   receives whether the request was successful or not.

The `rest.js` module can be further expanded to support and provide
functions that allow for other requests (e.g. GET, POST, PUT) to the
REST API.

Also, add functions that handle update & error messages for these PATCH
requests that match the Django messages framework format and form error
styling. These functions are internal to the module and aren't exposed
outside of the `rest.js` file.

Error and accompanying failed update messages are replaced by successful
update messages and vice versa. Consecutive successful update messages
add to a counter of updated objects. Consecutive error messages stack up.

Signed-off-by: Raxel Gutierrez <raxel@google.com>
Reviewed-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
htdocs/README.rst
htdocs/js/rest.js [new file with mode: 0644]