<commit_before>CustomLinkView = require './../core/customlinkview'
JobsItemView = require './jobsitemview'

module.exports = class JobsView extends KDView
  constructor : (options = {}) ->

    options.cssClass = KD.utils.curry 'jobs-view', options.cssClass
    options.apiUrl   = "#{KD.apiUri or window.location.origin}/-/jobs"

    super options

    @loader = new KDLoaderView
      size      :
        width   : 30
        height  : 30
      showLoader: yes

    @getJobs()


  getJobs : ->

    if @errorView then @errorView.destroy()

    @addSubView @loader

    $.ajax
      url     : @getOption 'apiUrl'
      timeOut : 5000
      success : @bound 'createView'
      error   : @bound 'showError'


  showError : (data) ->

    @loader.destroy()

    @addSubView @errorView = new KDCustomHTMLView
      partial   : "Couldn't fetch job openings, please "
      cssClass  : "jobs-error"

    @errorView.addSubView new CustomLinkView
      cssClass   : 'retry-link'
      title      : 'try again'
      click      : @bound 'getJobs'


  createView : (data) ->

    for jobData, index in data
      @addSubView jobView = new JobsItemView {}, jobData

    KD.utils.wait 100, => @setClass 'animate'
    @loader.destroy()



<commit_msg>About: job listing xhr error handling<commit_after>CustomLinkView = require './../core/customlinkview'
JobsItemView = require './jobsitemview'

module.exports = class JobsView extends KDView
  constructor : (options = {}) ->

    options.cssClass = KD.utils.curry 'jobs-view', options.cssClass
    options.apiUrl   = "#{KD.apiUri or window.location.origin}/-/jobs"

    super options

    @loader = new KDLoaderView
      size      :
        width   : 30
        height  : 30
      showLoader: yes

    @getJobs()


  getJobs : ->

    if @errorView then @errorView.destroy()

    @addSubView @loader

    $.ajax
      url     : @getOption 'apiUrl'
      timeOut : 5000
      success : @bound 'createView'
      error   : @bound 'showError'


  showError : (data) ->

    @loader.destroy()

    @addSubView @errorView = new KDCustomHTMLView
      partial   : "Couldn't fetch job openings, please "
      cssClass  : "jobs-error"

    @errorView.addSubView new CustomLinkView
      cssClass   : 'retry-link'
      title      : 'try again'
      click      : @bound 'getJobs'


  createView : (data) ->

    if Array.isArray data
      for jobData, index in data
        @addSubView jobView = new JobsItemView {}, jobData

    KD.utils.wait 100, => @setClass 'animate'
    @loader.destroy()




{'fraction_non_alphanumeric': 0.11146245059288537, 'fraction_numerical': 0.008695652173913044, 'mean_word_length': 2.356763925729443, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5036609', 'n_tokens_mistral': 859, 'n_tokens_neox': 774, 'n_words': 200}