# frozen_string_literal: true module C class Enquiry < ApplicationRecord enum job_type: [ 'Supply Only', 'Supply and Fit', ] enum response_type: [ 'Callback', 'Quote' ] enum timber_type: [ 'Hardwood', 'European Oak', 'Accoya', 'Other', ] enum frame: [ 'Braemar', 'Buttermilk', 'Dove Grey', 'Forest Green', 'Garsenia', 'Oxford Blue', 'Poppy Red', 'RAL7034', 'Techno White', 'Dark Oak', 'Mahogany', 'Rosewood', 'Sikkins Teak', 'African Walnut', 'Antique Pine', 'Ebony', 'Jacobean Walnut', 'Red Wood', 'Saddolins Teak' ] enum handle: [ 'Chrome', 'Black', 'Gold', 'Satin', 'White', 'Monkey Tail' ] mount_uploader :file, C::FileUploader validates :phone, presence: true validates :response_type, presence: true validates :name, presence: true scope :ordered, -> { order created_at: :desc } def get_jobs_selected this = [] this << 'Windows' if job_windows this << 'Doors' if job_doors this << 'Bi-Fold Doors' if job_bi this << 'Conservatory' if job_conservatory this << 'Lantern Tops' if job_lantern this << 'Garden Rooms' if job_garden this << 'Orangery' if job_orangery this << "Other: #{job_string}" if job_other return this.join(', ') end def get_timber_selected if timber_type == 'Other' return 'Other: ' + timber_string else return timber_type end end VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX } INDEX_TABLE = { "Name": { call: 'name', sort: 'name' }, "Email": { call: 'email', sort: 'email' }, "Message": { call: 'body' }, "Date": { call: 'created_at', sort: 'created_at' } }.freeze end end