Sha256: 01e830e2f27907f6f5223aef1bd64b6c94241d6dddbd862d2070bd33e9c856d0

Contents?: true

Size: 1.28 KB

Versions: 62

Compression:

Stored size: 1.28 KB

Contents

module Workarea
  module Admin
    class BulkActionsController < Admin::ApplicationController
      def create
        klass = params[:type].constantize
        raise unless klass < BulkAction
        bulk_action = Mongoid::Factory.build(klass, bulk_action_params(klass))

        if !bulk_action.valid?
          flash[:error] = bulk_action.errors.full_messages.to_sentence
          redirect_back(fallback_location: return_to || root_path)
        elsif !bulk_action.count.positive?
          flash[:error] = I18n.t('workarea.admin.bulk_actions.empty_selection')
          redirect_back(fallback_location: return_to || root_path)
        else
          bulk_action.save!
          redirect_to url_for([
            :edit,
            bulk_action,
            { only_path: true, return_to: return_to }
          ])
        end
      end

      def selected
        @search = BulkActionSelections.new(params[:id], params)
        @results = @search.results.map { |r| wrap_in_view_model(r) }
      end

      def destroy
        BulkAction.find(params[:id]).destroy
        redirect_to return_to || root_path
      end

      private

      def bulk_action_params(klass)
        base = params.select { |k, v| k.in?(klass.fields.keys) }
        base.merge(params[:bulk_action] || {})
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.45 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/bulk_actions_controller.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/bulk_actions_controller.rb