<commit_before>class PricingAppView extends KDView

  addWorkflow: (@workflow) ->
    @addSubView @workflow
    @workflow.on 'Finished', @bound "showThankYou"
    @workflow.on 'Cancel', @bound "showCancellation"

  hideWorkflow: ->
    @workflow.hide()

  showThankYou: (@workflowData, @subscription) ->
    @hideWorkflow()

    @thankYou = new KDCustomHTMLView
      partial:
        """
        <h1>Thank you!</h1>
        <p>
          Your order has been processed.
        </p>
        #{
          if @subscription.createAccount
          then "<p>Please check your email for your registration link.</p>"
          else "<p>We hope you enjoy your new subscription</p>"
        }
        """

    if "custom-plan" in @workflowData.productData.plan.tags
      @thankYou.addSubView @createGroupNameForm()

    @addSubView @thankYou

  createGroupNameForm: ->
    @groupForm              = new KDFormViewWithFields
      title                 : "Enter new group name"
      callback              : @bound "createGroup"
      buttons               :
        Create              :
          title             : "Create"
          type              : "submit"
      fields                :
        GroupName           :
          label             : "Group Name"
          type              : "text"
          name              : "groupName"
          placeholder       : "enter group name..."
          validate          :
            rules           :
              required      : yes
            messages        :
              required      : "Group name required"
        GroupUrl            :
          label             : "Group URL"
          type              : "text"
          name              : "groupURL"
          placeholder       : "enter group url..."
          keyup             : KD.utils.defer.bind this, @bound "checkSlug"
          validate          :
            rules           :
              required      : yes
            messages        :
              required      : "Group name required"
        Slug                :
          label             : "Address"
          itemClass         : KDCustomHTMLView
          partial           : "#{location.protocol}//#{location.host}/"
        Visibility          :
          itemClass         : KDSelectBox
          label             : "Visibility"
          type              : "select"
          name              : "visibility"
          defaultValue      : "hidden"
          selectOptions     : [
            { title : "Hidden",    value : "hidden"  }
            { title : "Visible",   value : "visible" }
          ]

  createGroup: ->
    unless @subscription
      return KD.showError "Subscription failed"

    groupName  = @groupForm.inputs.GroupName.getValue()
    visibility = @groupForm.inputs.Visibility.getValue()
    slug       = @groupForm.inputs.GroupUrl.getValue()

    options      =
      title      : groupName
      body       : groupName
      slug       : slug
      visibility : visibility

    KD.remote.api.JGroup.create options, (err, group) =>
      return KD.showError err  if err
      group.addSubscription @subscription.getId(), (err) =>
        return KD.showError err  if err
        @showSummaryModal group

  showSummaryModal: (group)->
    {planOptions: {userQuantity, resourceQuantity}} = @workflowData.productData

    modal              = new KDModalView
      title            : "Group successfully created"
      width            : 600
      overlay          : yes
      buttons          :
        "Go to Group"  :
          style        : "modal-clean-red"
          callback     : ->
            window.open "#{window.location.origin}/#{group.slug}", "_blank"
        Close          :
          style        : "modal-cancel"
          callback     : -> modal.destroy()
      content          :
        """
          <div>https://koding.com/#{group.slug}</div>
          <div>Users: #{userQuantity}</div>
          <div>Resource packs: #{resourceQuantity}</div>
        """

  checkSlug: ->
    slug      = @groupForm.inputs.GroupUrl<commit_msg> Merge branch 'master.groups.bot' into 'master.groups'<commit_after>class PricingAppView extends KDView

  addWorkflow: (@workflow) ->
    @addSubView @workflow
    @workflow.on 'Finished', @bound "showThankYou"
    @workflow.on 'Cancel', @bound "showCancellation"

  hideWorkflow: ->
    @workflow.hide()

  showThankYou: (@workflowData, @subscription) ->
    @hideWorkflow()

    @thankYou = new KDCustomHTMLView
      partial:
        """
        <h1>Thank you!</h1>
        <p>
          Your order has been processed.
        </p>
        #{
          if @subscription.createAccount
          then "<p>Please check your email for your registration link.</p>"
          else "<p>We hope you enjoy your new subscription</p>"
        }
        """

    if "custom-plan" in @workflowData.productData.plan.tags
      @thankYou.addSubView @createGroupNameForm()

    @addSubView @thankYou

  createGroupNameForm: ->
    @groupForm              = new KDFormViewWithFields
      title                 : "Enter new group name"
      callback              : @bound "createGroup"
      buttons               :
        Create              :
          title             : "Create"
          type              : "submit"
      fields                :
        GroupName           :
          label             : "Group Name"
          type              : "text"
          name              : "groupName"
          placeholder       : "enter group name..."
          validate          :
            rules           :
              required      : yes
            messages        :
              required      : "Group name required"
        GroupUrl            :
          label             : "Group URL"
          type              : "text"
          name              : "groupURL"
          placeholder       : "enter group url..."
          keyup             : KD.utils.defer.bind this, @bound "checkSlug"
          validate          :
            rules           :
              required      : yes
            messages        :
              required      : "Group name required"
        Slug                :
          label             : "Address"
          itemClass         : KDCustomHTMLView
          partial           : "#{location.protocol}//#{location.host}/"
        Visibility          :
          itemClass         : KDSelectBox
          label             : "Visibility"
          type              : "select"
          name              : "visibility"
          defaultValue      : "hidden"
          selectOptions     : [
            { title : "Hidden",    value : "hidden"  }
            { title : "Visible",   value : "visible" }
          ]

  createGroup: ->
    unless @subscription
      return KD.showError "Subscription failed"

    groupName  = @groupForm.inputs.GroupName.getValue()
    visibility = @groupForm.inputs.Visibility.getValue()
    slug       = @groupForm.inputs.GroupUrl.getValue()

    options      =
      title      : groupName
      body       : groupName
      slug       : slug
      visibility : visibility

    {JGroup} = KD.remote.api
    JGroup.create options, (err, group) =>
      return KD.showError err  if err
      group.addSubscription @subscription.getId(), (err) =>
        return KD.showError err  if err
        @showSummaryModal group
        # enter first post of group.
        JGroup.createGroupBotAndPostMessage
          "title": "Welcome"
          "body" : "Welcome to your group."
          "botname":"groupbot"
        ,(err, update)->
          return KD.showError err if err


  showSummaryModal: (group)->
    {planOptions: {userQuantity, resourceQuantity}} = @workflowData.productData

    modal              = new KDModalView
      title            : "Group successfully created"
      width            : 600
      overlay          : yes
      buttons          :
        "Go to Group"  :
          style        : "modal-clean-red"
          callback     : ->
            window.open "#{window.location.origin}/#{group.slug}", "_blank"
        Close          :
          style        : "modal-cancel"
          callback     : -> modal.destroy()
      content          :
        """
          <div>https://koding.com/#{group.slug}</div>
          <div>Users: #{userQuantity}</div>
          <div>Resource packs: #{resourceQuantity}</div>
        """

  checkSlug: ->
    slug      = @groupForm.inputs.GroupUrl
{'fraction_non_alphanumeric': 0.09654110400379057, 'fraction_numerical': 0.0011845534233593934, 'mean_word_length': 1.3005449591280653, 'pattern_counts': {'":': 2, '<': 31, '<?xml version=': 0, '>': 54, 'https://': 2, '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': '4912228', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2121, 'n_words': 503}