class Admin::StudentsController < Admin::BaseController

  include Admin::InheritedResource

  # Resend the activation mail to activate the account.
  def resend_activation
    UserMailer.delay(queue: :mailer).activation_needed_email(resource.id, true)
    respond_to do |format|
      format.js {}
    end
  end

  # It update all student as searchable.
  def mark_all_searchable
    respond_to do |format|
      if Student.active.not_searchable.update_all(searchable: true)
        Student.searchable.each do |student|
          Indexer.perform_async(:update,  student.class.to_s, student.id)
        end
        format.html {redirect_via_turbolinks_to admin_students_path, alert: 'All Active student are searchable. Please allow two to five minutes to complete the process in the background before they are visible in the Search Page.'}
      else
        format.js {redirect_to collection_path, alert: 'Unable to mark all students searchable.'}
      end
    end
  end

  # Update student as searchable.
  def mark_searchable
    respond_to do |format|
      if resource.update_attribute(:searchable, true)
        format.js {render 'referesh_datatable'}
      else
        format.js {redirect_to collection_path, alert: 'Unable to add in search.'}
      end
    end
  end

  # Update student as non searchable.
  def unmark_searchable
    respond_to do |format|
      if resource.update_attribute(:searchable, false)
        format.js {render 'referesh_datatable'}
      else
        format.js {redirect_to collection_path, alert: 'Unable to remove from search.'}
      end
    end
  end

end
