2014-02-27 11:13:53 +00:00
|
|
|
class ContractsController < ApplicationController
|
|
|
|
load_and_authorize_resource :contract
|
2014-03-03 02:06:39 +00:00
|
|
|
before_filter :authenticate_user!, :load_users
|
2014-02-27 11:13:53 +00:00
|
|
|
layout 'resources'
|
|
|
|
|
|
|
|
def index
|
2014-04-12 22:05:57 +00:00
|
|
|
if params[:user_id].present?
|
|
|
|
@contracts = Contract.where(user_id: params[:user_id])
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json { render :json => @contracts }
|
|
|
|
end
|
2014-02-27 11:13:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-04-12 22:05:57 +00:00
|
|
|
# if @contract.first_name.blank? && @contract.last_name.blank? && @contract.cosigner.blank? # assume autodetect of filename
|
|
|
|
# begin
|
|
|
|
# name_split = params[:contract][:document].original_filename.sub(".jpg","").split
|
|
|
|
# if name_split.count == 4 # we have one name
|
|
|
|
# @contract.first_name = name_split[0]
|
|
|
|
# @contract.last_name = name_split[1]
|
|
|
|
# # 2 is the hyphen
|
|
|
|
# @contract.signed_at = Date.parse(name_split[3])
|
|
|
|
# elsif name_split.count == 7 && name_split[2] == "by" # we have two names
|
|
|
|
# @contract.first_name = name_split[0]
|
|
|
|
# @contract.last_name = name_split[1]
|
|
|
|
# # 2 is "by"
|
|
|
|
# @contract.cosigner = "#{name_split[3]} #{name_split[4]}"
|
|
|
|
# # 5 is the hyphen
|
|
|
|
# @contract.signed_at = Date.parse(name_split[6])
|
|
|
|
# else
|
|
|
|
# Rails.logger.info "Couldn't determine name from filename array: #{name_split.inspect}"
|
|
|
|
# end
|
|
|
|
# rescue Exception => e
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
2014-04-11 03:10:04 +00:00
|
|
|
@contract.created_by = current_user
|
2014-02-27 11:13:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
if @contract.save
|
2014-03-03 04:48:49 +00:00
|
|
|
format.html { redirect_to @contract, :notice => 'Contract was successfully created.' }
|
2014-02-27 11:13:53 +00:00
|
|
|
format.json { render :json => @contract, :status => :created, :location => @contract }
|
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
format.json { render :json => @contract.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-12 22:05:57 +00:00
|
|
|
def find_for_user
|
|
|
|
end
|
|
|
|
|
2014-02-27 11:13:53 +00:00
|
|
|
def update
|
|
|
|
respond_to do |format|
|
|
|
|
if @contract.update_attributes(params[:contract])
|
2014-03-03 04:48:49 +00:00
|
|
|
format.html { redirect_to @contract, :notice => 'Contract was successfully updated.' }
|
2014-02-27 11:13:53 +00:00
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.json { render :json => @contract.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@contract.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to contracts_url }
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
2014-03-03 02:06:39 +00:00
|
|
|
|
|
|
|
def load_users
|
2014-04-11 02:45:29 +00:00
|
|
|
@users = User.accessible_by(current_ability).sort_by(&:name)
|
2014-03-03 02:06:39 +00:00
|
|
|
end
|
2014-02-27 11:13:53 +00:00
|
|
|
end
|