<commit_before>$(function() {
  $('#ri-grid').gridrotator({
    w1024: {rows: 2, columns: 3},
    w768 : {rows: 2, columns: 3},
    w480 : {rows: 2, columns: 3},
    w320 : {rows: 3, columns: 4},
    w240 : {rows: 3, columns: 3}
  });

  var loading = function(isLoading) {
    var $e = $('#loading');
    isLoading === true ? $e.show() : $e.hide();
  }

  var submitted = false;
  var $form = $('#demoLicense form');
  $form.validate({
    submitHandler: function(form) {
      if (submitted) {
        return;
      }
      submitted = true;
      loading(true);
      $.ajax({
        url: form.action,
        cache: false,
        type: 'POST',
        data: $form.serialize(),
        dataType: "jsonp",
        //timeout: 1000,
        crossDomain: true,
        success: function (data, status) {
            if (data == 'OK') {
                $form.parent().html("Спасибо за Вашу заявку")
            } else {
                $form.parent().html("Ошибка: " + data);
            }
        },
        error: function (xOptions, textStatus) {
            submitted = false;
            console.log(textStatus);
        },
        complete: function() {
            loading(false);
        }
      });
    }
  });
 
  var ViewModel = function(cards, poster, delivery) {
      this.cards = ko.observable(cards);
      this.poster = ko.observable(poster);
      this.delivery = ko.observable(delivery);
      this.deliveryOptions = [{
          disable: true,
          text: 'Самовывоз'
      }, {
          disable: true,
          text: 'Курьер'
      }, {
          disable: false,
          text: 'Посылка'
      }];
      for (var i in this.deliveryOptions) {
          var option = this.deliveryOptions[i];
          option.disable = ko.observable(option.disable);
      }
      this.addressCity = ko.observable();

      var productCost = function(value) {
          // discount if 10
          return value ? value + " * 399 : " + value * 399 + " руб" : "";
      };

      this.cardsCost = ko.pureComputed(function() {
          return productCost(this.cards());
      }, this);

      this.posterCost = ko.pureComputed(function() {
          return productCost(this.poster());
      }, this);

      var self = this;
      this.deliveryChanged = function(value) {
          self.delivery(value.text);
      };

      this.deliveryCost = ko.pureComputed(function() {
          var delivery = this.delivery();
          return delivery ? delivery : '';
      }, this);

      this.disableDeliveryOption = function(option, disable) {
          option.disable(disable);
          if (this.delivery() == option.text) {
              this.delivery('');
          }
      }

      this.addressChanged = function(value) {
          var selected = value.split(",");
          console.log(selected);
          this.addressCity(selected[0]);
          var disable = selected[0] != 'Москва';
          this.disableDeliveryOption(this.deliveryOptions[0], disable);
          this.disableDeliveryOption(this.deliveryOptions[1], disable);
      };
  };

  var model = new ViewModel(1, 0);<commit_msg>delivery cost<commit_after>$(function() {
  $('#ri-grid').gridrotator({
    w1024: {rows: 2, columns: 3},
    w768 : {rows: 2, columns: 3},
    w480 : {rows: 2, columns: 3},
    w320 : {rows: 3, columns: 4},
    w240 : {rows: 3, columns: 3}
  });

  var loading = function(isLoading) {
    var $e = $('#loading');
    isLoading === true ? $e.show() : $e.hide();
  }

  var submitted = false;
  var $form = $('#demoLicense form');
  $form.validate({
    submitHandler: function(form) {
      if (submitted) {
        return;
      }
      submitted = true;
      loading(true);
      $.ajax({
        url: form.action,
        cache: false,
        type: 'POST',
        data: $form.serialize(),
        dataType: "jsonp",
        //timeout: 1000,
        crossDomain: true,
        success: function (data, status) {
            if (data == 'OK') {
                $form.parent().html("Спасибо за Вашу заявку")
            } else {
                $form.parent().html("Ошибка: " + data);
            }
        },
        error: function (xOptions, textStatus) {
            submitted = false;
            console.log(textStatus);
        },
        complete: function() {
            loading(false);
        }
      });
    }
  });
 
  var ViewModel = function(cards, poster, delivery) {
      this.cards = ko.observable(cards);
      this.poster = ko.observable(poster);
      this.delivery = ko.observable(delivery);
      this.deliveryOptions = [{
          disable: true,
          text: 'Самовывоз',
          comment: 'м.Щелковская, м. Павелецкая или м.Водный стадион',
          cost: 0
      }, {
          disable: true,
          text: 'Курьер',
          comment: 'Доставка до любой станции метро',
          cost: 300
      }, {
          disable: false,
          text: 'Почта',
          comment: 'Почтой России, срок доставки 7-10 дней',
          cost: 0
      }];
      for (var i in this.deliveryOptions) {
          var option = this.deliveryOptions[i];
          option.disable = ko.observable(option.disable);
      }
      this.addressCity = ko.observable();

      var productCost = function(value) {
          // discount if 10
          return value ? value + " * 399 : " + value * 399 + " руб" : "";
      };

      this.cardsCost = ko.pureComputed(function() {
          return productCost(this.cards());
      }, this);

      this.posterCost = ko.pureComputed(function() {
          return productCost(this.poster());
      }, this);

      this.addressChanged = function(value) {
          var selected = value.split(",");
          this.addressCity(selected[0]);
          var disable = selected[0] != 'Москва';
          this.disableDeliveryOption(this.deliveryOptions[0], disable);
          this.disableDeliveryOption(this.deliveryOptions[1], disable);
      };

      this.disableDeliveryOption = function(option, disable) {
          option.disable(disable);
          if (this.delivery() == option.text) {
              this.delivery('');
          }
      };

      var self = this;
      this.deliveryChanged = function(value) {
          self.delivery(value);
      };

      this.deliveryCost = ko.pureComputed(function() {
          var delivery = this.delivery();
          if (!delivery) {
              return '';
          }
          var cost = delivery.cost;
          var cards = this.cards() || 0;
          var poster = this.poster() || 0;
          if (poster > 0 && delivery.text == 'Почта') {
              cost += 100 + 200; // FIXME: weight
          }
          if (cards > 0 && delivery.text == 'Почта') {
              cost += 100;
          }
          return cost + ' руб';
      }, this);

  };

  var model = new ViewModel(1, 0);
{'fraction_non_alphanumeric': 0.14605418138987045, 'fraction_numerical': 0.01604829210836278, 'mean_word_length': 1.8058653448988022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4382029', 'n_tokens_mistral': 2146, 'n_tokens_neox': 2047, 'n_words': 444}