Advertisement
Guest User

Inheration

a guest
Jan 17th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 4.70 KB | None | 0 0
  1. (function ($) {
  2.     'use strict';
  3.     var newComponent = function (options) {
  4.     };
  5.  
  6.     newComponent.prototype.bindAdditionalEvents = function () {
  7.         var self = this;
  8.         self.$container.find('#copy_element').on('click', function (e) {
  9.             e.preventDefault();
  10.             var thisButton = $(this);
  11.  
  12.             var $resultContainer = $('.js-errors');
  13.             var $chooseCopyToSale = $('#copy_sales_id');
  14.             if (typeof $chooseCopyToSale.val() === 'undefined' || $chooseCopyToSale.val() === '') {
  15.                 alert('Вам необходимо выбрать VDS для копирования');
  16.                 return;
  17.             }
  18.  
  19.             thisButton.prop('disabled', true);
  20.             thisButton.addClass('ui-btn-disabled');
  21.  
  22.             $resultContainer.html('');
  23.             $.ajax({
  24.                 url: '/local/components/gt/hl.form/templates/sales/ajax_copy_element.php',
  25.                 type: 'post',
  26.                 data: {'copy_to_sales_id': $chooseCopyToSale.val(), 'current_sales_id': $chooseCopyToSale.data('id')},
  27.                 dataType: 'json',
  28.                 success: function (data) {
  29.                     if (data['RESULT']) {
  30.                         var href = $chooseCopyToSale.data('href').replace('#ID#', $chooseCopyToSale.val());
  31.                         $resultContainer.html('Элемент успешно скопирован!<br><a target="_blank" href="' + href + '">Перейти к скопированному элементу</a>');
  32.                     } else {
  33.                         $resultContainer.html('Что то пошло не так');
  34.                     }
  35.                 }
  36.             }).always(function () {
  37.                 thisButton.prop('disabled', false);
  38.                 thisButton.removeClass('ui-btn-disabled');
  39.             });
  40.         });
  41.     };
  42.  
  43.     newComponent.prototype.isContinueSubmit = function ($currentButton) {
  44.         if ($currentButton.attr('name') === 'DELETE') {
  45.             if (!confirm('Вы уверены в удалении ресурса?')) {
  46.                 return false;
  47.             }
  48.         } else { //MODIFIED ZONE //TODO
  49.             var $price = $('#PRICE');
  50.             var $paymentFeature = $('#PAY_FEATURE_ID');
  51.             if (
  52.                 (typeof $price.val() === "undefined" || parseInt($price.val()) === 0 || isNaN(parseInt($price.val()))) &&
  53.                 (typeof $paymentFeature.val() === "undefined" || parseInt($paymentFeature.val()) === 0 || isNaN(parseInt($paymentFeature.val())))
  54.             ) {
  55.                 alert("Вы должны выбрать особенность оплаты, либо указать цену");
  56.                 return false;
  57.             }
  58.  
  59.             var $includedInSale = $('#INCLUDED_IN_SALE');
  60.             const $paymentFeatureIncludedInId = 3;
  61.  
  62.             if (parseInt($paymentFeature.val()) === $paymentFeatureIncludedInId) {
  63.                 if (typeof $includedInSale.val() === "undefined" || isNaN(parseInt($includedInSale.val())) || parseInt($includedInSale.val()) === 0) {
  64.                     alert('После выбора "Включено в стоимость", вы должны выбрать продажу');
  65.                     return false;
  66.                 } else {
  67.                     $price.val(0);
  68.                 }
  69.             }
  70.         }
  71.         return true;
  72.     };
  73.  
  74.     $(function () {
  75.         $.gtSalesFormComponent = {
  76.             extend: function (oldComponent, newOptions) {
  77.                 newComponent = function (options) {
  78.                     oldComponent.apply(this, arguments);
  79.                 };
  80.                 newComponent.prototype = Object.create(oldComponent.prototype);
  81.                 newComponent.prototype.constructor = newComponent;
  82.                 return new newComponent(newOptions);
  83.             },
  84.         };
  85.     });
  86. })(jQuery);
  87.  
  88. (function ($) {
  89.     'use strict';
  90.     var Component = function (options) {
  91.         var defaults = {};
  92.         if (typeof options !== 'object') {
  93.             options = {};
  94.         }
  95.         this.opts = $.extend({}, defaults, options);
  96.  
  97.         this.bindEvents();
  98.         this.initPlugins();
  99.     };
  100.  
  101.     Component.prototype.bindAdditionalEvents = function () {
  102.     };
  103.  
  104.     Component.prototype.bindEvents = function () {
  105.         var self = this;
  106.         self.bindAdditionalEvents();
  107.     };
  108.  
  109.     Component.prototype.isContinueSubmit = function ($currentButton) {
  110.     };
  111.  
  112.     $(function () {
  113.         $.gtFormComponent = {
  114.             init: function (options) {
  115.                 return new Component(options);
  116.             },
  117.             getComponent: function () {
  118.                 return Component;
  119.             }
  120.         };
  121.     });
  122. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement