PluginProbe ʕ •ᴥ•ʔ
Stock Locations for WooCommerce / 3.0.0
Stock Locations for WooCommerce v3.0.0
3.1.9 3.1.8 3.1.7 3.1.6 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 trunk 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2
stock-locations-for-woocommerce / js / admin-scripts.js
stock-locations-for-woocommerce / js Last commit date
admin-scripts.js 9 months ago archive.js 1 year ago bootstrap.min.js 2 years ago cart.js 3 years ago common.js 8 months ago fontawesome.min.js 4 years ago jquery.blockUI.js 1 year ago jquery.magnific-popup.min.js 4 years ago product.js 8 months ago underscore-min.js 3 years ago
admin-scripts.js
698 lines
1 function slw_gmap_initialize(input_id) {
2 var input = document.getElementById(input_id);//$('form#edittag input#name');//
3 var autocomplete = new google.maps.places.Autocomplete(input);
4
5 google.maps.event.addListener(autocomplete, 'place_changed', function() {
6 var place = autocomplete.getPlace();
7 jQuery('#slw-lat').val(place.geometry.location.lat());
8 jQuery('#slw-lng').val(place.geometry.location.lng());
9 });
10
11 }
12 (function($){
13
14 // Init after DOM is ready
15 $(document).ready(function() {
16 init();
17
18
19 //google.maps.event.addDomListener(window, 'load', gmap_initialize);
20 var input_id = '';
21 if($('form#edittag input#location_address').length>0){
22 input_id = 'location_address';
23 }
24 if($('form#addtag input#tag-name').length>0){
25 //input_id = 'tag-name';
26 }
27 if(input_id && slw_admin_scripts.slw_gkey!=''){
28 slw_gmap_initialize(input_id);
29 }
30
31
32 });
33
34 // Functions to initiate
35 function init() {
36 slwDisableVariableStockInput();
37 slwWcProductManageStock();
38 slwWcOrderItemStockPositiveNumbersOnly();
39 //slwEnableShowLocationsProductPage();
40 slwAjaxSaveProductDefaultLocation();
41 slwAjaxRemoveProductDefaultLocation();
42 slwEnableLockDefaultLocation();
43 }
44
45
46
47
48 function slwDisableVariableStockInput()
49 {
50 $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event) {
51 if(slw_admin_scripts.stock_locations==true){
52 $('input.variable_manage_stock').each(function(){
53 if( $(this).prop( "checked" ) === true ) {
54 for(i=0; i < $('input.variable_manage_stock').length; i++) {
55 $('input#variable_stock' + i).prop( "disabled", true );
56 }
57 }
58 });
59 }
60 });
61 }
62
63 function slwWcProductManageStock()
64 {
65 var pluginWrapper = $('#' + slw_admin_scripts.slug + '_tab_stock_locations_wrapper'); // Plugin class
66 var pluginNotice = $('#' + slw_admin_scripts.slug + '_tab_stock_locations_notice'); // Plugin class
67 var pluginAlert = $('#' + slw_admin_scripts.slug + '_tab_stock_locations_alert'); // Plugin class
68 var wcStock = $('#_stock'); // Default WooCommerce class
69 var wcManageStock = $('#_manage_stock'); // Default WooCommerce class
70
71 if(wcManageStock !== null) {
72 if(wcManageStock.is(':checked') === true) { // If stock management is active
73 if(slw_admin_scripts.stock_locations==true){
74 wcStock.prop( "disabled", true );
75 }
76 pluginWrapper.show();
77 pluginNotice.hide();
78 if(pluginAlert !== null) {
79 pluginAlert.show();
80 }
81 } else {
82 wcManageStock.on('click', function () {
83 if (pluginWrapper.css("display") === 'none') {
84 if(slw_admin_scripts.stock_locations==true){
85 wcStock.prop( "disabled", true );
86 }
87 pluginWrapper.show();
88 pluginNotice.hide();
89 if(pluginAlert !== null) {
90 pluginAlert.show();
91 }
92 } else {
93 wcStock.prop( "disabled", false );
94 pluginWrapper.hide();
95 pluginNoticepluginWrapper.show();
96 if(pluginAlert !== null) {
97 pluginAlert.hide();
98 }
99 }
100 });
101 }
102 }
103 }
104
105 function slwWcOrderItemStockPositiveNumbersOnly()
106 {
107 $('input.stock-locations-for-woocommerce_oitem').on('change', function() {
108 if ($(this).val() < 0) {
109 $(this).val('0');
110 alert('Positive numbers only!');
111 }
112 });
113 }
114 $('#different_location_per_cart_item').on('change', function(){
115 if($(this).val()=='no'){
116 $('.different_location_per_cart_item_no').show();
117 }else{
118 $('.different_location_per_cart_item_no').hide();
119 }
120 });
121
122 function slwEnableShowLocationsProductPage()
123 {
124 // initial
125 if( $('#show_in_cart').val() != 'yes' ) {
126 $('#different_location_per_cart_item').prop('disabled', true);
127
128 } else {
129 $('#different_location_per_cart_item').prop('disabled', false);
130
131 }
132 // on change
133 $('#show_in_cart').on('change', function() {
134 if( $(this).val() == 'yes' ) {
135 $('#different_location_per_cart_item').prop('disabled', false);
136
137 } else {
138 $('#different_location_per_cart_item').prop('disabled', true);
139
140 }
141 });
142 }
143
144 function slwEnableLockDefaultLocation()
145 {
146 // initial
147 if( $( '#default_location_in_frontend_selection' ).is(":checked") ) {
148 $( '#lock_default_location_in_frontend' ).prop( 'disabled', false );
149 } else {
150 $( '#lock_default_location_in_frontend' ).prop( 'disabled', true );
151 }
152 // on change
153 $( '#default_location_in_frontend_selection' ).on('change', function() {
154 if( $( '#default_location_in_frontend_selection' ).is(":checked") ) {
155 $( '#lock_default_location_in_frontend' ).prop( 'disabled', false );
156 } else {
157 $( '#lock_default_location_in_frontend' ).prop( 'disabled', true );
158 $( '#lock_default_location_in_frontend' ).prop( 'checked', false );
159 }
160 } );
161 }
162
163 function slwAjaxSaveProductDefaultLocation()
164 {
165 $( '.post-type-product #taxonomy-location .slw_location_make_default' ).on( 'click', function( e ) {
166 e.preventDefault();
167 var elem = $( this );
168 var product_id = $( this ).data( 'product_id' );
169 var term_id = $( this ).data( 'term_id' );
170
171 // block UI
172 $( '#locationdiv' ).block({
173 message: null,
174 overlayCSS: {
175 background: '#fff',
176 opacity: 0.6
177 }
178 });
179
180 // ajax request
181 $.ajax({
182 url: ajaxurl,
183 data: {
184 action: 'slw_save_product_default_location',
185 nonce: slw_admin_scripts.nonce,
186 product_id: product_id,
187 term_id: term_id,
188 },
189 type: 'POST',
190 cache: false,
191 success: function( response ) {
192 console.log( response );
193
194 // reload page
195 location.reload();
196 },
197 error: function( xhr, status, error ) {
198 console.log( error );
199
200 // unblock UI
201 $( '#locationdiv' ).unblock();
202 },
203 });
204
205 } );
206 }
207
208 function slwAjaxRemoveProductDefaultLocation()
209 {
210 $( '.post-type-product #taxonomy-location .slw_location_remove_default' ).on( 'click', function( e ) {
211 e.preventDefault();
212 var elem = $( this );
213 var product_id = $( this ).data( 'product_id' );
214
215 // block UI
216 $( '#locationdiv' ).block({
217 message: null,
218 overlayCSS: {
219 background: '#fff',
220 opacity: 0.6
221 }
222 });
223
224 // ajax request
225 $.ajax({
226 url: ajaxurl,
227 data: {
228 action: 'slw_remove_product_default_location',
229 nonce: slw_admin_scripts.nonce,
230 product_id: product_id,
231 },
232 type: 'POST',
233 cache: false,
234 success: function( response ) {
235 console.log( response );
236
237 // reload page
238 location.reload();
239 },
240 error: function( xhr, status, error ) {
241 console.log( error );
242
243 // unblock UI
244 $( '#locationdiv' ).unblock();
245 },
246 });
247
248 } );
249 }
250
251 $('a.slw_clear_debug_log').on('click', function (e) {
252
253 e.preventDefault();
254
255 $('.slw_logger ul.slw_debug_log').html('');
256
257 var data = {
258
259 action: 'slw_clear_debug_log',
260 slw_clear_debug_log: 'true',
261 slw_clear_debug_log_field: slw_admin_scripts.nonce,
262 }
263
264 $.blockUI({ message: false });
265 $.post(ajaxurl, data, function (response, code) {
266 $.unblockUI();
267 if (code == 'success') {
268 }
269 });
270
271 });
272
273 $('input#slw-logs-status').on('click', function () {
274 var isChecked = $(this).is(':checked');
275 var data = {
276 action: 'slw_logs_status',
277 status: isChecked ? $(this).val() : '',
278 slw_nonce_field: slw_admin_scripts.nonce
279 };
280
281 $.blockUI({ message: false });
282
283 $.post(ajaxurl, data, function (response) {
284 var message = '';
285
286 if (response.success) {
287 message = response.data.message + ' (Status: ' + response.data.status + ')';
288 } else {
289 message = 'Error: ' + response.data.message;
290 }
291
292 $.blockUI({ message: '<h4>' + message + '</h4>' });
293
294 setTimeout(function () {
295 $.unblockUI();
296 }, 3000);
297 }).fail(function () {
298 $.unblockUI();
299 alert(slw_admin_scripts.slw_error_occurred);
300 });
301 });
302
303 $('input#slw-update-product-locations-stock-values').bind('click', function (e) {
304 var data = {
305 action: 'slw_update_product_locations_stock_values',
306 status: $(this).is(':checked') ? $(this).val() : '',
307 slw_nonce_field: slw_admin_scripts.nonce,
308 };
309
310 $.blockUI({ message: false });
311 $.post(ajaxurl, data, function (response, code) {
312 $.unblockUI();
313 if (code == 'success') {
314 // Action after success (if needed)
315 }
316 });
317 });
318
319
320 $('input#slw-api-status').bind('click', function (e) {
321 var data = {
322
323 action: 'slw_api_status',
324 status: $(this).is(':checked')?$(this).val():'',
325 slw_nonce_field: slw_admin_scripts.nonce,
326 }
327
328 $.blockUI({ message: false });
329 $.post(ajaxurl, data, function (response, code) {
330 $.unblockUI();
331 if (code == 'success') {
332
333 }
334
335 });
336
337
338 });
339 $('input#slw-crons-status').on('click', function () {
340 var data = {
341 action: 'slw_crons_status',
342 status: $(this).is(':checked') ? $(this).val() : '',
343 slw_nonce_field: slw_admin_scripts.nonce
344 };
345
346 $.blockUI({ message: false });
347
348 $.post(ajaxurl, data, function (response) {
349 var message = '';
350
351 if (response.success) {
352 message = response.data.message + ' (Status: ' + response.data.status + ')';
353 } else {
354 message = 'Error: ' + response.data.message;
355 }
356
357 $.blockUI({ message: '<h4>' + message + '</h4>' });
358
359 setTimeout(function () {
360 $.unblockUI();
361 }, 3000);
362 });
363 });
364
365
366 $('#slw-location-assignment, a.slw-location-assignment').bind('click', function (e) {
367 var assignment_val = '';
368
369 if ($(this).is('input[type="checkbox"]')) {
370 assignment_val = $(this).is(':checked') ? $(this).val() : '';
371 } else {
372 assignment_val = $(this).hasClass('checked') ? '' : 'yes';
373 $(this).toggleClass('checked');
374 }
375
376 var data = {
377 action: 'slw_location_assignment',
378 assignment: assignment_val,
379 location_id: $(this).data('id'),
380 slw_nonce_field: slw_admin_scripts.nonce,
381 };
382
383 $.blockUI({ message: false });
384 $.post(ajaxurl, data, function (response, code) {
385 $.unblockUI();
386 if (code == 'success' && response.success) {
387
388 }
389 });
390 });
391
392
393 $('#slw-location-status, a.slw-location-status').bind('click', function (e) {
394
395
396 var status_val = '';
397
398 if($(this).is('input[type="checkbox"]')){
399 status_val = ($(this).is(':checked')?$(this).val():'');
400 }else{
401 status_val = $(this).hasClass('checked')?'':'yes';
402 $(this).toggleClass('checked');
403 }
404
405 var data = {
406 action: 'slw_location_status',
407 status: status_val,
408 location_id: $(this).data('id'),
409 slw_nonce_field: slw_admin_scripts.nonce,
410 }
411
412 $.blockUI({ message: false });
413 $.post(ajaxurl, data, function (response, code) {
414 $.unblockUI();
415 if (code == 'success') {
416 }
417
418 });
419
420
421 });
422
423
424 $('input#slw-map-status, a.slw-map-status').bind('click', function (e) {
425 var obj = $(this);
426 var is_checkbox = obj.is(':input[type="checkbox"]');
427 var is_status = (is_checkbox?($(this).is(':checked')?obj.val():''):obj.data('status'));
428
429 var data = {
430
431 action: 'slw_map_status',
432 status: is_status,
433 location_id: obj.data('id'),
434 slw_nonce_field: slw_admin_scripts.nonce,
435 }
436
437 $.blockUI({ message: false });
438 $.post(ajaxurl, data, function (response, code) {
439 $.unblockUI();
440 if (code == 'success') {
441 if(!is_checkbox){
442 obj.data('status', (is_status=='yes'?'':'yes'));
443
444 if(is_status=='yes'){
445 obj.find('.slw_map_status-disabled').hide();
446 obj.find('.slw_map_status-enabled').show();
447 }else{
448 obj.find('.slw_map_status-disabled').show();
449 obj.find('.slw_map_status-enabled').hide();
450 }
451 }
452 }
453
454 });
455
456
457 });
458
459
460 $('div.slw_widgets label.switch input[type="checkbox"]').bind('click', function (e) {
461
462 var data = {
463
464 action: 'slw_widgets_settings',
465 slw_widget_key: $(this).attr('name'),
466 slw_widget_value: $(this).is(':checked')?$(this).val():'',
467 slw_nonce_field: slw_admin_scripts.nonce,
468 }
469
470 $.blockUI({ message: false });
471 $.post(ajaxurl, data, function (response, code) {
472 $.unblockUI();
473 if (code == 'success') {
474 }
475 });
476
477 });
478
479
480 if($('select[name="auto_order_allocate"]').length>0){
481 $('select[name="auto_order_allocate"]').on('change', function(){
482 var id = $(this).data('id');
483 if($('select[name="auto_order_allocate"] option:selected').val()=='1'){
484 $('tr.'+id).addClass('selected');
485 }else{
486 $('tr.'+id).removeClass('selected');
487 }
488 });
489 $('select[name="auto_order_allocate"]').trigger('change');
490 }
491
492 var slw_widgets_update_request = false;
493 $('div.slw_widgets ul li').on('change', 'input', function(){
494 var data = {
495 action: 'slw_widgets_settings',
496 slw_widget_key: $(this).attr('name'),
497 slw_widget_value: $(this).val(),
498 slw_nonce_field: slw_admin_scripts.nonce,
499 }
500
501 if(!slw_widgets_update_request){
502 slw_widgets_update_request = true;
503 $.blockUI({ message: false });
504 $.post(ajaxurl, data, function (response, code) {
505 $.unblockUI();
506
507 if (code == 'success') {
508
509 }
510
511 slw_widgets_update_request = false;
512 });
513 }
514 });
515 if($('.slw_need_popup').length>0){
516 $('.slw_need_popup ul li[data-type="screenshot"] a, .slw_need_popup a[data-type="screenshot"]').magnificPopup({
517 type: 'image',
518 gallery: {
519 // options for gallery
520 enabled: false
521 },
522 mainClass: 'mfp-with-zoom', // this class is for CSS animation below
523
524 zoom: {
525 enabled: true, // By default it's false, so don't forget to enable it
526
527 duration: 400, // duration of the effect, in milliseconds
528 easing: 'ease-in', // CSS transition easing function
529
530 // The "opener" function should return the element from which popup will be zoomed in
531 // and to which popup will be scaled down
532 // By defailt it looks for an image tag:
533 opener: function(openerElement) {
534 // openerElement is the element on which popup was initialized, in this case its <a> tag
535 // you don't need to add "opener" option if this code matches your needs, it's defailt one.
536 return openerElement.is('img') ? openerElement : openerElement.find('img');
537 }
538 }
539 });
540 }
541
542 $('div.slw-sample-codes > a').on('click', function(){
543 $(this).parent().find('div.slw-sample-code').toggle();
544 });
545 $('body').on('click', 'li[data-type="shortcode"] > svg', function(){
546 $(this).parent().toggleClass('collapsed');
547 });
548
549 $('body').on('click', 'table.table-view-list td.stock_at_locations span i', function(){
550 var n = $(this).html().replace('(', '').replace(')', '');
551 $('table.table-view-list td.stock_at_locations span.clicked').removeClass('clicked');
552 $(this).parent().addClass('clicked');
553 $('table.table-view-list td.stock_at_locations span input.location_qty_update').val(n);
554 });
555 $('body').on('keydown', 'table.table-view-list td.stock_at_locations span input.location_qty_update', function(e){
556 if (e.which == 13) {
557 e.preventDefault();
558 $(this).trigger('blur');
559 return false;
560 }
561
562 });
563 $('body').on('blur', 'table.table-view-list td.stock_at_locations span input.location_qty_update', function(e){
564
565
566 $(this).focus();
567 $.blockUI({message:slw_admin_scripts.wc_slw_pro?'':slw_admin_scripts.wc_slw_premium_feature, blockMsgClass: 'slw-premium-block',});
568 var n = ($(this).val())*1;
569 var obj = $(this).parents().closest('tr').find('td[data-colname="Stock"]');
570
571 $(this).parent().removeClass('clicked');
572 $(this).parent().find('i').html('('+n+')');
573 if(slw_admin_scripts.wc_slw_pro){
574
575 var data = {
576 'action': 'slw_product_list_qty_update',
577 'quantity': n,
578 'product_id': $(this).data('product'),
579 'location_id': $(this).data('location'),
580 'slw_nonce_field': slw_admin_scripts.nonce
581 };
582
583 $.post(slw_admin_scripts.ajaxurl, data, function(response) {
584
585 obj.html('');
586
587 $.unblockUI();
588
589
590
591 });
592
593 $(this).parent().find('mark').prop('class', (n>0?'instock':'outofstock'));
594
595
596 }else{
597 setTimeout(function(){
598 $.unblockUI();
599 }, 30000);
600 }
601
602 });
603
604 setTimeout(function(){
605 if($('#different_location_per_cart_item').length>0){
606 $('#different_location_per_cart_item').trigger('change');
607 }
608 if($('#stock-locations-for-woocommerce_tab_stock_locations_wrapper').length){
609
610 var product_id = slw_admin_scripts.wc_slw_product_id;
611 //console.log(product_id);
612 if(product_id){
613 $.each(slw_admin_scripts.wc_slw_location_status, function(i,v){
614
615 var obj_str = '_stock-locations-for-woocommerce'+product_id+'_stock_location_'+i+'_field';
616
617 if($('p.'+obj_str).length>0){
618 if(v!='yes'){
619 $('p.'+obj_str).addClass('slw-location-disabled').attr('title', slw_admin_scripts.wc_slw_location_disabled_msg);
620 }
621 }
622
623 });
624 }
625 }
626
627 }, 3000);
628
629 $('body').on('click', 'div.slw-api-requests input[name^="validate_request"]', function(){
630
631
632 var requests = {};
633
634 $.each($('div.slw-api-requests input[name^="validate_request"]:checked'), function(i,v){
635 requests[i] = $(this).val();
636 })
637
638 var data = {
639
640 action: 'slw_validate_api_requests',
641 slw_validate_request: requests,
642 slw_nonce_check: slw_admin_scripts.nonce,
643 }
644
645 $.blockUI({ message: false });
646 $.post(ajaxurl, data, function (response, code) {
647 $.unblockUI();
648 if (code == 'success') {
649 }
650 });
651
652 });
653
654 $('body').on('click', 'div.slw-cron-requests input[name^="validate_request"]', function(){
655
656
657 var requests = {};
658
659 $.each($('div.slw-cron-requests input[name^="validate_request"]:checked'), function(i,v){
660 requests[i] = $(this).val();
661 })
662
663 var data = {
664
665 action: 'slw_validate_cron_requests',
666 slw_validate_request: requests,
667 slw_nonce_check: slw_admin_scripts.nonce,
668 }
669
670 $.blockUI({ message: false });
671 $.post(ajaxurl, data, function (response, code) {
672 $.unblockUI();
673 if (code == 'success') {
674 }
675 });
676
677 });
678
679 setTimeout(function(){
680
681
682 if($('a.page-title-action[href*="page=product_exporter"]').length>0 && $('#slw_import_export_video').length==0){
683 $('<input type="button" id="slw_import_export_video" class="page-title-action" value="'+slw_admin_scripts.slw_import_export_tutorial+'">').insertAfter($('body.post-type-product a.page-title-action[href*="page=product_exporter"]').eq(0));
684 }
685
686 if($('#doaction').length>0 && $('#slw_import_export_video').length==0){
687 $('<input type="button" id="slw_import_export_video" class="button action" value="'+slw_admin_scripts.slw_import_export_tutorial+'">').insertAfter($('body.post-type-product #doaction').eq(0));
688 }
689
690 }, 1000);
691
692 $('body').on('click', '#slw_import_export_video', function(){
693 window.open('https://www.youtube.com/embed/4KCexCuVetk', '');
694 });
695
696
697 }(jQuery));
698