Sha256: 853cd6165aac6154159b85108312dfb4d7aa20fa6e4c1906c8e8768f87247a94

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

module Sufia
  module BatchEditsControllerBehavior
    extend ActiveSupport::Concern
    include Sufia::Breadcrumbs

    included do
      layout "sufia-one-column"
      before_action :build_breadcrumbs, only: :edit
    end

    def edit
      super
      work = form_class.model_class.new
      work.depositor = current_user.user_key
      @form = form_class.new(work, current_user, batch)
    end

    def after_update
      respond_to do |format|
        format.json { head :no_content }
        format.html { redirect_to_return_controller }
      end
    end

    def after_destroy_collection
      redirect_to_return_controller unless request.xhr?
    end

    def update_document(obj)
      obj.attributes = work_params
      obj.date_modified = Time.current.ctime
      obj.visibility = params[:visibility]
    end

    def update
      case params["update_type"]
      when "update"
        super
      when "delete_all"
        destroy_batch
      end
    end

    protected

      def add_breadcrumb_for_controller
        add_breadcrumb I18n.t('sufia.dashboard.my.works'), sufia.dashboard_works_path
      end

      def _prefixes
        # This allows us to use the templates in curation_concerns/base
        @_prefixes ||= super + ['curation_concerns/base']
      end

      def destroy_batch
        batch.each { |id| ActiveFedora::Base.find(id).destroy }
        after_update
      end

      def form_class
        Forms::BatchEditForm
      end

      def terms
        form_class.terms
      end

      def work_params
        work_params = params[form_class.model_name.param_key] || ActionController::Parameters.new
        form_class.model_attributes(work_params)
      end

      def redirect_to_return_controller
        if params[:return_controller]
          redirect_to sufia.url_for(controller: params[:return_controller], only_path: true)
        else
          redirect_to sufia.dashboard_index_path
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sufia-7.1.0 app/controllers/concerns/sufia/batch_edits_controller_behavior.rb
sufia-7.0.0 app/controllers/concerns/sufia/batch_edits_controller_behavior.rb
sufia-7.0.0.rc2 app/controllers/concerns/sufia/batch_edits_controller_behavior.rb
sufia-7.0.0.rc1 app/controllers/concerns/sufia/batch_edits_controller_behavior.rb