overleaf/services/web/public/coffee/main/contact-us.coffee

93 lines
2.7 KiB
CoffeeScript
Raw Normal View History

define [
"base"
"libs/platform"
2016-07-14 10:15:31 +00:00
"services/algolia-search"
], (App, platform) ->
App.controller 'ContactModal', ($scope, $modal) ->
$scope.contactUsModal = () ->
modalInstance = $modal.open(
templateUrl: "supportModalTemplate"
controller: "SupportModalController"
)
2016-07-11 13:27:07 +00:00
App.controller 'SupportModalController', ($scope, $modalInstance, algoliaSearch, event_tracking) ->
$scope.form = {}
$scope.sent = false
$scope.sending = false
2016-06-24 16:10:07 +00:00
$scope.suggestions = [];
_handleSearchResults = (success, results) ->
2016-06-24 16:10:07 +00:00
suggestions = for hit in results.hits
page_underscored = hit.pageName.replace(/\s/g,'_')
suggestion =
2016-06-29 10:57:43 +00:00
url :"/learn/kb/#{page_underscored}"
name : hit._highlightResult.pageName.value
2016-06-24 16:10:07 +00:00
2016-08-10 16:29:43 +00:00
event_tracking.sendMB "contact-form-suggestions-shown" if results.hits.length
2016-07-11 13:27:07 +00:00
2016-06-24 16:10:07 +00:00
$scope.$applyAsync () ->
$scope.suggestions = suggestions
$scope.contactUs = ->
if !$scope.form.email?
console.log "email not set"
return
$scope.sending = true
ticketNumber = Math.floor((1 + Math.random()) * 0x10000).toString(32)
message = $scope.form.message
if $scope.form.project_url?
message = "#{message}\n\n project_url = #{$scope.form.project_url}"
params =
email: $scope.form.email
message: message or ""
subject: $scope.form.subject + " - [#{ticketNumber}]"
labels: "support"
about: "<div>browser: #{platform?.name} #{platform?.version}</div>
<div>os: #{platform?.os?.family} #{platform?.os?.version}</div>"
Groove.createTicket params, (err, json)->
$scope.sent = true
$scope.$apply()
2016-06-24 16:10:07 +00:00
$scope.$watch "form.subject", (newVal, oldVal) ->
if newVal and newVal != oldVal and newVal.length > 3
2016-06-29 10:57:43 +00:00
algoliaSearch.searchKB newVal, _handleSearchResults, {
hitsPerPage: 3
typoTolerance: 'strict'
}
else
$scope.suggestions = [];
2016-06-24 10:02:29 +00:00
2016-07-11 13:27:07 +00:00
$scope.clickSuggestionLink = (url) ->
2016-08-10 16:29:43 +00:00
event_tracking.sendMB "contact-form-suggestions-clicked", { url }
2016-07-11 13:27:07 +00:00
$scope.close = () ->
$modalInstance.close()
App.controller 'UniverstiesContactController', ($scope, $modal) ->
$scope.form = {}
$scope.sent = false
$scope.sending = false
$scope.contactUs = ->
if !$scope.form.email?
console.log "email not set"
return
$scope.sending = true
ticketNumber = Math.floor((1 + Math.random()) * 0x10000).toString(32)
params =
name: $scope.form.name || $scope.form.email
email: $scope.form.email
labels: "#{$scope.form.source} accounts"
message: "Please contact me with more details"
subject: $scope.form.subject + " - [#{ticketNumber}]"
about : "#{$scope.form.position || ''} #{$scope.form.university || ''}"
Groove.createTicket params, (err, json)->
$scope.sent = true
$scope.$apply()