|
|
@@ -1,172 +1,241 @@
|
|
|
-/**
|
|
|
- * Admin JavaScript for Studiou WC Product Category Manager
|
|
|
- */
|
|
|
-(function($) {
|
|
|
- 'use strict';
|
|
|
-
|
|
|
- // Initialize admin scripts
|
|
|
- $(document).ready(function() {
|
|
|
- // Import form handling
|
|
|
- if ($('#studiou-wcpcm-import-form').length) {
|
|
|
- initImportForm();
|
|
|
- }
|
|
|
-
|
|
|
- // Export form handling
|
|
|
- if ($('#studiou-wcpcm-export-form').length) {
|
|
|
- initExportForm();
|
|
|
- }
|
|
|
-
|
|
|
- // Sample CSV download handler
|
|
|
- if ($('#studiou-wcpcm-download-sample').length) {
|
|
|
- initSampleDownload();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- /**
|
|
|
- * Initialize import form
|
|
|
- */
|
|
|
- function initImportForm() {
|
|
|
- $('#studiou-wcpcm-import-form').on('submit', function(e) {
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- // Show spinner
|
|
|
- var $submitBtn = $(this).find('#studiou-wcpcm-import-button');
|
|
|
- var $spinner = $(this).find('.spinner');
|
|
|
-
|
|
|
- $submitBtn.prop('disabled', true);
|
|
|
- $spinner.css('visibility', 'visible');
|
|
|
-
|
|
|
- // Clear previous notices
|
|
|
- $('.studiou-wcpcm-notice-area').empty();
|
|
|
-
|
|
|
- // Create form data
|
|
|
- var formData = new FormData(this);
|
|
|
- formData.append('action', 'studiou_wcpcm_import');
|
|
|
- formData.append('nonce', studiouWcpcm.nonce);
|
|
|
-
|
|
|
- // Send AJAX request
|
|
|
- $.ajax({
|
|
|
- url: studiouWcpcm.ajaxUrl,
|
|
|
- type: 'POST',
|
|
|
- data: formData,
|
|
|
- processData: false,
|
|
|
- contentType: false,
|
|
|
- success: function(response) {
|
|
|
- if (response.success) {
|
|
|
- showNotice('success', studiouWcpcm.i18n.importSuccess);
|
|
|
-
|
|
|
- // Show results
|
|
|
- $('#studiou-wcpcm-import-results').text(response.data.message);
|
|
|
- $('.studiou-wcpcm-import-results').show();
|
|
|
- } else {
|
|
|
- showNotice('error', response.data.message);
|
|
|
- }
|
|
|
- },
|
|
|
- error: function() {
|
|
|
- showNotice('error', studiouWcpcm.i18n.importError);
|
|
|
- },
|
|
|
- complete: function() {
|
|
|
- // Hide spinner
|
|
|
- $submitBtn.prop('disabled', false);
|
|
|
- $spinner.css('visibility', 'hidden');
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Initialize export form
|
|
|
- */
|
|
|
- function initExportForm() {
|
|
|
- $('#studiou-wcpcm-export-form').on('submit', function(e) {
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- // Show spinner
|
|
|
- var $submitBtn = $(this).find('#studiou-wcpcm-export-button');
|
|
|
- var $spinner = $(this).find('.spinner');
|
|
|
-
|
|
|
- $submitBtn.prop('disabled', true);
|
|
|
- $spinner.css('visibility', 'visible');
|
|
|
-
|
|
|
- // Clear previous notices
|
|
|
- $('.studiou-wcpcm-notice-area').empty();
|
|
|
-
|
|
|
- // Send AJAX request
|
|
|
- $.ajax({
|
|
|
- url: studiouWcpcm.ajaxUrl,
|
|
|
- type: 'POST',
|
|
|
- data: {
|
|
|
- action: 'studiou_wcpcm_export',
|
|
|
- nonce: studiouWcpcm.nonce
|
|
|
- },
|
|
|
- success: function(response) {
|
|
|
- if (response.success) {
|
|
|
- showNotice('success', studiouWcpcm.i18n.exportSuccess);
|
|
|
-
|
|
|
- // Show download link
|
|
|
- $('#studiou-wcpcm-export-message').text(response.data.message);
|
|
|
- $('#studiou-wcpcm-download-export').attr('href', response.data.download_url);
|
|
|
- $('.studiou-wcpcm-export-results').show();
|
|
|
- } else {
|
|
|
- showNotice('error', response.data.message);
|
|
|
- }
|
|
|
- },
|
|
|
- error: function() {
|
|
|
- showNotice('error', studiouWcpcm.i18n.exportError);
|
|
|
- },
|
|
|
- complete: function() {
|
|
|
- // Hide spinner
|
|
|
- $submitBtn.prop('disabled', false);
|
|
|
- $spinner.css('visibility', 'hidden');
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Initialize sample CSV download
|
|
|
- */
|
|
|
- function initSampleDownload() {
|
|
|
- $('#studiou-wcpcm-download-sample').on('click', function(e) {
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- // Sample CSV content
|
|
|
- var csvContent = 'name,url-name,parent-name,description,display-type,visibility,protected-passwords,operation\n' +
|
|
|
- '"Clothing","clothing","","Top quality clothing","default","public","","A"\n' +
|
|
|
- '"Men","men","Clothing","Men\'s clothing","products","public","","A"\n' +
|
|
|
- '"Women","women","Clothing","Women\'s clothing","products","protected","password123","A"\n' +
|
|
|
- '"Kids","kids","Clothing","Kids clothing","products","public","","U"\n' +
|
|
|
- '"Accessories","accessories","","All accessories","default","public","","D"';
|
|
|
-
|
|
|
- // Create download link
|
|
|
- var blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
|
|
- var url = URL.createObjectURL(blob);
|
|
|
- var link = document.createElement('a');
|
|
|
-
|
|
|
- link.setAttribute('href', url);
|
|
|
- link.setAttribute('download', 'sample-product-categories.csv');
|
|
|
- link.style.visibility = 'hidden';
|
|
|
-
|
|
|
- document.body.appendChild(link);
|
|
|
- link.click();
|
|
|
- document.body.removeChild(link);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Show notice message
|
|
|
- *
|
|
|
- * @param {string} type Notice type (success, error)
|
|
|
- * @param {string} message Notice message
|
|
|
- */
|
|
|
- function showNotice(type, message) {
|
|
|
- var $notice = $('<div class="studiou-wcpcm-notice studiou-wcpcm-notice-' + type + '"></div>').text(message);
|
|
|
- $('.studiou-wcpcm-notice-area').append($notice);
|
|
|
-
|
|
|
- // Scroll to notice
|
|
|
- $('html, body').animate({
|
|
|
- scrollTop: $('.studiou-wcpcm-notice-area').offset().top - 50
|
|
|
- }, 500);
|
|
|
- }
|
|
|
-
|
|
|
+/**
|
|
|
+ * Admin JavaScript for Studiou WC Product Category Manager
|
|
|
+ */
|
|
|
+(function($) {
|
|
|
+ 'use strict';
|
|
|
+
|
|
|
+ // Initialize admin scripts
|
|
|
+ $(document).ready(function() {
|
|
|
+ // Import form handling
|
|
|
+ if ($('#studiou-wcpcm-import-form').length) {
|
|
|
+ initImportForm();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Export form handling
|
|
|
+ if ($('#studiou-wcpcm-export-form').length) {
|
|
|
+ initExportForm();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Move products form handling
|
|
|
+ if ($('#studiou-wcpcm-move-form').length) {
|
|
|
+ initMoveForm();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Sample CSV download handler
|
|
|
+ if ($('#studiou-wcpcm-download-sample').length) {
|
|
|
+ initSampleDownload();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initialize import form
|
|
|
+ */
|
|
|
+ function initImportForm() {
|
|
|
+ $('#studiou-wcpcm-import-form').on('submit', function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ // Show spinner
|
|
|
+ var $submitBtn = $(this).find('#studiou-wcpcm-import-button');
|
|
|
+ var $spinner = $(this).find('.spinner');
|
|
|
+
|
|
|
+ $submitBtn.prop('disabled', true);
|
|
|
+ $spinner.css('visibility', 'visible');
|
|
|
+
|
|
|
+ // Clear previous notices
|
|
|
+ $('.studiou-wcpcm-notice-area').empty();
|
|
|
+
|
|
|
+ // Create form data
|
|
|
+ var formData = new FormData(this);
|
|
|
+ formData.append('action', 'studiou_wcpcm_import');
|
|
|
+ formData.append('nonce', studiouWcpcm.nonce);
|
|
|
+
|
|
|
+ // Send AJAX request
|
|
|
+ $.ajax({
|
|
|
+ url: studiouWcpcm.ajaxUrl,
|
|
|
+ type: 'POST',
|
|
|
+ data: formData,
|
|
|
+ processData: false,
|
|
|
+ contentType: false,
|
|
|
+ success: function(response) {
|
|
|
+ if (response.success) {
|
|
|
+ showNotice('success', studiouWcpcm.i18n.importSuccess);
|
|
|
+
|
|
|
+ // Show results
|
|
|
+ $('#studiou-wcpcm-import-results').text(response.data.message);
|
|
|
+ $('.studiou-wcpcm-import-results').show();
|
|
|
+ } else {
|
|
|
+ showNotice('error', response.data.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function() {
|
|
|
+ showNotice('error', studiouWcpcm.i18n.importError);
|
|
|
+ },
|
|
|
+ complete: function() {
|
|
|
+ // Hide spinner
|
|
|
+ $submitBtn.prop('disabled', false);
|
|
|
+ $spinner.css('visibility', 'hidden');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initialize export form
|
|
|
+ */
|
|
|
+ function initExportForm() {
|
|
|
+ $('#studiou-wcpcm-export-form').on('submit', function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ // Show spinner
|
|
|
+ var $submitBtn = $(this).find('#studiou-wcpcm-export-button');
|
|
|
+ var $spinner = $(this).find('.spinner');
|
|
|
+
|
|
|
+ $submitBtn.prop('disabled', true);
|
|
|
+ $spinner.css('visibility', 'visible');
|
|
|
+
|
|
|
+ // Clear previous notices
|
|
|
+ $('.studiou-wcpcm-notice-area').empty();
|
|
|
+
|
|
|
+ // Send AJAX request
|
|
|
+ $.ajax({
|
|
|
+ url: studiouWcpcm.ajaxUrl,
|
|
|
+ type: 'POST',
|
|
|
+ data: {
|
|
|
+ action: 'studiou_wcpcm_export',
|
|
|
+ nonce: studiouWcpcm.nonce
|
|
|
+ },
|
|
|
+ success: function(response) {
|
|
|
+ if (response.success) {
|
|
|
+ showNotice('success', studiouWcpcm.i18n.exportSuccess);
|
|
|
+
|
|
|
+ // Show download link
|
|
|
+ $('#studiou-wcpcm-export-message').text(response.data.message);
|
|
|
+ $('#studiou-wcpcm-download-export').attr('href', response.data.download_url);
|
|
|
+ $('.studiou-wcpcm-export-results').show();
|
|
|
+ } else {
|
|
|
+ showNotice('error', response.data.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function() {
|
|
|
+ showNotice('error', studiouWcpcm.i18n.exportError);
|
|
|
+ },
|
|
|
+ complete: function() {
|
|
|
+ // Hide spinner
|
|
|
+ $submitBtn.prop('disabled', false);
|
|
|
+ $spinner.css('visibility', 'hidden');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initialize move products form
|
|
|
+ */
|
|
|
+ function initMoveForm() {
|
|
|
+ $('#studiou-wcpcm-move-form').on('submit', function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ // Validate that different categories are selected
|
|
|
+ var sourceCategory = $('#source_category').val();
|
|
|
+ var targetCategory = $('#target_category').val();
|
|
|
+
|
|
|
+ if (sourceCategory === targetCategory) {
|
|
|
+ showNotice('error', studiouWcpcm.i18n.selectDifferentCategories);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Show spinner
|
|
|
+ var $submitBtn = $(this).find('#studiou-wcpcm-move-button');
|
|
|
+ var $spinner = $(this).find('.spinner');
|
|
|
+
|
|
|
+ $submitBtn.prop('disabled', true);
|
|
|
+ $spinner.css('visibility', 'visible');
|
|
|
+
|
|
|
+ // Clear previous notices
|
|
|
+ $('.studiou-wcpcm-notice-area').empty();
|
|
|
+
|
|
|
+ // Send AJAX request
|
|
|
+ $.ajax({
|
|
|
+ url: studiouWcpcm.ajaxUrl,
|
|
|
+ type: 'POST',
|
|
|
+ data: {
|
|
|
+ action: 'studiou_wcpcm_move_products',
|
|
|
+ source_category: sourceCategory,
|
|
|
+ target_category: targetCategory,
|
|
|
+ nonce: studiouWcpcm.nonce
|
|
|
+ },
|
|
|
+ success: function(response) {
|
|
|
+ if (response.success) {
|
|
|
+ showNotice('success', studiouWcpcm.i18n.moveSuccess);
|
|
|
+
|
|
|
+ // Show results
|
|
|
+ $('#studiou-wcpcm-move-message').html('<p>' + response.data.message + '</p>');
|
|
|
+ $('.studiou-wcpcm-move-results').show();
|
|
|
+
|
|
|
+ // Refresh the page to update category counts
|
|
|
+ setTimeout(function() {
|
|
|
+ location.reload();
|
|
|
+ }, 3000);
|
|
|
+ } else {
|
|
|
+ showNotice('error', response.data.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function() {
|
|
|
+ showNotice('error', studiouWcpcm.i18n.moveError);
|
|
|
+ },
|
|
|
+ complete: function() {
|
|
|
+ // Hide spinner
|
|
|
+ $submitBtn.prop('disabled', false);
|
|
|
+ $spinner.css('visibility', 'hidden');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initialize sample CSV download
|
|
|
+ */
|
|
|
+ function initSampleDownload() {
|
|
|
+ $('#studiou-wcpcm-download-sample').on('click', function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ // Sample CSV content
|
|
|
+ var csvContent = 'name,url-name,parent-name,description,display-type,visibility,protected-passwords,operation\n' +
|
|
|
+ '"Clothing","clothing","","Top quality clothing","default","public","","A"\n' +
|
|
|
+ '"Men","men","Clothing","Men\'s clothing","products","public","","A"\n' +
|
|
|
+ '"Women","women","Clothing","Women\'s clothing","products","protected","password123","A"\n' +
|
|
|
+ '"Kids","kids","Clothing","Kids clothing","products","public","","U"\n' +
|
|
|
+ '"Accessories","accessories","","All accessories","default","public","","D"';
|
|
|
+
|
|
|
+ // Create download link
|
|
|
+ var blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
|
|
+ var url = URL.createObjectURL(blob);
|
|
|
+ var link = document.createElement('a');
|
|
|
+
|
|
|
+ link.setAttribute('href', url);
|
|
|
+ link.setAttribute('download', 'sample-product-categories.csv');
|
|
|
+ link.style.visibility = 'hidden';
|
|
|
+
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Show notice message
|
|
|
+ *
|
|
|
+ * @param {string} type Notice type (success, error)
|
|
|
+ * @param {string} message Notice message
|
|
|
+ */
|
|
|
+ function showNotice(type, message) {
|
|
|
+ var $notice = $('<div class="studiou-wcpcm-notice studiou-wcpcm-notice-' + type + '"></div>').text(message);
|
|
|
+ $('.studiou-wcpcm-notice-area').append($notice);
|
|
|
+
|
|
|
+ // Scroll to notice
|
|
|
+ $('html, body').animate({
|
|
|
+ scrollTop: $('.studiou-wcpcm-notice-area').offset().top - 50
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+
|
|
|
})(jQuery);
|