<commit_before>$.Controller 'Dreamcatcher.Controllers.Settings',

  init: ->
    @setupDefaults()
    @setupAjaxBinding()
    
  setupDefaults: ->
    defaultSharingLevel = $('#default-sharing').data 'id'
    defaultLandingPage = $('#default-landingPage').data 'id'
    defaultMenuStyle = $('#default-menuStyle').data 'id'
    log('fms: '+ defaultMenuStyle)
    $('#default-sharing-list').val(defaultSharingLevel)
    $('#default-landingPage-list').val(defaultLandingPage)
    $('#default-menuStyle-list').val(defaultMenuStyle)
    
    @displayDefaultSharingLevel defaultSharingLevel
    @displayDefaultLandingPage defaultLandingPage
    @displayDefaultMenuStyle defaultMenuStyle
 
    
  showPanel: ->    
    $('#settingsPanel').show()

  displayDefaultSharingLevel: (defaultSharingLevel) ->
    # TODO: after SASS refactor, replace with class
    defaultSharingLevel = parseInt defaultSharingLevel
    switch defaultSharingLevel
      when 500 then background = 'sharing-24-hover.png'
      when 200 then background = 'friend-24.png'
      when 150 then background = 'friend-24-follower.png'
      when 50 then background = 'anon-24-hover.png'
      when 0 then background = 'private-24-hover.png'

    $('.sharing-icon').css "background","url(/images/icons/#{background}) no-repeat center transparent"

  displayDefaultLandingPage: (defaultLandingPage) ->
    # TODO: after SASS refactor, replace with class
    switch defaultLandingPage
      when 'stream' then background = 'stream-24-hover.png'
      when 'home' then background = 'home-24-hover.png'
      when 'today' then background = 'home-24-hover.png'
    
    $('.landing-icon').css "background","url(/images/icons/#{background}) no-repeat center transparent"

  displayDefaultMenuStyle: (defaultMenuStyle) ->
    # TODO: after SASS refactor, replace with class
    switch defaultMenuStyle
      when 'stream' then background = 'stream-24-hover.png'
      when 'home' then background = 'home-24-hover.png'
      when 'today' then background = 'home-24-hover.png'

    $('.landing-icon').css "background","url(/images/icons/#{background}) no-repeat center transparent"
    
    
  updateSettingsModel: (params) ->
    Dreamcatcher.Models.Settings.update params


  setupAjaxBinding: ->
    #TODO: Needs refactoring.
    $('#fbLink').bind 'ajax:success', (event, xhr, status)->
      $('#fbLink').remove()
      $('.network').append '<a id="fbLink" href="/auth/facebook" class="linkAccount">link account</a>'

    $('form#change_password').bind 'ajax:beforeSend', (xhr, settings)->
      $('.changePassword .target').hide()

    $('form#change_password').bind 'ajax:success', (data, xhr, status)->
      $('p.notice').text xhr.message
      if xhr.errors
        for error, message of xhr.errors
          $('#user_' + error).prev().text message[0]<commit_msg>refactored 3 displayDefault* methods to work with classes instead of backgrounds<commit_after>$.Controller 'Dreamcatcher.Controllers.Settings',

  init: ->
    @setupDefaults()
    @setupAjaxBinding()
    
  setupDefaults: ->
    defaultSharingLevel = $('#default-sharing').data 'id'
    defaultLandingPage = $('#default-landingPage').data 'id'
    defaultMenuStyle = $('#default-menuStyle').data 'id'

    $('#default-sharing-list').val(defaultSharingLevel)
    $('#default-landingPage-list').val(defaultLandingPage)
    $('#default-menuStyle-list').val(defaultMenuStyle)
    
    @displayDefaultSharingLevel defaultSharingLevel
    @displayDefaultLandingPage defaultLandingPage
    @displayDefaultMenuStyle defaultMenuStyle
 
    
  showPanel: ->    
    $('#settingsPanel').show()

  displayDefaultSharingLevel: (defaultSharingLevel) ->
    # TODO: after SASS refactor, replace with class
    defaultSharingLevel = parseInt defaultSharingLevel
    switch defaultSharingLevel
      when 500 then class = 'everyone'
      when 200 then class = 'friend'
      when 150 then class = 'follower'
      when 50 then class = 'anonymous'
      when 0 then class = 'private'

    # $('.sharing-icon').css "background","url(/images/icons/#{background}) no-repeat center transparent"
    
    sharingIcon = $('#sharing-icon')
    sharingIcon.removeClass(className) for className in ['everyone','friend','follower','anonymous','private']
    sharingIcon.addClass(defaultSharingLevel)    
    

  displayDefaultLandingPage: (defaultLandingPage) ->
    landingIcon = $('#landing-icon')
    landingIcon.removeClass(className) for className in ['stream','home','today']
    landingIcon.addClass(defaultLandingPage)

  displayDefaultMenuStyle: (defaultMenuStyle) ->
    # TODO: after SASS refactor, replace with class
    switch defaultMenuStyle
      when 'stream' then class = 'stream'
      when 'home' then class = 'home'
      when 'today' then class = 'home'

    # $('.landing-icon').css "background","url(/images/icons/#{background}) no-repeat center transparent"
    menuIcon = $('#menu-icon')
    menuIcon.removeClass(className) for className in ['stream','home']
    menuIcon.addClass(defaultMenuStyle)
    
    
  updateSettingsModel: (params) ->
    Dreamcatcher.Models.Settings.update params


  setupAjaxBinding: ->
    #TODO: Needs refactoring.
    $('#fbLink').bind 'ajax:success', (event, xhr, status)->
      $('#fbLink').remove()
      $('.network').append '<a id="fbLink" href="/auth/facebook" class="linkAccount">link account</a>'

    $('form#change_password').bind 'ajax:beforeSend', (xhr, settings)->
      $('.changePassword .target').hide()

    $('form#change_password').bind 'ajax:success', (data, xhr, status)->
      $('p.notice').text xhr.message
      if xhr.errors
        for error, message of xhr.errors
          $('#user_' + error).prev().text message[0]
{'fraction_non_alphanumeric': 0.14350877192982456, 'fraction_numerical': 0.008596491228070175, 'mean_word_length': 3.823181049069374, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '5009596', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1633, 'n_words': 356}