Skip to content

Commit

Permalink
replace last jquery with plain browser api (#2222)
Browse files Browse the repository at this point in the history
* readd X-CSRFToken header to jquery requests

* revert changes

* replace jquery with plain js

* fix formatting and import

* form-encode body

* formencode index update data

* check for undefined explicitly

* use ! to (not) check for undefined

* fOrMaT

* revert undefined to !
  • Loading branch information
Kakadus authored Jun 17, 2024
1 parent 332f557 commit 6b30430
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions evap/static/ts/src/datagrid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CSRF_HEADERS } from "./csrf-utils.js";

declare const Sortable: typeof import("sortablejs");

interface Row {
Expand Down Expand Up @@ -341,11 +343,19 @@ export class QuestionnaireGrid extends TableGrid {
draggable: ".sortable",
scrollSensitivity: 70,
onUpdate: event => {
if (event.oldIndex && event.newIndex) {
if (event.oldIndex !== undefined && event.newIndex !== undefined) {
this.reorderRow(event.oldIndex, event.newIndex);
}
const questionnaireIndices = this.rows.map((row, index) => [$(row.element).data("id"), index]);
$.post(this.updateUrl, Object.fromEntries(questionnaireIndices));
fetch(this.updateUrl, {
method: "POST",
headers: CSRF_HEADERS,
body: new URLSearchParams(
this.rows.map((row, index) => [row.element.dataset.id!, index.toString()]),
),
}).catch(error => {
console.error(error);
window.alert(window.gettext("The server is not responding."));
});
},
});
}
Expand Down

0 comments on commit 6b30430

Please sign in to comment.