From 560ff7c51de83251b0555bf6801c00bbc82eab16 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 13 Oct 2017 12:40:42 +0200 Subject: [PATCH 1/9] does not use custom implementation to disable submit button --- .../javascripts/prevent_double_submission.js.coffee | 10 ++++++---- app/views/officing/voters/_can_vote.html.erb | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/prevent_double_submission.js.coffee b/app/assets/javascripts/prevent_double_submission.js.coffee index 2a4ef9c5e..abb8f8314 100644 --- a/app/assets/javascripts/prevent_double_submission.js.coffee +++ b/app/assets/javascripts/prevent_double_submission.js.coffee @@ -22,11 +22,13 @@ App.PreventDoubleSubmission = initialize: -> $('form').on('submit', (event) -> - buttons = $(this).find(':button, :submit') - App.PreventDoubleSubmission.disable_buttons(buttons) + unless event.target.id == "new_officing_voter" + buttons = $(this).find(':button, :submit') + App.PreventDoubleSubmission.disable_buttons(buttons) ).on('ajax:success', -> - buttons = $(this).find(':button, :submit') - App.PreventDoubleSubmission.reset_buttons(buttons) + unless event.target.id == "new_officing_voter" + buttons = $(this).find(':button, :submit') + App.PreventDoubleSubmission.reset_buttons(buttons) ) false diff --git a/app/views/officing/voters/_can_vote.html.erb b/app/views/officing/voters/_can_vote.html.erb index 27c5e9dbc..b953946ce 100644 --- a/app/views/officing/voters/_can_vote.html.erb +++ b/app/views/officing/voters/_can_vote.html.erb @@ -5,7 +5,9 @@
- <%= form_for @user, as: :voter, url: officing_voters_path, method: :post, remote: true do |f| %> + <%= form_for @user, as: :voter, url: officing_voters_path, + method: :post, remote: true, + html: { id: "new_officing_voter" } do |f| %> <%= f.hidden_field :poll_id, value: poll.id %> <%= f.hidden_field :user_id, value: @user.id %> <%= f.submit t("officing.voters.show.submit"), class: "button success expanded" %> From cd6cf3bda11f3615853a1ffcd0c9e2d47d2cce13 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 13 Oct 2017 12:41:33 +0200 Subject: [PATCH 2/9] uses default rails helper to disable submit button --- app/views/officing/voters/_can_vote.html.erb | 4 +++- config/locales/en/officing.yml | 2 ++ config/locales/es/officing.yml | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/officing/voters/_can_vote.html.erb b/app/views/officing/voters/_can_vote.html.erb index b953946ce..b5c9663ac 100644 --- a/app/views/officing/voters/_can_vote.html.erb +++ b/app/views/officing/voters/_can_vote.html.erb @@ -10,7 +10,9 @@ html: { id: "new_officing_voter" } do |f| %> <%= f.hidden_field :poll_id, value: poll.id %> <%= f.hidden_field :user_id, value: @user.id %> - <%= f.submit t("officing.voters.show.submit"), class: "button success expanded" %> + <%= f.submit t("officing.voters.show.submit"), + class: "button success expanded", + data: { disable_with: t("officing.voters.can_vote.submit_disable_with") } %> <% end %>
diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 378b87b15..e51e03510 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -64,3 +64,5 @@ en: error_already_voted: Has already participated in this poll submit: Confirm vote success: "Vote introduced!" + can_vote: + submit_disable_with: "WAIT, confirming vote" diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index 354b59710..c23b42568 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -64,3 +64,5 @@ es: error_already_voted: "Ya ha participado en esta votación." submit: Confirmar voto success: "¡Voto introducido!" + can_vote: + submit_disable_with: "ESPERA, confirmando voto" \ No newline at end of file From c097cf236cedd9713500e665532a00cc3bf7e5cd Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 13 Oct 2017 12:41:43 +0200 Subject: [PATCH 3/9] updates specs --- spec/features/polls/voter_spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 256807928..41886653b 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -51,8 +51,12 @@ feature "Voter" do expect(page).to have_content poll.name - first(:button, "Confirm vote").click - expect(page).to have_content "Vote introduced!" + within("#poll_#{poll.id}") do + click_button("Confirm vote") + expect(page).to_not have_button("Confirm vote") + expect(page).to have_button('WAIT, confirming vote', disabled: true) + expect(page).to have_content "Vote introduced!" + end expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.first.origin).to eq("booth") From 386fe785c7c88793a89ae6ce2f258c0c8468bf03 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 13 Oct 2017 14:16:21 +0200 Subject: [PATCH 4/9] improves text and layouts for officing voters views --- app/assets/stylesheets/admin.scss | 1 + app/views/officing/voters/_voted.html.erb | 10 ++---- app/views/officing/voters/new.html.erb | 39 +++++++++++++++++------ config/locales/en/officing.yml | 6 ++-- config/locales/es/officing.yml | 8 +++-- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 8f6912716..85997aecd 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -605,6 +605,7 @@ table { .callout { height: $line-height * 2; line-height: $line-height * 2; + margin: 0; padding: 0 $line-height / 2; } } diff --git a/app/views/officing/voters/_voted.html.erb b/app/views/officing/voters/_voted.html.erb index edd098403..49d1523a6 100644 --- a/app/views/officing/voters/_voted.html.erb +++ b/app/views/officing/voters/_voted.html.erb @@ -1,7 +1,3 @@ -
-
-
- <%= t("officing.voters.show.success") %> -
-
-
+ + <%= t("officing.voters.show.success") %> + diff --git a/app/views/officing/voters/new.html.erb b/app/views/officing/voters/new.html.erb index 0f8fa2958..212a9d8f8 100644 --- a/app/views/officing/voters/new.html.erb +++ b/app/views/officing/voters/new.html.erb @@ -7,7 +7,8 @@ <%= t("officing.voters.new.table_poll") %> - <%= t("officing.voters.new.table_actions") %> + <%= t("officing.voters.new.table_status") %> + <%= t("officing.voters.new.table_actions") %> @@ -16,15 +17,35 @@ <%= poll.name %> - - <% if poll.votable_by?(@user) %> - <%= render "can_vote", poll: poll %> - <% else %> - <%= render "already_voted" %> - <% end %> - + <% if poll.votable_by?(@user) %> + +

+ <%= t("officing.voters.show.can_vote") %> +

+ + + <%= form_for @user, as: :voter, url: officing_voters_path, + method: :post, remote: true, + html: { id: "new_officing_voter" } do |f| %> + <%= f.hidden_field :poll_id, value: poll.id %> + <%= f.hidden_field :user_id, value: @user.id %> + <%= f.submit t("officing.voters.show.submit"), + class: "button success", + data: { disable_with: t("officing.voters.can_vote.submit_disable_with") } %> + <% end %> + + <% else %> + +

+ <%= t("officing.voters.show.error_already_voted") %> +

+ + + <%= t("officing.voters.show.no_actions") %> + + <% end %> <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index e51e03510..bb9ef6bd2 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -58,11 +58,13 @@ en: new: title: Polls table_poll: Poll - table_actions: Polls status + table_status: Polls status + table_actions: Actions show: can_vote: Can vote error_already_voted: Has already participated in this poll + no_actions: There is no available actions submit: Confirm vote success: "Vote introduced!" can_vote: - submit_disable_with: "WAIT, confirming vote" + submit_disable_with: "Wait, confirming vote..." diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index c23b42568..86d6982fc 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -58,11 +58,13 @@ es: new: title: Votaciones table_poll: Votación - table_actions: Estado de las votaciones + table_status: Estado de las votaciones + table_actions: Acciones show: can_vote: Puede votar - error_already_voted: "Ya ha participado en esta votación." + error_already_voted: "Ya ha participado en esta votación" + no_actions: No hay acciones disponibles submit: Confirmar voto success: "¡Voto introducido!" can_vote: - submit_disable_with: "ESPERA, confirmando voto" \ No newline at end of file + submit_disable_with: "Espera, confirmando voto..." \ No newline at end of file From 5540f130e1b9b0b50c20961e8724075c9b808d1d Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 13 Oct 2017 14:16:33 +0200 Subject: [PATCH 5/9] removes unused partials --- .../officing/voters/_already_voted.html.erb | 7 ------- app/views/officing/voters/_can_vote.html.erb | 18 ------------------ 2 files changed, 25 deletions(-) delete mode 100644 app/views/officing/voters/_already_voted.html.erb delete mode 100644 app/views/officing/voters/_can_vote.html.erb diff --git a/app/views/officing/voters/_already_voted.html.erb b/app/views/officing/voters/_already_voted.html.erb deleted file mode 100644 index 1476913f9..000000000 --- a/app/views/officing/voters/_already_voted.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -
-
-
- <%= t("officing.voters.show.error_already_voted") %> -
-
-
diff --git a/app/views/officing/voters/_can_vote.html.erb b/app/views/officing/voters/_can_vote.html.erb deleted file mode 100644 index b5c9663ac..000000000 --- a/app/views/officing/voters/_can_vote.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -
-
-
- <%= t("officing.voters.show.can_vote") %> -
-
-
- <%= form_for @user, as: :voter, url: officing_voters_path, - method: :post, remote: true, - html: { id: "new_officing_voter" } do |f| %> - <%= f.hidden_field :poll_id, value: poll.id %> - <%= f.hidden_field :user_id, value: @user.id %> - <%= f.submit t("officing.voters.show.submit"), - class: "button success expanded", - data: { disable_with: t("officing.voters.can_vote.submit_disable_with") } %> - <% end %> -
-
From f94a3763920a2e93c33ddafbcb17cb280dbd51e1 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 13 Oct 2017 14:16:46 +0200 Subject: [PATCH 6/9] updates text on specs --- spec/features/polls/voter_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 41886653b..334696768 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -54,7 +54,7 @@ feature "Voter" do within("#poll_#{poll.id}") do click_button("Confirm vote") expect(page).to_not have_button("Confirm vote") - expect(page).to have_button('WAIT, confirming vote', disabled: true) + expect(page).to have_button('Wait, confirming vote...', disabled: true) expect(page).to have_content "Vote introduced!" end From 6b721e7750559bcd73ccc854a5deb86267a3a71b Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 13 Oct 2017 14:40:39 +0200 Subject: [PATCH 7/9] moves table content to partials --- .../officing/voters/_already_voted.html.erb | 8 ++++++ app/views/officing/voters/_can_vote.html.erb | 16 ++++++++++++ app/views/officing/voters/new.html.erb | 26 ++----------------- 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 app/views/officing/voters/_already_voted.html.erb create mode 100644 app/views/officing/voters/_can_vote.html.erb diff --git a/app/views/officing/voters/_already_voted.html.erb b/app/views/officing/voters/_already_voted.html.erb new file mode 100644 index 000000000..1af002b3f --- /dev/null +++ b/app/views/officing/voters/_already_voted.html.erb @@ -0,0 +1,8 @@ + +

+ <%= t("officing.voters.show.error_already_voted") %> +

+ + + <%= t("officing.voters.show.no_actions") %> + diff --git a/app/views/officing/voters/_can_vote.html.erb b/app/views/officing/voters/_can_vote.html.erb new file mode 100644 index 000000000..c179f854b --- /dev/null +++ b/app/views/officing/voters/_can_vote.html.erb @@ -0,0 +1,16 @@ + +

+ <%= t("officing.voters.show.can_vote") %> +

+ + + <%= form_for @user, as: :voter, url: officing_voters_path, + method: :post, remote: true, + html: { id: "new_officing_voter" } do |f| %> + <%= f.hidden_field :poll_id, value: poll.id %> + <%= f.hidden_field :user_id, value: @user.id %> + <%= f.submit t("officing.voters.show.submit"), + class: "button success", + data: { disable_with: t("officing.voters.can_vote.submit_disable_with") } %> + <% end %> + diff --git a/app/views/officing/voters/new.html.erb b/app/views/officing/voters/new.html.erb index 212a9d8f8..a6ab32d33 100644 --- a/app/views/officing/voters/new.html.erb +++ b/app/views/officing/voters/new.html.erb @@ -18,31 +18,9 @@ <%= poll.name %> <% if poll.votable_by?(@user) %> - -

- <%= t("officing.voters.show.can_vote") %> -

- - - <%= form_for @user, as: :voter, url: officing_voters_path, - method: :post, remote: true, - html: { id: "new_officing_voter" } do |f| %> - <%= f.hidden_field :poll_id, value: poll.id %> - <%= f.hidden_field :user_id, value: @user.id %> - <%= f.submit t("officing.voters.show.submit"), - class: "button success", - data: { disable_with: t("officing.voters.can_vote.submit_disable_with") } %> - <% end %> - + <%= render "can_vote", poll: poll %> <% else %> - -

- <%= t("officing.voters.show.error_already_voted") %> -

- - - <%= t("officing.voters.show.no_actions") %> - + <%= render "already_voted" %> <% end %> <% end %> From 234d4d3f54cb1825218347987387f9144b0e67a3 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 13 Oct 2017 14:45:30 +0200 Subject: [PATCH 8/9] hides can vote callout when voted --- app/views/officing/voters/_can_vote.html.erb | 2 +- app/views/officing/voters/create.js.erb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/officing/voters/_can_vote.html.erb b/app/views/officing/voters/_can_vote.html.erb index c179f854b..0d01f97fe 100644 --- a/app/views/officing/voters/_can_vote.html.erb +++ b/app/views/officing/voters/_can_vote.html.erb @@ -1,5 +1,5 @@ -

+

<%= t("officing.voters.show.can_vote") %>

diff --git a/app/views/officing/voters/create.js.erb b/app/views/officing/voters/create.js.erb index ee280faa2..964987a87 100644 --- a/app/views/officing/voters/create.js.erb +++ b/app/views/officing/voters/create.js.erb @@ -1 +1,2 @@ -$("#<%= dom_id(@poll) %> #actions").html('<%= j render("voted") %>'); \ No newline at end of file +$("#<%= dom_id(@poll) %> #actions").html('<%= j render("voted") %>'); +$("#can_vote_callout").hide(); From 200db22cbbf2d6269b7bc85b8329882a43c724b7 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 13 Oct 2017 15:15:54 +0200 Subject: [PATCH 9/9] only update the poll that was just voted --- app/views/officing/voters/create.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/officing/voters/create.js.erb b/app/views/officing/voters/create.js.erb index 964987a87..3837f017e 100644 --- a/app/views/officing/voters/create.js.erb +++ b/app/views/officing/voters/create.js.erb @@ -1,2 +1,2 @@ $("#<%= dom_id(@poll) %> #actions").html('<%= j render("voted") %>'); -$("#can_vote_callout").hide(); +$("#<%= dom_id(@poll) %> #can_vote_callout").hide(); \ No newline at end of file