Sha256: a97810eb231a6d14288c75af6eefadba08956c3a6bf74137c1d091a33afa5f26

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

/* eslint-disable require-jsdoc */

// show a message to the user if comunication is lost
import "src/decidim/elections/broken_promises_handler";
import { VoteComponent } from "@decidim/decidim-bulletin_board";

import * as VotingSchemesDummy from "@decidim/voting_schemes-dummy";
const DummyVoterWrapperAdapter = VotingSchemesDummy.VoterWrapperAdapter;
import * as VotingSchemesElectionGuard from "@decidim/voting_schemes-electionguard";
const ElectionGuardVoterWrapperAdapter =
  VotingSchemesElectionGuard.VoterWrapperAdapter;

export default function setupVoteComponent($voteWrapper) {
  // Data
  const bulletinBoardClientParams = {
    apiEndpointUrl: $voteWrapper.data("apiEndpointUrl")
  };
  const electionUniqueId = $voteWrapper.data("electionUniqueId");
  const authorityPublicKeyJSON = JSON.stringify(
    $voteWrapper.data("authorityPublicKey")
  );
  const voterUniqueId = $voteWrapper.data("voterId");
  const schemeName = $voteWrapper.data("schemeName");

  // Use the correct voter wrapper adapter
  let voterWrapperAdapter = null;

  if (schemeName === "dummy") {
    voterWrapperAdapter = new DummyVoterWrapperAdapter({
      voterId: voterUniqueId
    });
  } else if (schemeName === "electionguard") {
    voterWrapperAdapter = new ElectionGuardVoterWrapperAdapter({
      voterId: voterUniqueId,
      workerUrl: "/assets/electionguard/webworker.js"
    });
  } else {
    throw new Error(`Voting scheme ${schemeName} not supported.`);
  }

  // Returns the vote component
  return new VoteComponent({
    bulletinBoardClientParams,
    authorityPublicKeyJSON,
    electionUniqueId,
    voterUniqueId,
    voterWrapperAdapter
  });
}

/* Fallback for non-handled failed promises */
window.addEventListener("unhandledrejection", (event) => {
  $("#server-failure .tech-info").html(event.reason);
  $("#server-failure").foundation("open");
});

window.Decidim = window.Decidim || {};
window.Decidim.setupVoteComponent = setupVoteComponent;

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.26.9 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.26.8 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.26.7 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.26.5 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.26.4 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.26.3 app/packs/src/decidim/elections/voter/setup-vote.js