<commit_before>class ComputePlansModal.Paid extends ComputePlansModal

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

    options.cssClass = 'paid-plan'
    options.height   = 323

    super options, data

  viewAppended:->

    { usage, limits, plan } = @getOptions()

    @addSubView content = new KDView
      cssClass : 'container'

    remaining = Math.max 0, limits.total - usage.total

    content.addSubView title = new KDView
      cssClass : "modal-title"
      partial  : """
        Remaining VM slots:
          <strong>
            #{remaining}/#{limits.total}
          </strong>
      """

    title.setClass 'warn'  if usage.total >= limits.total

    content.addSubView storageContainer = new KDView
      cssClass : "storage-container"

    storageContainer.addSubView new KDView
      cssClass : "storage-title"
      partial  : "choose storage capacity"

    storageContainer.addSubView @storageSlider = new CustomPlanStorageSlider
      cssClass : 'storage-slider'
      maxValue : limits.storage * 2 # limits.storage - usage.storage
      minValue : 3
      handles  : [5]

    storageContainer.addSubView @usageTextView = new KDView

    content.addSubView @createVMButton = new KDButtonView
      title    : "Create your VM"
      style    : 'solid medium green'
      loader   : yes
      disabled : usage.total >= limits.total

    content.addSubView new CustomLinkView
      title    : 'Upgrade your account for more VMs RAM and Storage'
      href     : '/Pricing'

    @updateUsageText 5, usage, limits
    @storageSlider.on "ValueIsChanging", (val)=>
      @updateUsageText val, usage, limits

  updateUsageText: (val, usage, limits)->

    newUsage = usage.storage + val

    if newUsage > limits.storage
      @usageTextView.setClass 'warn'
      @createVMButton.disable()
    else
      @usageTextView.unsetClass 'warn'
      @createVMButton.enable()  unless usage.total >= limits.total

    @usageTextView.updatePartial """
      You will be using <strong>#{newUsage}GB/#{limits.storage}GB</strong> storage
    """<commit_msg>ComputePlansModal.Paid: createVM from modal implemented.<commit_after>class ComputePlansModal.Paid extends ComputePlansModal

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

    options.cssClass = 'paid-plan'
    options.height   = 323

    super options, data

  viewAppended:->

    { usage, limits, plan } = @getOptions()

    @addSubView content = new KDView
      cssClass : 'container'

    remaining = Math.max 0, limits.total - usage.total

    content.addSubView title = new KDView
      cssClass : "modal-title"
      partial  : """
        Remaining VM slots:
          <strong>
            #{remaining}/#{limits.total}
          </strong>
      """

    title.setClass 'warn'  if usage.total >= limits.total

    content.addSubView storageContainer = new KDView
      cssClass : "storage-container"

    storageContainer.addSubView new KDView
      cssClass : "storage-title"
      partial  : "choose storage capacity"

    storageContainer.addSubView @storageSlider = new CustomPlanStorageSlider
      cssClass : 'storage-slider'
      maxValue : limits.storage * 2 # limits.storage - usage.storage
      minValue : 3
      handles  : [5]

    storageContainer.addSubView @usageTextView = new KDView

    content.addSubView @createVMButton = new KDButtonView
      title    : "Create your VM"
      style    : 'solid medium green'
      loader   : yes
      callback : @bound "createVM"
      disabled : usage.total >= limits.total

    content.addSubView new CustomLinkView
      title    : 'Upgrade your account for more VMs RAM and Storage'
      href     : '/Pricing'

    @updateUsageText 5, usage, limits
    @storageSlider.on "ValueIsChanging", (val)=>
      @updateUsageText val, usage, limits

  updateUsageText: (val, usage, limits)->

    newUsage = usage.storage + val

    if newUsage > limits.storage
      @usageTextView.setClass 'warn'
      @createVMButton.disable()
    else
      @usageTextView.unsetClass 'warn'
      @createVMButton.enable()  unless usage.total >= limits.total

    @usageTextView.updatePartial """
      You will be using <strong>#{newUsage}GB/#{limits.storage}GB</strong> storage
    """

  createVM:->

    { computeController } = KD.singletons

    stack = computeController.stacks.first._id
    storage = @storageSlider.handles.first.value

    computeController.create {
      provider : "koding", stack, storage
    }, (err)=>

      KD.showError err

      @createVMButton.hideLoader()
      @destroy()
{'fraction_non_alphanumeric': 0.09993337774816789, 'fraction_numerical': 0.0035531867643793028, 'mean_word_length': 2.7253928866832093, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, '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': '7053057', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1271, 'n_words': 326}