Browse Source

Move JS to file

Vova Tkach 5 years ago
parent
commit
15a6eefa1f
3 changed files with 38 additions and 22 deletions
  1. 33 0
      assets/cp.scripts.js
  2. 0 0
      assets/cp.scripts.js.go
  3. 5 22
      modules/module_shop.go

+ 33 - 0
assets/cp.scripts.js

@@ -3824,6 +3824,39 @@
 				PreventDataLost();
 			},
 
+			ShopProductsUploadImage: function(action_name, product_id, input_id) {
+				var fd = new FormData();
+				fd.append('action', action_name);
+				fd.append('id', product_id);
+				fd.append('file', $('#' + input_id)[0].files[0]);
+				$.ajax({
+					url: '/cp/',
+					method: 'POST',
+					type: 'POST',
+					data: fd,
+					contentType: false,
+					processData: false
+				}).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);
+						}
+					}
+				});
+			},
+
 			ActionLogout: function(message) {
 				if(confirm(message)) {
 					$.ajax({

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


+ 5 - 22
modules/module_shop.go

@@ -854,27 +854,10 @@ func (this *Modules) RegisterModule_Shop() *Module {
 					Name:    "",
 					Value:   "",
 					CallBack: func(field *builder.DataFormField) string {
-						return `<script>` +
-							`function UploadProductImage(product_id, input_id) {` +
-							`var fd = new FormData();` +
-							`var files = $('#' + input_id)[0].files[0];` +
-							`fd.append('action', 'shop-upload-image');` +
-							`fd.append('id', product_id);` +
-							`fd.append('file', files);` +
-							`$.ajax({` +
-							`url: '/cp/',` +
-							`method: 'POST',` +
-							`type: 'POST',` +
-							`data: fd,` +
-							`contentType: false,` +
-							`processData: false,` +
-							`success: function(response) {` +
-							`console.log('resp', response);` +
-							`}` +
-							`});` +
-							`}` +
-							`</script>` +
-							`<div class="form-group n6">` +
+						if data.A_id == 0 {
+							return ``
+						}
+						return `<div class="form-group n6">` +
 							`<div class="row">` +
 							`<div class="col-md-3">` +
 							`<label>Product images</label>` +
@@ -886,7 +869,7 @@ func (this *Modules) RegisterModule_Shop() *Module {
 							`` +
 							`</div>` +
 							`<div class="list-button position-relative">` +
-							`<input class="form-control" type="file" id="file" name="file" /><button type="button" class="btn btn-success btn-dynamic-remove" onclick="UploadProductImage(` + utils.IntToStr(data.A_id) + `, 'file');">Upload</button>` +
+							`<input class="form-control" type="file" id="file" name="file" /><button type="button" class="btn btn-success btn-dynamic-remove" onclick="fave.ShopProductsUploadImage('shop-upload-image', ` + utils.IntToStr(data.A_id) + `, 'file');">Upload</button>` +
 							`</div>` +
 							//
 							`</div>` +

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