PluginProbe
PayPlug for WooCommerce (Official) / 1.10.1
PayPlug for WooCommerce (Official) v1.10.1
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
payplug / assets / js / payplug-admin-oney.js

payplug-admin-oney.js in PayPlug for WooCommerce (Official) 1.10.1, at assets/js/payplug-admin-oney.js

179 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery */
2
3 (($, undefined) => {
4
5 var pao = {
6 init: function() {
7 // setup modal
8 pao.$dialogoney = $('#payplug-oney-modal').dialog({
9 autoOpen: false,
10 modal: true,
11 closeText : "",
12 draggable: false,
13 buttons: [
14 {
15 class: "ui-dialog-submit",
16 text: payplug_admin_config.btn_ok,
17 click: pao.onDialogOneyClose
18 }
19 ],
20 show: true,
21 hide: 100
22 })
23 pao.$yes_no_description = $("#live-mode-test-p");
24 if ($("#woocommerce_payplug_oney").length) {
25 pao.$payplug_oney = $("#woocommerce_payplug_oney")
26 pao.$payplug_oney_type = $("#woocommerce_payplug_oney_type, #woocommerce_payplug_oney_thresholds, #oney_installments_pop_up")
27 if (pao.$payplug_oney.prop('checked')) {
28 pao.$payplug_oney_type.css('display', 'table-row')
29 } else {
30 pao.$payplug_oney_type.css('display', 'none')
31 }
32 }
33 if ($('input[name=woocommerce_payplug_mode]').length) {
34 pao.$payplug_mode = $('input[name=woocommerce_payplug_mode]:checked').val()
35 pao.showHideDescription();
36 $('input[name=woocommerce_payplug_mode]').on(
37 'click',
38 pao.toggleMode
39 )
40 }
41
42 pao.$payplug_oney.on('change', function() {
43 if (pao.$payplug_oney.prop('checked')) {
44 if (1 == pao.$payplug_mode) {
45 pao.verifyOney()
46 } else {
47 pao.$payplug_oney_type.css('display', 'table-row')
48 }
49 } else {
50 pao.$payplug_oney_type.css('display', 'none')
51 }
52 })
53 pao.init_oney_thresholds();
54
55 },
56 verifyOney: function() {
57 pao.$payplug_oney.prop('disabled', true)
58 pao.xhr = $
59 .post(
60 payplug_admin_config.ajax_url,
61 {
62 action: 'check_live_permissions',
63 livekey : $('#woocommerce_payplug_payplug_live_key').length ? $('#woocommerce_payplug_payplug_live_key').val() : ''
64 }
65 ).done((res) => {
66 pao.is_oney_refresh = false
67 pao.$payplug_oney.prop('disabled', false)
68 pao.xhr = false
69 if (false === res.success) {
70 alert(res.data.error)
71 setTimeout(() => pao.$payplug_oney.prop('checked', false), 200)
72 }
73 if (false === res.data.can_use_oney) {
74 pao.$dialogoney.dialog('open')
75 setTimeout(() => pao.$payplug_oney.prop('checked', false), 200)
76 pao.$payplug_oney_type.css('display', 'none')
77 } else {
78 pao.$payplug_oney.prop('checked', true)
79 pao.$payplug_oney_type.css('display', 'table-row')
80 }
81 })
82 .fail((res) => {
83 pao.$payplug_oney.prop('disabled', false)
84 pao.$payplug_oney_type.css('display', 'none')
85 })
86 },
87 toggleMode: (event) => {
88 pao.$payplug_mode = $('input[name=woocommerce_payplug_mode]:checked').val()
89 pao.showHideDescription();
90 if (pao.$payplug_oney.prop('checked')) {
91 if(payplug_admin_config.has_live_key)
92 pao.verifyOney()
93 }
94 },
95 showHideDescription: function(){
96 pao.$payplug_mode = $('input[name=woocommerce_payplug_mode]:checked').val()
97 if(pao.$payplug_mode == 1){
98 pao.$yes_no_description.css('display', 'none');
99 }else{
100 pao.$yes_no_description.css('display', 'block');
101 }
102 },
103 onDialogOneyClose: function() {
104 pao.$dialogoney.dialog('close')
105 if (pao.is_oney_refresh) {
106 window.location.reload()
107 }
108 },
109
110 init_oney_thresholds: function () {
111
112 var min = Number(payplug_admin_config.min_oney_price);
113 var max = Number(payplug_admin_config.max_oney_price);
114
115 var $hidden_min_input = $("#woocommerce_payplug_oney_thresholds_min");
116 var $hidden_max_input = $("#woocommerce_payplug_oney_thresholds_max");
117
118 var $min_input = $("#payplug_oney_thresholds_min");
119 var $max_input = $("#payplug_oney_thresholds_max");
120
121 $min_input.val(Number($hidden_min_input.val()));
122 $max_input.val(Number($hidden_max_input.val()));
123
124 $( "#slider-range" ).slider({
125 range: true,
126 min: min,
127 max: max,
128 step: 10,
129 values: [payplug_admin_config.oney_thresholds_min, payplug_admin_config.oney_thresholds_max],
130 slide: function( event, ui ) {
131
132 $hidden_min_input.val( ui.values[ 0 ] );
133 $hidden_max_input.val( ui.values[ 1 ]);
134
135 $min_input.val( Number(ui.values[ 0 ]) );
136 $max_input.val( Number(ui.values[ 1 ]) );
137
138 $("#slider-range .ui-slider-handle:first-of-type .tooltip").text( ui.values[ 0 ] + '€');
139 $("#slider-range .ui-slider-handle:last-of-type .tooltip").text( ui.values[ 1 ] + '€');
140 $("#oney_thresholds_description .min").text( ui.values[ 0 ]);
141 $("#oney_thresholds_description .max").text( ui.values[ 1 ]);
142 }
143 });
144
145 $("#payplug_oney_thresholds_min, #payplug_oney_thresholds_max").on( "change", function() {
146
147 if( Number($max_input.val()) < Number($min_input.val()) ){
148 $max_input.val( max );
149 $min_input.val( min );
150 }
151
152 if( $min_input.val() < min )
153 $min_input.val(min);
154
155 if( $max_input.val() > max )
156 $max_input.val( max );
157
158 //slider values
159 $( "#slider-range" ).slider( "option", "values", [ $min_input.val(), $max_input.val() ]);
160 $("#slider-range .ui-slider-handle:first-of-type .tooltip").text( $min_input.val() + '€');
161 $("#slider-range .ui-slider-handle:last-of-type .tooltip").text( $max_input.val() + '€');
162 $("#oney_thresholds_description .min").text( $min_input.val());
163 $("#oney_thresholds_description .max").text( $max_input.val());
164 $("#woocommerce_payplug_oney_thresholds_min").val($min_input.val());
165 $("#woocommerce_payplug_oney_thresholds_max").val($max_input.val());
166
167 });
168
169 $("#oney_thresholds_description").html($("#oney_thresholds_description").html().replaceAll("€", "<b>€</b>"))
170 $('.ui-slider-handle').html('<span class="tooltip"></span>')
171 $("#slider-range .ui-slider-handle:first-of-type .tooltip").html(payplug_admin_config.oney_thresholds_min + '€')
172 $("#slider-range .ui-slider-handle:last-of-type .tooltip").html(payplug_admin_config.oney_thresholds_max + '€')
173
174 }
175 }
176 pao.init()
177
178 })(jQuery)
179