Skip to content

Commit

Permalink
Ajax submit transition page refresh (senaite#2142)
Browse files Browse the repository at this point in the history
* Implemented event handler

* Additional DOM attributes

* Production JS

* Improved page reload logic

NOTE:  Requires senaite/senaite.app.listing#92

* Production JS

* Better naming

* Remove portal_type check

* Build js

* Better comment

* Build js

Co-authored-by: Jordi Puiggené <jp@naralabs.com>
  • Loading branch information
ramonski and xispa committed Sep 26, 2022
1 parent 1014fab commit 82bd3cc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/senaite/core/browser/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ def get_data_settings(self):
data = {
"data-base-url": self.context.absolute_url(),
"data-view-url": self.context_state.view_url(),
"data-view-name": self.context_state.view_template_id(),
"data-review-state": self.context_state.workflow_state(),
"data-portal-url": portal_url,
"data-i18ncatalogurl": portal_url + "/plonejsi18n",
"data-auto-logoff": setup.getAutoLogOff(),
"data-portal-type": api.get_portal_type(self.context),
}
return data

Expand Down
2 changes: 1 addition & 1 deletion src/senaite/core/browser/static/bundles/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/senaite/core/browser/static/bundles/main.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions webpack/app/senaite.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ document.addEventListener("DOMContentLoaded", () => {
return false;
}
// get the base url from the `data-base-url` attribute
// -> see IBootstrapView
let base_url = document.body.dataset.baseUrl;
if (base_url === undefined) {
// fallback to the current location URL
Expand All @@ -111,4 +112,21 @@ document.addEventListener("DOMContentLoaded", () => {
})
});

// Reload the whole view if the status of the view's context has changed
// due to the transition submission of some items from the listing
document.body.addEventListener("listing:submit", (event) => {
// get the old workflow state of the view context
let old_workflow_state = document.body.dataset.reviewState;

// get the new workflow state of the view context
// https://github.com/senaite/senaite.app.listing/pull/92
let data = event.detail.data;
let new_workflow_state = data.view_context_state;

// reload the entire page if workflow state of the view context changed
if (old_workflow_state != new_workflow_state) {
location.reload()
}
});

});

0 comments on commit 82bd3cc

Please sign in to comment.