Module: MyProjectsHelper

Defined in:
app/helpers/my_projects_helper.rb

Instance Method Summary collapse

Instance Method Details

#class_for_zip(country_iso3) ⇒ Object



35
36
37
38
39
40
41
42
# File 'app/helpers/my_projects_helper.rb', line 35

def class_for_zip(country_iso3)
  case country_iso3
  when 'USA'
    'zip_code'
  else
    'canadian_postal_code'
  end
end


52
53
54
55
56
57
58
# File 'app/helpers/my_projects_helper.rb', line 52

def project_filter_links
  (:p, link_to("Active (#{@all_projects.open_opportunities.size})", (view: 'active'), class: "#{'link-underline' if params[:view] == 'active' or params[:view].nil?}")) +
  (:p, link_to("Purchased (#{@all_projects.won.size})", (view: 'purchased'), class: "#{'link-underline' if params[:view] == 'purchased'}")) +
  (:p, link_to("Archived (#{@all_projects.lost_or_abandoned.size})", (view: 'archived'), class: "#{'link-underline' if params[:view] == 'archived'}")) +
  (:p, link_to("View All (#{@all_projects.not_cancelled.size})", (view: 'all'), class: "#{'link-underline' if params[:view] == 'all'}"))

end


11
12
13
14
15
16
# File 'app/helpers/my_projects_helper.rb', line 11

def project_link_helper
  links = []
  links << link_to("Edit Project info", edit_my_project_path(@project), {:class => "secondary_button"})
	links << link_to("Cancel Project", cancel_my_project_path(@project, :authenticity_token => form_authenticity_token), {data: { turbo_method: :put, turbo_confirm: "Are you sure you want to cancel this project?" }, :class => "secondary_button"}) if @project.ok_to_customer_cancel?
	return raw links.join(' ')
end

#room_cart_helper(room) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/my_projects_helper.rb', line 18

def room_cart_helper(room)
  if room.orders.non_carts.present?
    raw(%(
    You purchased this heating system as part of order #
    #{room.orders.non_carts.collect{|o| link_to o.reference_number, (o)}.join(" ")}
    ))
  elsif @context_user.cart.room_configuration_ids.include?room.id
    raw(%(
      #{link_to "Remove Heated Space from cart", remove_from_cart_my_room_path(room), :class => 'default_button' }
    ))
  elsif room.line_items.present?
    raw(%(
    #{ link_to "+ Add Heated Space to Cart", add_to_cart_my_room_path(room), :class => 'default_button' }
    ))
  end
end

#setup_project(project) ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/my_projects_helper.rb', line 3

def setup_project(project)
  project.tap do |p|
    p.room_configurations.build if p.room_configurations.empty?
    p.name ||= "Project ##{(@context_user.opportunities.length + 1)}"
  end

end

#shorten_name(name, max = 40) ⇒ Object



44
45
46
47
48
49
50
# File 'app/helpers/my_projects_helper.rb', line 44

def shorten_name(name, max=40)
  res = name.to_s
  if res.length > max
    res = res[0..(max-4)]+"..."
  end
  return res
end