validate-button.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import define from "../../utils/define.js";
  2. import {globalBus} from "../../utils/events.js";
  3. const VALIDATED_CLASS = "validated";
  4. export default define('validate-button', class extends HTMLButtonElement {
  5. constructor() {
  6. super();
  7. this.__setup();
  8. }
  9. __setup() {
  10. this.__events();
  11. }
  12. __events() {
  13. this.addEventListener('click', (e) => {
  14. console.log("Validate button");
  15. const result = this.closest('.result');
  16. const parent = result.parentNode;
  17. const index = Array.prototype.indexOf.call(parent.children, result);
  18. console.log("Validate index", index);
  19. const curationValidateEvent = new CustomEvent('curate-validate-result', {
  20. detail: {
  21. data: {
  22. validate_index: index
  23. }
  24. }
  25. });
  26. globalBus.dispatch(curationValidateEvent);
  27. })
  28. }
  29. isValidated() {
  30. return this.classList.contains(VALIDATED_CLASS);
  31. }
  32. validate() {
  33. this.classList.add(VALIDATED_CLASS);
  34. }
  35. unvalidate() {
  36. this.classList.remove(VALIDATED_CLASS);
  37. }
  38. toggleValidate() {
  39. this.classList.toggle(VALIDATED_CLASS);
  40. }
  41. }, { extends: 'button' });