Sha256: 1d43bff63f417cbe5caea2721ee8d9d938dcd165bfd5b77a52a30e565a8a3b4c

Contents?: true

Size: 1.71 KB

Versions: 14

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    # Helper for questions controller
    module QuestionsHelper
      # Returns a link to the next/previous question if found.
      # Else, returns a disabled link to the current question.
      def display_next_previous_button(direction, optional_classes = "")
        css = "card__button button hollow " + optional_classes

        # Do not show anything if is a lonely question
        return unless previous_published_question || next_published_question

        case direction
        when :previous
          i18n_text = t("previous_button", scope: "decidim.questions")
          question = previous_published_question || current_question
          css << " disabled" if previous_published_question.nil?
        when :next
          i18n_text = t("next_button", scope: "decidim.questions")
          question = next_published_question || current_question
          css << " disabled" if next_published_question.nil?
        end

        link_to(i18n_text, decidim_consultations.question_path(question), class: css)
      end

      def authorized_vote_modal_button(question, html_options, &block)
        return if current_user && action_authorized_to(:vote, resource: nil, permissions_holder: question).ok?

        tag = "button"
        html_options ||= {}

        if !current_user
          html_options["data-open"] = "loginModal"
        else
          html_options["data-open"] = "authorizationModal"
          html_options["data-open-url"] = decidim_consultations.authorization_vote_modal_question_path(question)
        end

        html_options["onclick"] = "event.preventDefault();"

        send("#{tag}_to", "", html_options, &block)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-consultations-0.23.6 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.23.5 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.23.4 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.23.3 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.23.2 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.23.1 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.23.1.rc1 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.23.0 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.22.0 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.21.0 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.20.1 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.20.0 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.19.1 app/helpers/decidim/consultations/questions_helper.rb
decidim-consultations-0.19.0 app/helpers/decidim/consultations/questions_helper.rb