<commit_before>class GroupPlanAddProductsModal extends KDModalView

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

    options.title ?= "Add products"

    options.overlay ?= yes

    super options, data

    data = @getData()

    @loader = new KDLoaderView { size: 14 }

    @addSubView @loader
    @loader.show()

    @planExplanation = new KDCustomHTMLView
      cssClass: 'modalformline'
      partial:
        """
        <h2>Plan</h2>
        """

    @planView = new GroupProductView
      cssClass: 'modalformline'
      tagName: 'div'
    , data

    @productsExplanation = new KDCustomHTMLView
      cssClass: 'modalformline'
      partial:
        """
        <h2>Products</h2>
        <p>Add some products to this plan</p>
        """

    @products = new KDListViewController
      itemClass: GroupAddProductListItem

    @buttonField = new KDView
      cssClass: "formline button-field clearfix"

    @buttonField.addSubView new KDButtonView
      title     : 'Save'
      cssClass  : 'modal-clean-green'
      callback  : => @save @bound 'destroy'

    @buttonField.addSubView new KDButtonView
      title     : 'cancel'
      cssClass  : 'modal-cancel'
      callback  : @bound 'destroy'

    @addSubView @planExplanation
    @addSubView @planView
    @addSubView @productsExplanation
    @addSubView @products.getView()
    @addSubView @buttonField

  save: (callback) ->
    quantities = {}

    plan = @getData()

    @products.getItemsOrdered().forEach (item) ->
      { planCode } = item.getData()
      qty = item.qtyView.getValue()
      quantities[planCode] = qty  if qty > 0

    plan.quantities = quantities

    plan.modify { quantities }, callback

    @emit 'ProductsAdded'

  setProducts: (products) ->
    @loader.hide()

    plan = @getData()

    for product in products
      qty = plan.quantities?[product.planCode] ? 0
      item = @products.addItem product
      item.setQuantity qty<commit_msg>payment: fix a race condition<commit_after>class GroupPlanAddProductsModal extends KDModalView

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

    options.title ?= "Add products"

    options.overlay ?= yes

    super options, data

    data = @getData()

    @loader = new KDLoaderView { size: 14 }

    @addSubView @loader
    @loader.show()

    @planExplanation = new KDCustomHTMLView
      cssClass: 'modalformline'
      partial:
        """
        <h2>Plan</h2>
        """

    @planView = new GroupProductView
      cssClass: 'modalformline'
      tagName: 'div'
    , data

    @productsExplanation = new KDCustomHTMLView
      cssClass: 'modalformline'
      partial:
        """
        <h2>Products</h2>
        <p>Add some products to this plan</p>
        """

    @products = new KDListViewController
      itemClass: GroupAddProductListItem

    @buttonField = new KDView
      cssClass: "formline button-field clearfix"

    @buttonField.addSubView new KDButtonView
      title     : 'Save'
      cssClass  : 'modal-clean-green'
      callback  : => @save @bound 'destroy'

    @buttonField.addSubView new KDButtonView
      title     : 'cancel'
      cssClass  : 'modal-cancel'
      callback  : @bound 'destroy'

    @addSubView @planExplanation
    @addSubView @planView
    @addSubView @productsExplanation
    @addSubView @products.getView()
    @addSubView @buttonField

  save: (callback) ->
    quantities = {}

    plan = @getData()

    @products.getItemsOrdered().forEach (item) ->
      { planCode } = item.getData()
      qty = item.qtyView.getValue()
      quantities[planCode] = qty  if qty > 0

    plan.quantities = quantities

    plan.modify { quantities }, (err) =>
      return callback err  if err
      callback null

      @emit 'ProductsAdded'

  setProducts: (products) ->
    @loader.hide()

    plan = @getData()

    for product in products
      qty = plan.quantities?[product.planCode] ? 0
      item = @products.addItem product
      item.setQuantity qty
{'fraction_non_alphanumeric': 0.10575942915392457, 'fraction_numerical': 0.004077471967380225, 'mean_word_length': 2.5170250896057347, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 28, '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': '3876179', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1178, 'n_words': 282}