Sha256: 1b0765f3d3df94d1e287700e5af77186d9d7355997f49f222c841455882b5163

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Decidim
  module Plans
    module AttachedProposalsHelper
      include Decidim::ApplicationHelper

      def attached_proposals_picker_field(form, name)
        picker_options = {
          id: "attached_proposals",
          "class": "picker-multiple",
          name: "proposal_ids",
          multiple: true
        }

        prompt_params = {
          url: plan_search_proposals_path(current_component, format: :html),
          text: t("decidim.plans.attached_proposals_helper.attach_proposal")
        }

        form.data_picker(name, picker_options, prompt_params) do |item|
          { url: plan_search_proposals_path(current_component, format: :json),
            text: item.title }
        end
      end

      def search_proposals
        respond_to do |format|
          format.html do
            render partial: "decidim/plans/attached_proposals/proposals"
          end
          format.json do
            query = Decidim
                    .find_resource_manifest(:proposals)
                    .try(:resource_scope, current_component)
                    &.order(title: :asc)
                    &.where("title ilike ?", "%#{params[:term]}%")
                    &.where("state IS NULL OR state != ?", "rejected")
                    &.where&.not(published_at: nil)
            render json: query.all.collect { |p| [present(p).title, p.id] }
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-plans-0.16.6 app/helpers/decidim/plans/attached_proposals_helper.rb
decidim-plans-0.16.5 app/helpers/decidim/plans/attached_proposals_helper.rb
decidim-plans-0.16.4 app/helpers/decidim/plans/attached_proposals_helper.rb