<commit_before>define [
  'views/base/view'
  'views/community_select_view'
  'views/tag_select_view'
  'models/communities'
  'views/flash_view'
], (View, CommunitySelectView, TagSelectView, Communities, FlashView) ->
  'use strict'

  class ProfileEditView extends View
    templateName: 'profile_edit'
    className: 'profile-edit container-fluid'

    regions:
      communitySelect: "#community_select_container"
      tagSelect: "#tag_select_container"

    initialize: (options) ->
      super
      @delegate 'click', '#profile-edit-tabs a', @switchTabs
      @delegate('submit', 'form', @save)

    render: (options) ->
      super
      @communitySelect = new CommunitySelectView region: 'communitySelect', collection: new Communities
      @subview 'communitySelect', @communitySelect

      @acceptedCurrenciesSelect = new TagSelectView region: 'tagSelect', collection: @model.acceptedCurrenciesCollection, label: "Accepted Currencies", fieldName: "accepted_currencies"
      @subview 'acceptedCurrenciesSelect', @acceptedCurrenciesSelect

      Backbone.Validation.bind(@)
      bindings = Backbone.ModelBinder.createDefaultBindings(@$el, 'name');
      bindings["community_name"] = "#current-community"
      @modelBinder.bind(@model, @$el, bindings)

    switchTabs: (event) ->
      event.preventDefault()
      $(event.currentTarget).tab('show')

    save: (event) ->
      event.preventDefault()
      request = @model.save()
      request.fail(=>
        @displayFormError()
        # TODO: Handle server side failure.<commit_msg>Fixes #30. Update community name on profile save.<commit_after>define [
  'views/base/view'
  'views/community_select_view'
  'views/tag_select_view'
  'models/communities'
  'views/flash_view'
], (View, CommunitySelectView, TagSelectView, Communities, FlashView) ->
  'use strict'

  class ProfileEditView extends View
    templateName: 'profile_edit'
    className: 'profile-edit container-fluid'

    regions:
      communitySelect: "#community_select_container"
      tagSelect: "#tag_select_container"

    initialize: (options) ->
      super
      @delegate 'click', '#profile-edit-tabs a', @switchTabs
      @delegate('submit', 'form', @save)

    render: (options) ->
      super
      @communitySelect = new CommunitySelectView region: 'communitySelect', collection: new Communities
      @subview 'communitySelect', @communitySelect

      @acceptedCurrenciesSelect = new TagSelectView region: 'tagSelect', collection: @model.acceptedCurrenciesCollection, label: "Accepted Currencies", fieldName: "accepted_currencies"
      @subview 'acceptedCurrenciesSelect', @acceptedCurrenciesSelect

      Backbone.Validation.bind(@)
      bindings = Backbone.ModelBinder.createDefaultBindings(@$el, 'name');
      bindings["community_name"] = "#current-community"
      @modelBinder.bind(@model, @$el, bindings)

    switchTabs: (event) ->
      event.preventDefault()
      $(event.currentTarget).tab('show')

    save: (event) ->
      event.preventDefault()
      request = @model.save()
      request.done(=>
        @model.set('community_name', @communitySelect.collection.get(@model.get('community_id')).get('name'))
      )
      request.fail(=>
        @displayFormError()
        # TODO: Handle server side failure.
{'fraction_non_alphanumeric': 0.12431276725717777, 'fraction_numerical': 0.0006108735491753207, 'mean_word_length': 3.9174174174174174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5321952', 'n_tokens_mistral': 973, 'n_tokens_neox': 927, 'n_words': 193}