Browse Source

Duplicate product JS function

Vova Tkach 5 years ago
parent
commit
20f2888f7e
2 changed files with 41 additions and 0 deletions
  1. 41 0
      assets/cp.scripts.js
  2. 0 0
      assets/cp.scripts.js.go

+ 41 - 0
assets/cp.scripts.js

@@ -3503,6 +3503,10 @@
 			}
 		};
 
+		function FormDataIsChanged() {
+			return FormDataWasChanged;
+		}
+
 		function HtmlDecode(value) {
 			var doc = new DOMParser().parseFromString(value, "text/html");
 			return doc.documentElement.textContent;
@@ -3897,6 +3901,43 @@
 				});
 			},
 
+			ShopProductsDuplicate: function(button, product_id) {
+				if($(button).hasClass('in-progress')) return;
+				if(FormDataIsChanged()) {
+					fave.ShowMsgError('Warning!', 'Something was changed, save changes before duplicate product', true);
+					return;
+				}
+				$(button).addClass('in-progress');
+				$.ajax({
+					type: "POST",
+					url: '/cp/',
+					data: {
+						action: 'shop-duplicate',
+						id: product_id,
+					}
+				}).done(function(data) {
+					try {
+						eval(data);
+					} catch(e) {
+						if(e instanceof SyntaxError) {
+							console.log(data);
+							console.log('Error: JavaScript code eval error', e.message);
+						}
+					}
+				}).fail(function(xhr, status, error) {
+					try {
+						eval(xhr.responseText);
+					} catch(e) {
+						if(e instanceof SyntaxError) {
+							console.log(xhr.responseText);
+							console.log('Error: JavaScript code eval error', e.message);
+						}
+					}
+				}).always(function() {
+					$(button).removeClass('in-progress');
+				});
+			},
+
 			ActionLogout: function(message) {
 				if(confirm(message)) {
 					$.ajax({

File diff suppressed because it is too large
+ 0 - 0
assets/cp.scripts.js.go


Some files were not shown because too many files changed in this diff