-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle links and references more effectively Now works consistently across actions, descriptions and timeline and avoids nasty HTML * Show actions which are done * Move webpack output to `./dist` * Permit watching and hot-reloading of FE assets Mount the output folder so you can run `yarn watch` locally to see your change live * Add rest_framework to INSTALLED_APPS We need this for the internal API to work * Add markup for actions module * Add Actions module This automatically sends an AJAX request to update the `done` and `done_date` fields of an action when you (un)check the checkbox * Load JS asynchronously Ensures the DOM has loaded before trying to run JavaScript
- Loading branch information
Showing
13 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import './main.scss'; | ||
import GOVUKFrontend from 'govuk-frontend/govuk/all.js'; | ||
import MOJFrontend from '@ministryofjustice/frontend/moj/all.js'; | ||
// import MOJFrontend from '@ministryofjustice/frontend/moj/all.js'; | ||
import { initAll } from './src/all.js'; | ||
|
||
GOVUKFrontend.initAll(); | ||
initAll(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { nodeListForEach } from 'govuk-frontend/govuk/common' | ||
import api from './lib/api'; | ||
|
||
function Actions ($module) { | ||
this.$module = $module; | ||
this.incidentId = $module.getAttribute('data-incident-id'); | ||
this.$actions = $module.querySelectorAll('input[type="checkbox"]'); | ||
} | ||
|
||
Actions.prototype.init = function init() { | ||
nodeListForEach(this.$actions, $action => { | ||
$action.addEventListener('change', this.handleCheck.bind(this)); | ||
}); | ||
} | ||
|
||
Actions.prototype.handleCheck = function handleCheck(event) { | ||
const actionId = event.target.value; | ||
|
||
const form = new FormData(); | ||
form.set('done', event.target.checked); | ||
form.set('done_date', event.target.checked ? (new Date()).toISOString() : ''); | ||
|
||
api('PATCH', `/incidents/${this.incidentId}/actions/${actionId}/`, form); | ||
} | ||
|
||
export default Actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { nodeListForEach } from 'govuk-frontend/govuk/common' | ||
import Actions from './action.js' | ||
|
||
function initAll() { | ||
const $actions = document.querySelectorAll('[data-module="app-actions"]'); | ||
nodeListForEach($actions, ($el) => { | ||
new Actions($el).init(); | ||
}) | ||
} | ||
|
||
export { initAll, Actions } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import getCookie from "./getCookie"; | ||
|
||
export default function api(method, path, body = null, config = {}) { | ||
const csrftoken = getCookie('csrftoken'); | ||
|
||
return fetch(`/core${path}`, Object.assign({ | ||
method, | ||
mode: 'same-origin', | ||
body, | ||
headers: { | ||
'X-CSRFToken': csrftoken | ||
} | ||
}, config)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default function getCookie(name) { | ||
let cookieValue = null; | ||
if (document.cookie && document.cookie !== '') { | ||
const cookies = document.cookie.split(';'); | ||
for (let i = 0; i < cookies.length; i++) { | ||
const cookie = cookies[i].trim(); | ||
// Does this cookie string begin with the name we want? | ||
if (cookie.substring(0, name.length + 1) === (name + '=')) { | ||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | ||
break; | ||
} | ||
} | ||
} | ||
return cookieValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters