<commit_before>//= require ./views/items-table
//= require ./views/item-quantity-price
//= require ./views/item
//= require ./views/payment

orders = {

  t: function (key, options) {
    return I18n.t(key, $.extend(options, {scope: 'orders_plugin'}))
  },

  locales: {
    noneSelected: '',
  },

  order: {

    reload: function(context, url) {
      var order = $(context).parents('.order-view')

      loading_overlay.show(order)
      $.getScript(url, function () {
        loading_overlay.hide(order)
      })
    },

    submit: function(form) {
      var order = $(form).parents('.order-view')

      $(form).ajaxSubmit({dataType: 'script',
        beforeSubmit: function(){ loading_overlay.show(order) },
        success: function(){ loading_overlay.hide(order) },
      })

      return false
    },

    add_payment: function(context) {
      var data = $(context).siblings(".order-input-data")
      $('#payment_orders_plugin_order_id').val(data.attr('data-id'))
      $('#payment_value').val("")
      $('#payment_description').val("")

      var pm = $('#payment_payment_method_id')
      var slug = data.attr('data-payment-method')
      var option = pm.find('option').filter(function() { return $(this).html() == slug })
      if (option) { pm.val(option.val()) }
    },

    payment: {
      submit: function() {
        var id = $("#payment_orders_plugin_order_id").val()
        var order = $('#order-'+id)
        var form = order.find('form')
        orders.order.submit(form)
      }
    },
  },

  item: {

    edit_quantity: function (item) {
      item = $(item);
      toggle_edit.edit(item);

      var quantity = item.find('.quantity input');
      quantity.focus();
    },
<commit_msg>orders: pre-fill payment modal value with remaining total<commit_after>//= require ./views/items-table
//= require ./views/item-quantity-price
//= require ./views/item
//= require ./views/payment

orders = {

  t: function (key, options) {
    return I18n.t(key, $.extend(options, {scope: 'orders_plugin'}))
  },

  locales: {
    noneSelected: '',
  },

  order: {

    reload: function(context, url) {
      var order = $(context).parents('.order-view')

      loading_overlay.show(order)
      $.getScript(url, function () {
        loading_overlay.hide(order)
      })
    },

    submit: function(form) {
      var order = $(form).parents('.order-view')

      $(form).ajaxSubmit({dataType: 'script',
        beforeSubmit: function(){ loading_overlay.show(order) },
        success: function(){ loading_overlay.hide(order) },
      })

      return false
    },

    add_payment: function(context) {
      var data = $(context).siblings(".order-input-data")
      $('#payment_orders_plugin_order_id').val(data.attr('data-id'))

      // pre-fill with the remaining total
			var yet_to_pay = $(context).parents('form').find('.total_yet_to_pay .value span').eq(0)
			if (yet_to_pay) {
				yet_to_pay = yet_to_pay.html().replace("R$", "").replace('.','').replace(',','.').trim()  
      }
			else {
				yet_to_pay = ""
      }
      $('#payment_value').val(yet_to_pay)

      $('#payment_description').val("")

      var pm = $('#payment_payment_method_id')
      var slug = data.attr('data-payment-method')
      var option = pm.find('option').filter(function() { return $(this).html() == slug })
      if (option) { pm.val(option.val()) }
    },

    payment: {
      submit: function() {
        var id = $("#payment_orders_plugin_order_id").val()
        var order = $('#order-'+id)
        var form = order.find('form')
        orders.order.submit(form)
      }
    },
  },

  item: {

    edit_quantity: function (item) {
      item = $(item);
      toggle_edit.edit(item);

      var quantity = item.find('.quantity input');
      quantity.focus();
    },

{'fraction_non_alphanumeric': 0.18306878306878308, 'fraction_numerical': 0.0013227513227513227, 'mean_word_length': 2.67444120505345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4616141', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1171, 'n_words': 214}