Skip to content

Commit

Permalink
Merge pull request #38 from 2lenet/fix_ajax_move_+handle_errors
Browse files Browse the repository at this point in the history
fix: ajax move + error handling
  • Loading branch information
SpaghettiBolognaise authored Jan 20, 2023
2 parents fa7c97e + b4a3abf commit 5134d70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ onLoad(() => {
* Initialize dashboard
*/
const grid = GridStack.init(options);
grid.disable();

// Update grid when user adds a new widget
initializeAddedHandler(grid);
Expand Down Expand Up @@ -73,20 +74,26 @@ onLoad(() => {
.then((response) => {
response.text().then((html) => {

let loadedWidget = createWidgetElement(html);
if (!response.ok) {
let htmlError = "<div>Error loading wigdet</div>";
document.getElementById("widget_body_" + widget.getAttribute("gs-id")).innerHTML = htmlError;
} else {
let loadedWidget = createWidgetElement(html);

grid.update(widget, {
content: loadedWidget.children[0].innerHTML
});
grid.update(widget, {
content: loadedWidget.children[0].innerHTML
});

initializeButtons({
id: widget.id.replace("widget_", "")
});
enableScripts(widget);
initializeButtons({
id: widget.id.replace("widget_", "")
});
enableScripts(widget);
}
total++;

if (loading && total === grid.getGridItems().length) {
toggleSpin();
grid.enable();
}
});
});
Expand All @@ -96,6 +103,7 @@ onLoad(() => {

if (loading && total === grid.getGridItems().length) {
toggleSpin();
grid.enable();
}
}
}
Expand Down
Loading

0 comments on commit 5134d70

Please sign in to comment.