Sha256: a6ec61842e6f800564006b25cb699d4e5feded8f847a5a954c050e3f0dcc9060

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

class ExportEmailController < UmlautController

  before_filter :load_objects
  layout :search_layout_except_xhr

  def email
  end

  def send_email
    @email = params[:email]
    @fulltexts = @user_request.get_service_type('fulltext', { :refresh=>true })
    @holdings = @user_request.get_service_type('holding', { :refresh=>true })
    if valid_email?
      Emailer.citation(@email, @user_request, @fulltexts, @holdings).deliver
    else
      flash[:alert] = email_validation_error
      render :email and return
    end
  end

  def txt
  end

  def send_txt
    @number = params[:number]
    # Remove any punctuation or spaces etc
    @number.gsub!(/[^\d]/, '') if @number
    @provider = params[:provider]
    @email = "#{@number}@#{@provider}" unless @number.nil? or @provider.nil?
    @holding = params[:holding]
    if valid_txt_number? && valid_txt_holding?
      Emailer.short_citation(@email, @user_request, holding_location(@holding), call_number(@holding)).deliver
    else
      flash[:alert] = txt_validation_error
      render :txt and return
    end
  end

  protected

  def load_objects
    @svc_response = ServiceResponse.find(params[:id])
    @user_request = @svc_response.request if @svc_response
  end

  def valid_txt_number?
    ((not @number.blank?) && @number.length == 10)
  end

  def valid_txt_holding?
    (not @holding.blank?)
  end

  def valid_email?
    (@email =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
  end

  def txt_validation_error
    errors = []
    errors << "a valid number" unless valid_txt_number?
    errors << "the item you wish to send" unless valid_txt_holding?
    errors
  end

  def email_validation_error
    errors = []
    errors << "a valid email address"
    errors
  end

  def holding(id)
    return ServiceResponse.find(id) unless id.nil?
  end

  def holding_location(id)
    return holding(id).view_data[:collection_str] unless holding(id).nil?
  end

  def call_number(id)
    return holding(id).view_data[:call_number] unless holding(id).nil?
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
umlaut-4.0.3 app/controllers/export_email_controller.rb
umlaut-4.0.2 app/controllers/export_email_controller.rb
umlaut-4.0.1 app/controllers/export_email_controller.rb
umlaut-4.0.0 app/controllers/export_email_controller.rb
umlaut-4.0.0.beta5 app/controllers/export_email_controller.rb
umlaut-4.0.0.beta4 app/controllers/export_email_controller.rb
umlaut-4.0.0.beta3 app/controllers/export_email_controller.rb
umlaut-4.0.0.beta2 app/controllers/export_email_controller.rb
umlaut-4.0.0.beta1 app/controllers/export_email_controller.rb