2014-01-14 01:29:58 -05:00
|
|
|
View = require 'views/kinds/RootView'
|
|
|
|
template = require 'templates/employers'
|
2014-04-07 18:21:05 -04:00
|
|
|
app = require 'application'
|
2014-04-06 20:01:56 -04:00
|
|
|
User = require 'models/User'
|
2014-06-17 16:03:08 -04:00
|
|
|
UserRemark = require 'models/UserRemark'
|
2014-04-24 20:36:07 -04:00
|
|
|
{me} = require 'lib/auth'
|
2014-04-22 15:42:26 -04:00
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
2014-04-11 15:49:44 -04:00
|
|
|
EmployerSignupView = require 'views/modal/employer_signup_modal'
|
2014-04-06 20:01:56 -04:00
|
|
|
|
|
|
|
class CandidatesCollection extends CocoCollection
|
|
|
|
url: '/db/user/x/candidates'
|
|
|
|
model: User
|
|
|
|
|
2014-06-17 16:03:08 -04:00
|
|
|
class UserRemarksCollection extends CocoCollection
|
|
|
|
url: '/db/user.remark?project=contact,contactName,user'
|
|
|
|
model: UserRemark
|
|
|
|
|
2014-01-14 01:29:58 -05:00
|
|
|
module.exports = class EmployersView extends View
|
|
|
|
id: "employers-view"
|
|
|
|
template: template
|
2014-04-05 20:05:03 -04:00
|
|
|
|
2014-04-07 18:21:05 -04:00
|
|
|
events:
|
2014-04-07 20:58:02 -04:00
|
|
|
'click tbody tr': 'onCandidateClicked'
|
2014-04-07 18:21:05 -04:00
|
|
|
|
2014-04-06 20:01:56 -04:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@getCandidates()
|
2014-06-10 01:17:53 -04:00
|
|
|
|
2014-04-05 20:05:03 -04:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
2014-04-06 20:01:56 -04:00
|
|
|
@sortTable() if @candidates.models.length
|
|
|
|
|
2014-04-29 18:12:50 -04:00
|
|
|
afterInsert: ->
|
|
|
|
super()
|
|
|
|
_.delay @checkForEmployerSignupHash, 500
|
|
|
|
|
2014-04-06 20:01:56 -04:00
|
|
|
getRenderData: ->
|
2014-06-10 01:17:53 -04:00
|
|
|
ctx = super()
|
|
|
|
ctx.isEmployer = @isEmployer()
|
|
|
|
ctx.candidates = _.sortBy @candidates.models, (c) -> c.get('jobProfile').updated
|
|
|
|
ctx.activeCandidates = _.filter ctx.candidates, (c) -> c.get('jobProfile').active
|
|
|
|
ctx.inactiveCandidates = _.reject ctx.candidates, (c) -> c.get('jobProfile').active
|
|
|
|
ctx.featuredCandidates = _.filter ctx.activeCandidates, (c) -> c.get('jobProfileApproved')
|
|
|
|
ctx.otherCandidates = _.reject ctx.activeCandidates, (c) -> c.get('jobProfileApproved')
|
2014-06-17 16:03:08 -04:00
|
|
|
ctx.remarks = {}
|
|
|
|
ctx.remarks[remark.get('user')] = remark for remark in @remarks.models
|
2014-06-10 01:17:53 -04:00
|
|
|
ctx.moment = moment
|
|
|
|
ctx._ = _
|
|
|
|
ctx
|
2014-04-25 11:47:31 -04:00
|
|
|
|
2014-06-10 01:17:53 -04:00
|
|
|
isEmployer: ->
|
|
|
|
userPermissions = me.get('permissions') ? []
|
|
|
|
_.contains userPermissions, "employer"
|
2014-04-06 20:01:56 -04:00
|
|
|
|
|
|
|
getCandidates: ->
|
|
|
|
@candidates = new CandidatesCollection()
|
|
|
|
@candidates.fetch()
|
2014-06-17 16:03:08 -04:00
|
|
|
@remarks = new UserRemarksCollection()
|
|
|
|
@remarks.fetch()
|
2014-04-06 20:01:56 -04:00
|
|
|
# Re-render when we have fetched them, but don't wait and show a progress bar while loading.
|
2014-05-01 19:56:39 -04:00
|
|
|
@listenToOnce @candidates, 'all', @renderCandidatesAndSetupScrolling
|
2014-06-17 16:03:08 -04:00
|
|
|
@listenToOnce @remarks, 'all', @renderCandidatesAndSetupScrolling
|
2014-05-01 19:56:39 -04:00
|
|
|
|
|
|
|
renderCandidatesAndSetupScrolling: =>
|
|
|
|
@render()
|
|
|
|
$(".nano").nanoScroller()
|
2014-05-08 14:17:15 -04:00
|
|
|
if window.history?.state?.lastViewedCandidateID
|
|
|
|
$(".nano").nanoScroller({scrollTo:$("#" + window.history.state.lastViewedCandidateID)})
|
|
|
|
else if window.location.hash.length is 25
|
2014-05-01 19:56:39 -04:00
|
|
|
$(".nano").nanoScroller({scrollTo:$(window.location.hash)})
|
2014-04-05 20:05:03 -04:00
|
|
|
|
2014-06-10 01:17:53 -04:00
|
|
|
checkForEmployerSignupHash: =>
|
|
|
|
if window.location.hash is "#employerSignupLoggingIn" and not ("employer" in me.get("permissions"))
|
|
|
|
@openModalView application.router.getView("modal/employer_signup","_modal")
|
|
|
|
window.location.hash = ""
|
|
|
|
|
2014-04-05 20:05:03 -04:00
|
|
|
sortTable: ->
|
|
|
|
# http://mottie.github.io/tablesorter/docs/example-widget-bootstrap-theme.html
|
|
|
|
$.extend $.tablesorter.themes.bootstrap,
|
|
|
|
# these classes are added to the table. To see other table classes available,
|
|
|
|
# look here: http://twitter.github.com/bootstrap/base-css.html#tables
|
|
|
|
table: "table table-bordered"
|
|
|
|
caption: "caption"
|
|
|
|
header: "bootstrap-header" # give the header a gradient background
|
|
|
|
footerRow: ""
|
|
|
|
footerCells: ""
|
|
|
|
icons: "" # add "icon-white" to make them white; this icon class is added to the <i> in the header
|
|
|
|
sortNone: "bootstrap-icon-unsorted"
|
|
|
|
sortAsc: "icon-chevron-up" # glyphicon glyphicon-chevron-up" # we are still using v2 icons
|
|
|
|
sortDesc: "icon-chevron-down" # glyphicon-chevron-down" # we are still using v2 icons
|
|
|
|
active: "" # applied when column is sorted
|
|
|
|
hover: "" # use custom css here - bootstrap class may not override it
|
|
|
|
filterRow: "" # filter row class
|
|
|
|
even: "" # odd row zebra striping
|
|
|
|
odd: "" # even row zebra striping
|
|
|
|
|
2014-04-24 14:08:42 -04:00
|
|
|
|
|
|
|
# e = exact text from cell
|
|
|
|
# n = normalized value returned by the column parser
|
|
|
|
# f = search filter input value
|
|
|
|
# i = column index
|
|
|
|
# $r = ???
|
|
|
|
filterSelectExactMatch = (e, n, f, i, $r) -> e is f
|
|
|
|
|
2014-04-05 20:05:03 -04:00
|
|
|
# call the tablesorter plugin and apply the uitheme widget
|
2014-04-24 14:08:42 -04:00
|
|
|
@$el.find(".tablesorter").tablesorter
|
2014-04-05 20:05:03 -04:00
|
|
|
theme: "bootstrap"
|
|
|
|
widthFixed: true
|
|
|
|
headerTemplate: "{content} {icon}"
|
2014-04-24 14:08:42 -04:00
|
|
|
textSorter:
|
|
|
|
6: (a, b, direction, column, table) ->
|
|
|
|
days = []
|
|
|
|
for s in [a, b]
|
|
|
|
n = parseInt s
|
|
|
|
n = 0 unless _.isNumber n
|
2014-06-07 21:58:06 -04:00
|
|
|
n = 1 if /^a/.test s
|
2014-04-24 14:08:42 -04:00
|
|
|
for [duration, factor] in [
|
|
|
|
[/second/i, 1 / (86400 * 1000)]
|
|
|
|
[/minute/i, 1 / 1440]
|
|
|
|
[/hour/i, 1 / 24]
|
|
|
|
[/week/i, 7]
|
|
|
|
[/month/i, 30.42]
|
|
|
|
[/year/i, 365.2425]
|
|
|
|
]
|
|
|
|
if duration.test s
|
|
|
|
n *= factor
|
|
|
|
break
|
|
|
|
if /^in /i.test s
|
|
|
|
n *= -1
|
|
|
|
days.push n
|
|
|
|
days[0] - days[1]
|
2014-06-10 01:17:53 -04:00
|
|
|
sortList: if @isEmployer() or me.isAdmin() then [[6, 0]] else [[0, 1]]
|
2014-04-05 20:05:03 -04:00
|
|
|
# widget code contained in the jquery.tablesorter.widgets.js file
|
|
|
|
# use the zebra stripe widget if you plan on hiding any rows (filter widget)
|
2014-04-24 14:08:42 -04:00
|
|
|
widgets: ["uitheme", "zebra", "filter"]
|
2014-04-05 20:05:03 -04:00
|
|
|
widgetOptions:
|
|
|
|
# using the default zebra striping class name, so it actually isn't included in the theme variable above
|
|
|
|
# this is ONLY needed for bootstrap theming if you are using the filter widget, because rows are hidden
|
2014-04-24 14:08:42 -04:00
|
|
|
zebra: ["even", "odd"]
|
|
|
|
|
|
|
|
# extra css class applied to the table row containing the filters & the inputs within that row
|
|
|
|
filter_cssFilter: ""
|
|
|
|
|
|
|
|
# If there are child rows in the table (rows with class name from "cssChildRow" option)
|
|
|
|
# and this option is true and a match is found anywhere in the child row, then it will make that row
|
|
|
|
# visible; default is false
|
|
|
|
filter_childRows: false
|
|
|
|
|
|
|
|
# if true, filters are collapsed initially, but can be revealed by hovering over the grey bar immediately
|
|
|
|
# below the header row. Additionally, tabbing through the document will open the filter row when an input gets focus
|
|
|
|
filter_hideFilters: false
|
|
|
|
|
|
|
|
# Set this option to false to make the searches case sensitive
|
|
|
|
filter_ignoreCase: true
|
|
|
|
|
|
|
|
# jQuery selector string of an element used to reset the filters
|
2014-04-05 20:05:03 -04:00
|
|
|
filter_reset: ".reset"
|
2014-04-24 14:08:42 -04:00
|
|
|
|
|
|
|
# Use the $.tablesorter.storage utility to save the most recent filters
|
|
|
|
filter_saveFilters: true
|
|
|
|
|
|
|
|
# Delay in milliseconds before the filter widget starts searching; This option prevents searching for
|
|
|
|
# every character while typing and should make searching large tables faster.
|
|
|
|
filter_searchDelay: 150
|
|
|
|
|
|
|
|
# Set this option to true to use the filter to find text from the start of the column
|
|
|
|
# So typing in "a" will find "albert" but not "frank", both have a's; default is false
|
|
|
|
filter_startsWith: false
|
|
|
|
|
|
|
|
filter_functions:
|
|
|
|
2:
|
|
|
|
"Full-time": filterSelectExactMatch
|
|
|
|
"Part-time": filterSelectExactMatch
|
|
|
|
"Contracting": filterSelectExactMatch
|
|
|
|
"Remote": filterSelectExactMatch
|
|
|
|
"Internship": filterSelectExactMatch
|
|
|
|
5:
|
|
|
|
"0-1": (e, n, f, i, $r) -> n <= 1
|
|
|
|
"2-5": (e, n, f, i, $r) -> 2 <= n <= 5
|
|
|
|
"6+": (e, n, f, i, $r) -> 6 <= n
|
|
|
|
6:
|
|
|
|
"Last day": (e, n, f, i, $r) ->
|
|
|
|
days = parseFloat $($r.find('td')[i]).data('profile-age')
|
|
|
|
days <= 1
|
|
|
|
"Last week": (e, n, f, i, $r) ->
|
|
|
|
days = parseFloat $($r.find('td')[i]).data('profile-age')
|
|
|
|
days <= 7
|
|
|
|
"Last 4 weeks": (e, n, f, i, $r) ->
|
|
|
|
days = parseFloat $($r.find('td')[i]).data('profile-age')
|
|
|
|
days <= 28
|
2014-06-17 16:03:08 -04:00
|
|
|
8:
|
2014-04-24 14:08:42 -04:00
|
|
|
"✓": filterSelectExactMatch
|
|
|
|
"✗": filterSelectExactMatch
|
2014-04-07 18:21:05 -04:00
|
|
|
|
|
|
|
onCandidateClicked: (e) ->
|
|
|
|
id = $(e.target).closest('tr').data('candidate-id')
|
2014-04-11 17:59:09 -04:00
|
|
|
if id
|
2014-05-08 14:17:15 -04:00
|
|
|
if window.history
|
|
|
|
oldState = _.cloneDeep window.history.state ? {}
|
|
|
|
oldState["lastViewedCandidateID"] = id
|
|
|
|
window.history.replaceState(oldState,"")
|
2014-06-07 21:58:06 -04:00
|
|
|
else
|
2014-05-08 14:17:15 -04:00
|
|
|
window.location.hash = id
|
2014-04-07 18:21:05 -04:00
|
|
|
url = "/account/profile/#{id}"
|
2014-05-14 13:37:16 -04:00
|
|
|
window.open url,"_blank"
|
2014-04-07 18:21:05 -04:00
|
|
|
else
|
2014-04-11 15:49:44 -04:00
|
|
|
@openModalView new EmployerSignupView
|