admin-scripts.js
1 month 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
1 month ago
underscore-min.js
3 years ago
admin-scripts.js
901 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 | slwApiDemo(); |
| 44 | } |
| 45 | function slw_build_api_url(params) { |
| 46 | //console.log(params); |
| 47 | var base = slw_admin_scripts.home_url + '/?slw-api&'; |
| 48 | var parts = []; |
| 49 | |
| 50 | $.each(slw_admin_scripts.wc_slw_api_valid_keys, function (key, config) { |
| 51 | |
| 52 | |
| 53 | if (config.scope === 'variable') { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | var value = params[key] !== undefined ? params[key] : ''; |
| 59 | |
| 60 | parts.push('<span>' + key + '=' + value + '</span>'); |
| 61 | }); |
| 62 | |
| 63 | return base + parts.join('&'); |
| 64 | } |
| 65 | /** |
| 66 | * Build JSON payload for product variations + locations |
| 67 | * @param {Object} data - AJAX response from slw_api_get_product_stock_data |
| 68 | * @param {String} actionType - 'get' or 'set' |
| 69 | * @param {String} formatType - 'json' or 'default' |
| 70 | * @returns {Array} - array of payload objects for each variation |
| 71 | */ |
| 72 | function slw_build_json_payload(data, actionType = 'get', formatType = 'json') { |
| 73 | var payloads = []; |
| 74 | |
| 75 | $.each(data.variations, function (i, variation) { |
| 76 | |
| 77 | // Construct base object |
| 78 | var baseObj = { |
| 79 | id: variation.variation_id || data.product_id, // variation or main product |
| 80 | product_id: data.product_id, |
| 81 | variation_id: variation.variation_id, |
| 82 | action: actionType, |
| 83 | format: formatType |
| 84 | }; |
| 85 | |
| 86 | // Each location becomes an object with id, stock_value, stock_price |
| 87 | var locations = []; |
| 88 | |
| 89 | $.each(variation.locations, function (j, loc) { |
| 90 | locations.push({ |
| 91 | variation_id: variation.variation_id, |
| 92 | location_id: loc.location_id, |
| 93 | stock_value: loc.stock_value, |
| 94 | stock_price: loc.stock_price |
| 95 | }); |
| 96 | }); |
| 97 | |
| 98 | // Attach locations array |
| 99 | baseObj.location = locations; |
| 100 | |
| 101 | // Add to final array |
| 102 | payloads.push(baseObj); |
| 103 | }); |
| 104 | |
| 105 | return payloads; |
| 106 | } |
| 107 | |
| 108 | function slwApiDemo(){ |
| 109 | |
| 110 | $('button.slw-api-id-try').on('click', function(){ |
| 111 | $('.slw-api-id-input').change(); |
| 112 | }); |
| 113 | |
| 114 | $('.slw-api-id-input').on('change', function () { |
| 115 | |
| 116 | var product_id = $(this).val(); |
| 117 | |
| 118 | if (!product_id) { |
| 119 | return; |
| 120 | } |
| 121 | $.blockUI({ message: false }); |
| 122 | $.ajax({ |
| 123 | url: slw_admin_scripts.ajaxurl, |
| 124 | type: 'POST', |
| 125 | dataType: 'json', |
| 126 | data: { |
| 127 | action: 'slw_api_get_product_stock_data', |
| 128 | nonce: slw_admin_scripts.nonce, |
| 129 | product_id: product_id |
| 130 | }, |
| 131 | success: function (response) { |
| 132 | |
| 133 | $.unblockUI(); // always first |
| 134 | |
| 135 | if (!response.success) { |
| 136 | |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | var data = response.data; |
| 142 | var payloads = slw_build_json_payload(response.data, 'set', 'json'); |
| 143 | |
| 144 | |
| 145 | var html = ''; |
| 146 | |
| 147 | $.each(data.variations, function (i, variation) { |
| 148 | |
| 149 | // Iterate over locations inside this variation |
| 150 | $.each(variation.locations, function (j, loc) { |
| 151 | |
| 152 | // STOCK URL |
| 153 | var stockParams = { |
| 154 | id: variation.variation_id || data.product_id, // variation or main product |
| 155 | product_id: data.product_id, |
| 156 | variation_id: variation.variation_id, |
| 157 | item: 'stock', |
| 158 | value: loc.stock_value, |
| 159 | location_id: loc.location_id |
| 160 | }; |
| 161 | |
| 162 | var stockUrl = slw_build_api_url(stockParams); |
| 163 | html += '<b>' + stockUrl + '</b><br/>'; |
| 164 | |
| 165 | // PRICE URL |
| 166 | var priceParams = { |
| 167 | id: variation.variation_id || data.product_id, |
| 168 | product_id: data.product_id, |
| 169 | variation_id: variation.variation_id, |
| 170 | item: 'price', |
| 171 | value: loc.stock_price, |
| 172 | location_id: loc.location_id |
| 173 | }; |
| 174 | |
| 175 | var priceUrl = slw_build_api_url(priceParams); |
| 176 | html += '<b>' + priceUrl + '</b><br/>'; |
| 177 | }); |
| 178 | |
| 179 | }); |
| 180 | |
| 181 | $('.slw-api-urls ul li u').html(html); |
| 182 | |
| 183 | var prettyJson = JSON.stringify(payloads, null, 2); |
| 184 | $('div.slw-api-json-payload div').html('var payloads = '+prettyJson + `; |
| 185 | $.ajax({ |
| 186 | url: '`+slw_admin_scripts.home_url+`?slw-api', |
| 187 | type: 'POST', |
| 188 | dataType: 'json', |
| 189 | contentType: 'application/json', |
| 190 | data: JSON.stringify({ payload: payloads }), |
| 191 | success: function(res) { |
| 192 | |
| 193 | } |
| 194 | }); |
| 195 | `).fadeIn(); |
| 196 | |
| 197 | }, |
| 198 | error: function (xhr, textStatus, errorThrown) { |
| 199 | //console.log('error'); |
| 200 | console.log(xhr); |
| 201 | |
| 202 | $('div.slw-api-json-payload div').html(xhr.responseText).show(); |
| 203 | $.unblockUI(); |
| 204 | |
| 205 | }, |
| 206 | complete: function (xhr) { |
| 207 | //console.log('complete'); |
| 208 | //console.log(xhr); |
| 209 | $.unblockUI(); |
| 210 | } |
| 211 | |
| 212 | }); |
| 213 | |
| 214 | }); |
| 215 | |
| 216 | } |
| 217 | |
| 218 | |
| 219 | function slwDisableVariableStockInput() |
| 220 | { |
| 221 | $('#woocommerce-product-data').on('woocommerce_variations_loaded', function(event) { |
| 222 | if(slw_admin_scripts.stock_locations==true){ |
| 223 | $('input.variable_manage_stock').each(function(){ |
| 224 | if( $(this).prop( "checked" ) === true ) { |
| 225 | for(i=0; i < $('input.variable_manage_stock').length; i++) { |
| 226 | $('input#variable_stock' + i).prop( "disabled", true ); |
| 227 | } |
| 228 | } |
| 229 | }); |
| 230 | } |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | function slwWcProductManageStock() |
| 235 | { |
| 236 | var pluginWrapper = $('#' + slw_admin_scripts.slug + '_tab_stock_locations_wrapper'); // Plugin class |
| 237 | var pluginNotice = $('#' + slw_admin_scripts.slug + '_tab_stock_locations_notice'); // Plugin class |
| 238 | var pluginAlert = $('#' + slw_admin_scripts.slug + '_tab_stock_locations_alert'); // Plugin class |
| 239 | var wcStock = $('#_stock'); // Default WooCommerce class |
| 240 | var wcManageStock = $('#_manage_stock'); // Default WooCommerce class |
| 241 | |
| 242 | if(wcManageStock !== null) { |
| 243 | if(wcManageStock.is(':checked') === true) { // If stock management is active |
| 244 | if(slw_admin_scripts.stock_locations==true){ |
| 245 | wcStock.prop( "disabled", true ); |
| 246 | } |
| 247 | pluginWrapper.show(); |
| 248 | pluginNotice.hide(); |
| 249 | if(pluginAlert !== null) { |
| 250 | pluginAlert.show(); |
| 251 | } |
| 252 | } else { |
| 253 | wcManageStock.on('click', function () { |
| 254 | if (pluginWrapper.css("display") === 'none') { |
| 255 | if(slw_admin_scripts.stock_locations==true){ |
| 256 | wcStock.prop( "disabled", true ); |
| 257 | } |
| 258 | pluginWrapper.show(); |
| 259 | pluginNotice.hide(); |
| 260 | if(pluginAlert !== null) { |
| 261 | pluginAlert.show(); |
| 262 | } |
| 263 | } else { |
| 264 | wcStock.prop( "disabled", false ); |
| 265 | pluginWrapper.hide(); |
| 266 | pluginNoticepluginWrapper.show(); |
| 267 | if(pluginAlert !== null) { |
| 268 | pluginAlert.hide(); |
| 269 | } |
| 270 | } |
| 271 | }); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | function slwWcOrderItemStockPositiveNumbersOnly() |
| 277 | { |
| 278 | $('input.stock-locations-for-woocommerce_oitem').on('change', function() { |
| 279 | if ($(this).val() < 0) { |
| 280 | $(this).val('0'); |
| 281 | alert('Positive numbers only!'); |
| 282 | } |
| 283 | }); |
| 284 | } |
| 285 | $('#different_location_per_cart_item').on('change', function(){ |
| 286 | if($(this).val()=='no'){ |
| 287 | $('.different_location_per_cart_item_no').show(); |
| 288 | }else{ |
| 289 | $('.different_location_per_cart_item_no').hide(); |
| 290 | } |
| 291 | }); |
| 292 | |
| 293 | function slwEnableShowLocationsProductPage() |
| 294 | { |
| 295 | // initial |
| 296 | if( $('#show_in_cart').val() != 'yes' ) { |
| 297 | $('#different_location_per_cart_item').prop('disabled', true); |
| 298 | |
| 299 | } else { |
| 300 | $('#different_location_per_cart_item').prop('disabled', false); |
| 301 | |
| 302 | } |
| 303 | // on change |
| 304 | $('#show_in_cart').on('change', function() { |
| 305 | if( $(this).val() == 'yes' ) { |
| 306 | $('#different_location_per_cart_item').prop('disabled', false); |
| 307 | |
| 308 | } else { |
| 309 | $('#different_location_per_cart_item').prop('disabled', true); |
| 310 | |
| 311 | } |
| 312 | }); |
| 313 | } |
| 314 | |
| 315 | function slwEnableLockDefaultLocation() |
| 316 | { |
| 317 | // initial |
| 318 | if( $( '#default_location_in_frontend_selection' ).is(":checked") ) { |
| 319 | $( '#lock_default_location_in_frontend' ).prop( 'disabled', false ); |
| 320 | } else { |
| 321 | $( '#lock_default_location_in_frontend' ).prop( 'disabled', true ); |
| 322 | } |
| 323 | // on change |
| 324 | $( '#default_location_in_frontend_selection' ).on('change', function() { |
| 325 | if( $( '#default_location_in_frontend_selection' ).is(":checked") ) { |
| 326 | $( '#lock_default_location_in_frontend' ).prop( 'disabled', false ); |
| 327 | } else { |
| 328 | $( '#lock_default_location_in_frontend' ).prop( 'disabled', true ); |
| 329 | $( '#lock_default_location_in_frontend' ).prop( 'checked', false ); |
| 330 | } |
| 331 | } ); |
| 332 | } |
| 333 | |
| 334 | function slwAjaxSaveProductDefaultLocation() |
| 335 | { |
| 336 | $( '.post-type-product #taxonomy-location .slw_location_make_default' ).on( 'click', function( e ) { |
| 337 | e.preventDefault(); |
| 338 | var elem = $( this ); |
| 339 | var product_id = $( this ).data( 'product_id' ); |
| 340 | var term_id = $( this ).data( 'term_id' ); |
| 341 | |
| 342 | // block UI |
| 343 | $( '#locationdiv' ).block({ |
| 344 | message: null, |
| 345 | overlayCSS: { |
| 346 | background: '#fff', |
| 347 | opacity: 0.6 |
| 348 | } |
| 349 | }); |
| 350 | |
| 351 | // ajax request |
| 352 | $.ajax({ |
| 353 | url: ajaxurl, |
| 354 | data: { |
| 355 | action: 'slw_save_product_default_location', |
| 356 | nonce: slw_admin_scripts.nonce, |
| 357 | product_id: product_id, |
| 358 | term_id: term_id, |
| 359 | }, |
| 360 | type: 'POST', |
| 361 | cache: false, |
| 362 | success: function( response ) { |
| 363 | console.log( response ); |
| 364 | |
| 365 | // reload page |
| 366 | location.reload(); |
| 367 | }, |
| 368 | error: function( xhr, status, error ) { |
| 369 | console.log( error ); |
| 370 | |
| 371 | // unblock UI |
| 372 | $( '#locationdiv' ).unblock(); |
| 373 | }, |
| 374 | }); |
| 375 | |
| 376 | } ); |
| 377 | } |
| 378 | |
| 379 | function slwAjaxRemoveProductDefaultLocation() |
| 380 | { |
| 381 | $( '.post-type-product #taxonomy-location .slw_location_remove_default' ).on( 'click', function( e ) { |
| 382 | e.preventDefault(); |
| 383 | var elem = $( this ); |
| 384 | var product_id = $( this ).data( 'product_id' ); |
| 385 | |
| 386 | // block UI |
| 387 | $( '#locationdiv' ).block({ |
| 388 | message: null, |
| 389 | overlayCSS: { |
| 390 | background: '#fff', |
| 391 | opacity: 0.6 |
| 392 | } |
| 393 | }); |
| 394 | |
| 395 | // ajax request |
| 396 | $.ajax({ |
| 397 | url: ajaxurl, |
| 398 | data: { |
| 399 | action: 'slw_remove_product_default_location', |
| 400 | nonce: slw_admin_scripts.nonce, |
| 401 | product_id: product_id, |
| 402 | }, |
| 403 | type: 'POST', |
| 404 | cache: false, |
| 405 | success: function( response ) { |
| 406 | console.log( response ); |
| 407 | |
| 408 | // reload page |
| 409 | location.reload(); |
| 410 | }, |
| 411 | error: function( xhr, status, error ) { |
| 412 | console.log( error ); |
| 413 | |
| 414 | // unblock UI |
| 415 | $( '#locationdiv' ).unblock(); |
| 416 | }, |
| 417 | }); |
| 418 | |
| 419 | } ); |
| 420 | } |
| 421 | |
| 422 | $('a.slw_clear_debug_log').on('click', function (e) { |
| 423 | |
| 424 | e.preventDefault(); |
| 425 | |
| 426 | $('.slw_logger ul.slw_debug_log').html(''); |
| 427 | |
| 428 | var data = { |
| 429 | |
| 430 | action: 'slw_clear_debug_log', |
| 431 | slw_clear_debug_log: 'true', |
| 432 | slw_clear_debug_log_field: slw_admin_scripts.nonce, |
| 433 | } |
| 434 | |
| 435 | $.blockUI({ message: false }); |
| 436 | $.post(ajaxurl, data, function (response, code) { |
| 437 | $.unblockUI(); |
| 438 | if (code == 'success') { |
| 439 | } |
| 440 | }); |
| 441 | |
| 442 | }); |
| 443 | |
| 444 | $('input#slw-logs-status').on('click', function () { |
| 445 | var isChecked = $(this).is(':checked'); |
| 446 | var data = { |
| 447 | action: 'slw_logs_status', |
| 448 | status: isChecked ? $(this).val() : '', |
| 449 | slw_nonce_field: slw_admin_scripts.nonce |
| 450 | }; |
| 451 | |
| 452 | $.blockUI({ message: false }); |
| 453 | |
| 454 | $.post(ajaxurl, data, function (response) { |
| 455 | var message = ''; |
| 456 | |
| 457 | if (response.success) { |
| 458 | message = response.data.message + ' (Status: ' + response.data.status + ')'; |
| 459 | } else { |
| 460 | message = 'Error: ' + response.data.message; |
| 461 | } |
| 462 | |
| 463 | $.blockUI({ message: '<h4>' + message + '</h4>' }); |
| 464 | |
| 465 | setTimeout(function () { |
| 466 | $.unblockUI(); |
| 467 | }, 3000); |
| 468 | }).fail(function () { |
| 469 | $.unblockUI(); |
| 470 | alert(slw_admin_scripts.slw_error_occurred); |
| 471 | }); |
| 472 | }); |
| 473 | |
| 474 | $('input#slw-update-product-locations-stock-values').bind('click', function (e) { |
| 475 | var data = { |
| 476 | action: 'slw_update_product_locations_stock_values', |
| 477 | status: $(this).is(':checked') ? $(this).val() : '', |
| 478 | slw_nonce_field: slw_admin_scripts.nonce, |
| 479 | }; |
| 480 | |
| 481 | $.blockUI({ message: false }); |
| 482 | $.post(ajaxurl, data, function (response, code) { |
| 483 | $.unblockUI(); |
| 484 | if (code == 'success') { |
| 485 | // Action after success (if needed) |
| 486 | } |
| 487 | }); |
| 488 | }); |
| 489 | |
| 490 | |
| 491 | $('input#slw-api-status').bind('click', function (e) { |
| 492 | var data = { |
| 493 | |
| 494 | action: 'slw_api_status', |
| 495 | status: $(this).is(':checked')?$(this).val():'', |
| 496 | slw_nonce_field: slw_admin_scripts.nonce, |
| 497 | } |
| 498 | |
| 499 | $.blockUI({ message: false }); |
| 500 | $.post(ajaxurl, data, function (response, code) { |
| 501 | $.unblockUI(); |
| 502 | if (code == 'success') { |
| 503 | |
| 504 | } |
| 505 | |
| 506 | }); |
| 507 | |
| 508 | |
| 509 | }); |
| 510 | $('input#slw-crons-status').on('click', function () { |
| 511 | var data = { |
| 512 | action: 'slw_crons_status', |
| 513 | status: $(this).is(':checked') ? $(this).val() : '', |
| 514 | slw_nonce_field: slw_admin_scripts.nonce |
| 515 | }; |
| 516 | |
| 517 | $.blockUI({ message: false }); |
| 518 | |
| 519 | $.post(ajaxurl, data, function (response) { |
| 520 | var message = ''; |
| 521 | |
| 522 | if (response.success) { |
| 523 | message = response.data.message + ' (Status: ' + response.data.status + ')'; |
| 524 | } else { |
| 525 | message = 'Error: ' + response.data.message; |
| 526 | } |
| 527 | |
| 528 | $.blockUI({ message: '<h4>' + message + '</h4>' }); |
| 529 | |
| 530 | setTimeout(function () { |
| 531 | $.unblockUI(); |
| 532 | }, 3000); |
| 533 | }); |
| 534 | }); |
| 535 | |
| 536 | $('body').on('change', '.slw-optional-features-btn input', function () { |
| 537 | |
| 538 | var $input = $(this); |
| 539 | |
| 540 | var data = { |
| 541 | action: 'slw_update_optional_feature', |
| 542 | feature_key: $input.data('feature-key'), |
| 543 | feature_status: $input.is(':checked') ? 1 : 0, |
| 544 | slw_nonce_field: slw_admin_scripts.nonce |
| 545 | }; |
| 546 | |
| 547 | $.blockUI({ message: false }); |
| 548 | |
| 549 | $.post(ajaxurl, data, function (response) { |
| 550 | |
| 551 | var message = ''; |
| 552 | |
| 553 | if (response.success) { |
| 554 | message = response.data.message; |
| 555 | } else { |
| 556 | message = 'Error: ' + response.data.message; |
| 557 | } |
| 558 | |
| 559 | $.blockUI(); |
| 560 | |
| 561 | setTimeout(function () { |
| 562 | $.unblockUI(); |
| 563 | }, 2000); |
| 564 | |
| 565 | }); |
| 566 | |
| 567 | }); |
| 568 | |
| 569 | $('#slw-location-assignment, a.slw-location-assignment').bind('click', function (e) { |
| 570 | var assignment_val = ''; |
| 571 | |
| 572 | if ($(this).is('input[type="checkbox"]')) { |
| 573 | assignment_val = $(this).is(':checked') ? $(this).val() : ''; |
| 574 | } else { |
| 575 | assignment_val = $(this).hasClass('checked') ? '' : 'yes'; |
| 576 | $(this).toggleClass('checked'); |
| 577 | } |
| 578 | |
| 579 | var data = { |
| 580 | action: 'slw_location_assignment', |
| 581 | assignment: assignment_val, |
| 582 | location_id: $(this).data('id'), |
| 583 | slw_nonce_field: slw_admin_scripts.nonce, |
| 584 | }; |
| 585 | |
| 586 | $.blockUI({ message: false }); |
| 587 | $.post(ajaxurl, data, function (response, code) { |
| 588 | $.unblockUI(); |
| 589 | if (code == 'success' && response.success) { |
| 590 | |
| 591 | } |
| 592 | }); |
| 593 | }); |
| 594 | |
| 595 | |
| 596 | $('#slw-location-status, a.slw-location-status').bind('click', function (e) { |
| 597 | |
| 598 | |
| 599 | var status_val = ''; |
| 600 | |
| 601 | if($(this).is('input[type="checkbox"]')){ |
| 602 | status_val = ($(this).is(':checked')?$(this).val():''); |
| 603 | }else{ |
| 604 | status_val = $(this).hasClass('checked')?'':'yes'; |
| 605 | $(this).toggleClass('checked'); |
| 606 | } |
| 607 | |
| 608 | var data = { |
| 609 | action: 'slw_location_status', |
| 610 | status: status_val, |
| 611 | location_id: $(this).data('id'), |
| 612 | slw_nonce_field: slw_admin_scripts.nonce, |
| 613 | } |
| 614 | |
| 615 | $.blockUI({ message: false }); |
| 616 | $.post(ajaxurl, data, function (response, code) { |
| 617 | $.unblockUI(); |
| 618 | if (code == 'success') { |
| 619 | } |
| 620 | |
| 621 | }); |
| 622 | |
| 623 | |
| 624 | }); |
| 625 | |
| 626 | |
| 627 | $('input#slw-map-status, a.slw-map-status').bind('click', function (e) { |
| 628 | var obj = $(this); |
| 629 | var is_checkbox = obj.is(':input[type="checkbox"]'); |
| 630 | var is_status = (is_checkbox?($(this).is(':checked')?obj.val():''):obj.data('status')); |
| 631 | |
| 632 | var data = { |
| 633 | |
| 634 | action: 'slw_map_status', |
| 635 | status: is_status, |
| 636 | location_id: obj.data('id'), |
| 637 | slw_nonce_field: slw_admin_scripts.nonce, |
| 638 | } |
| 639 | |
| 640 | $.blockUI({ message: false }); |
| 641 | $.post(ajaxurl, data, function (response, code) { |
| 642 | $.unblockUI(); |
| 643 | if (code == 'success') { |
| 644 | if(!is_checkbox){ |
| 645 | obj.data('status', (is_status=='yes'?'':'yes')); |
| 646 | |
| 647 | if(is_status=='yes'){ |
| 648 | obj.find('.slw_map_status-disabled').hide(); |
| 649 | obj.find('.slw_map_status-enabled').show(); |
| 650 | }else{ |
| 651 | obj.find('.slw_map_status-disabled').show(); |
| 652 | obj.find('.slw_map_status-enabled').hide(); |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | }); |
| 658 | |
| 659 | |
| 660 | }); |
| 661 | |
| 662 | |
| 663 | $('div.slw_widgets label.switch input[type="checkbox"]').bind('click', function (e) { |
| 664 | |
| 665 | var data = { |
| 666 | |
| 667 | action: 'slw_widgets_settings', |
| 668 | slw_widget_key: $(this).attr('name'), |
| 669 | slw_widget_value: $(this).is(':checked')?$(this).val():'', |
| 670 | slw_nonce_field: slw_admin_scripts.nonce, |
| 671 | } |
| 672 | |
| 673 | $.blockUI({ message: false }); |
| 674 | $.post(ajaxurl, data, function (response, code) { |
| 675 | $.unblockUI(); |
| 676 | if (code == 'success') { |
| 677 | } |
| 678 | }); |
| 679 | |
| 680 | }); |
| 681 | |
| 682 | |
| 683 | if($('select[name="auto_order_allocate"]').length>0){ |
| 684 | $('select[name="auto_order_allocate"]').on('change', function(){ |
| 685 | var id = $(this).data('id'); |
| 686 | if($('select[name="auto_order_allocate"] option:selected').val()=='1'){ |
| 687 | $('tr.'+id).addClass('selected'); |
| 688 | }else{ |
| 689 | $('tr.'+id).removeClass('selected'); |
| 690 | } |
| 691 | }); |
| 692 | $('select[name="auto_order_allocate"]').trigger('change'); |
| 693 | } |
| 694 | |
| 695 | var slw_widgets_update_request = false; |
| 696 | $('div.slw_widgets ul li').on('change', 'input', function(){ |
| 697 | var data = { |
| 698 | action: 'slw_widgets_settings', |
| 699 | slw_widget_key: $(this).attr('name'), |
| 700 | slw_widget_value: $(this).val(), |
| 701 | slw_nonce_field: slw_admin_scripts.nonce, |
| 702 | } |
| 703 | |
| 704 | if(!slw_widgets_update_request){ |
| 705 | slw_widgets_update_request = true; |
| 706 | $.blockUI({ message: false }); |
| 707 | $.post(ajaxurl, data, function (response, code) { |
| 708 | $.unblockUI(); |
| 709 | |
| 710 | if (code == 'success') { |
| 711 | |
| 712 | } |
| 713 | |
| 714 | slw_widgets_update_request = false; |
| 715 | }); |
| 716 | } |
| 717 | }); |
| 718 | if($('.slw_need_popup').length>0){ |
| 719 | $('.slw_need_popup ul li[data-type="screenshot"] a, .slw_need_popup a[data-type="screenshot"]').magnificPopup({ |
| 720 | type: 'image', |
| 721 | gallery: { |
| 722 | // options for gallery |
| 723 | enabled: false |
| 724 | }, |
| 725 | mainClass: 'mfp-with-zoom', // this class is for CSS animation below |
| 726 | |
| 727 | zoom: { |
| 728 | enabled: true, // By default it's false, so don't forget to enable it |
| 729 | |
| 730 | duration: 400, // duration of the effect, in milliseconds |
| 731 | easing: 'ease-in', // CSS transition easing function |
| 732 | |
| 733 | // The "opener" function should return the element from which popup will be zoomed in |
| 734 | // and to which popup will be scaled down |
| 735 | // By defailt it looks for an image tag: |
| 736 | opener: function(openerElement) { |
| 737 | // openerElement is the element on which popup was initialized, in this case its <a> tag |
| 738 | // you don't need to add "opener" option if this code matches your needs, it's defailt one. |
| 739 | return openerElement.is('img') ? openerElement : openerElement.find('img'); |
| 740 | } |
| 741 | } |
| 742 | }); |
| 743 | } |
| 744 | |
| 745 | $('div.slw-sample-codes > a').on('click', function(){ |
| 746 | $(this).parent().find('div.slw-sample-code').toggle(); |
| 747 | }); |
| 748 | $('body').on('click', 'li[data-type="shortcode"] > svg', function(){ |
| 749 | $(this).parent().toggleClass('collapsed'); |
| 750 | }); |
| 751 | |
| 752 | $('body').on('click', 'table.table-view-list td.stock_at_locations span i', function(){ |
| 753 | var n = $(this).html().replace('(', '').replace(')', ''); |
| 754 | $('table.table-view-list td.stock_at_locations span.clicked').removeClass('clicked'); |
| 755 | $(this).parent().addClass('clicked'); |
| 756 | $('table.table-view-list td.stock_at_locations span input.location_qty_update').val(n); |
| 757 | }); |
| 758 | $('body').on('keydown', 'table.table-view-list td.stock_at_locations span input.location_qty_update', function(e){ |
| 759 | if (e.which == 13) { |
| 760 | e.preventDefault(); |
| 761 | $(this).trigger('blur'); |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | }); |
| 766 | $('body').on('blur', 'table.table-view-list td.stock_at_locations span input.location_qty_update', function(e){ |
| 767 | |
| 768 | |
| 769 | $(this).focus(); |
| 770 | $.blockUI({message:slw_admin_scripts.wc_slw_pro?'':slw_admin_scripts.wc_slw_premium_feature, blockMsgClass: 'slw-premium-block',}); |
| 771 | var n = ($(this).val())*1; |
| 772 | var obj = $(this).parents().closest('tr').find('td[data-colname="Stock"]'); |
| 773 | |
| 774 | $(this).parent().removeClass('clicked'); |
| 775 | $(this).parent().find('i').html('('+n+')'); |
| 776 | if(slw_admin_scripts.wc_slw_pro){ |
| 777 | |
| 778 | var data = { |
| 779 | 'action': 'slw_product_list_qty_update', |
| 780 | 'quantity': n, |
| 781 | 'product_id': $(this).data('product'), |
| 782 | 'location_id': $(this).data('location'), |
| 783 | 'slw_nonce_field': slw_admin_scripts.nonce |
| 784 | }; |
| 785 | |
| 786 | $.post(slw_admin_scripts.ajaxurl, data, function(response) { |
| 787 | |
| 788 | obj.html(''); |
| 789 | |
| 790 | $.unblockUI(); |
| 791 | |
| 792 | |
| 793 | |
| 794 | }); |
| 795 | |
| 796 | $(this).parent().find('mark').prop('class', (n>0?'instock':'outofstock')); |
| 797 | |
| 798 | |
| 799 | }else{ |
| 800 | setTimeout(function(){ |
| 801 | $.unblockUI(); |
| 802 | }, 30000); |
| 803 | } |
| 804 | |
| 805 | }); |
| 806 | |
| 807 | setTimeout(function(){ |
| 808 | if($('#different_location_per_cart_item').length>0){ |
| 809 | $('#different_location_per_cart_item').trigger('change'); |
| 810 | } |
| 811 | if($('#stock-locations-for-woocommerce_tab_stock_locations_wrapper').length){ |
| 812 | |
| 813 | var product_id = slw_admin_scripts.wc_slw_product_id; |
| 814 | //console.log(product_id); |
| 815 | if(product_id){ |
| 816 | $.each(slw_admin_scripts.wc_slw_location_status, function(i,v){ |
| 817 | |
| 818 | var obj_str = '_stock-locations-for-woocommerce'+product_id+'_stock_location_'+i+'_field'; |
| 819 | |
| 820 | if($('p.'+obj_str).length>0){ |
| 821 | if(v!='yes'){ |
| 822 | $('p.'+obj_str).addClass('slw-location-disabled').attr('title', slw_admin_scripts.wc_slw_location_disabled_msg); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | }); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | }, 3000); |
| 831 | |
| 832 | $('body').on('click', 'div.slw-api-requests input[name^="validate_request"]', function(){ |
| 833 | |
| 834 | |
| 835 | var requests = {}; |
| 836 | |
| 837 | $.each($('div.slw-api-requests input[name^="validate_request"]:checked'), function(i,v){ |
| 838 | requests[i] = $(this).val(); |
| 839 | }) |
| 840 | |
| 841 | var data = { |
| 842 | |
| 843 | action: 'slw_validate_api_requests', |
| 844 | slw_validate_request: requests, |
| 845 | slw_nonce_check: slw_admin_scripts.nonce, |
| 846 | } |
| 847 | |
| 848 | $.blockUI({ message: false }); |
| 849 | $.post(ajaxurl, data, function (response, code) { |
| 850 | $.unblockUI(); |
| 851 | if (code == 'success') { |
| 852 | } |
| 853 | }); |
| 854 | |
| 855 | }); |
| 856 | |
| 857 | $('body').on('click', 'div.slw-cron-requests input[name^="validate_request"]', function(){ |
| 858 | |
| 859 | |
| 860 | var requests = {}; |
| 861 | |
| 862 | $.each($('div.slw-cron-requests input[name^="validate_request"]:checked'), function(i,v){ |
| 863 | requests[i] = $(this).val(); |
| 864 | }) |
| 865 | |
| 866 | var data = { |
| 867 | |
| 868 | action: 'slw_validate_cron_requests', |
| 869 | slw_validate_request: requests, |
| 870 | slw_nonce_check: slw_admin_scripts.nonce, |
| 871 | } |
| 872 | |
| 873 | $.blockUI({ message: false }); |
| 874 | $.post(ajaxurl, data, function (response, code) { |
| 875 | $.unblockUI(); |
| 876 | if (code == 'success') { |
| 877 | } |
| 878 | }); |
| 879 | |
| 880 | }); |
| 881 | |
| 882 | setTimeout(function(){ |
| 883 | |
| 884 | |
| 885 | if($('a.page-title-action[href*="page=product_exporter"]').length>0 && $('#slw_import_export_video').length==0){ |
| 886 | $('<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)); |
| 887 | } |
| 888 | |
| 889 | if($('#doaction').length>0 && $('#slw_import_export_video').length==0){ |
| 890 | $('<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)); |
| 891 | } |
| 892 | |
| 893 | }, 1000); |
| 894 | |
| 895 | $('body').on('click', '#slw_import_export_video', function(){ |
| 896 | window.open('https://www.youtube.com/embed/4KCexCuVetk', ''); |
| 897 | }); |
| 898 | |
| 899 | |
| 900 | }(jQuery)); |
| 901 |