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