decidim-elections 0.23.6 → 0.24.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/app/assets/config/admin/decidim_votings_manifest.css +0 -0
  4. data/app/assets/config/admin/decidim_votings_manifest.js +4 -0
  5. data/app/assets/config/decidim_elections_manifest.css +3 -0
  6. data/app/assets/config/decidim_elections_manifest.js +6 -0
  7. data/app/assets/config/decidim_votings_manifest.css +3 -0
  8. data/app/assets/config/decidim_votings_manifest.js +0 -0
  9. data/app/assets/images/decidim/votings/icon.svg +1 -0
  10. data/app/assets/javascripts/decidim/elections/admin/pending_action.js.es6 +16 -0
  11. data/app/assets/javascripts/decidim/elections/admin/vote_statistics.js.es6 +11 -0
  12. data/app/assets/javascripts/decidim/elections/trustee_zone/key_ceremony.js.es6 +126 -0
  13. data/app/assets/javascripts/decidim/elections/trustee_zone/tally.js.es6 +104 -0
  14. data/app/assets/javascripts/decidim/elections/trustee_zone.js.es6 +54 -0
  15. data/app/assets/javascripts/decidim/elections/vote.js.es6 +107 -160
  16. data/app/assets/javascripts/decidim/elections/vote_questions.component.js.es6 +129 -0
  17. data/app/assets/javascripts/decidim/elections/vote_verify.js.es6 +71 -0
  18. data/app/assets/javascripts/decidim/votings/admin/monitoring_committee_members_form.js.es6 +35 -0
  19. data/app/assets/javascripts/decidim/votings/admin/polling_officers_form.js.es6 +35 -0
  20. data/app/assets/javascripts/decidim/votings/admin/polling_officers_picker.js.es6 +35 -0
  21. data/app/assets/javascripts/decidim/votings/admin/polling_stations_form.js.es6 +5 -0
  22. data/app/assets/stylesheets/decidim/elections/elections.scss +0 -4
  23. data/app/assets/stylesheets/decidim/elections/focus/_accordion.scss +36 -0
  24. data/app/assets/stylesheets/decidim/elections/focus/_evote.scss +58 -0
  25. data/app/assets/stylesheets/decidim/elections/trustee_zone.scss +24 -0
  26. data/app/assets/stylesheets/decidim/votings/votings/_votings-header.scss +99 -0
  27. data/app/assets/stylesheets/decidim/votings/votings/_votings-home-banner.scss +11 -0
  28. data/app/assets/stylesheets/decidim/votings/votings.scss +1 -0
  29. data/app/cells/decidim/votings/content_block_cell.rb +17 -0
  30. data/app/cells/decidim/votings/content_blocks/highlighted_votings/show.erb +30 -0
  31. data/app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb +33 -0
  32. data/app/cells/decidim/votings/content_blocks/highlighted_votings_settings_form/show.erb +3 -0
  33. data/app/cells/decidim/votings/content_blocks/highlighted_votings_settings_form_cell.rb +19 -0
  34. data/app/cells/decidim/votings/content_blocks/landing_page/attachments_and_folders_cell.rb +15 -0
  35. data/app/cells/decidim/votings/content_blocks/landing_page/description_cell.rb +15 -0
  36. data/app/cells/decidim/votings/content_blocks/landing_page/elections_cell.rb +15 -0
  37. data/app/cells/decidim/votings/content_blocks/landing_page/header_cell.rb +15 -0
  38. data/app/cells/decidim/votings/content_blocks/landing_page/metrics_cell.rb +15 -0
  39. data/app/cells/decidim/votings/content_blocks/landing_page/polling_stations_cell.rb +15 -0
  40. data/app/cells/decidim/votings/content_blocks/landing_page/stats_cell.rb +15 -0
  41. data/app/cells/decidim/votings/content_blocks/landing_page/timeline_cell.rb +15 -0
  42. data/app/cells/decidim/votings/polling_officers/polling_officers_picker/polling_officers.erb +12 -0
  43. data/app/cells/decidim/votings/polling_officers/polling_officers_picker/show.erb +14 -0
  44. data/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb +73 -0
  45. data/app/cells/decidim/votings/voting_cell.rb +19 -0
  46. data/app/cells/decidim/votings/voting_m/data.erb +21 -0
  47. data/app/cells/decidim/votings/voting_m/footer.erb +5 -0
  48. data/app/cells/decidim/votings/voting_m_cell.rb +94 -0
  49. data/app/commands/decidim/elections/admin/add_user_as_trustee.rb +81 -0
  50. data/app/commands/decidim/elections/admin/create_election.rb +2 -1
  51. data/app/commands/decidim/elections/admin/end_vote.rb +63 -0
  52. data/app/commands/decidim/elections/admin/publish_results.rb +59 -0
  53. data/app/commands/decidim/elections/admin/remove_trustee_from_participatory_space.rb +37 -0
  54. data/app/commands/decidim/elections/admin/setup_election.rb +160 -0
  55. data/app/commands/decidim/elections/admin/start_key_ceremony.rb +63 -0
  56. data/app/commands/decidim/elections/admin/start_tally.rb +63 -0
  57. data/app/commands/decidim/elections/admin/start_vote.rb +63 -0
  58. data/app/commands/decidim/elections/admin/update_action_status.rb +47 -0
  59. data/app/commands/decidim/elections/admin/update_answer_selection.rb +41 -0
  60. data/app/commands/decidim/elections/admin/update_trustee_participatory_space.rb +40 -0
  61. data/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb +39 -0
  62. data/app/commands/decidim/elections/trustee_zone/update_trustee.rb +41 -0
  63. data/app/commands/decidim/elections/voter/cast_vote.rb +59 -0
  64. data/app/commands/decidim/elections/voter/update_vote_status.rb +70 -0
  65. data/app/commands/decidim/votings/admin/create_monitoring_committee_member.rb +99 -0
  66. data/app/commands/decidim/votings/admin/create_polling_officer.rb +99 -0
  67. data/app/commands/decidim/votings/admin/create_polling_station.rb +59 -0
  68. data/app/commands/decidim/votings/admin/create_voting.rb +59 -0
  69. data/app/commands/decidim/votings/admin/destroy_monitoring_committee_member.rb +51 -0
  70. data/app/commands/decidim/votings/admin/destroy_polling_officer.rb +52 -0
  71. data/app/commands/decidim/votings/admin/destroy_polling_station.rb +40 -0
  72. data/app/commands/decidim/votings/admin/manage_polling_station.rb +64 -0
  73. data/app/commands/decidim/votings/admin/publish_voting.rb +40 -0
  74. data/app/commands/decidim/votings/admin/unpublish_voting.rb +40 -0
  75. data/app/commands/decidim/votings/admin/update_polling_station.rb +50 -0
  76. data/app/commands/decidim/votings/admin/update_voting.rb +85 -0
  77. data/app/constraints/decidim/votings/current_component.rb +28 -0
  78. data/app/constraints/decidim/votings/current_voting.rb +43 -0
  79. data/app/controllers/concerns/decidim/elections/orderable.rb +2 -2
  80. data/app/controllers/concerns/decidim/polling_officers/admin/filterable.rb +58 -0
  81. data/app/controllers/concerns/decidim/polling_stations/admin/filterable.rb +57 -0
  82. data/app/controllers/concerns/decidim/votings/admin/filterable.rb +27 -0
  83. data/app/controllers/concerns/decidim/votings/admin/voting_admin.rb +48 -0
  84. data/app/controllers/concerns/decidim/votings/needs_voting.rb +44 -0
  85. data/app/controllers/concerns/decidim/votings/orderable.rb +32 -0
  86. data/app/controllers/decidim/elections/admin/answers_controller.rb +32 -0
  87. data/app/controllers/decidim/elections/admin/elections_controller.rb +2 -2
  88. data/app/controllers/decidim/elections/admin/feedback_forms_controller.rb +55 -0
  89. data/app/controllers/decidim/elections/admin/steps_controller.rb +96 -0
  90. data/app/controllers/decidim/elections/admin/trustees_participatory_spaces_controller.rb +89 -0
  91. data/app/controllers/decidim/elections/elections_controller.rb +5 -1
  92. data/app/controllers/decidim/elections/feedbacks_controller.rb +38 -0
  93. data/app/controllers/decidim/elections/trustee_zone/application_controller.rb +45 -0
  94. data/app/controllers/decidim/elections/trustee_zone/elections_controller.rb +35 -0
  95. data/app/controllers/decidim/elections/trustee_zone/trustees_controller.rb +36 -0
  96. data/app/controllers/decidim/elections/votes_controller.rb +54 -2
  97. data/app/controllers/decidim/votings/admin/application_controller.rb +26 -0
  98. data/app/controllers/decidim/votings/admin/component_permissions_controller.rb +13 -0
  99. data/app/controllers/decidim/votings/admin/components_controller.rb +15 -0
  100. data/app/controllers/decidim/votings/admin/monitoring_committee_members_controller.rb +62 -0
  101. data/app/controllers/decidim/votings/admin/polling_officers_controller.rb +66 -0
  102. data/app/controllers/decidim/votings/admin/polling_stations_controller.rb +92 -0
  103. data/app/controllers/decidim/votings/admin/voting_attachment_collections_controller.rb +22 -0
  104. data/app/controllers/decidim/votings/admin/voting_attachments_controller.rb +21 -0
  105. data/app/controllers/decidim/votings/admin/votings_controller.rb +124 -0
  106. data/app/controllers/decidim/votings/admin/votings_landing_page_content_blocks_controller.rb +44 -0
  107. data/app/controllers/decidim/votings/admin/votings_landing_page_controller.rb +46 -0
  108. data/app/controllers/decidim/votings/application_controller.rb +26 -0
  109. data/app/controllers/decidim/votings/polling_officer_zone/application_controller.rb +33 -0
  110. data/app/controllers/decidim/votings/polling_officer_zone/polling_officers_controller.rb +17 -0
  111. data/app/controllers/decidim/votings/polling_officer_zone/polling_stations_controller.rb +22 -0
  112. data/app/controllers/decidim/votings/votings_controller.rb +98 -0
  113. data/app/events/decidim/elections/trustees/notify_new_trustee_event.rb +28 -0
  114. data/app/events/decidim/elections/trustees/notify_trustee_new_election_event.rb +14 -0
  115. data/app/events/decidim/elections/votes/vote_accepted_event.rb +24 -0
  116. data/app/events/decidim/votings/polling_officers/polling_station_assigned_event.rb +44 -0
  117. data/app/forms/decidim/elections/admin/action_form.rb +34 -0
  118. data/app/forms/decidim/elections/admin/answer_form.rb +3 -2
  119. data/app/forms/decidim/elections/admin/election_form.rb +3 -2
  120. data/app/forms/decidim/elections/admin/setup_form.rb +79 -0
  121. data/app/forms/decidim/elections/admin/trustees_participatory_space_form.rb +22 -0
  122. data/app/forms/decidim/elections/admin/vote_period_form.rb +37 -0
  123. data/app/forms/decidim/elections/ballot/verify_vote_form.rb +29 -0
  124. data/app/forms/decidim/elections/trustee_zone/trustee_form.rb +26 -0
  125. data/app/forms/decidim/elections/voter/encrypted_vote_form.rb +49 -0
  126. data/app/forms/decidim/votings/admin/monitoring_committee_member_form.rb +27 -0
  127. data/app/forms/decidim/votings/admin/polling_officer_form.rb +27 -0
  128. data/app/forms/decidim/votings/admin/polling_station_form.rb +58 -0
  129. data/app/forms/decidim/votings/admin/voting_form.rb +71 -0
  130. data/app/helpers/decidim/elections/admin/answers_helper.rb +19 -0
  131. data/app/helpers/decidim/elections/admin/steps_helper.rb +23 -0
  132. data/app/helpers/decidim/elections/admin/trustees_participatory_spaces_helper.rb +31 -0
  133. data/app/helpers/decidim/elections/elections_helper.rb +29 -0
  134. data/app/helpers/decidim/votings/admin/polling_officers_picker_helper.rb +29 -0
  135. data/app/helpers/decidim/votings/votings_helper.rb +20 -0
  136. data/app/models/decidim/elections/action.rb +13 -0
  137. data/app/models/decidim/elections/election.rb +54 -3
  138. data/app/models/decidim/elections/elections_trustee.rb +11 -0
  139. data/app/models/decidim/elections/question.rb +19 -0
  140. data/app/models/decidim/elections/trustee.rb +26 -0
  141. data/app/models/decidim/elections/trustees_participatory_space.rb +13 -0
  142. data/app/models/decidim/elections/vote.rb +15 -0
  143. data/app/models/decidim/votings/monitoring_committee_member.rb +24 -0
  144. data/app/models/decidim/votings/polling_officer.rb +76 -0
  145. data/app/models/decidim/votings/polling_station.rb +64 -0
  146. data/app/models/decidim/votings/voting.rb +138 -0
  147. data/app/permissions/decidim/elections/admin/permissions.rb +50 -10
  148. data/app/permissions/decidim/elections/permissions.rb +20 -2
  149. data/app/permissions/decidim/elections/trustee_zone/permissions.rb +32 -0
  150. data/app/permissions/decidim/votings/admin/permissions.rb +127 -0
  151. data/app/permissions/decidim/votings/permissions.rb +40 -0
  152. data/app/permissions/decidim/votings/polling_officer_zone/permissions.rb +32 -0
  153. data/app/presenters/decidim/elections/admin_log/election_presenter.rb +1 -1
  154. data/app/presenters/decidim/elections/trustee_presenter.rb +24 -0
  155. data/app/presenters/decidim/votings/admin_log/voting_presenter.rb +45 -0
  156. data/app/presenters/decidim/votings/polling_station_presenter.rb +27 -0
  157. data/app/presenters/decidim/votings/voting_presenter.rb +36 -0
  158. data/app/queries/decidim/elections/admin/pending_actions.rb +20 -0
  159. data/app/queries/decidim/elections/admin/votes_for_statistics.rb +24 -0
  160. data/app/queries/decidim/elections/elections_finished_to_end.rb +19 -0
  161. data/app/queries/decidim/elections/elections_ready_to_start.rb +25 -0
  162. data/app/queries/decidim/elections/trustees/by_participatory_space.rb +24 -0
  163. data/app/queries/decidim/elections/trustees/by_participatory_space_trustee_ids.rb +24 -0
  164. data/app/queries/decidim/elections/votes/election_votes.rb +19 -0
  165. data/app/queries/decidim/elections/votes/pending_votes.rb +20 -0
  166. data/app/queries/decidim/elections/votes/user_election_last_vote.rb +26 -0
  167. data/app/queries/decidim/elections/votes/user_votes.rb +19 -0
  168. data/app/queries/decidim/votings/admin/admin_users.rb +39 -0
  169. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb +33 -0
  170. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations_and_user.rb +34 -0
  171. data/app/queries/decidim/votings/admin/polling_officers_join_user.rb +32 -0
  172. data/app/queries/decidim/votings/organization_prioritized_votings.rb +21 -0
  173. data/app/queries/decidim/votings/organization_promoted_votings.rb +16 -0
  174. data/app/queries/decidim/votings/organization_published_votings.rb +19 -0
  175. data/app/queries/decidim/votings/organization_votings.rb +16 -0
  176. data/app/queries/decidim/votings/prioritized_votings.rb +13 -0
  177. data/app/queries/decidim/votings/published_votings.rb +12 -0
  178. data/app/services/decidim/votings/voting_search.rb +46 -0
  179. data/app/views/decidim/elections/admin/answers/index.html.erb +12 -0
  180. data/app/views/decidim/elections/admin/elections/index.html.erb +13 -1
  181. data/app/views/decidim/elections/admin/proposals_imports/new.html.erb +1 -1
  182. data/app/views/decidim/elections/admin/questions/index.html.erb +5 -1
  183. data/app/views/decidim/elections/admin/shared/_trustees_secondary_nav.html.erb +3 -0
  184. data/app/views/decidim/elections/admin/steps/_create_election.html.erb +38 -0
  185. data/app/views/decidim/elections/admin/steps/_created.html.erb +16 -0
  186. data/app/views/decidim/elections/admin/steps/_key_ceremony.html.erb +16 -0
  187. data/app/views/decidim/elections/admin/steps/_key_ceremony_ended.html.erb +15 -0
  188. data/app/views/decidim/elections/admin/steps/_tally.html.erb +17 -0
  189. data/app/views/decidim/elections/admin/steps/_tally_ended.html.erb +9 -0
  190. data/app/views/decidim/elections/admin/steps/_vote.html.erb +21 -0
  191. data/app/views/decidim/elections/admin/steps/_vote_ended.html.erb +15 -0
  192. data/app/views/decidim/elections/admin/steps/_vote_stats.html.erb +31 -0
  193. data/app/views/decidim/elections/admin/steps/index.html.erb +43 -0
  194. data/app/views/decidim/elections/admin/trustees_participatory_spaces/_form.html.erb +19 -0
  195. data/app/views/decidim/elections/admin/trustees_participatory_spaces/index.html.erb +64 -0
  196. data/app/views/decidim/elections/admin/trustees_participatory_spaces/new.html.erb +7 -0
  197. data/app/views/decidim/elections/elections/_preview.html.erb +26 -0
  198. data/app/views/decidim/elections/elections/_results.html.erb +47 -0
  199. data/app/views/decidim/elections/elections/show.html.erb +43 -18
  200. data/app/views/decidim/elections/trustee_zone/elections/_backup_modal.html.erb +24 -0
  201. data/app/views/decidim/elections/trustee_zone/elections/_key_ceremony_steps.html.erb +44 -0
  202. data/app/views/decidim/elections/trustee_zone/elections/_restore_modal.html.erb +25 -0
  203. data/app/views/decidim/elections/trustee_zone/elections/_tally_steps.html.erb +43 -0
  204. data/app/views/decidim/elections/trustee_zone/elections/show.html.erb +38 -0
  205. data/app/views/decidim/elections/trustee_zone/elections/update.js.erb +5 -0
  206. data/app/views/decidim/elections/trustee_zone/trustees/show.html.erb +102 -0
  207. data/app/views/decidim/elections/votes/_election_votes_confirmed.html.erb +38 -17
  208. data/app/views/decidim/elections/votes/_election_votes_failed.html.erb +21 -0
  209. data/app/views/decidim/elections/votes/_election_votes_question.html.erb +4 -4
  210. data/app/views/decidim/elections/votes/cast_failed.js.erb +1 -0
  211. data/app/views/decidim/elections/votes/cast_success.js.erb +1 -0
  212. data/app/views/decidim/elections/votes/new.html.erb +41 -33
  213. data/app/views/decidim/elections/votes/verify.html.erb +78 -0
  214. data/app/views/decidim/votings/admin/monitoring_committee_members/_form.html.erb +27 -0
  215. data/app/views/decidim/votings/admin/monitoring_committee_members/index.html.erb +41 -0
  216. data/app/views/decidim/votings/admin/monitoring_committee_members/new.html.erb +7 -0
  217. data/app/views/decidim/votings/admin/polling_officers/_form.html.erb +27 -0
  218. data/app/views/decidim/votings/admin/polling_officers/index.html.erb +50 -0
  219. data/app/views/decidim/votings/admin/polling_officers/new.html.erb +7 -0
  220. data/app/views/decidim/votings/admin/polling_stations/_form.html.erb +40 -0
  221. data/app/views/decidim/votings/admin/polling_stations/edit.html.erb +7 -0
  222. data/app/views/decidim/votings/admin/polling_stations/index.html.erb +55 -0
  223. data/app/views/decidim/votings/admin/polling_stations/new.html.erb +7 -0
  224. data/app/views/decidim/votings/admin/votings/_form.html.erb +63 -0
  225. data/app/views/decidim/votings/admin/votings/edit.html.erb +31 -0
  226. data/app/views/decidim/votings/admin/votings/index.html.erb +87 -0
  227. data/app/views/decidim/votings/admin/votings/new.html.erb +13 -0
  228. data/app/views/decidim/votings/admin/votings/polling_officers_picker.html.erb +2 -0
  229. data/app/views/decidim/votings/polling_officer_zone/polling_officers/show.html.erb +42 -0
  230. data/app/views/decidim/votings/polling_officer_zone/polling_stations/show.html.erb +1 -0
  231. data/app/views/decidim/votings/votings/_count.html.erb +1 -0
  232. data/app/views/decidim/votings/votings/_filters.html.erb +25 -0
  233. data/app/views/decidim/votings/votings/_filters_small_view.html.erb +23 -0
  234. data/app/views/decidim/votings/votings/_promoted_voting.html.erb +27 -0
  235. data/app/views/decidim/votings/votings/_voting_details.html.erb +7 -0
  236. data/app/views/decidim/votings/votings/_votings.html.erb +25 -0
  237. data/app/views/decidim/votings/votings/index.html.erb +42 -0
  238. data/app/views/decidim/votings/votings/index.js.erb +10 -0
  239. data/app/views/decidim/votings/votings/show.html.erb +20 -0
  240. data/app/views/layouts/decidim/_voting_header.html.erb +16 -0
  241. data/app/views/layouts/decidim/admin/voting.html.erb +101 -0
  242. data/app/views/layouts/decidim/voting.html.erb +16 -0
  243. data/config/initializers/decidim_bulletin_board.rb +23 -0
  244. data/config/locales/ca.yml +53 -20
  245. data/config/locales/cs.yml +641 -7
  246. data/config/locales/de.yml +635 -6
  247. data/config/locales/el.yml +0 -6
  248. data/config/locales/en.yml +636 -6
  249. data/config/locales/es-MX.yml +7 -11
  250. data/config/locales/es-PY.yml +6 -10
  251. data/config/locales/es.yml +15 -19
  252. data/config/locales/fi-plain.yml +636 -7
  253. data/config/locales/fi.yml +637 -8
  254. data/config/locales/fr-CA.yml +422 -6
  255. data/config/locales/fr.yml +422 -6
  256. data/config/locales/gl.yml +63 -8
  257. data/config/locales/it.yml +97 -10
  258. data/config/locales/ja.yml +8 -10
  259. data/config/locales/lv.yml +0 -6
  260. data/config/locales/nl.yml +498 -6
  261. data/config/locales/no.yml +0 -5
  262. data/config/locales/pl.yml +570 -7
  263. data/config/locales/pt.yml +0 -10
  264. data/config/locales/ro-RO.yml +0 -44
  265. data/config/locales/sv.yml +8 -12
  266. data/config/locales/tr-TR.yml +114 -6
  267. data/config/locales/zh-CN.yml +0 -10
  268. data/db/migrate/20200915142713_add_questionnaire_to_existing_elections.rb +29 -0
  269. data/db/migrate/20200918153813_create_decidim_elections_trustees_participatory_spaces.rb +13 -0
  270. data/db/migrate/20200918153824_create_decidim_elections_elections_trustees.rb +10 -0
  271. data/db/migrate/20200918153835_create_decidim_elections_trustees.rb +12 -0
  272. data/db/migrate/20201026163334_add_blocked_at_and_bb_status_to_elections.rb +8 -0
  273. data/db/migrate/20201028090110_add_votes_to_decidim_elections_answers.rb +7 -0
  274. data/db/migrate/20201028135614_add_selected_to_decidim_elections_answers.rb +7 -0
  275. data/db/migrate/20201209110653_create_decidim_elections_votes.rb +14 -0
  276. data/db/migrate/20201216091123_add_name_to_trustees.rb +7 -0
  277. data/db/migrate/20210113113818_add_message_id_to_decidim_elections_votes.rb +7 -0
  278. data/db/migrate/20210113120115_create_decidim_elections_votings.rb +20 -0
  279. data/db/migrate/20210114100749_add_published_at_to_decidim_votings_votings.rb +7 -0
  280. data/db/migrate/20210114111850_add_user_to_decidim_elections_votes.rb +7 -0
  281. data/db/migrate/20210120164634_add_promoted_to_voting.rb +7 -0
  282. data/db/migrate/20210125124801_add_voting_type_to_voting_voting.rb +7 -0
  283. data/db/migrate/20210129124956_create_decidim_elections_actions.rb +14 -0
  284. data/db/migrate/20210204132111_add_votings_polling_stations.rb +19 -0
  285. data/db/migrate/20210208090441_add_polling_officers_to_votings.rb +12 -0
  286. data/db/migrate/20210210090738_add_votings_polling_station_references_to_votings_polling_officer.rb +8 -0
  287. data/db/migrate/20210216074707_add_monitoring_committee_member.rb +12 -0
  288. data/db/seeds/city.jpeg +0 -0
  289. data/lib/decidim/api/election_answer_type.rb +23 -0
  290. data/lib/decidim/api/election_question_type.rb +22 -0
  291. data/lib/decidim/api/election_type.rb +27 -0
  292. data/lib/decidim/api/elections_type.rb +32 -0
  293. data/lib/decidim/api/trustee_type.rb +16 -0
  294. data/lib/decidim/api/voting_type.rb +20 -0
  295. data/lib/decidim/elections/admin_engine.rb +42 -1
  296. data/lib/decidim/elections/answer_serializer.rb +48 -0
  297. data/lib/decidim/elections/api.rb +11 -0
  298. data/lib/decidim/elections/component.rb +367 -24
  299. data/lib/decidim/elections/engine.rb +8 -1
  300. data/lib/decidim/elections/test/factories.rb +201 -4
  301. data/lib/decidim/elections/trustee_zone.rb +10 -0
  302. data/lib/decidim/elections/trustee_zone_engine.rb +35 -0
  303. data/lib/decidim/elections/version.rb +1 -1
  304. data/lib/decidim/elections.rb +19 -2
  305. data/lib/decidim/votings/admin.rb +10 -0
  306. data/lib/decidim/votings/admin_engine.rb +71 -0
  307. data/lib/decidim/votings/api.rb +7 -0
  308. data/lib/decidim/votings/engine.rb +147 -0
  309. data/lib/decidim/votings/participatory_space.rb +92 -0
  310. data/lib/decidim/votings/polling_officer_zone.rb +10 -0
  311. data/lib/decidim/votings/polling_officer_zone_engine.rb +33 -0
  312. data/lib/decidim/votings/query_extensions.rb +43 -0
  313. data/lib/decidim/votings/test/capybara_polling_officers_picker.rb +49 -0
  314. data/lib/decidim/votings/test/factories.rb +83 -0
  315. data/lib/decidim/votings/voting_serializer.rb +54 -0
  316. data/lib/decidim/votings.rb +16 -0
  317. data/lib/tasks/decidim_elections.rake +68 -5
  318. metadata +304 -21
  319. data/app/types/decidim/elections/election_answer_type.rb +0 -24
  320. data/app/types/decidim/elections/election_question_type.rb +0 -25
  321. data/app/types/decidim/elections/election_type.rb +0 -27
  322. data/app/types/decidim/elections/elections_type.rb +0 -32
  323. data/config/i18n-tasks.yml +0 -10
  324. data/lib/decidim/elections/bulletin_board_client.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47ca26b39d17124a27f85e043a8a0080f748efef0696b82959af145e677f93dd
4
- data.tar.gz: 902a0dcafdbb4d958402f4d9b29183c9a4d1632b636349c29b34ec5d6058e4b3
3
+ metadata.gz: 74b9a4d949bccb66faf132d06a4470bd102827fcfa80cbecb358a72bca53eb5c
4
+ data.tar.gz: f2495933e037f55d58db95c9747e11c7b10b996fd295840d7afdd7e9540b313b
5
5
  SHA512:
6
- metadata.gz: 4ab0779486487282059a0d0dbe0be29381674a976201be87db54e4bec32ef4acfac00056813538221a1e8fe3c2d5149367331e5a870af1b0816674d69b0c59d8
7
- data.tar.gz: a4e06ab29599cb0187866e6e5cf211d5fdfddd6347cf6cadb27e6a7d3a3db5ca7ab105975f4858f1419d0490a0310ca761dd6b05f25e304df188e4f76c775c02
6
+ metadata.gz: b5de7e5d13942469f5d1555215661cb1178f6e665b0705b9c7c16495eb4572acf9c467ec70c82d1acb4d81bba97f637740f1f27fedd6c6dec6d9e2b72c3ea22e
7
+ data.tar.gz: debb1fffc6043d24201a51f8e1539da2722db180e6d74c96b1c1c93cefd931f281278316b118d9d37dc0fae29d80cb53b142035414db4d7bfec81516b0ba9c01
data/README.md CHANGED
@@ -8,6 +8,8 @@ The Elections module adds elections to any participatory space.
8
8
 
9
9
  Elections will be available as a Component for a Participatory Space.
10
10
 
11
+ In order to celebrate [End-to-end auditable votings](https://en.wikipedia.org/wiki/End-to-end_auditable_voting_systems) using the Elections module, you will need to connect your Decidim instance with an instance of the [Decidim Bulletin Board application](https://github.com/decidim/decidim-bulletin-board/). To create this connection, please check the [instructions](https://github.com/decidim/decidim/blob/develop/docs/services/elections_bulletin_board.md).
12
+
11
13
  ## Installation
12
14
 
13
15
  Add this line to your application's Gemfile:
@@ -0,0 +1,4 @@
1
+ //= link decidim/votings/admin/polling_officers_form.js
2
+ //= link decidim/votings/admin/polling_officers_picker.js
3
+ //= link decidim/votings/admin/polling_stations_form.js
4
+ //= link decidim/votings/admin/monitoring_committee_members_form.js
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= link decidim/elections/trustee_zone.scss
3
+ */
@@ -1,2 +1,8 @@
1
+ //= link decidim/elections/admin/pending_action.js
2
+ //= link decidim/elections/admin/vote_statistics.js.es6
3
+ //= link decidim/elections/trustee_zone/key_ceremony.js
4
+ //= link decidim/elections/trustee_zone/tally.js
5
+ //= link decidim/elections/trustee_zone.js
1
6
  //= link decidim/elections/vote.js
7
+ //= link decidim/elections/vote_verify.js
2
8
  //= link_tree ../images/decidim
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= link decidim/votings/votings.scss
3
+ */
File without changes
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8"><path d="M2.91-.03a1 1 0 0 0-.13.03 1 1 0 0 0-.78 1v2a1 1 0 1 0 2 0v-2a1 1 0 0 0-1.09-1.03zm-2.56 2.03a.5.5 0 0 0-.34.5v.5c0 1.48 1.09 2.69 2.5 2.94v1.06h-.5c-.55 0-1 .45-1 1h4.01c0-.55-.45-1-1-1h-.5v-1.06c1.41-.24 2.5-1.46 2.5-2.94v-.5a.5.5 0 1 0-1 0v.5c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2v-.5a.5.5 0 0 0-.59-.5.5.5 0 0 0-.06 0z" transform="translate(1)"/></svg>
@@ -0,0 +1,16 @@
1
+ // = require decidim/bulletin_board/decidim-bulletin_board
2
+
3
+ $(() => {
4
+ const { Client } = decidimBulletinBoard;
5
+ const $form = $("form.step");
6
+ const $pendingAction = $form.find("#pending_action")
7
+ const bulletinBoardClient = new Client({
8
+ apiEndpointUrl: $pendingAction.data("apiEndpointUrl")
9
+ });
10
+ const messageId = $pendingAction.data("messageId")
11
+
12
+ bulletinBoardClient.waitForPendingMessageToBeProcessed(messageId).then(() => {
13
+ $form.submit();
14
+ });
15
+ });
16
+
@@ -0,0 +1,11 @@
1
+ /* eslint-disable no-inline-comments */
2
+ /* eslint-disable line-comment-position */
3
+ // fetches Vote stats every 3 seconds
4
+
5
+ $(() => {
6
+ const WAIT_TIME_MS = 3000; // 3s
7
+
8
+ setInterval(function() {
9
+ $("#vote-stats").load($("#vote-stats").data("refreshUrl"));
10
+ }, WAIT_TIME_MS);
11
+ })
@@ -0,0 +1,126 @@
1
+ // = require decidim/bulletin_board/decidim-bulletin_board
2
+
3
+ /**
4
+ * This file is responsible to generate election keys,
5
+ * create a backup of keys for the trustee and
6
+ * update the election bulletin board status
7
+ */
8
+ $(() => {
9
+ const {
10
+ KeyCeremonyComponent,
11
+ MessageIdentifier,
12
+ IdentificationKeys,
13
+ MESSAGE_RECEIVED
14
+ } = window.decidimBulletinBoard;
15
+
16
+ // UI Elements
17
+ const $keyCeremony = $(".key-ceremony");
18
+ const $startButton = $keyCeremony.find(".start");
19
+ const $backupModal = $("#show-backup-modal");
20
+ const $backupButton = $backupModal.find(".download-election-keys");
21
+ const $backButton = $keyCeremony.find(".back");
22
+ const $restoreModal = $("#show-restore-modal");
23
+ const $restoreButton = $restoreModal.find(".upload-election-keys");
24
+ const getStepRow = (step) => {
25
+ return $(`#${step.replace(".", "-")}`);
26
+ };
27
+
28
+ // Data
29
+ const bulletinBoardClientParams = {
30
+ apiEndpointUrl: $keyCeremony.data("apiEndpointUrl")
31
+ }
32
+ const electionUniqueId = `${$keyCeremony.data("authorityUniqueId")}.${$keyCeremony.data("electionId")}`
33
+ const trusteeContext = {
34
+ uniqueId: $keyCeremony.data("trusteeUniqueId"),
35
+ publicKeyJSON: JSON.stringify($keyCeremony.data("trusteePublicKey"))
36
+ };
37
+ let currentStep = null;
38
+ const trusteeIdentificationKeys = new IdentificationKeys(
39
+ trusteeContext.uniqueId,
40
+ trusteeContext.publicKeyJSON
41
+ );
42
+
43
+ // Use the key ceremony controller and bind all UI events
44
+ const controller = new KeyCeremonyComponent({
45
+ bulletinBoardClientParams,
46
+ electionUniqueId,
47
+ trusteeUniqueId: trusteeContext.uniqueId,
48
+ trusteeIdentificationKeys
49
+ });
50
+
51
+ trusteeIdentificationKeys.present(async (exists) => {
52
+ if (exists) {
53
+ await controller.bindEvents({
54
+ onBindRestoreButton(onEventTriggered) {
55
+ $restoreButton.on("change", ".restore-button-input", onEventTriggered);
56
+ },
57
+ onBindStartButton(onEventTriggered) {
58
+ $startButton.on("click", onEventTriggered);
59
+ },
60
+ onBindBackupButton(backupData, backupFilename, onEventTriggered) {
61
+ $backupButton.attr(
62
+ "href",
63
+ `data:text/plain;charset=utf-8,${backupData}`
64
+ );
65
+ $backupButton.attr("download", backupFilename);
66
+ $backupButton.on("click", onEventTriggered);
67
+ },
68
+ onSetup() {
69
+ $startButton.prop("disabled", false);
70
+ },
71
+ onEvent(event) {
72
+ let messageIdentifier = MessageIdentifier.parse(
73
+ event.message.messageId
74
+ );
75
+
76
+ if (event.type === MESSAGE_RECEIVED) {
77
+ if (currentStep && currentStep !== messageIdentifier.typeSubtype) {
78
+ const $previousStep = getStepRow(currentStep);
79
+ $previousStep.attr("data-step-status", "completed");
80
+ }
81
+ currentStep = messageIdentifier.typeSubtype;
82
+
83
+ const $currentStep = getStepRow(currentStep);
84
+ if ($currentStep.data("step-status") !== "completed") {
85
+ $currentStep.attr("data-step-status", "processing");
86
+ }
87
+ }
88
+ },
89
+ onRestore() {
90
+ $restoreModal.foundation("close");
91
+ },
92
+ onComplete() {
93
+ const $allSteps = $(".step_status");
94
+ $allSteps.attr("data-step-status", "completed");
95
+
96
+ $startButton.addClass("hide");
97
+ $backButton.removeClass("hide");
98
+
99
+ $.ajax({
100
+ method: "PATCH",
101
+ url: $keyCeremony.data("updateElectionStatusUrl"),
102
+ contentType: "application/json",
103
+ data: JSON.stringify({
104
+ status: "key_ceremony"
105
+ }),
106
+ headers: {
107
+ "X-CSRF-Token": $("meta[name=csrf-token]").attr("content")
108
+ }
109
+ });
110
+ },
111
+ onStart() {
112
+ $startButton.prop("disabled", true);
113
+ },
114
+ onTrusteeNeedsToBeRestored() {
115
+ $restoreModal.foundation("open");
116
+ },
117
+ onBackupNeeded() {
118
+ $backupModal.foundation("open");
119
+ },
120
+ onBackupStarted() {
121
+ $backupModal.foundation("close");
122
+ }
123
+ });
124
+ }
125
+ });
126
+ });
@@ -0,0 +1,104 @@
1
+ // = require decidim/bulletin_board/decidim-bulletin_board
2
+
3
+ $(() => {
4
+ const { TallyComponent, IdentificationKeys, MessageIdentifier, MESSAGE_RECEIVED } = window.decidimBulletinBoard;
5
+
6
+ // UI Elements
7
+ const $tally = $(".tally");
8
+ const $startButton = $tally.find(".start");
9
+ const getStepRow = (step) => {
10
+ return $(`#${step.replace(".", "-")}`);
11
+ };
12
+ const $restoreModal = $("#show-restore-modal");
13
+ const $restoreButton = $restoreModal.find(".upload-election-keys");
14
+ const $backButton = $tally.find(".back");
15
+
16
+ // Data
17
+ const bulletinBoardClientParams = {
18
+ apiEndpointUrl: $tally.data("apiEndpointUrl")
19
+ };
20
+ const electionUniqueId = `${$tally.data("authorityUniqueId")}.${$tally.data("electionId")}`
21
+ const trusteeContext = {
22
+ uniqueId: $tally.data("trusteeUniqueId"),
23
+ publicKeyJSON: JSON.stringify($tally.data("trusteePublicKey"))
24
+ };
25
+ const trusteeIdentificationKeys = new IdentificationKeys(
26
+ trusteeContext.uniqueId,
27
+ trusteeContext.publicKeyJSON
28
+ );
29
+ let currentStep = null;
30
+
31
+ // Use the tally component and bind all UI events
32
+ const component = new TallyComponent({
33
+ bulletinBoardClientParams,
34
+ electionUniqueId,
35
+ trusteeUniqueId: trusteeContext.uniqueId,
36
+ trusteeIdentificationKeys
37
+ });
38
+
39
+ const bindComponentEvents = async () => {
40
+ await component.bindEvents({
41
+ onEvent(event) {
42
+ let messageIdentifier = MessageIdentifier.parse(
43
+ event.message.messageId
44
+ );
45
+
46
+ if (event.type === MESSAGE_RECEIVED) {
47
+ if (currentStep && currentStep !== messageIdentifier.typeSubtype) {
48
+ const $previousStep = getStepRow(currentStep);
49
+ $previousStep.attr("data-step-status", "completed");
50
+ }
51
+ currentStep = messageIdentifier.typeSubtype;
52
+
53
+ const $currentStep = getStepRow(currentStep);
54
+ if ($currentStep.data("step-status") !== "completed") {
55
+ $currentStep.attr("data-step-status", "processing");
56
+ }
57
+ }
58
+ },
59
+ onSetup() {
60
+ $startButton.prop("disabled", false);
61
+ },
62
+ onBindStartButton(onEventTriggered) {
63
+ $startButton.on("click", onEventTriggered);
64
+ },
65
+ onStart() {
66
+ $startButton.prop("disabled", true);
67
+ },
68
+ onComplete() {
69
+ const $allSteps = $(".step_status");
70
+ $allSteps.attr("data-step-status", "completed");
71
+
72
+ $startButton.addClass("hide");
73
+ $backButton.removeClass("hide");
74
+
75
+ $.ajax({
76
+ method: "PATCH",
77
+ url: $tally.data("updateElectionStatusUrl"),
78
+ contentType: "application/json",
79
+ data: JSON.stringify({
80
+ status: "tally"
81
+ }),
82
+ headers: {
83
+ "X-CSRF-Token": $("meta[name=csrf-token]").attr("content")
84
+ }
85
+ });
86
+ },
87
+ onTrusteeNeedsToBeRestored() {
88
+ $restoreModal.foundation("open");
89
+ },
90
+ onBindRestoreButton(onEventTriggered) {
91
+ $restoreButton.on("change", ".restore-button-input", onEventTriggered);
92
+ },
93
+ onRestore() {
94
+ $restoreModal.foundation("close");
95
+ }
96
+ });
97
+ };
98
+
99
+ trusteeIdentificationKeys.present(async (exists) => {
100
+ if (exists) {
101
+ await bindComponentEvents();
102
+ }
103
+ });
104
+ });
@@ -0,0 +1,54 @@
1
+ /* eslint-disable require-jsdoc, no-alert, func-style */
2
+ // = require decidim/bulletin_board/decidim-bulletin_board
3
+
4
+ window.Decidim = window.Decidim || {};
5
+
6
+ $(() => {
7
+ const { IdentificationKeys } = window.decidimBulletinBoard;
8
+
9
+ function identificationKeys() {
10
+ const $form = $(".trustee_zone form");
11
+ const $trusteeUniqueId = $("#trustee_unique_id", $form);
12
+ const $trusteePublicKey = $("#trustee_public_key", $form);
13
+
14
+ window.trusteeIdentificationKeys = new IdentificationKeys($trusteeUniqueId.val(), $trusteePublicKey.val());
15
+ if (!window.trusteeIdentificationKeys.browserSupport) {
16
+ $("#not_supported_browser").addClass("visible");
17
+ return;
18
+ }
19
+
20
+ const $submit = $("#submit_identification_keys");
21
+ const $generate = $("#generate_identification_keys");
22
+ const $upload = $("#upload_identification_keys");
23
+
24
+ $("button", $generate).click(() => {
25
+ window.trusteeIdentificationKeys.generate().then(() => {
26
+ $trusteePublicKey.val(JSON.stringify(window.trusteeIdentificationKeys.publicKey));
27
+ $submit.addClass("visible");
28
+ }).catch(() => {
29
+ alert($generate.data("error"))
30
+ });
31
+ });
32
+
33
+ $("button.hollow", $submit).click(() => {
34
+ $trusteePublicKey.val("");
35
+ $submit.removeClass("visible");
36
+ });
37
+
38
+ $("button", $upload).click(() => {
39
+ window.trusteeIdentificationKeys.upload().then(() => {
40
+ $upload.addClass("hide");
41
+ }).catch((errorMessage) => {
42
+ alert($upload.data(errorMessage));
43
+ });
44
+ })
45
+
46
+ window.trusteeIdentificationKeys.present((result) => {
47
+ $upload.toggleClass("hide", result);
48
+ });
49
+ }
50
+
51
+ $(document).ready(() => {
52
+ identificationKeys()
53
+ })
54
+ })
@@ -1,170 +1,117 @@
1
- /* eslint-disable require-jsdoc, prefer-template, func-style, id-length, no-use-before-define, init-declarations, no-invalid-this */
2
- /* eslint no-unused-vars: ["error", { "args": "none" }] */
3
-
4
- $(() => {
5
- const $vote = $(".focus");
6
- const $continueButton = $vote.find("a.focus__next");
7
- const $confirmButton = $vote.find("a.focus__next.confirm");
8
- const $continueSpan = $vote.find("span.disabled-continue");
9
- let $answerCounter = 0;
10
- let $currentStep,
11
- $currentStepMaxSelection = "";
12
- let $formData = $vote.find(".answer_input");
13
-
14
- function initStep() {
15
- setCurrentStep();
16
- toggleContinueButton();
17
- $($confirmButton).addClass("show").removeClass("hide");
18
- $(".evote__counter-min").text($answerCounter);
19
- answerCounter();
20
- disableCheckbox();
21
- }
22
-
23
- initStep()
24
-
25
- function setCurrentStep() {
26
- $currentStep = $vote.find(".focus__step:visible")
27
- setSelections();
28
- onSelectionChange();
29
- }
30
-
31
- function setSelections() {
32
- $currentStepMaxSelection = $currentStep.find(".evote__options").data("max-selection")
33
- }
1
+ // = require decidim/bulletin_board/decidim-bulletin_board
2
+ // = require ./vote_questions.component
3
+
4
+ $(async () => {
5
+ const { VoteQuestionsComponent } = window.Decidim;
6
+ const { VoteComponent } = window.decidimBulletinBoard;
7
+
8
+ // UI Elements
9
+ const $voteWrapper = $(".vote-wrapper");
10
+
11
+ // Data
12
+ const bulletinBoardClientParams = {
13
+ apiEndpointUrl: $voteWrapper.data("apiEndpointUrl")
14
+ };
15
+ const electionUniqueId = $voteWrapper.data("electionUniqueId");
16
+ const voterUniqueId = $voteWrapper.data("voterId");
17
+
18
+ // Use the questions component
19
+ const questionsComponent = new VoteQuestionsComponent($voteWrapper);
20
+ questionsComponent.init();
21
+ $(document).on("on.zf.toggler", () => {
22
+ // continue and back btn
23
+ questionsComponent.init()
24
+ });
34
25
 
35
- function onSelectionChange() {
36
- let $voteOptions = $currentStep.find(".evote__options");
37
- $voteOptions.on("change", (event) => {
38
- toggleContinueButton();
39
- toggleConfirmAnswers();
40
- answerCounter();
41
- });
42
- }
26
+ // Use the voter component and bind all UI events
27
+ const voteComponent = new VoteComponent({
28
+ bulletinBoardClientParams,
29
+ electionUniqueId,
30
+ voterUniqueId
31
+ });
43
32
 
44
- // disable checkboxes if NOTA option is selected
45
- function disableCheckbox() {
46
- $("[data-disabled-by]").on("click", function(e) {
47
- if ($(this).attr("aria-disabled") || $(this).hasClass("is-disabled")) {
48
- e.preventDefault();
33
+ await voteComponent.bindEvents({
34
+ onSetup() {},
35
+ onBindStartButton(onEventTriggered) {
36
+ $(".button.confirm").on("click", onEventTriggered);
37
+ },
38
+ onStart() {},
39
+ onVoteValidation(validVoteFn) {
40
+ const getFormData = (formData) => {
41
+ return formData.serializeArray().reduce((acc, {name, value}) => {
42
+ if (!acc[name]) {
43
+ acc[name] = [];
44
+ }
45
+ acc[name] = [...acc[name], value];
46
+ return acc;
47
+ }, {"ballot_style": "unique"});
49
48
  }
50
- });
51
-
52
- $("[data-disable-check]").on("change", function() {
53
- let checkId = $(this).attr("id");
54
- let checkStatus = this.checked;
55
49
 
56
- $($currentStep).find("[data-disabled-by='#" + checkId + "']").each(function() {
57
- if (checkStatus) {
58
- $(this).addClass("is-disabled");
59
- $(this).find("input[type=checkbox]").prop("checked", false);
60
- } else {
61
- $(this).removeClass("is-disabled");
50
+ const formData = getFormData($voteWrapper.find(".answer_input"));
51
+ validVoteFn(formData);
52
+ },
53
+ async onVoteEncrypted({encryptedVote, encryptedVoteHash}) {
54
+ const simulatePreviewDelay = () => {
55
+ return new Promise((resolve) => setTimeout(resolve, 500));
56
+ };
57
+ const isPreview = $voteWrapper.data("booth-mode") === "preview";
58
+
59
+ await $.ajax({
60
+ method: "POST",
61
+ url: $voteWrapper.data("castVoteUrl"),
62
+ contentType: "application/json",
63
+ data: JSON.stringify({ encrypted_vote: encryptedVote, encrypted_vote_hash: encryptedVoteHash }), // eslint-disable-line camelcase
64
+ headers: {
65
+ "X-CSRF-Token": $("meta[name=csrf-token]").attr("content")
62
66
  }
63
-
64
- $(this).find("input[type=checkbox]").attr("aria-disabled", checkStatus);
65
67
  });
66
- });
67
- }
68
-
69
- function toggleContinueButton() {
70
- if (checkAnswers() === true) {
71
- // next step enabled
72
- $($continueButton).addClass("show").removeClass("hide")
73
- $($continueSpan).addClass("hide").removeClass("show")
74
- } else {
75
- // next step disabled
76
- $($continueButton).addClass("hide").removeClass("show")
77
- $($continueSpan).addClass("show").removeClass("hide")
78
- }
79
- }
80
-
81
- // check if answers are correctly checked
82
- function checkAnswers() {
83
- let currentAnswersChecked = $("#" + $currentStep.attr("id") + " .answer_input:checked").length
84
- let notaAnswerChecked = $("#" + $currentStep.attr("id") + " .nota_input:checked").length
85
-
86
- if ((currentAnswersChecked >= 1 || notaAnswerChecked > 0) && (currentAnswersChecked <= $currentStepMaxSelection)) {
87
- return true;
88
- }
89
-
90
- return false;
91
- }
92
-
93
- // receive confirmed answers
94
- function toggleConfirmAnswers() {
95
- $(".answer_input:checked").each(function() {
96
- let confirmedAnswer = $(".evote__confirm").find("#" + this.value);
97
- $(confirmedAnswer).removeClass("hide")
98
- })
99
-
100
- $(".answer_input").not(":checked").each(function() {
101
- let confirmedAnswer = $(".evote__confirm").find("#" + this.value);
102
- $(confirmedAnswer).addClass("hide")
103
- })
104
68
 
105
- $(".nota_input:checked").each(function() {
106
- let confirmedAnswer = $(".evote__confirm").find("." + this.value);
107
- $(confirmedAnswer).removeClass("hide")
108
- })
109
-
110
- $(".nota_input").not(":checked").each(function() {
111
- let confirmedAnswer = $(".evote__confirm").find("." + this.value);
112
- $(confirmedAnswer).addClass("hide")
113
- })
114
- }
115
-
116
- function answerCounter() {
117
- let checked = $("#" + $currentStep.attr("id") + " .answer_input:checked").length
118
- $(".evote__counter-min").text(checked);
119
- }
120
-
121
- // get form Data
122
- function getFormData(formData) {
123
- let unindexedArray = formData.serializeArray();
124
- let indexedArray = {};
125
- $.map(unindexedArray, function(n, i) {
126
- indexedArray[n.name] = n.value;
127
- });
128
-
129
- return indexedArray;
130
- }
131
-
132
- // confirm vote
133
- $(".button.confirm").on("click", (event) => {
134
- const boothMode = $(event.currentTarget).data("booth-mode");
135
- const formData = getFormData($formData);
136
- castVote(boothMode, formData)
137
- });
138
-
139
- // cast vote
140
- function castVote(boothMode, formData) {
141
- // log form Data
142
- console.log(`Your vote got encrypted successfully. The booth mode is ${boothMode}. Your vote content is:`, formData) // eslint-disable-line no-console
143
-
144
- window.setTimeout(function() {
145
- $($vote).find("#encrypting").addClass("hide")
146
- $($vote).find("#confirmed_page").removeClass("hide")
147
- window.confirmed = true;
148
- }, 3000)
149
- }
150
-
151
- // exit message before confirming
152
- const $form = $(".evote__options");
153
- if ($form.length > 0) {
154
-
155
- window.onbeforeunload = () => {
156
- const voteCast = window.confirmed;
157
-
158
- if (voteCast) {
159
- return null;
69
+ if (isPreview) {
70
+ await simulatePreviewDelay();
71
+ $voteWrapper.find("#encrypting").addClass("hide");
72
+ $voteWrapper.find("#confirmed_page").removeClass("hide");
73
+ $voteWrapper.find(".vote-confirmed-result").hide();
74
+ questionsComponent.voteCasted = true;
75
+ await simulatePreviewDelay()
76
+ $voteWrapper.find(".vote-confirmed-processing").hide();
77
+ $voteWrapper.find(".vote-confirmed-result").show();
78
+ } else {
79
+ const messageId = $voteWrapper.find(".vote-confirmed-result").data("messageId");
80
+ const voteId = $voteWrapper.find(".vote-confirmed-result").data("voteId");
81
+ const pendingMessage = await voteComponent.bulletinBoardClient.waitForPendingMessageToBeProcessed(messageId);
82
+
83
+ await $.ajax({
84
+ method: "PATCH",
85
+ url: $voteWrapper.data("updateVoteStatusUrl"),
86
+ contentType: "application/json",
87
+ data: JSON.stringify({ vote_id: voteId }), // eslint-disable-line camelcase
88
+ headers: {
89
+ "X-CSRF-Token": $("meta[name=csrf-token]").attr("content")
90
+ }
91
+ });
92
+
93
+ if (pendingMessage.status === "accepted") {
94
+ $voteWrapper.find("#encrypting").addClass("hide");
95
+ $voteWrapper.find("#confirmed_page").removeClass("hide");
96
+ $voteWrapper.find(".vote-confirmed-result").hide();
97
+ questionsComponent.voteCasted = true;
98
+
99
+ const logEntry = await voteComponent.voter.verifyVote(encryptedVoteHash);
100
+
101
+ if (logEntry) {
102
+ $voteWrapper.find(".vote-confirmed-processing").hide();
103
+ $voteWrapper.find(".vote-confirmed-result").show();
104
+ } else {
105
+ const $error = $voteWrapper.find(".vote-confirmed-result").data("error");
106
+ alert($error); // eslint-disable-line no-alert
107
+ }
108
+ } else {
109
+ const $error = $voteWrapper.find(".vote-confirmed-result").data("error");
110
+ alert($error); // eslint-disable-line no-alert
111
+ }
160
112
  }
161
-
162
- return "";
163
- }
164
- }
165
-
166
- $(document).on("on.zf.toggler", (event) => {
167
- // continue and back btn
168
- initStep()
113
+ },
114
+ onComplete() {},
115
+ onInvalid() {}
169
116
  });
170
117
  });