-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from alphagov/contacts
Merge contacts frontend into government frontend
- Loading branch information
Showing
19 changed files
with
1,634 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
(function (global) { | ||
'use strict' | ||
var $ = global.jQuery | ||
var windowLocationPathname = global.location.pathname | ||
var windowOpen = global.open | ||
if (typeof global.GOVUK === 'undefined') { global.GOVUK = {} } | ||
var GOVUK = global.GOVUK | ||
|
||
// Each page will have a different entryPointID, which is a queue id. | ||
// Don't enable this plugin on pages that don't exist in this map, and | ||
// uncomment the additional routes as we obtain them. | ||
// Whether the actual template is displayed is in `contact_presenter#show_webchat?`. | ||
var entryPointIDs = {} | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/child-benefit'] = 1027 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees'] = 1030 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk'] = 1026 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/national-insurance-numbers'] = 1021 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/self-assessment-online-services-helpdesk'] = 1003 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/self-assessment'] = 1004 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries'] = 1016 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/vat-enquiries'] = 1028 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries'] = 1034 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/trusts'] = 1036 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/employer-enquiries'] = 1023 | ||
entryPointIDs['/government/organisations/hm-revenue-customs/contact/construction-industry-scheme'] = 1048 | ||
|
||
var API_URL = 'https://online.hmrc.gov.uk/webchatprod/egain/chat/entrypoint/checkEligibility/' | ||
var OPEN_CHAT_URL = function (entryPointID) { | ||
return 'https://online.hmrc.gov.uk/webchatprod/templates/chat/hmrc7/chat.html?entryPointId=' + entryPointID + '&templateName=hmrc7&languageCode=en&countryCode=US&ver=v11' | ||
} | ||
var CODE_AGENTS_AVAILABLE = 0 | ||
var CODE_AGENTS_UNAVAILABLE = 1 | ||
var CODE_AGENTS_BUSY = 2 | ||
var POLL_INTERVAL = 15 * 1000 | ||
var AJAX_TIMEOUT = 5 * 1000 | ||
|
||
function Webchat (options) { | ||
var $el = $(options.$el) | ||
var location = options.location || windowLocationPathname | ||
|
||
var $advisersUnavailable = $el.find('.js-webchat-advisers-unavailable') | ||
var $advisersBusy = $el.find('.js-webchat-advisers-busy') | ||
var $advisersAvailable = $el.find('.js-webchat-advisers-available') | ||
var $advisersError = $el.find('.js-webchat-advisers-error') | ||
var $openButton = $el.find('.js-webchat-open-button') | ||
|
||
var entryPointID = entryPointIDs[location] | ||
var pollingEnabled = true | ||
|
||
if (entryPointID) { | ||
pollAvailability() | ||
|
||
$openButton.on('click', handleOpenChat) | ||
} | ||
|
||
function pollAvailability () { | ||
checkAvailability() | ||
|
||
setTimeout(function () { | ||
if (pollingEnabled) { | ||
pollAvailability() | ||
} | ||
}, POLL_INTERVAL) | ||
} | ||
|
||
function checkAvailability () { | ||
$.ajax({ | ||
url: API_URL + entryPointID, | ||
type: 'GET', | ||
timeout: AJAX_TIMEOUT, | ||
success: handleApiCallSuccess, | ||
error: handleApiCallError | ||
}) | ||
} | ||
|
||
function handleApiCallSuccess (result) { | ||
var $xml = $(result) | ||
var response = parseInt($xml.find('checkEligibility').attr('responseType'), 10) | ||
|
||
switch (response) { | ||
case CODE_AGENTS_UNAVAILABLE: | ||
handleAdvisersUnavailable() | ||
break | ||
case CODE_AGENTS_BUSY: | ||
handleAdvisersBusy() | ||
break | ||
case CODE_AGENTS_AVAILABLE: | ||
handleAdvisersAvailable() | ||
break | ||
default: | ||
handleApiCallError() | ||
break | ||
} | ||
} | ||
|
||
function handleApiCallError () { | ||
pollingEnabled = false | ||
handleAdvisersError() | ||
} | ||
|
||
function handleOpenChat (evt) { | ||
evt.preventDefault() | ||
var url = OPEN_CHAT_URL(entryPointID) | ||
windowOpen(url, 'newwin', 'width=200,height=100') | ||
|
||
GOVUK.analytics.trackEvent('webchat', 'accepted') | ||
} | ||
|
||
function handleAdvisersError () { | ||
$advisersError.removeClass('hidden') | ||
|
||
$advisersAvailable.addClass('hidden') | ||
$advisersBusy.addClass('hidden') | ||
$advisersUnavailable.addClass('hidden') | ||
|
||
GOVUK.analytics.trackEvent('webchat', 'error') | ||
} | ||
|
||
function handleAdvisersUnavailable () { | ||
$advisersUnavailable.removeClass('hidden') | ||
|
||
$advisersAvailable.addClass('hidden') | ||
$advisersBusy.addClass('hidden') | ||
$advisersError.addClass('hidden') | ||
|
||
GOVUK.analytics.trackEvent('webchat', 'unavailable') | ||
} | ||
|
||
function handleAdvisersBusy () { | ||
$advisersBusy.removeClass('hidden') | ||
|
||
$advisersUnavailable.addClass('hidden') | ||
$advisersAvailable.addClass('hidden') | ||
$advisersError.addClass('hidden') | ||
|
||
GOVUK.analytics.trackEvent('webchat', 'busy') | ||
} | ||
|
||
function handleAdvisersAvailable () { | ||
$advisersAvailable.removeClass('hidden') | ||
|
||
$advisersBusy.addClass('hidden') | ||
$advisersError.addClass('hidden') | ||
$advisersUnavailable.addClass('hidden') | ||
|
||
GOVUK.analytics.trackEvent('webchat', 'offered') | ||
} | ||
} | ||
|
||
GOVUK.Webchat = Webchat | ||
})(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable */ | ||
//= require ./legacy-modules/webchat.js | ||
/*eslint-enable */ | ||
|
||
var $ = window.$ | ||
|
||
$(document).ready(function () { | ||
var GOVUK = window.GOVUK | ||
if (GOVUK.Webchat) { | ||
$('.js-webchat').map(function () { | ||
return new GOVUK.Webchat({ $el: $(this) }) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.contact { | ||
.add-title-margin { | ||
@include responsive-top-margin; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
class ContactPresenter < ContentItemPresenter | ||
include TitleAndContext | ||
|
||
def title_and_context | ||
super.tap do |t| | ||
t.delete(:average_title_length) | ||
t.delete(:context) | ||
end | ||
end | ||
|
||
def related_items | ||
sections = [] | ||
sections << { | ||
title: "Elsewhere on GOV.UK", | ||
items: quick_links | ||
} if quick_links.any? | ||
|
||
sections << { | ||
title: "Other contacts", | ||
items: related_contacts_links | ||
} if related_contacts_links.any? | ||
|
||
{ | ||
sections: sections | ||
} | ||
end | ||
|
||
def online_form_links | ||
content_item["details"]["contact_form_links"].map do |link| | ||
{ | ||
url: link['link'], | ||
title: link['title'], | ||
description: link['description'].html_safe | ||
} | ||
end | ||
end | ||
|
||
def online_form_body | ||
content_item["details"]["more_info_contact_form"].html_safe | ||
end | ||
|
||
def phone | ||
phone_number_groups.map do |group| | ||
details = { | ||
numbers: [ | ||
{ | ||
label: 'Telephone', | ||
number: group['number'] | ||
}, | ||
{ | ||
label: 'Textphone', | ||
number: group['textphone'] | ||
}, | ||
{ | ||
label: 'Outside UK', | ||
number: group['international_phone'] | ||
}, | ||
{ | ||
label: 'Fax', | ||
number: group['fax'] | ||
} | ||
], | ||
title: group['title'], | ||
description: group['description'].strip.html_safe, | ||
opening_times: group['open_hours'].strip.html_safe, | ||
best_time_to_call: group['best_time_to_call'].strip.html_safe | ||
} | ||
|
||
details[:numbers].select! { |n| n[:number].present? } | ||
details | ||
end | ||
end | ||
|
||
def phone_body | ||
content_item["details"]["more_info_phone_number"].html_safe | ||
end | ||
|
||
def post | ||
post_address_groups.map do |group| | ||
details = { | ||
description: group['description'].strip.html_safe, | ||
v_card: [ | ||
v_card_part('fn', group['title']), | ||
v_card_part('street-address', group['street_address']), | ||
v_card_part('locality', group['locality']), | ||
v_card_part('postal-code', group['postal_code']), | ||
v_card_part('region', group['region']), | ||
v_card_part('country-name', group['world_location']), | ||
] | ||
} | ||
|
||
details[:v_card].select! { |v| v[:value].present? } | ||
details | ||
end | ||
end | ||
|
||
def post_body | ||
content_item["details"]["more_info_post_address"].html_safe | ||
end | ||
|
||
def email | ||
email_address_groups.map do |group| | ||
details = { | ||
description: group['description'] ? group['description'].strip.html_safe : '', | ||
email: group['email'].strip, | ||
v_card: [v_card_part('fn', group['title'])], | ||
} | ||
|
||
details[:v_card].select! { |v| v[:value].present? } | ||
details | ||
end | ||
end | ||
|
||
def email_body | ||
content_item["details"]["more_info_email_address"].html_safe | ||
end | ||
|
||
def show_webchat? | ||
# These are the routes on which we plan to roll out webchat, in stages. | ||
whitelisted_paths = [ | ||
'/government/organisations/hm-revenue-customs/contact/child-benefit', | ||
'/government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees', | ||
'/government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk', | ||
'/government/organisations/hm-revenue-customs/contact/national-insurance-numbers', | ||
'/government/organisations/hm-revenue-customs/contact/self-assessment-online-services-helpdesk', | ||
'/government/organisations/hm-revenue-customs/contact/self-assessment', | ||
'/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries', | ||
'/government/organisations/hm-revenue-customs/contact/vat-enquiries', | ||
'/government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries', | ||
'/government/organisations/hm-revenue-customs/contact/trusts', | ||
'/government/organisations/hm-revenue-customs/contact/employer-enquiries', | ||
'/government/organisations/hm-revenue-customs/contact/construction-industry-scheme', | ||
] | ||
whitelisted_paths.include?(content_item["base_path"]) | ||
end | ||
|
||
private | ||
|
||
def v_card_part(v_card_class, value) | ||
{ | ||
v_card_class: v_card_class, | ||
value: value.strip.html_safe | ||
} | ||
end | ||
|
||
def email_address_groups | ||
content_item["details"]["email_addresses"] || [] | ||
end | ||
|
||
def post_address_groups | ||
content_item["details"]["post_addresses"] || [] | ||
end | ||
|
||
def phone_number_groups | ||
content_item["details"]["phone_numbers"] || [] | ||
end | ||
|
||
def related_contacts_links | ||
related = content_item["links"]["related"] || [] | ||
related.map do |link| | ||
{ | ||
title: link["title"], | ||
url: link["base_path"] | ||
} | ||
end | ||
end | ||
|
||
def quick_links | ||
quick = content_item["details"]["quick_links"] || [] | ||
quick.map do |link| | ||
{ | ||
title: link["title"], | ||
url: link["url"] | ||
} | ||
end | ||
end | ||
end |
Oops, something went wrong.