         Slug                :
           label             : "Address"
           itemClass         : KDCustomHTMLView
-          partial           : "#{location.protocol}//#{location.host}/"
+          partial           : "#{window.location.origin}"
         Visibility          :
           itemClass         : KDSelectBox
           label             : "Visibility"

      KD.remote.api.JGroup.suggestUniqueSlug slugy, (err, newSlug)->
        slugView.updatePartial "#{location.origin}/#{newSlug}"
        slug.setValue newSlug

  showCancellation: ->
    @hideWorkflow()
    return  if @cancellation
    @cancellation = new KDView partial: "<h1>This order has been cancelled.</h1>"
    @addSubView @cancellation


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

  hideWorkflow: ->
    @workflow.hide()

  workflowFinished: (@formData, @subscription) ->
    @hideWorkflow()

    {productData: {plan: {tags}}} = @formData
    if "vm" in tags
    then @showPaymentSucceded()
    else if "custom-plan" in tags
    then @showGroupForm()

  showCancellation: ->
    return  if @cancellation
    @hideWorkflow()
    @cancellation = new KDView partial: "<h1>This order has been cancelled.</h1>"
    @addSubView @cancellation

  showGroupForm: ->
    return  if @groupForm and not @groupForm.isDestroyed
    @hideWorkflow()
    @addSubView @groupForm = @createGroupForm()

  showPaymentSucceded: ->
    subtitle =
      if @formData.createAccount
      then "Please check your email to complete your registration."
      else "Now it’s time, time to start Koding!"

    @addSubView thankYou = new KDCustomHTMLView
      cssClass : "pricing-thank-you"
      partial  :
        """
        <i class="check-icon"></i>
        <h3 class="pricing-title">So much wow, so much horse-power!</h3>
        <h6 class="pricing-subtitle">#{subtitle}</h6>
        """

    if @formData.loggedIn
      thankYou.addSubView new KDButtonView
        style    : "solid green"
        title    : "Go to your environment"
        callback : ->
          KD.singleton("router").handleRoute "/Environments"

  showGroupCreated: (group, subscription) ->
    planCodes = Object.keys subscription.quantities
    KD.remote.api.JPaymentProduct.some {planCode: $in: planCodes}, limit: 30, (err, products) =>
      return  if KD.showError err

      subtitle =
        if @formData.createAccount
        then "Please check your email to complete your registration."
        else ""

      @addSubView thankYou = new KDCustomHTMLView
        cssClass : "pricing-thank-you"
        partial  :
          """
          <i class="check-icon"></i>
          <h3 class="pricing-title"><strong>#{group.title}</strong> has been successfully created</h3>
          <h6 class="pricing-subtitle">#{subtitle}</h6>
          """

      productList = products.map (product) ->
        "<div>#{subscription.quantities[product.planCode]}x #{product.title}</div>"

      thankYou.addSubView new KDCustomHTMLView
        cssClass : "product-list"
        partial  : productList.join ""

      if @formData.loggedIn
        thankYou.addSubView new KDButtonView
          title    : "Go to Group"
          callback : ->
            window.open "#{window.location.origin}/#{group.slug}", "_blank"

  createGroupForm: ->
    return new KDFormViewWithFields
      title                 : "Enter new group name"
      cssClass              : "pricing-create-group"
      callback              : @bound "createGroup"
