<commit_before>class DomainCreationForm extends KDTabViewWithForms

  domainNameValidation =
    rules      :
      required : yes
      regExp   : /^([\da-z\.-]+)\.([a-z\.]{2,6})$/i
    messages   :
      required : "Enter your domain name"
      regExp   : "This doesn't look like a valid domain name."

  constructor:->

    {nickname, firstName, lastName} = KD.whoami().profile

    domainOptions     = [
      { title : "Create a subdomain", value : "subdomain" }
      { title : "I want to register a domain", value : "new" }
      { title : "I already have a domain", value : "existing" }
    ]

    super
      navigable                       : no
      goToNextFormOnSubmit            : no
      hideHandleContainer             : yes
      forms                           :
        "Domain Address"              :
          callback                    : @bound "registerDomain"
          buttons                     :
            registerButton             :
              title                   : "Register Domain"
              style                   : "cupid-green hidden"
              type                    : "submit"
              loader                  :
                color                 : "#ffffff"
                diameter              : 24
              callback                : =>

            createButton              :
              title                   : "Add Domain"
              style                   : "cupid-green"
              type                    : "submit"
              loader                  :
                color                 : "#ffffff"
                diameter              : 24
            close                     :
              title                   : "Back to settings"
              style                   : "cupid-green hidden"
              callback                : => @reset()
            cancel                    :
              style                   : "modal-cancel"
              callback                : => @emit 'DomainCreationCancelled'
            another                   :
              title                   : "add another domain"
              style                   : "modal-cancel hidden"
              callback                : => @addAnotherDomainClicked()
          fields                      :
            header                    :
              title                   : "Add a domain"
              itemClass               : KDHeaderView
            DomainOption              :
              name                    : "DomainOption"
              itemClass               : KDRadioGroup
              cssClass                : "group-type"
              defaultValue            : "subdomain"
              radios                  : domainOptions
              change                  : =>
                {DomainOption, domainName, domains, regYears} = @forms["Domain Address"].inputs
                actionState = DomainOption.getValue()
                domainName.getElement().setAttribute 'placeholder', switch actionState
                  when "new"
                    @suggestionBox?.show()
                    # domainName.setValidation domainNameValidation
                    domains.hide()
                    regYears.show()
                    @needBilling yes
                    "#{KD.utils.slugify firstName}s-new-domain.com"
                  when "existing"
                    @suggestionBox?.hide()
                    # domainName.setValidation domainNameValidation
                    domains.hide()
                    regYears.hide()
                    @needBilling no
                    "#{KD.utils.slugify firstName}s-existing-domain.com"
                  when "subdomain"
                    # domainName.unsetValidation()
                    @suggestionBox?.hide()
                    domains.show()
                    regYears.hide()
                    @needBilling no
                    "#{KD.utils.slugify firstName}s-subdomain"
            domainName                :
              cssClass                : "domain"
              placeholder             : "#{KD.utils.slugify firstName}s-subdomain"
              validate                :
                rules                 :
                  required            : yes
                messages              :
                  required            : "Subdomain name is required!"
              nextElement             :
                regYears              :
                  cssClass            : "hidden"
                  itemClass           : KDSelectBox
                  selectOptions       : ({title: "#{i} Year#{if i > 1 then 's' else ''}", value:i} for i in [1..10])
                domains               :
                  cssClass            : "domains"
                  itemClass           : KDSelectBox
                  validate            :
                    rules             :
                      required        : yes
                    messages          :
                      required        : "Please select a parent domain."
            suggestionBox             :
              type                    : "hidden"

    form = @forms["Domain Address"]
    {createButton} = form.buttons

    form.on "FormValidationFailed", createButton.bound 'hideLoader'
    @on "DomainCreationCancelled", createButton.bound 'hideLoader'

  viewAppended:->
    KD.whoami().fetchDomains (err, userDomains)=>
      warn err  if err
      domainList = []
      for domain in userDomains
        if not domain.regYears > 0
          domainList.push {title:".#{domain.domain}", value:domain.domain}
      @forms["Domain Address"].inputs.domains.setSelectOptions domainList

  needBilling:(paymentRequired)->
    form = @forms["Domain Address"]
    {createButton, registerButton} = form.buttons

    unless paymentRequired
      createButton.show()
      registerButton.hide()
      return
    createButton.hide()
    registerButton.show()

  registerDomain:->
    form = @forms["Domain Address"]
    {createButton, registerButton} = form.buttons
    @clearSuggestions()

    {DomainOption, domainName, regYears, domains} = form.inputs
    splittedDomain    = domainName.getValue().split "."
    domain            = splittedDomain.first
    tld               = splittedDomain.slice(1).join('')
    domainInput       = domainName
    domainName        = domainInput.getValue()

    domainOptionValue = DomainOption.getValue()

    if domainOptionValue is 'new'
      KD.remote.api.JDomain.isDomainAvailable domain, tld, (avErr, status, suggestions)=>

        if avErr
          createButton.hideLoader()
          log domain
          log tld
          log avErr
          return notifyUser "An error occured: #{avErr}"

        switch status
          when "regthroughus", "regthroughothers"
            @showSuggestions suggestions
            registerButton.hideLoader()
            return createButton.hideLoader()
          when "unknown"
            notifyUser "An error occured. Please try again later."
            return createButton.hideLoader()
        form = @forms["Domain Address"]
        {createButton, registerButton} = form.buttons
        paymentController = KD.getSingleton('paymentController')
        group             = KD.getSingleton("groupsController").getCurrentGroup()

        registerTheDomain () = ->
            KD.remote.api.JDomain.registerDomain
              domainName : domainInput.getValue()
              years      : regYears.getValue()
            , (err, domain)=><commit_msg>added tld price endpoint and client<commit_after>class DomainCreationForm extends KDTabViewWithForms

  domainNameValidation =
    rules      :
      required : yes
      regExp   : /^([\da-z\.-]+)\.([a-z\.]{2,6})$/i
    messages   :
      required : "Enter your domain name"
      regExp   : "This doesn't look like a valid domain name."

  constructor:->

    {nickname, firstName, lastName} = KD.whoami().profile

    domainOptions     = [
      { title : "Create a subdomain", value : "subdomain" }
      { title : "I want to register a domain", value : "new" }
      { title : "I already have a domain", value : "existing" }
    ]

    super
      navigable                       : no
      goToNextFormOnSubmit            : no
      hideHandleContainer             : yes
      forms                           :
        "Domain Address"              :
          callback                    : @bound "registerDomain"
          buttons                     :
            registerButton             :
              title                   : "Register Domain"
              style                   : "cupid-green hidden"
              type                    : "submit"
              loader                  :
                color                 : "#ffffff"
                diameter              : 24
              callback                : =>

            createButton              :
              title                   : "Add Domain"
              style                   : "cupid-green"
              type                    : "submit"
              loader                  :
                color                 : "#ffffff"
                diameter              : 24
            close                     :
              title                   : "Back to settings"
              style                   : "cupid-green hidden"
              callback                : => @reset()
            cancel                    :
              style                   : "modal-cancel"
              callback                : => @emit 'DomainCreationCancelled'
            another                   :
              title                   : "add another domain"
              style                   : "modal-cancel hidden"
              callback                : => @addAnotherDomainClicked()
          fields                      :
            header                    :
              title                   : "Add a domain"
              itemClass               : KDHeaderView
            DomainOption              :
              name                    : "DomainOption"
              itemClass               : KDRadioGroup
              cssClass                : "group-type"
              defaultValue            : "subdomain"
              radios                  : domainOptions
              change                  : =>
                {DomainOption, domainName, domains, regYears} = @forms["Domain Address"].inputs
                actionState = DomainOption.getValue()
                domainName.getElement().setAttribute 'placeholder', switch actionState
                  when "new"
                    @suggestionBox?.show()
                    # domainName.setValidation domainNameValidation
                    domains.hide()
                    regYears.show()
                    @needBilling yes
                    "#{KD.utils.slugify firstName}s-new-domain.com"
                  when "existing"
                    @suggestionBox?.hide()
                    # domainName.setValidation domainNameValidation
                    domains.hide()
                    regYears.hide()
                    @needBilling no
                    "#{KD.utils.slugify firstName}s-existing-domain.com"
                  when "subdomain"
                    # domainName.unsetValidation()
                    @suggestionBox?.hide()
                    domains.show()
                    regYears.hide()
                    @needBilling no
                    "#{KD.utils.slugify firstName}s-subdomain"
            domainName                :
              cssClass                : "domain"
              placeholder             : "#{KD.utils.slugify firstName}s-subdomain"
              validate                :
                rules                 :
                  required            : yes
                messages              :
                  required            : "Subdomain name is required!"
              nextElement             :
                regYears              :
                  cssClass            : "hidden"
                  itemClass           : KDSelectBox
                  selectOptions       : ({title: "#{i} Year#{if i > 1 then 's' else ''}", value:i} for i in [1..10])
                domains               :
                  cssClass            : "domains"
                  itemClass           : KDSelectBox
                  validate            :
                    rules             :
                      required        : yes
                    messages          :
                      required        : "Please select a parent domain."
            suggestionBox             :
              type                    : "hidden"

    form = @forms["Domain Address"]
    {createButton} = form.buttons

    form.on "FormValidationFailed", createButton.bound 'hideLoader'
    @on "DomainCreationCancelled", createButton.bound 'hideLoader'

  viewAppended:->
    KD.whoami().fetchDomains (err, userDomains)=>
      warn err  if err
      domainList = []
      for domain in userDomains
        if not domain.regYears > 0
          domainList.push {title:".#{domain.domain}", value:domain.domain}
      @forms["Domain Address"].inputs.domains.setSelectOptions domainList

  needBilling:(paymentRequired)->
    form = @forms["Domain Address"]
    {createButton, registerButton} = form.buttons

    unless paymentRequired
      createButton.show()
      registerButton.hide()
      return
    createButton.hide()
    registerButton.show()

  registerDomain:->
    form = @forms["Domain Address"]
    {createButton, registerButton} = form.buttons
    @clearSuggestions()

    {DomainOption, domainName, regYears, domains} = form.inputs
    splittedDomain    = domainName.getValue().split "."
    domain            = splittedDomain.first
    tld               = splittedDomain.slice(1).join('')
    domainInput       = domainName
    domainName        = domainInput.getValue()

    domainOptionValue = DomainOption.getValue()

    if domainOptionValue is 'new'
      KD.remote.api.JDomain.isDomainAvailable domain, tld, (avErr, status, suggestions)=>

        if avErr
          createButton.hideLoader()
          log domain
          log tld
          log avErr
          return notifyUser "An error occured: #{avErr}"

        switch status
          when "regthroughus", "regthroughothers"
            @showSuggestions suggestions
            registerButton.hideLoader()
            return createButton.hideLoader()
          when "unknown"
            notifyUser "An error occured. Please try again later."
            return createButton.hideLoader()
        form = @forms["Domain Address"]
        {createButton, registerButton} = form.buttons
        paymentController = KD.getSingleton('paymentController')
        group             = KD.getSingleton("groupsController").getCurrentGroup()

        registerTheDomain = ->
            KD.remote.api.JDomain.registerDomain
              domainName : domainInput.getValue()
              years      : regYears.getValue()
            , (err, domain)=>
{'fraction_non_alphanumeric': 0.07949041204963174, 'fraction_numerical': 0.0015924623449008028, 'mean_word_length': 1.097703549060543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '5665202', 'n_tokens_mistral': 3497, 'n_tokens_neox': 3254, 'n_words': 766}