<commit_before>class GroupCreationModal extends KDModalView

  constructor:(options = {}, data)->

    options.title    or= 'Create a new group'
    options.height   or= 'auto'
    options.cssClass or= "group-admin-modal compose-message-modal admin-kdmodal"
    options.width     ?= 684
    options.overlay   ?= yes

    super options, data

  fetchRecurlyPlans:(callback)->

    # Recurly name: group_vm_*_1
    KD.remote.api.JRecurlyPlan.getPlans "group", "vm", callback
      # plans.forEach (p)->
      #   console.log p.product.item # xs, s, m, l, xl
      #   console.log p.feeMonthly # in cents

    # p.getToken ->
    #   console.log "Emailed PIN"

  charge:(callback)->
    p.subscribe
      pin: '0000'
    , (err, subs)->
      console.log subs

  viewAppended:->

    @addSubView @typeSelector = new KDFormViewWithFields
      fields                   :
        label                  :
          itemClass            : KDCustomHTMLView
          tagName              : 'h2'
          cssClass             : 'heading'
          partial              : "<span>1</span> What will be this group for?"
        selector               :
          name                 : "type"
          itemClass            : GroupCreationSelector
          cssClass             : "group-type"
          radios               : [
            { title : "University/School", value : "educational" }
            { title : "Company",           value : "company" }
            { title : "Project",           value : "project" }
            { title : "Other",             value : "custom" }
          ]
          change               : =>
            # log @typeSelector.inputs.selector.getValue()
            @hostSelector?.show()

    @fetchRecurlyPlans (err, plans)=>

      # fix this one on radios value cannot have some chars and that's why i keep index as the value
      radios = plans.map (plan,i)-> { title : plan.product.item.slice(1), value : i }

      @addSubView @hostSelector = new KDFormViewWithFields
        cssClass                 : 'hidden'
        buttons                  :
          submit                 :
            title                : "Pay & Create the Group"
            style                : "modal-clean-gray hidden"
            type                 : "button"
            callback             : ->
              # Copy account creator's billing information
              KD.remote.api.JRecurlyPlan.getUserAccount (err, data)->
                if err or not data
                  data = {}
                delete data.cardNumber
                delete data.cardMonth
                delete data.cardYear
                delete data.cardCV
                modal = createAccountPaymentMethodModal data, (newData, onError, onSuccess) ->
                  KD.remote.api.JRecurlyAccount.create newData, (err, account)->
                    if err
                      onError()
                    else
                      onSuccess()
                      # FIXME: Call plan.charge({pin: 'xxxx}) here
        fields                   :
          label                  :
            itemClass            : KDCustomHTMLView
            tagName              : 'h2'
            cssClass             : 'heading'
            partial              : "<span>2</span> How big should the host server be?"
          selector               :
            name                 : "host"
            itemClass            : GroupCreationSelector
            cssClass             : "host-type"
            radios               : radios
            change               : =>
              {submit}         = @hostSelector.buttons
              {desc, selector} = @hostSelector.inputs
              descField        = @hostSelector.fields.desc
              descField.show()
              desc.show()
              index      = parseInt selector.getValue(), 10
              monthlyFee = (plans[index].feeMonthly/100).toFixed(2)
              submit.setTitle "Pay & Create the Group for $#{monthlyFee}/mo"
              submit.show()
              desc.$('p').addClass 'hidden'
              desc.$('p').eq(index).removeClass 'hidden'
          desc                   :
            itemClass            : KDCustomHTMLView<commit_msg>Ask for credit card information<commit_after>class GroupCreationModal extends KDModalView

  constructor:(options = {}, data)->

    options.title    or= 'Create a new group'
    options.height   or= 'auto'
    options.cssClass or= "group-admin-modal compose-message-modal admin-kdmodal"
    options.width     ?= 684
    options.overlay   ?= yes

    super options, data

  fetchRecurlyPlans:(callback)->

    # Recurly name: group_vm_*_1
    KD.remote.api.JRecurlyPlan.getPlans "group", "vm", callback
      # plans.forEach (p)->
      #   console.log p.product.item # xs, s, m, l, xl
      #   console.log p.feeMonthly # in cents

    # p.getToken ->
    #   console.log "Emailed PIN"

  charge:(callback)->
    p.subscribe
      pin: '0000'
    , (err, subs)->
      console.log subs

  viewAppended:->

    @addSubView @typeSelector = new KDFormViewWithFields
      fields                   :
        label                  :
          itemClass            : KDCustomHTMLView
          tagName              : 'h2'
          cssClass             : 'heading'
          partial              : "<span>1</span> What will be this group for?"
        selector               :
          name                 : "type"
          itemClass            : GroupCreationSelector
          cssClass             : "group-type"
          radios               : [
            { title : "University/School", value : "educational" }
            { title : "Company",           value : "company" }
            { title : "Project",           value : "project" }
            { title : "Other",             value : "custom" }
          ]
          change               : =>
            # log @typeSelector.inputs.selector.getValue()
            @hostSelector?.show()

    @fetchRecurlyPlans (err, plans)=>

      # fix this one on radios value cannot have some chars and that's why i keep index as the value
      radios = plans.map (plan,i)-> { title : plan.product.item.slice(1), value : i }

      @addSubView @hostSelector = new KDFormViewWithFields
        cssClass                 : 'hidden'
        buttons                  :
          submit                 :
            title                : "Pay & Create the Group"
            style                : "modal-clean-gray hidden"
            type                 : "button"
            callback             : =>

              # Copy account creator's billing information
              KD.remote.api.JRecurlyPlan.getUserAccount (err, data)=>
                if err or not data
                  data = {}

                # These will go into Recurly module
                delete data.cardNumber
                delete data.cardMonth
                delete data.cardYear
                delete data.cardCV

                modal = createAccountPaymentMethodModal data, (newData, onError, onSuccess)=>

                  # These will go into Recurly module
                  newData.username    = 'group_unnamed'
                  newData.ipAddress   = '0.0.0.0'
                  newData.firstName   = 'Group'
                  newData.lastName    = 'Unnamed'
                  newData.email       = '<EMAIL>'
                  newData.pin         = 'xxx'
                  newData.accountCode = yes

                  {selector}   = @hostSelector.inputs
                  index        = parseInt selector.getValue(), 10

                  selectedPlan = plans[index]
                  selectedPlan.subscribe newData, (err, subscription)->
                    if err
                      # Show error messages here.
                      onError()
                    else
                      # DONE
                      console.log "Subscribed user account:", subscription.userCode
                      onSuccess()

        fields                   :
          label                  :
            itemClass            : KDCustomHTMLView
            tagName              : 'h2'
            cssClass             : 'heading'
            partial              : "<span>2</span> How big should the host server be?"
          selector               :
            name                 : "host"
            itemClass            : GroupCreationSelector
            cssClass             : "host-type"
            radios               : radios
            change               : =>
              {submit}         = @hostSelector.buttons
              {desc, selector} = @hostSelector.inputs
              descField        = @hostSelector.fields.desc
              descField.show()
              desc.show()
              index      = parseInt selector.getValue(), 10
              monthlyFee = (plans[index].feeMonthly/100).toFixed(2)
              submit.setTitle "Pay & Create the Group for $#{monthlyFee}/mo"
              submit.show()
              desc.$('p').addClass 'hidden'
              desc.$('p').eq(index).removeClass 'hidden'
          desc                   :
            itemClass            : KDCustomHTMLView
{'fraction_non_alphanumeric': 0.08821929729141738, 'fraction_numerical': 0.004786250407919069, 'mean_word_length': 1.175579744439186, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3023724', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2191, 'n_words': 556}