2014-01-03 13:32:13 -05:00
|
|
|
View = require 'views/kinds/RootView'
|
|
|
|
template = require 'templates/account/profile'
|
|
|
|
User = require 'models/User'
|
2014-04-10 17:59:32 -04:00
|
|
|
JobProfileContactView = require 'views/modal/job_profile_contact_modal'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
module.exports = class ProfileView extends View
|
|
|
|
id: "profile-view"
|
|
|
|
template: template
|
|
|
|
|
2014-04-07 20:58:02 -04:00
|
|
|
events:
|
|
|
|
'click #toggle-job-profile-approved': 'toggleJobProfileApproved'
|
|
|
|
'keyup #job-profile-notes': 'onJobProfileNotesChanged'
|
2014-04-10 17:59:32 -04:00
|
|
|
'click #contact-candidate': 'onContactCandidate'
|
2014-04-25 19:57:42 -04:00
|
|
|
'click #enter-espionage-mode': 'enterEspionageMode'
|
2014-04-07 20:58:02 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
constructor: (options, @userID) ->
|
2014-04-07 20:58:02 -04:00
|
|
|
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
|
2014-01-03 13:32:13 -05:00
|
|
|
super options
|
2014-04-09 19:46:44 -04:00
|
|
|
if @userID is me.id
|
|
|
|
@user = me
|
|
|
|
else
|
|
|
|
@user = User.getByID(@userID)
|
2014-04-29 18:12:50 -04:00
|
|
|
@user.fetch()
|
|
|
|
@listenTo @user, "sync", =>
|
|
|
|
@render()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
2014-04-09 19:46:44 -04:00
|
|
|
context.user = @user
|
|
|
|
context.myProfile = @user.id is context.me.id
|
2014-04-07 18:21:05 -04:00
|
|
|
context.marked = marked
|
|
|
|
context.moment = moment
|
2014-04-09 16:14:52 -04:00
|
|
|
context.iconForLink = @iconForLink
|
|
|
|
if links = @user.get('jobProfile')?.links
|
|
|
|
links = ($.extend(true, {}, link) for link in links)
|
|
|
|
link.icon = @iconForLink link for link in links
|
|
|
|
context.profileLinks = _.sortBy links, (link) -> not link.icon # icons first
|
2014-01-03 13:32:13 -05:00
|
|
|
context
|
2014-04-07 20:58:02 -04:00
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@updateProfileApproval() if me.isAdmin()
|
2014-04-10 20:54:28 -04:00
|
|
|
unless @user.get('jobProfile')?.projects?.length
|
|
|
|
@$el.find('.right-column').hide()
|
|
|
|
@$el.find('.middle-column').addClass('double-column')
|
2014-04-07 20:58:02 -04:00
|
|
|
|
|
|
|
updateProfileApproval: ->
|
|
|
|
approved = @user.get 'jobProfileApproved'
|
|
|
|
@$el.find('.approved').toggle Boolean(approved)
|
|
|
|
@$el.find('.not-approved').toggle not approved
|
|
|
|
|
|
|
|
toggleJobProfileApproved: ->
|
|
|
|
approved = not @user.get 'jobProfileApproved'
|
|
|
|
@user.set 'jobProfileApproved', approved
|
|
|
|
@user.save()
|
|
|
|
@updateProfileApproval()
|
|
|
|
|
2014-04-25 19:57:42 -04:00
|
|
|
enterEspionageMode: ->
|
|
|
|
postData = emailLower: @user.get('email').toLowerCase(), usernameLower: @user.get('name').toLowerCase()
|
|
|
|
$.ajax
|
|
|
|
type: "POST",
|
|
|
|
url: "/auth/spy"
|
|
|
|
data: postData
|
|
|
|
success: @espionageSuccess
|
|
|
|
|
|
|
|
espionageSuccess: (model) ->
|
|
|
|
window.location.reload()
|
|
|
|
|
2014-04-07 20:58:02 -04:00
|
|
|
onJobProfileNotesChanged: (e) =>
|
|
|
|
notes = @$el.find("#job-profile-notes").val()
|
|
|
|
@user.set 'jobProfileNotes', notes
|
|
|
|
@user.save()
|
2014-04-09 16:14:52 -04:00
|
|
|
|
|
|
|
iconForLink: (link) ->
|
|
|
|
icons = [
|
2014-04-23 14:26:20 -04:00
|
|
|
{icon: 'facebook', name: 'Facebook', domain: /facebook\.com/, match: /facebook/i}
|
|
|
|
{icon: 'twitter', name: 'Twitter', domain: /twitter\.com/, match: /twitter/i}
|
|
|
|
{icon: 'github', name: 'GitHub', domain: /github\.(com|io)/, match: /github/i}
|
|
|
|
{icon: 'gplus', name: 'Google Plus', domain: /plus\.google\.com/, match: /(google|^g).?(\+|plus)/i}
|
|
|
|
{icon: 'linkedin', name: 'LinkedIn', domain: /linkedin\.com/, match: /(google|^g).?(\+|plus)/i}
|
2014-04-09 16:14:52 -04:00
|
|
|
]
|
|
|
|
for icon in icons
|
|
|
|
if (link.name.search(icon.match) isnt -1) or (link.link.search(icon.domain) isnt -1)
|
|
|
|
icon.url = "/images/pages/account/profile/icon_#{icon.icon}.png"
|
|
|
|
return icon
|
|
|
|
null
|
2014-04-10 17:59:32 -04:00
|
|
|
|
|
|
|
onContactCandidate: (e) ->
|
|
|
|
@openModalView new JobProfileContactView recipientID: @user.id
|