From 645ff8ce85c8fc78e0a5f588d52c35c32aaa0384 Mon Sep 17 00:00:00 2001 From: Vera Rojman Date: Thu, 3 Jun 2021 14:57:59 +0200 Subject: [PATCH] Fix modal pop up when project exceeds budget amount (#13) --- .../decidim/budgets/projects.js.es6 | 5 ++ .../budgets/budget/_budget-vote-button.scss | 33 +++------- .../project_list_item/project_data.erb | 2 +- .../show.erb} | 0 .../budgets/project_vote_button_cell.rb | 10 +++ .../projects/_project_budget_button.html.erb | 63 ++++--------------- 6 files changed, 38 insertions(+), 75 deletions(-) rename decidim-budgets/app/cells/decidim/budgets/{project_list_item/project_data_vote_button.erb => project_vote_button/show.erb} (100%) create mode 100644 decidim-budgets/app/cells/decidim/budgets/project_vote_button_cell.rb diff --git a/decidim-budgets/app/assets/javascripts/decidim/budgets/projects.js.es6 b/decidim-budgets/app/assets/javascripts/decidim/budgets/projects.js.es6 index 40192702d7f83..d15cca2c73eb0 100644 --- a/decidim-budgets/app/assets/javascripts/decidim/budgets/projects.js.es6 +++ b/decidim-budgets/app/assets/javascripts/decidim/budgets/projects.js.es6 @@ -6,6 +6,7 @@ $(() => { const $budgetSummaryTotal = $(".budget-summary__total"); const $budgetExceedModal = $("#budget-excess"); const $budgetSummary = $(".budget-summary__progressbox"); + const $voteButton = $(".budget-vote-button"); const totalAllocation = parseInt($budgetSummaryTotal.attr("data-total-allocation"), 10); const cancelEvent = (event) => { @@ -24,6 +25,10 @@ $(() => { return false; } + $voteButton.on("click", "span", (event) => { + $(".budget-list__action").click(); + }); + $projects.on("click", ".budget-list__action", (event) => { const currentAllocation = parseInt($budgetSummary.attr("data-current-allocation"), 10); const $currentTarget = $(event.currentTarget); diff --git a/decidim-budgets/app/assets/stylesheets/decidim/budgets/budget/_budget-vote-button.scss b/decidim-budgets/app/assets/stylesheets/decidim/budgets/budget/_budget-vote-button.scss index 4f7fb989d4e1e..387505f041f1f 100644 --- a/decidim-budgets/app/assets/stylesheets/decidim/budgets/budget/_budget-vote-button.scss +++ b/decidim-budgets/app/assets/stylesheets/decidim/budgets/budget/_budget-vote-button.scss @@ -4,30 +4,17 @@ justify-content: space-between; align-items: center; - .icon-wrapper { - @extend .budget-list__action; - } - - &.added { - @extend .budget-list__data--added; - color: $body-font-color; - - .icon-wrapper { - background: var(--success); - border-color: $body-font-color; - color: $body-font-color; - } - } - - &.hollow { - .icon-wrapper { - border: $button-hollow-border-width solid var(--primary); - color: var(--primary); + &:hover, + &:focus { + &.added { + .budget-list__action { + background: var(--primary); + border-color: white; + color: white; + } } - - &:hover, - &:focus { - .icon-wrapper { + &:not(.added) { + .budget-list__action { border-color: white; color: white; } diff --git a/decidim-budgets/app/cells/decidim/budgets/project_list_item/project_data.erb b/decidim-budgets/app/cells/decidim/budgets/project_list_item/project_data.erb index 53abf5cf3d717..e6f3b53350d61 100644 --- a/decidim-budgets/app/cells/decidim/budgets/project_list_item/project_data.erb +++ b/decidim-budgets/app/cells/decidim/budgets/project_list_item/project_data.erb @@ -14,6 +14,6 @@ <%= cell("decidim/budgets/project_voted_hint", model, class: "display-block margin-top-1") if current_order_checked_out? && resource_added? %> - <%= render :project_data_vote_button if !current_order_checked_out? && voting_open? %> + <%= cell("decidim/budgets/project_vote_button", model) if !current_order_checked_out? && voting_open? %> <% end %> diff --git a/decidim-budgets/app/cells/decidim/budgets/project_list_item/project_data_vote_button.erb b/decidim-budgets/app/cells/decidim/budgets/project_vote_button/show.erb similarity index 100% rename from decidim-budgets/app/cells/decidim/budgets/project_list_item/project_data_vote_button.erb rename to decidim-budgets/app/cells/decidim/budgets/project_vote_button/show.erb diff --git a/decidim-budgets/app/cells/decidim/budgets/project_vote_button_cell.rb b/decidim-budgets/app/cells/decidim/budgets/project_vote_button_cell.rb new file mode 100644 index 0000000000000..bd4d9d6d43c76 --- /dev/null +++ b/decidim-budgets/app/cells/decidim/budgets/project_vote_button_cell.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Decidim + module Budgets + # This cell renders an authorized_action button + # to vote a given instance of a Project in a budget list + class ProjectVoteButtonCell < ProjectListItemCell + end + end +end diff --git a/decidim-budgets/app/views/decidim/budgets/projects/_project_budget_button.html.erb b/decidim-budgets/app/views/decidim/budgets/projects/_project_budget_button.html.erb index 6adc0afbb4e16..604a5053b0bf4 100644 --- a/decidim-budgets/app/views/decidim/budgets/projects/_project_budget_button.html.erb +++ b/decidim-budgets/app/views/decidim/budgets/projects/_project_budget_button.html.erb @@ -1,54 +1,15 @@ -
- <% if voted_for?(project) %> - <%= action_authorized_button_to( - "vote", - budget_order_line_item_path(budget, project_id: project), - method: :delete, - remote: true, - data: { - disable: true, - budget: project.budget_amount, - "redirect-url": budget_project_path(budget, project) - }, - disabled: !can_have_order? || current_order_checked_out?, - class: "button expanded button--sc budget-vote-button added", - "aria-label": t(".added_descriptive", resource_name: translated_attribute(project.title)) - ) do %> - - - <%= t(".added") %> - - - <%= icon "x", class: "icon--small", role: "img" %> - - <% end %> - <% elsif current_user.present? %> - <%= action_authorized_button_to( - "vote", - budget_order_line_item_path(budget, project_id: project), - method: :post, - remote: true, - data: { - disable: true, - budget: project.budget_amount, - add: true, - "redirect-url": budget_project_path(budget, project) - }, - disabled: !can_have_order? || current_order_checked_out?, - class: "button expanded button--sc budget-vote-button hollow", - "aria-label": t(".add_descriptive", resource_name: translated_attribute(project.title)) - ) do %> - - - <%= t(".add") %> - - - <%= icon "check", class: "icon--small", role: "img" %> - - <% end %> - <% else %> +<% if current_user.blank? %> +
- <% end %> -
+
+<% else %> +
button expanded button--sc budget-vote-button budget-list__data"> + + <%= t(voted_for?(project) ? ".added" : ".add") %> + + + <%= cell("decidim/budgets/project_vote_button", project) %> +
+<% end %>