<commit_before>Template.newNeed.rendered = ->
  $('#tags').select2({tags:["mentoring", "funding"]})

Template.newNeed.helpers
  chars: ->                 Session.get('chars')
  showCharLengthMessage: -> Session.get('chars') > 0

  charLengthClass: ->
    if Session.get('chars') < 30 || Session.get('chars') > 200
      'red'
    else
      ''
  saveButtonClass: ->
    if Session.get('chars') < 30 || Session.get('chars') > 200
      'hidden'
    else
      ''
  charLengthMessage: ->
    message = ''
    if Session.get('chars') < 30
      message = '(be more descriptive)'
    if Session.get('chars') > 200
      message = '(be less descriptive)'

    message

addNeed = ->
  user = Meteor.user()
  if user and user.username
    newNeed = $('#newNeed').val()
    if newNeed.length >= 30
      if newNeed.length <= 200
        Session.set('chars', 0)
        $('#newNeed').val ''
        Needs.insert
          content: newNeed
          createdAt: new Date()
          userId: Meteor.userId()
          username: user.username
          offerCount: 0
          score: Supporter.computeScore({stars: 0, createdAt: new Date()})
          tags: $('#tags').val().split(",")
          backgroundId: $('#backgroundId').val()
          backgroundName: Backgrounds.findOne($('#backgroundId').val()).name
        , ->
          Router.go('needs')
      else
        alert 'Be less descriptive'
    else
      alert 'Be more descriptive'

updateChars = ->
  Session.set('chars', $('textarea#newNeed').val().length)

Template.newNeed.events
  "click input#newNeedButton": (e) ->
    addNeed()

  "keyup textarea#newNeed": (e)->
    _.debounce(updateChars, 1000)()<commit_msg>bug in adding new need without defining a project<commit_after>Template.newNeed.rendered = ->
  $('#tags').select2({tags:["mentoring", "funding"]})

Template.newNeed.helpers
  chars: ->                 Session.get('chars')
  showCharLengthMessage: -> Session.get('chars') > 0

  charLengthClass: ->
    if Session.get('chars') < 30 || Session.get('chars') > 200
      'red'
    else
      ''
  saveButtonClass: ->
    if Session.get('chars') < 30 || Session.get('chars') > 200
      'hidden'
    else
      ''
  charLengthMessage: ->
    message = ''
    if Session.get('chars') < 30
      message = '(be more descriptive)'
    if Session.get('chars') > 200
      message = '(be less descriptive)'

    message

addNeed = ->
  user = Meteor.user()
  if user and user.username
    newNeed = $('#newNeed').val()
    if newNeed.length >= 30
      if newNeed.length <= 200
        Session.set('chars', 0)
        $('#newNeed').val ''
        bkgrnd = $('#backgroundId').val()
        Needs.insert
          content: newNeed
          createdAt: new Date()
          userId: Meteor.userId()
          username: user.username
          offerCount: 0
          score: Supporter.computeScore({stars: 0, createdAt: new Date()})
          tags: $('#tags').val().split(",")
          backgroundId: if bkgrnd is not "No Project" then bkgrnd else null
          backgroundName: if bkgrnd is not "No Project" then Backgrounds.findOne($('#backgroundId').val()).name else null
        , ->
          Router.go('needs')
      else
        alert 'Be less descriptive'
    else
      alert 'Be more descriptive'

updateChars = ->
  Session.set('chars', $('textarea#newNeed').val().length)

Template.newNeed.events
  "click input#newNeedButton": (e) ->
    addNeed()

  "keyup textarea#newNeed": (e)->
    _.debounce(updateChars, 1000)()
{'fraction_non_alphanumeric': 0.1592996555683123, 'fraction_numerical': 0.016647531572904706, 'mean_word_length': 2.4919839679358717, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 35, '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': '6866799', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1036, 'n_words': 243}