Sha256: 19577cb02b797b35d764526f7002f0d5c75587172eca519cb64ee67225073e7d

Contents?: true

Size: 1.55 KB

Versions: 21

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # Exposes the line items resource so users can create and remove from orders.
    class LineItemsController < Decidim::Budgets::ApplicationController
      include NeedsCurrentOrder

      helper_method :budget, :project

      def create
        enforce_permission_to :vote, :project, project: project, budget: budget, workflow: current_workflow

        respond_to do |format|
          AddLineItem.call(persisted_current_order, project, current_user) do
            on(:ok) do |order|
              self.current_order = order
              format.html { redirect_back(fallback_location: budget_path(budget)) }
              format.js { render "update_budget" }
            end

            on(:invalid) do
              render nothing: true, status: :unprocessable_entity
            end
          end
        end
      end

      def destroy
        respond_to do |format|
          RemoveLineItem.call(current_order, project) do
            on(:ok) do |_order|
              format.html { redirect_back(fallback_location: budget_path(budget)) }
              format.js { render "update_budget" }
            end

            on(:invalid) do
              render nothing: true, status: :unprocessable_entity
            end
          end
        end
      end

      private

      def project
        @project ||= Project.includes(:budget).find_by(id: params[:project_id], decidim_budgets_budget_id: params[:budget_id])
      end

      def budget
        @budget ||= project.budget
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-budgets-0.25.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.25.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.25.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.25.0.rc4 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.25.0.rc3 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.25.0.rc2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.25.0.rc1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.24.3 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.23.6 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.24.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.23.5 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.24.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.24.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.24.0.rc2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.23.4 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.24.0.rc1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.23.3 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.23.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.23.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.23.1.rc1 app/controllers/decidim/budgets/line_items_controller.rb