<commit_before>class GroupCreationModal extends KDModalView

  GROUP_TYPES = [
    { title : "University/School", value : "educational" }
    { title : "Company",           value : "company" }
    { title : "Project",           value : "project" }
    { title : "Other",             value : "custom" }
  ]

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

    options.title    or= 'Create a new group'
    options.height   or= 'auto'
    options.cssClass or= "group-creation-modal"
    options.width     ?= 704
    options.overlay   ?= yes
    options.buttons    =
      submit           :
        title          : "Create"
        style          : "modal-clean-gray hidden"
        type           : "button"
        callback       : @bound "createGroup"
      next             :
        title          : "Next"
        style          : "modal-clean-gray"
        type           : "button"
        callback       : @bound "next"
      back             :
        title          : "back"
        style          : "modal-cancel hidden"
        type           : "button"
        callback       : @bound "back"

    super options, data

    @plans = []

  charge:(plan, callback)-> plan.subscribe { pin: '0000' }, callback

  setPositions:->
    super
    $scroller = @$('.kdmodal-content').eq(0)
    $scroller?.scrollTop $scroller[0].scrollHeight

  viewAppended:->

    @addSubView @typeSelector = new KDFormViewWithFields
      cssClass      : "type-selector"
      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    : GROUP_TYPES
          change    : =>
            @ready =>
              typeSelector = @typeSelector.inputs.selector
              # hostSelector = @hostSelector.inputs.selector
              sharedHost   = @hostSelector.inputs.sharedHost

              # @hostSelector?.show()

              # hostSelector.setValue switch typeSelector.getValue()
              #   when "educational" then "4"
              #   when "company"     then "2"
              #   when "project"     then "1"
              #   when "custom"      then "0"

              @setPositions()

    @addSubView @mainSettings = new KDFormViewWithFields
      cssClass                 : "general-settings hidden"
      fields                   :
        "Title"                :
          label                : "Title"
          name                 : "title"
          validate             :
            event              : "blur"
            rules              :
              required         : yes
              minLength        : 4
          keyup                : KD.utils.defer.bind this, @bound "makeSlug"
          placeholder          : 'Please enter your group title...'
        "HiddenSlug"           : { name : "slug", type : "hidden", cssClass : "hidden" }
        "Slug"                 :
          label                : "Address"
          partial              : "#{location.protocol}//#{location.host}/"
          itemClass            : KDCustomHTMLView
        "Description"          :
          label                : "Description"
          type                 : "textarea"
          name                 : "body"
          placeholder          : "Please enter a description for your group here..."
        "Privacy"              :
          label                : "Privacy/Visibility"
          itemClass            : KDSelectBox
          type                 : "select"
          name                 : "privacy"
          defaultValue         : "public"
          selectOptions        :
            Public             : [ { title : "Anyone can join",    value : "public" } ]
            Private            : [
              { title : "By invitation",       value : "by-invite" }
              { title : "By access request",   value : "by-request" }
              { title : "In same domain",      value : "same-domain" }
            ]
          nextElement          :
            "Visibility"       :
              itemClass        : KDSelectBox
              type             : "select"
              name             : "visibility"
              defaultValue     : "visible"
              cssClass         : "visibility"
              selectOptions    : [
                { title : "Visible in group listings", value : "visible" }
                { title : "Hidden in group listings",  value : "hidden" }
              ]

    vmController = @getSingleton('vmController')
    vmController.fetchVMPlans (err, plans)=>
      @plans = plans
      {descriptions, hostTypes} = vmController.sanitizeVMPlansForInputs plans

      descPartial = ""
      for d in descriptions
        descPartial += """
          <section>
            <p class='hidden'>
              <i>Good for:</i>
              <span>#{d.meta.goodFor}</span>
              <cite>VMs</cite>
            </p>
            #{d.description}
          </section>"""
      @addSubView @hostSelector = new KDFormViewWithFields
        cssClass         : "host-selector"
        fields           :
          label          :
            itemClass    : KDCustomHTMLView
            tagName      : 'h2'
            cssClass     : 'heading'
            partial      : "<span>2</span> Do you want a shared host for your Group?"
          sharedHost     :
            itemClass    : KDOnOffSwitch
            name         : "shared-vm"
            defaultValue : no
            cssClass     : "shared-vm"
            callback     : @bound "hostChanged"
          # selector    :
          #   name      : "host"
          #   itemClass : HostCreationSelector
          #   cssClass  : "host-type"
          #   radios    : hostTypes
          #   change    : @bound "hostChanged"
          desc        :
            itemClass : KDCustomHTMLView
            cssClass  : "description-field hidden"
            partial   : """<section>
              This VM is going to be shared among all members of your group, admins will receive sudo rights, each member will have a unix user account.
              </section>"""


      @addSubView @allocation = new KDFormViewWithFields
        cssClass          : "allocation"
        fields            :
          label           :
            itemClass     : KDCustomHTMLView
            tagName       : 'h2'
            cssClass      : 'heading'
            partial       : "<span>3</span> How much resources do you want to allocate to your each user?"
          sharedHost      :
            itemClass     : KDSelectBox
            type          : "select"
            name          : "allocation"
            defaultValue  : "10"
            cssClass      : "allocation"
            change        : @bound "allocationChanged"
            selectOptions : [
              { title : "$ 10",  value : "1000" }
              { title : "$ 20",  value : "2000" }
              { title : "$ 30",  value : "3000" }
              { title : "$ 50",  value : "5000" }
              { title : "$ 100", value : "10000" }
            ]<commit_msg>Show dollars in UI.<commit_after>class GroupCreationModal extends KDModalView

  GROUP_TYPES = [
    { title : "University/School", value : "educational" }
    { title : "Company",           value : "company" }
    { title : "Project",           value : "project" }
    { title : "Other",             value : "custom" }
  ]

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

    options.title    or= 'Create a new group'
    options.height   or= 'auto'
    options.cssClass or= "group-creation-modal"
    options.width     ?= 704
    options.overlay   ?= yes
    options.buttons    =
      submit           :
        title          : "Create"
        style          : "modal-clean-gray hidden"
        type           : "button"
        callback       : @bound "createGroup"
      next             :
        title          : "Next"
        style          : "modal-clean-gray"
        type           : "button"
        callback       : @bound "next"
      back             :
        title          : "back"
        style          : "modal-cancel hidden"
        type           : "button"
        callback       : @bound "back"

    super options, data

    @plans = []

  charge:(plan, callback)-> plan.subscribe { pin: '0000' }, callback

  setPositions:->
    super
    $scroller = @$('.kdmodal-content').eq(0)
    $scroller?.scrollTop $scroller[0].scrollHeight

  viewAppended:->

    @addSubView @typeSelector = new KDFormViewWithFields
      cssClass      : "type-selector"
      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    : GROUP_TYPES
          change    : =>
            @ready =>
              typeSelector = @typeSelector.inputs.selector
              # hostSelector = @hostSelector.inputs.selector
              sharedHost   = @hostSelector.inputs.sharedHost

              # @hostSelector?.show()

              # hostSelector.setValue switch typeSelector.getValue()
              #   when "educational" then "4"
              #   when "company"     then "2"
              #   when "project"     then "1"
              #   when "custom"      then "0"

              @setPositions()

    @addSubView @mainSettings = new KDFormViewWithFields
      cssClass                 : "general-settings hidden"
      fields                   :
        "Title"                :
          label                : "Title"
          name                 : "title"
          validate             :
            event              : "blur"
            rules              :
              required         : yes
              minLength        : 4
          keyup                : KD.utils.defer.bind this, @bound "makeSlug"
          placeholder          : 'Please enter your group title...'
        "HiddenSlug"           : { name : "slug", type : "hidden", cssClass : "hidden" }
        "Slug"                 :
          label                : "Address"
          partial              : "#{location.protocol}//#{location.host}/"
          itemClass            : KDCustomHTMLView
        "Description"          :
          label                : "Description"
          type                 : "textarea"
          name                 : "body"
          placeholder          : "Please enter a description for your group here..."
        "Privacy"              :
          label                : "Privacy/Visibility"
          itemClass            : KDSelectBox
          type                 : "select"
          name                 : "privacy"
          defaultValue         : "public"
          selectOptions        :
            Public             : [ { title : "Anyone can join",    value : "public" } ]
            Private            : [
              { title : "By invitation",       value : "by-invite" }
              { title : "By access request",   value : "by-request" }
              { title : "In same domain",      value : "same-domain" }
            ]
          nextElement          :
            "Visibility"       :
              itemClass        : KDSelectBox
              type             : "select"
              name             : "visibility"
              defaultValue     : "visible"
              cssClass         : "visibility"
              selectOptions    : [
                { title : "Visible in group listings", value : "visible" }
                { title : "Hidden in group listings",  value : "hidden" }
              ]

    vmController = @getSingleton('vmController')
    vmController.fetchVMPlans (err, plans)=>
      @plans = plans
      {descriptions, hostTypes} = vmController.sanitizeVMPlansForInputs plans

      descPartial = ""
      for d in descriptions
        descPartial += """
          <section>
            <p class='hidden'>
              <i>Good for:</i>
              <span>#{d.meta.goodFor}</span>
              <cite>VMs</cite>
            </p>
            #{d.description}
          </section>"""
      @addSubView @hostSelector = new KDFormViewWithFields
        cssClass         : "host-selector"
        fields           :
          label          :
            itemClass    : KDCustomHTMLView
            tagName      : 'h2'
            cssClass     : 'heading'
            partial      : "<span>2</span> Do you want a shared host for your Group?"
          sharedHost     :
            itemClass    : KDOnOffSwitch
            name         : "shared-vm"
            defaultValue : no
            cssClass     : "shared-vm"
            callback     : @bound "hostChanged"
          # selector    :
          #   name      : "host"
          #   itemClass : HostCreationSelector
          #   cssClass  : "host-type"
          #   radios    : hostTypes
          #   change    : @bound "hostChanged"
          desc        :
            itemClass : KDCustomHTMLView
            cssClass  : "description-field hidden"
            partial   : """<section>
              This VM is going to be shared among all members of your group, admins will receive sudo rights, each member will have a unix user account.
              </section>"""


      @addSubView @allocation = new KDFormViewWithFields
        cssClass          : "allocation"
        fields            :
          label           :
            itemClass     : KDCustomHTMLView
            tagName       : 'h2'
            cssClass      : 'heading'
            partial       : "<span>3</span> How much resources do you want to allocate to your each user?"
          sharedHost      :
            itemClass     : KDSelectBox
            type          : "select"
            name          : "allocation"
            defaultValue  : "10"
            cssClass      : "allocation"
            change        : @bound "allocationChanged"
            selectOptions : [
              { title : "$ 10",  value : "10" }
              { title : "$ 20",  value : "20" }
              { title : "$ 30",  value : "30" }
              { title : "$ 50",  value : "50" }
              { title : "$ 100", value : "100" }
            ]
{'fraction_non_alphanumeric': 0.0956960974259618, 'fraction_numerical': 0.006781068364240243, 'mean_word_length': 1.165892402217893, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 53, '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': '7152009', 'n_tokens_mistral': 3734, 'n_tokens_neox': 3580, 'n_words': 901}