<commit_before>class CreateKiteModal extends KDModalViewWithForms

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

    options.title             = "Create new Kite"
    options.overlay           = yes
    options.content           = ""
    options.cssClass          = "create-kite-modal"
    options.width             = 760
    options.height            = "auto"
    options.tabs              =
      # navigable               : no
      forms                   :
        Details               :
          buttons             :
            Next              :
              title           : "Next"
              style           : "modal-clean-gray"
              type            : "submit"
              loader          :
                color         : "#444444"
              callback        : -> @hideLoader()
            Cancel            :
              title           : "Cancel"
              style           : "modal-cancel"
              callback        : => @destroy()
          fields              :
            nameField         :
              label           : "Name"
              name            : "name"
              placeholder     : "Name of your Kite"
              validate        :
                rules         :
                  required    : yes
                messages      :
                  required    : "Please enter a kite name"
            descriptionField  :
              label           : "Description"
              name            : "description"
              placeholder     : "Description of your Kite"
              validate        :
                rules         :
                  required    : yes
                messages      :
                  required    : "Please enter a kite name"
        Pricing               :
          fields              :
            container         :
              itemClass       : KDView
              cssClass        : "pricing-items"
          buttons             :
            Save              :
              title           : "Save"
              style           : "modal-clean-gray"
              type            : "submit"
              loader          :
                color         : "#444444"
              callback        : @bound "save"
            Cancel            :
              title           : "Cancel"
              style           : "modal-cancel"
              callback        : => @destroy()

    super options, data

    @pricingForms = []

    @modalTabs.forms.Pricing.addSubView new KDButtonView
      title    : "ADD NEW"
      cssClass : "solid green small add-pricing"
      callback : @bound "createPricingView"

    @createPricingView()

  createPricingView: ->
    pricingForm = new KitePricingFormView

    @modalTabs.forms.Pricing.fields.container.addSubView pricingForm
    @pricingForms.push pricingForm

  save: ->
    details = @modalTabs.forms.Details.getFormData()
    plans   = (form.getFormData() for form in @pricingForms)

    KD.remote.api.JKite.create details, (err, kite)=>
      return  KD.showError err if err
      {dash} = Bongo
      queue = plans.map (plan) -> ->
        kite.createPlan plan, (err, kiteplan)->
          return queue.fin err  if err
          queue.fin()

      dash queue, (err) =>
        return KD.showError err if err
        @destroy()


class KitePricingFormView extends KDFormViewWithFields

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

    options.cssClass      = "kite-pricing-view"
    options.fields        =
      planId              :
        label             : "Plan Id"
        name              : "planId"
        cssClass          : "thin half"
        nextElement       :
          planName        :
            label         : "Plan Name"
            name          : "planName"
            cssClass      : "thin half"
      planprice           :
        label             : "Plan Price"
        name              : "planPrice"
        cssClass          : "thin half"
        nextElement       :
          planRecurring   :
            cssClass      : "thin half"
            label         : "Recurring"
            type          : "select"
            itemClass     : KDSelectBox
            name          : "planRecurring"
            defaultValue  : "free"
            selectOptions : [
              { title     : "Free",      value : "free"    }
              { title     : "Monthly",   value : "monthly" }
              { title     : "Yearly",    value : "yearly"  }
            ]
      planDescription     :
        label             : "Plan Description"
        name              : "planDescription"
        type              : "textarea"

    super options, data<commit_msg>KiteSubscription: modify kite modal variable names.<commit_after>class CreateKiteModal extends KDModalViewWithForms

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

    options.title             = "Create New Kite"
    options.overlay           = yes
    options.content           = ""
    options.cssClass          = "create-kite-modal"
    options.width             = 760
    options.height            = "auto"
    options.tabs              =
      # navigable               : no
      forms                   :
        Details               :
          buttons             :
            Next              :
              title           : "Next"
              style           : "modal-clean-gray"
              type            : "submit"
              loader          :
                color         : "#444444"
              callback        : -> @hideLoader()
            Cancel            :
              title           : "Cancel"
              style           : "modal-cancel"
              callback        : => @destroy()
          fields              :
            nameField         :
              label           : "Name"
              name            : "name"
              placeholder     : "Name of your Kite"
              validate        :
                rules         :
                  required    : yes
                messages      :
                  required    : "Please enter a kite name"
            descriptionField  :
              label           : "Description"
              name            : "description"
              placeholder     : "Description of your Kite"
              validate        :
                rules         :
                  required    : yes
                messages      :
                  required    : "Please enter a kite name"
        Pricing               :
          fields              :
            container         :
              itemClass       : KDView
              cssClass        : "pricing-items"
          buttons             :
            Save              :
              title           : "Save"
              style           : "modal-clean-gray"
              type            : "submit"
              loader          :
                color         : "#444444"
              callback        : @bound "save"
            Cancel            :
              title           : "Cancel"
              style           : "modal-cancel"
              callback        : => @destroy()

    super options, data

    @pricingForms = []

    @modalTabs.forms.Pricing.addSubView new KDButtonView
      title    : "ADD NEW"
      cssClass : "solid green small add-pricing"
      callback : @bound "createPricingView"

    @createPricingView()

  createPricingView: ->
    pricingForm = new KitePricingFormView

    @modalTabs.forms.Pricing.fields.container.addSubView pricingForm
    @pricingForms.push pricingForm

  save: ->
    details = @modalTabs.forms.Details.getFormData()
    plans   = (form.getFormData() for form in @pricingForms)

    KD.remote.api.JKite.create details, (err, kite)=>
      return  KD.showError err if err
      {dash} = Bongo
      queue = plans.map (plan) -> ->
        kite.createPlan plan, (err, kiteplan)->
          return queue.fin err  if err
          queue.fin()

      dash queue, (err) =>
        return KD.showError err if err
        @destroy()


class KitePricingFormView extends KDFormViewWithFields

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

    options.cssClass      = "kite-pricing-view"
    options.fields        =
      planId              :
        label             : "Plan Id"
        name              : "userTag"
        cssClass          : "thin half"
        nextElement       :
          planName        :
            label         : "Plan Name"
            name          : "title"
            cssClass      : "thin half"
      planprice           :
        label             : "Plan Price"
        name              : "feeAmount"
        cssClass          : "thin half"
        nextElement       :
          planRecurring   :
            cssClass      : "thin half"
            label         : "Recurring"
            type          : "select"
            itemClass     : KDSelectBox
            name          : "planRecurring"
            defaultValue  : "free"
            selectOptions : [
              { title     : "Free",      value : "free"    }
              { title     : "Monthly",   value : "monthly" }
              { title     : "Yearly",    value : "yearly"  }
            ]
      planDescription     :
        label             : "Plan Description"
        name              : "description"
        type              : "textarea"

    super options, data

{'fraction_non_alphanumeric': 0.07696430485582592, 'fraction_numerical': 0.003215778754421696, 'mean_word_length': 0.9397089397089398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '970464', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2215, 'n_words': 528}