<commit_before>class ELMO.Views.BroadcastsView extends Backbone.View
  el: '.broadcast_form'

  initialize: ->
    @medium_changed()
    @$("#broadcast_recipient_ids").select2()

  events:
    'change #broadcast_medium': 'medium_changed'
    'keyup #broadcast_body': 'update_char_limit'

  medium_changed: (e) ->
    selected = @$('#broadcast_medium').val()
    sms_possible = selected != "email_only" && selected != ""

    # Hide/show char limit and subject
    if sms_possible
      @$('#char_limit').show()
      @$('.form_field.broadcast_which_phone').show()
      @$('.form_field.broadcast_subject').hide()
      @$('.form_field.broadcast_balance').show()
      @update_char_limit()
    else
      @$('#char_limit').hide()
      @$('.form_field.broadcast_which_phone').hide()
      @$('.form_field.broadcast_subject').show()
      @$('.form_field.broadcast_balance').hide()

  update_char_limit: ->
    div = @$('#char_limit')
    if div.is(':visible')
      diff = 140 - @$('#broadcast_body').val().length
      msg = I18n.t('broadcast.chars.' + (if diff >= 0 then 'remaining' else 'too_many'))
      div.text("#{Math.abs(diff)} #{msg}")
      div.css('color', if diff >= 0 then 'black' else '#d02000')<commit_msg>852: Made recipient_ids show/hide based on recipient_selection<commit_after>class ELMO.Views.BroadcastsView extends Backbone.View
  el: '.broadcast_form'

  initialize: ->
    @medium_changed()
    @recipient_selection_changed()
    @$("#broadcast_recipient_ids").select2()

  events:
    'change #broadcast_medium': 'medium_changed'
    'change #broadcast_recipient_selection': 'recipient_selection_changed'
    'keyup #broadcast_body': 'update_char_limit'

  recipient_selection_changed: (e) ->
    specific = @$('#broadcast_recipient_selection').val() == 'specific_users'
    @$('.form_field.broadcast_recipient_ids')[if specific then 'show' else 'hide']()

  medium_changed: (e) ->
    selected = @$('#broadcast_medium').val()
    sms_possible = selected != 'email_only' && selected != ''

    # Hide/show char limit and subject
    if sms_possible
      @$('#char_limit').show()
      @$('.form_field.broadcast_which_phone').show()
      @$('.form_field.broadcast_subject').hide()
      @$('.form_field.broadcast_balance').show()
      @update_char_limit()
    else
      @$('#char_limit').hide()
      @$('.form_field.broadcast_which_phone').hide()
      @$('.form_field.broadcast_subject').show()
      @$('.form_field.broadcast_balance').hide()

  update_char_limit: ->
    div = @$('#char_limit')
    if div.is(':visible')
      diff = 140 - @$('#broadcast_body').val().length
      msg = I18n.t('broadcast.chars.' + (if diff >= 0 then 'remaining' else 'too_many'))
      div.text("#{Math.abs(diff)} #{msg}")
      div.css('color', if diff >= 0 then 'black' else '#d02000')
{'fraction_non_alphanumeric': 0.18159115233678202, 'fraction_numerical': 0.010346057795219408, 'mean_word_length': 3.9106830122591942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '3955252', 'n_tokens_mistral': 952, 'n_tokens_neox': 926, 'n_words': 156}