<commit_before><script lang="coffee">
import AppConfig      from '@/shared/services/app_config'
import AbilityService from '@/shared/services/ability_service'
import Records  from '@/shared/services/records'
import { groupPrivacy, groupPrivacyStatement } from '@/shared/helpers/helptext'
import { submitForm }          from '@/shared/helpers/form'
import { groupPrivacyConfirm } from '@/shared/helpers/helptext'
import { submitOnEnter }       from '@/shared/helpers/keyboard'

export default
  props:
    group: Object
    close: Function

  data: ->
    clone: @group.clone()
    isDisabled: false
    rules: {
      required: (value) ->
        !!value || 'Required.'
    }
    submit: null
    uploading: false
    progress: 0

  mounted: ->
    @featureNames = AppConfig.features.group
    @submit = submitForm @, @clone,
      prepareFn: =>
        allowPublic = @clone.allowPublicThreads
        @clone.discussionPrivacyOptions = switch @clone.groupPrivacy
          when 'open'   then 'public_only'
          when 'closed' then (if allowPublic then 'public_or_private' else 'private_only')
          when 'secret' then 'private_only'

        @clone.parentMembersCanSeeDiscussions = switch @clone.groupPrivacy
          when 'open'   then true
          when 'closed' then @clone.parentMembersCanSeeDiscussions
          when 'secret' then false
      confirmFn: (model)          => @$t groupPrivacyConfirm(model)
      flashSuccess:               => "group_form.messages.group_#{@actionName}"
      successCallback: (data) =>
        @isExpanded = false
        groupKey = data.groups[0].key
        @close()
        @$router.push("/g/#{groupKey}")
  methods:
    expandForm: ->
      @isExpanded = true

    privacyStringFor: (privacy) ->
      @$t groupPrivacy(@clone, privacy),
        parent: @clone.parentName()

    selectCoverPhoto: ->
      @$refs.coverPhotoInput.click()

    selectLogo: ->
      @$refs.logoInput.click()

    uploadCoverPhoto: ->
      @uploading = true
      Records.groups.remote.onUploadSuccess = (response) =>
        Records.import response
        @uploading = false
      Records.groups.remote.upload("#{@group.id}/upload_photo/cover_photo", @$refs.coverPhotoInput.files[0], {}, (args) => @progress = args.loaded / args.total * 100)

    uploadLogo: ->
      @uploading = true
      Records.groups.remote.onUploadSuccess = (response) =>
        Records.import response
        @uploading = false
      Records.groups.remote.upload("#{@group.id}/upload_photo/logo", @$refs.logoInput.files[0], {}, (args) => @progress = args.loaded / args.total * 100)

  computed:
    actionName: ->
      if @clone.isNew() then 'created' else 'updated'

    titleLabel: ->
      if @clone.isParent()
        "group_form.group_name"
      else
        "group_form.subgroup_name"

    privacyOptions: ->
      if @clone.isSubgroup() && @clone.parent().groupPrivacy == 'secret'
        ['closed', 'secret']
      else
        ['open', 'closed', 'secret']

    privacyStatement: ->
      @$t groupPrivacyStatement(@clone),
        parent: @clone.parentName()

    showGroupFeatures: ->
      AbilityService.isSiteAdmin() and _.some(@featureNames)

    groupNamePlaceholder: ->
      if @clone.parentId
        'group_form.group_name_placeholder'
      else
        'group_form.organization_name_placeholder'

    groupNameLabel: ->
      if @clone.parentId
        'group_form.group_name'
      else
        'group_form.organization_name'
</script>

<template lang="pug">
v-card.group-form
  v-overlay(:value="uploading")
    v-progress-circular(size="64" :value="progress")
  submit-overlay(:value='clone.processing')
  v-card-title
    v-layout(justify-space-between style="align-items: center")
      .group-form__group-title
        h1.headline(v-if='clone.parentId', v-t="'group_form.edit_group_heading'")
        h1.headline(v-if='!clone.parentId', v-t="'group_form.edit_organization_heading'")
      dismiss-modal-button(:close='close')
  v-card-text

    v-tabs(fixed-tabs)
      v-tab(v-t="'group_form.profile'")
      v-tab(v-t="'group_form.privacy'")
      v-tab(v-t="'group_form.permissions'")

      v-tab-item.mt-8
        v-img.group_form__file-select(:src="group.coverUrl()" width="100%"  @click="selectCoverPhoto()")
        group-avatar.group_form__file-select.group_form__logo(v-if="!group.parentId" :group="group" size="72px" :on-click="selectLogo" :elevation="4")
        v-text-field.group-form__name#group-name.mt-4(v-model='clone.name', :placeholder="$t(groupNamePlaceholder)", :rules='[rules.required]', maxlength='255', :label="$t(groupNameLabel)")
        v-spacer

        input.hidden.change-picture-form__file-input(type="file" ref="coverPhotoInput" @change='uploadCoverPhoto')
        input.hidden.change-picture-form__file-input(type="file" ref="logoInput" @change='uploadLogo')

        lmo-textarea.group-form__group-description(:model='group' field="description" :placeholder="$t('group_form.description_placeholder')" :label="$t('group_form.description')")
        validation-errors(:subject="group", field="name")

      v-tab-item.mt-8
        .group-form__section.group-form__privacy
          v-radio-group(v-model='clone.groupPrivacy')
            v-radio(v-for='privacy in privacyOptions' :key="privacy" :class="'md-checkbox--with-summary group-form__privacy-' + privacy" :value='privacy' :aria-label='privacy')
              template(slot='label')
                .group-form__privacy-title
                  strong(v-t="'common.privacy.' + privacy")
                  mid-dot
                  span {{ privacyStringFor(privacy) }}<commit_msg>fix(group): incorrect model for textarea; use the clone not the og<commit_after><script lang="coffee">
import AppConfig      from '@/shared/services/app_config'
import AbilityService from '@/shared/services/ability_service'
import Records  from '@/shared/services/records'
import { groupPrivacy, groupPrivacyStatement } from '@/shared/helpers/helptext'
import { submitForm }          from '@/shared/helpers/form'
import { groupPrivacyConfirm } from '@/shared/helpers/helptext'
import { submitOnEnter }       from '@/shared/helpers/keyboard'

export default
  props:
    group: Object
    close: Function

  data: ->
    clone: @group.clone()
    isDisabled: false
    rules: {
      required: (value) ->
        !!value || 'Required.'
    }
    submit: null
    uploading: false
    progress: 0

  mounted: ->
    @featureNames = AppConfig.features.group
    @submit = submitForm @, @clone,
      prepareFn: =>
        allowPublic = @clone.allowPublicThreads
        @clone.discussionPrivacyOptions = switch @clone.groupPrivacy
          when 'open'   then 'public_only'
          when 'closed' then (if allowPublic then 'public_or_private' else 'private_only')
          when 'secret' then 'private_only'

        @clone.parentMembersCanSeeDiscussions = switch @clone.groupPrivacy
          when 'open'   then true
          when 'closed' then @clone.parentMembersCanSeeDiscussions
          when 'secret' then false
      confirmFn: (model)          => @$t groupPrivacyConfirm(model)
      flashSuccess:               => "group_form.messages.group_#{@actionName}"
      successCallback: (data) =>
        @isExpanded = false
        groupKey = data.groups[0].key
        @close()
        @$router.push("/g/#{groupKey}")
  methods:
    expandForm: ->
      @isExpanded = true

    privacyStringFor: (privacy) ->
      @$t groupPrivacy(@clone, privacy),
        parent: @clone.parentName()

    selectCoverPhoto: ->
      @$refs.coverPhotoInput.click()

    selectLogo: ->
      @$refs.logoInput.click()

    uploadCoverPhoto: ->
      @uploading = true
      Records.groups.remote.onUploadSuccess = (response) =>
        Records.import response
        @uploading = false
      Records.groups.remote.upload("#{@group.id}/upload_photo/cover_photo", @$refs.coverPhotoInput.files[0], {}, (args) => @progress = args.loaded / args.total * 100)

    uploadLogo: ->
      @uploading = true
      Records.groups.remote.onUploadSuccess = (response) =>
        Records.import response
        @uploading = false
      Records.groups.remote.upload("#{@group.id}/upload_photo/logo", @$refs.logoInput.files[0], {}, (args) => @progress = args.loaded / args.total * 100)

  computed:
    actionName: ->
      if @clone.isNew() then 'created' else 'updated'

    titleLabel: ->
      if @clone.isParent()
        "group_form.group_name"
      else
        "group_form.subgroup_name"

    privacyOptions: ->
      if @clone.isSubgroup() && @clone.parent().groupPrivacy == 'secret'
        ['closed', 'secret']
      else
        ['open', 'closed', 'secret']

    privacyStatement: ->
      @$t groupPrivacyStatement(@clone),
        parent: @clone.parentName()

    showGroupFeatures: ->
      AbilityService.isSiteAdmin() and _.some(@featureNames)

    groupNamePlaceholder: ->
      if @clone.parentId
        'group_form.group_name_placeholder'
      else
        'group_form.organization_name_placeholder'

    groupNameLabel: ->
      if @clone.parentId
        'group_form.group_name'
      else
        'group_form.organization_name'
</script>

<template lang="pug">
v-card.group-form
  v-overlay(:value="uploading")
    v-progress-circular(size="64" :value="progress")
  submit-overlay(:value='clone.processing')
  v-card-title
    v-layout(justify-space-between style="align-items: center")
      .group-form__group-title
        h1.headline(v-if='clone.parentId', v-t="'group_form.edit_group_heading'")
        h1.headline(v-if='!clone.parentId', v-t="'group_form.edit_organization_heading'")
      dismiss-modal-button(:close='close')
  v-card-text

    v-tabs(fixed-tabs)
      v-tab(v-t="'group_form.profile'")
      v-tab(v-t="'group_form.privacy'")
      v-tab(v-t="'group_form.permissions'")

      v-tab-item.mt-8
        v-img.group_form__file-select(:src="group.coverUrl()" width="100%"  @click="selectCoverPhoto()")
        group-avatar.group_form__file-select.group_form__logo(v-if="!group.parentId" :group="group" size="72px" :on-click="selectLogo" :elevation="4")
        v-text-field.group-form__name#group-name.mt-4(v-model='clone.name', :placeholder="$t(groupNamePlaceholder)", :rules='[rules.required]', maxlength='255', :label="$t(groupNameLabel)")
        v-spacer

        input.hidden.change-picture-form__file-input(type="file" ref="coverPhotoInput" @change='uploadCoverPhoto')
        input.hidden.change-picture-form__file-input(type="file" ref="logoInput" @change='uploadLogo')

        lmo-textarea.group-form__group-description(:model='clone' field="description" :placeholder="$t('group_form.description_placeholder')" :label="$t('group_form.description')")
        validation-errors(:subject="clone", field="name")

      v-tab-item.mt-8
        .group-form__section.group-form__privacy
          v-radio-group(v-model='clone.groupPrivacy')
            v-radio(v-for='privacy in privacyOptions' :key="privacy" :class="'md-checkbox--with-summary group-form__privacy-' + privacy" :value='privacy' :aria-label='privacy')
              template(slot='label')
                .group-form__privacy-title
                  strong(v-t="'common.privacy.' + privacy")
                  mid-dot
                  span {{ privacyStringFor(privacy) }}
{'fraction_non_alphanumeric': 0.1457353332741635, 'fraction_numerical': 0.00461524806958374, 'mean_word_length': 3.0634691669671836, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, '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': '2211642', 'n_tokens_mistral': 3542, 'n_tokens_neox': 3441, 'n_words': 558}