<commit_before>Spine = require 'spine'
UserGroup = require 'models/user_group'
User = require 'zooniverse/lib/models/user'

class Group extends Spine.Controller
  constructor: ->
    super
    @headingText = $("#heading_text")
    UserGroup.bind 'create', @displayElements

    UserGroup.bind 'invited', (result) =>
      unless _.isEmpty(result.rejected_invites)
        message = I18n.t('navigator.groups.invited_users') + 
          I18n.t('navigator.groups.rejected') + 
          result.rejected_invites.join ', '
        @usersInvited.text message
      if @group.id is result.id
        UserGroup.create result
        @emails.val('')
        @submitButton.removeAttr 'disabled'
        @usersInvited.show()

    UserGroup.bind 'participate', =>
      @participateButton.hide()
      @stopParticipateButton.show()

    UserGroup.bind 'stop', =>
      @participateButton.show()
      @stopParticipateButton.hide()

  render: =>
    @html require('views/interactive/participate')(@)
    if @groupId
      if UserGroup.exists @groupId
        UserGroup.destroy(@groupId)
        UserGroup.fetch(@groupId)
      else
        UserGroup.fetch(@groupId)
    else
      @headingText.html "<h2>#{ I18n.t('navigator.groups.create') }</h2>"
      @submitButton.text I18n.t('navigator.groups.create_button')
      @signUpForm.show()
      @inviteForm.show()
      @classFollowupQuestion.hide()
      @classFollowupQuestionOpen.hide()
      @noClassroom.hide()
      @participation.hide()
      @statistics.hide()
      @talkLabel.show()

  displayElements: (group) =>
    @group = group
    @headingText.html "<h2>#{@group.name}</h2>"
    @groupStats()
    if @groupId is null
      @navigate "/navigator/group/#{ @group.id }"
    if @group.owner.id is User.current.id
      @submitButton.removeAttr 'disabled'
      @leaveGroupButton.hide()
      @destroyGroupButton.show()
      @inviteForm.show()
      @usersInvited.hide()
      @signUpForm.hide()
      @participation.show()
      url = "http://galaxyzoo.org/#/user_groups/#{group.unique_name}"
      @groupUrlHref.attr 'href', url
      @groupUrlHref.html url
      @groupUrl.show()
    if @group.id is User.current?.user_group_id<commit_msg>Add www so Safari doesn't reload page<commit_after>Spine = require 'spine'
UserGroup = require 'models/user_group'
User = require 'zooniverse/lib/models/user'

class Group extends Spine.Controller
  constructor: ->
    super
    @headingText = $("#heading_text")
    UserGroup.bind 'create', @displayElements

    UserGroup.bind 'invited', (result) =>
      unless _.isEmpty(result.rejected_invites)
        message = I18n.t('navigator.groups.invited_users') + 
          I18n.t('navigator.groups.rejected') + 
          result.rejected_invites.join ', '
        @usersInvited.text message
      if @group.id is result.id
        UserGroup.create result
        @emails.val('')
        @submitButton.removeAttr 'disabled'
        @usersInvited.show()

    UserGroup.bind 'participate', =>
      @participateButton.hide()
      @stopParticipateButton.show()

    UserGroup.bind 'stop', =>
      @participateButton.show()
      @stopParticipateButton.hide()

  render: =>
    @html require('views/interactive/participate')(@)
    if @groupId
      if UserGroup.exists @groupId
        UserGroup.destroy(@groupId)
        UserGroup.fetch(@groupId)
      else
        UserGroup.fetch(@groupId)
    else
      @headingText.html "<h2>#{ I18n.t('navigator.groups.create') }</h2>"
      @submitButton.text I18n.t('navigator.groups.create_button')
      @signUpForm.show()
      @inviteForm.show()
      @classFollowupQuestion.hide()
      @classFollowupQuestionOpen.hide()
      @noClassroom.hide()
      @participation.hide()
      @statistics.hide()
      @talkLabel.show()

  displayElements: (group) =>
    @group = group
    @headingText.html "<h2>#{@group.name}</h2>"
    @groupStats()
    if @groupId is null
      @navigate "/navigator/group/#{ @group.id }"
    if @group.owner.id is User.current.id
      @submitButton.removeAttr 'disabled'
      @leaveGroupButton.hide()
      @destroyGroupButton.show()
      @inviteForm.show()
      @usersInvited.hide()
      @signUpForm.hide()
      @participation.show()
      url = "http://www.galaxyzoo.org/#/user_groups/#{group.unique_name}"
      @groupUrlHref.attr 'href', url
      @groupUrlHref.html url
      @groupUrl.show()
    if @group.id is User.current?.user_group_id
{'fraction_non_alphanumeric': 0.13774354327140914, 'fraction_numerical': 0.005437245129134572, 'mean_word_length': 2.90017667844523, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '525299', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1391, 'n_words': 233}