Skip to content

Commit

Permalink
Refactoring the JavaScript used to confirm the license granted for a (#…
Browse files Browse the repository at this point in the history
…1910)

dataset
  • Loading branch information
jrgriffiniii authored Aug 22, 2024
1 parent cebd7d8 commit 94cb55d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/javascript/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import './vendor/jquery-ui-triggeredAutocomplete';

import PdcUiLoader from './pdc/pdc_ui_loader.es6';
import WorksWizardPolicy from './works_wizard_policy';
import WorksWizardReview from './works_wizard_review';

// If using a TypeScript entrypoint file:
// <%= vite_typescript_tag 'application' %>
Expand Down Expand Up @@ -44,6 +45,7 @@ function ready() {
loader.run();

WorksWizardPolicy.bind('#agreement');
WorksWizardReview.bind('#grant-button');
}

// Must run the javascript loader on every page even if turbolinks loads it
Expand Down
32 changes: 32 additions & 0 deletions app/javascript/entrypoints/works_wizard_review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class WorksWizardReview {
static bind(elementSelector) {
let built;
const root = document.querySelector(elementSelector);

if (root) {
built = new WorksWizardReview(root);
}

return built;
}

static handleClick(event) {
const message = "You're about to grant license for this dataset. Are you sure?";
const input = window.confirm(message);

if (input === false) {
event.preventDefault();
}
}

constructor(root) {
this.root = root;

if (this.root) {
const handleClick = WorksWizardReview.handleClick.bind(this);
this.root.addEventListener('click', handleClick);
}
}
}

export default WorksWizardReview;
9 changes: 0 additions & 9 deletions app/views/works_wizard/review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,3 @@
<% end %>
</div>

<script>
$("#grant-button").on("click", (event) => {
var message = "You're about to grant license for this dataset. Are you sure?";
var input = confirm(message);
if(input == false){
event.preventDefault();
}
});
</script>

0 comments on commit 94cb55d

Please sign in to comment.