From 3cd6c59df073c282e4a5df40f862429fca462c0e Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Sun, 2 Mar 2014 21:48:49 -0700 Subject: [PATCH] More contract tweaks --- app/controllers/contracts_controller.rb | 4 ++-- app/controllers/users_controller.rb | 2 +- app/models/ability.rb | 1 - app/models/contract.rb | 2 +- app/models/user.rb | 6 +++++- app/views/contracts/_form.html.erb | 12 +++++++++++- app/views/contracts/index.html.erb | 1 + app/views/contracts/show.html.erb | 7 ++++++- app/views/layouts/application.html.erb | 1 + app/views/layouts/resources.html.erb | 1 + app/views/users/index.html.erb | 16 ++++++++-------- app/views/users/show.html.erb | 12 +++++++++--- .../20140303030220_add_cosigner_to_contracts.rb | 5 +++++ db/schema.rb | 3 ++- 14 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20140303030220_add_cosigner_to_contracts.rb diff --git a/app/controllers/contracts_controller.rb b/app/controllers/contracts_controller.rb index fbb4905..0b66c9c 100644 --- a/app/controllers/contracts_controller.rb +++ b/app/controllers/contracts_controller.rb @@ -20,7 +20,7 @@ class ContractsController < ApplicationController Rails.logger.info @contract.inspect respond_to do |format| if @contract.save - format.html { redirect_to Contract, :notice => 'Contract was successfully created.' } + format.html { redirect_to @contract, :notice => 'Contract was successfully created.' } format.json { render :json => @contract, :status => :created, :location => @contract } else format.html { render :action => "new" } @@ -32,7 +32,7 @@ class ContractsController < ApplicationController def update respond_to do |format| if @contract.update_attributes(params[:contract]) - format.html { redirect_to Contract, :notice => 'Contract was successfully updated.' } + format.html { redirect_to @contract, :notice => 'Contract was successfully updated.' } format.json { head :no_content } else format.html { render :action => "edit" } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9adaefe..278cea9 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -35,7 +35,7 @@ class UsersController < ApplicationController when "orientation" @users = @users.sort_by{ |u| [-u.orientation.to_i,u.name] } when "waiver" - @users = @users.sort_by{ |u| [-u.waiver.to_i,u.name] } + @users = @users.sort_by{ |u| [-u.contract_date.to_i,u.name] } when "member" @users = @users.sort_by{ |u| [-u.member_status.to_i,u.name] } when "card" diff --git a/app/models/ability.rb b/app/models/ability.rb index 55cfe63..5ac0d4c 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -12,7 +12,6 @@ class Ability # By default, users can only see their own stuff can :read, Card, :user_id => user.id can :read, Certification - can :read, Contract can :read_details, Mac can [:update], Mac, :user_id => nil can [:create,:update], Mac, :user_id => user.id diff --git a/app/models/contract.rb b/app/models/contract.rb index 52a4c21..a588fe3 100644 --- a/app/models/contract.rb +++ b/app/models/contract.rb @@ -1,6 +1,6 @@ class Contract < ActiveRecord::Base belongs_to :user - attr_accessible :user_id, :first_name, :last_name, :signed_at, :document, :document_file_name, :document_content_type, :document_file_size, :document_updated_at + attr_accessible :user_id, :first_name, :last_name, :cosigner, :signed_at, :document, :document_file_name, :document_content_type, :document_file_size, :document_updated_at validates_presence_of :first_name, :signed_at #, :last_name diff --git a/app/models/user.rb b/app/models/user.rb index ecfa34d..1829249 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -145,7 +145,11 @@ class User < ActiveRecord::Base end end - private + def contract_date + self.contracts.first.signed_at unless self.contracts.blank? + end + +private def send_new_user_email Rails.logger.info UserMailer.new_user_email(self).deliver diff --git a/app/views/contracts/_form.html.erb b/app/views/contracts/_form.html.erb index 067737b..ee863e1 100644 --- a/app/views/contracts/_form.html.erb +++ b/app/views/contracts/_form.html.erb @@ -19,6 +19,10 @@ <%= f.label :last_name %>
<%= f.text_field :last_name, class: "form-control" %> +
+ <%= f.label :cosigner %>
+ <%= f.text_field :cosigner, class: "form-control" %> +
<%= f.label :user_id, "User" %>
@@ -32,7 +36,13 @@
<%= f.label :document %>
- <%= f.file_field :document %> + <%= link_to "View Existing Document", @contract.document.url, class: "btn btn-default" unless @contract.document.blank? %> +

+ <%= link_to "Upload New Document", "#", class: "btn btn-default", onclick: "$('#document_upload').removeClass('hidden'); $(this).addClass('hidden')" unless @contract.document.blank? %> +

"> + <%= f.file_field :document %> +
+

diff --git a/app/views/contracts/index.html.erb b/app/views/contracts/index.html.erb index 6f04953..3d53ad6 100644 --- a/app/views/contracts/index.html.erb +++ b/app/views/contracts/index.html.erb @@ -23,6 +23,7 @@ <%= contract.last_name %>, <%= contract.first_name %> + <%= "and #{contract.cosigner}" unless contract.cosigner.blank? %> <%= link_to contract.user.name, contract.user if contract.user %> diff --git a/app/views/contracts/show.html.erb b/app/views/contracts/show.html.erb index f1fdebc..be4755d 100644 --- a/app/views/contracts/show.html.erb +++ b/app/views/contracts/show.html.erb @@ -2,6 +2,7 @@

Contract <%= link_to 'Back', contracts_path, :class => "btn btn-default" %> + <%= link_to 'Edit', edit_contract_path(@contract), :class => "btn btn-primary" %> <%= link_to 'Delete', contract_path(@contract), {:confirm => 'Are you sure you want to delete this forever?', :method => :delete, :class => "btn btn-danger"} if can? :destroy, @contract %>

@@ -10,6 +11,7 @@

<%= @contract.first_name %> <%= @contract.last_name %> + <%= "and #{@contract.cosigner}" unless @contract.cosigner.blank? %> <%= link_to "(#{@contract.user.name})", @contract.user if @contract.user %> signed @@ -17,12 +19,15 @@

- +<% if @contract.document.blank? %> + No document uploaded +<% else %>

<%= link_to "Download Contract", @contract.document.url %>

+<% end %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5f5a180..1e83331 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -24,6 +24,7 @@ <% else %> <%= link_to 'Certifications', certifications_path if can? :read, Certification %> <% end %> + <%= link_to 'Waivers', contracts_path if can? :read, Contract %> <%= link_to 'Payments', payments_path if can? :create, Payment %> <%= link_to 'Computers', macs_path if user_signed_in? || (can? :read, Mac) %> <%= link_to 'Settings', settings_path if can? :read, Setting %> diff --git a/app/views/layouts/resources.html.erb b/app/views/layouts/resources.html.erb index 7c941cd..2af4f5a 100755 --- a/app/views/layouts/resources.html.erb +++ b/app/views/layouts/resources.html.erb @@ -89,6 +89,7 @@ <% else %> <%= li_link_to 'Certifications', certifications_path if can? :read, Certification %> <% end %> + <%= li_link_to 'Waivers', contracts_path if can? :read, Contract %> <%= li_link_to 'Computers', macs_path if user_signed_in? || (can? :read, Mac) %> <%= li_link_to 'Payments', payments_path if can? :create, Payment %> <%= li_link_to 'Settings', settings_path if can? :read, Setting %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 4379de5..26e6b62 100755 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -34,18 +34,18 @@ <% end %> - Name - Member? + Name + Member? <% if current_user.admin? then %>Email<% end %> <% if current_user.admin? then %> - Orientation? + Orientation? <% end %> - Waiver? - Card? - Instructor? + Waiver? + Card? + Instructor? <% if current_user.admin? then %>Admin?<% end %> <% @certifications.each do |c| %> - <%= c.name %> + <%= c.name %> <% end %> @@ -61,7 +61,7 @@ <% if current_user.admin? then %> <%= unless user.orientation.blank? then raw("") end %> <% end %> - <%= unless user.waiver.blank? then raw("") end %> + <%= unless user.contracts.blank? then raw("") end %> <%= unless user.cards.blank? then raw("") end %> <%= if user.instructor? then raw("✓") end %> <% if current_user.admin? then %><%= if user.admin? then raw("✓") end %><% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 40ff60b..b969896 100755 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -173,9 +173,15 @@ margin-right: auto; <%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %>
Contracts: <%= link_to "+ Add", new_contract_path, :class => 'btn' if can? :create, Contract %>
    - <% @user.contracts.each do |contract| %> -
  • <%= link_to contract.signed_at.strftime("%B %d %Y"), contract %>
  • - <% end %> + <% @user.contracts.each do |contract| %> +
  • + <% if can? :read, contract %> + <%= link_to contract.signed_at.strftime("%B %d %Y"), contract %> + <% else %> + <%= contract.signed_at.strftime("%B %d %Y") %> + <% end %> +
  • + <% end %>

diff --git a/db/migrate/20140303030220_add_cosigner_to_contracts.rb b/db/migrate/20140303030220_add_cosigner_to_contracts.rb new file mode 100644 index 0000000..15e6420 --- /dev/null +++ b/db/migrate/20140303030220_add_cosigner_to_contracts.rb @@ -0,0 +1,5 @@ +class AddCosignerToContracts < ActiveRecord::Migration + def change + add_column :contracts, :cosigner, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 9ab036f..940db09 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140227095847) do +ActiveRecord::Schema.define(:version => 20140303030220) do create_table "cards", :force => true do |t| t.string "card_number" @@ -41,6 +41,7 @@ ActiveRecord::Schema.define(:version => 20140227095847) do t.datetime "document_updated_at" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "cosigner" end create_table "door_logs", :force => true do |t|