Sha256: 8cef24796126c11ad5d1f4dd71a7396f0caf4d5f520fe263c79a490292b9a8b2

Contents?: true

Size: 1.25 KB

Versions: 62

Compression:

Stored size: 1.25 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 :project

      def create
        authorize_action! "vote"

        respond_to do |format|
          AddLineItem.call(current_order, project, current_user) do
            on(:ok) do |order|
              self.current_order = order
              format.html { redirect_to :back }
              format.js { render "update_budget" }
            end

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

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

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

      private

      def project
        @project ||= Project.where(id: params[:project_id], feature: current_feature).first
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 2 rubygems

Version Path
decidim-budgets-0.10.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.10.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.9.3 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.9.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.9.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.9.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.8.4 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.8.3 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.8.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.8.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.8.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.7.4 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.7.3 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.7.2 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.7.1 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.7.0 app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.6.8 app/controllers/decidim/budgets/line_items_controller.rb
decidim-0.6.8 decidim-budgets/app/controllers/decidim/budgets/line_items_controller.rb
decidim-budgets-0.6.7 app/controllers/decidim/budgets/line_items_controller.rb
decidim-0.6.7 decidim-budgets/app/controllers/decidim/budgets/line_items_controller.rb