Browse Source

Fix image deleting if file is not exists, fix images preload on slow internet connection

Vova Tkach 5 years ago
parent
commit
76f1cd8d5f

+ 7 - 4
assets/cp.scripts.js

@@ -3884,9 +3884,11 @@
 			},
 
 			ShopProductsDeleteImage: function(button, product_id, filename) {
+				if($(button).hasClass('in-progress')) return;
 				if(!confirm('Are you sure want to delete image?')) {
 					return;
 				}
+				$(button).addClass('in-progress');
 				$.ajax({
 					type: "POST",
 					url: '/cp/',
@@ -3941,11 +3943,12 @@
 				});
 			},
 
-			ShopProductsRetryImage: function(img) {
-				var original = $(img).attr('src');
-				$(img).attr('src', '/assets/cp/img-load.gif');
+			ShopProductsRetryImage: function(img, id) {
+				var target = $('#' + id);
+				var src = target.attr('src');
+				target.attr('src', '/assets/cp/img-load.gif');
 				setTimeout(function() {
-					$(img).attr('src', original);
+					target.attr('src', src);
 				}, 1000);
 			},
 

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


+ 1 - 0
assets/cp.styles.css

@@ -1015,6 +1015,7 @@ ul.pagination {
 	border-radius: 12px;
 	background: #d9534f;
 	text-align: center;
+	cursor: pointer;
 }
 
 #list-images .attached-img a.remove:hover {

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


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


+ 1 - 1
assets/tmpl.cp.base.html

@@ -24,7 +24,7 @@
 				email: '{{$.Data.UserEmail}}'
 			};
 			function WaitForFave(callback) {
-				if(fave) {
+				if(window && window.fave) {
 					callback();
 				} else {
 					setTimeout(function() {

+ 1 - 1
consts/consts.go

@@ -5,7 +5,7 @@ import (
 )
 
 const AssetsPath = "assets"
-const AssetsVersion = "47"
+const AssetsVersion = "49"
 const DirIndexFile = "index.html"
 
 // Bootstrap resources

+ 1 - 1
modules/module_shop.go

@@ -239,7 +239,7 @@ func (this *Modules) shop_GetAllProductImages(wrap *wrapper.Wrapper, product_id
 		for rows.Next() {
 			err = rows.Scan(scan...)
 			if err == nil {
-				result += `<div class="attached-img"><a href="/products/images/` + html.EscapeString(string(values[0])) + `/` + html.EscapeString(string(values[1])) + `" title="` + html.EscapeString(string(values[1])) + `" target="_blank"><img src="/products/images/` + string(values[0]) + `/thumb-0-` + string(values[1]) + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this);});" /></a><a class="remove" href="javascript:fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[0])) + `, '` + html.EscapeString(string(values[1])) + `');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>`
+				result += `<div class="attached-img"><a href="/products/images/` + html.EscapeString(string(values[0])) + `/` + html.EscapeString(string(values[1])) + `" title="` + html.EscapeString(string(values[1])) + `" target="_blank"><img id="pimg_` + string(values[0]) + `_` + strings.Replace(string(values[1]), ".", "_", -1) + `" src="/products/images/` + string(values[0]) + `/thumb-0-` + string(values[1]) + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this, 'pimg_` + string(values[0]) + `_` + strings.Replace(string(values[1]), ".", "_", -1) + `');});" /></a><a class="remove" onclick="fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[0])) + `, '` + html.EscapeString(string(values[1])) + `');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>`
 			}
 		}
 	}

+ 1 - 3
modules/module_shop_act_upload_delete.go

@@ -42,9 +42,7 @@ func (this *Modules) RegisterAction_ShopUploadDelete() *Action {
 
 			// Delete file
 			target_file_full := wrap.DHtdocs + string(os.PathSeparator) + "products" + string(os.PathSeparator) + "images" + string(os.PathSeparator) + pf_id + string(os.PathSeparator) + pf_file
-			if err := os.Remove(target_file_full); err != nil {
-				return err
-			}
+			_ = os.Remove(target_file_full)
 
 			// Delete thumbnails
 			if err := wrap.RemoveProductImageThumbnails(pf_id, "thumb-*-"+pf_file); err != nil {

+ 2 - 1
modules/module_shop_act_upload_image.go

@@ -6,6 +6,7 @@ import (
 	"io/ioutil"
 	"os"
 	"path/filepath"
+	"strings"
 	"time"
 
 	_ "image/jpeg"
@@ -74,7 +75,7 @@ func (this *Modules) RegisterAction_ShopUploadImage() *Action {
 									}
 									return nil
 								}); err == nil {
-									wrap.Write(`$('#list-images').append('<div class="attached-img"><a href="/products/images/` + pf_id + `/` + target_file_name + `" title="` + target_file_name + `" target="_blank"><img src="/products/images/` + pf_id + `/thumb-0-` + target_file_name + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this);});" /></a><a class="remove" href="javascript:fave.ShopProductsDeleteImage(this, ` + pf_id + `, \'` + target_file_name + `\');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>');`)
+									wrap.Write(`$('#list-images').append('<div class="attached-img"><a href="/products/images/` + pf_id + `/` + target_file_name + `" title="` + target_file_name + `" target="_blank"><img id="pimg_` + pf_id + `_` + strings.Replace(target_file_name, ".", "_", -1) + `" src="/products/images/` + pf_id + `/thumb-0-` + target_file_name + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this, \'pimg_` + pf_id + `_` + strings.Replace(target_file_name, ".", "_", -1) + `\');});" /></a><a class="remove" onclick="fave.ShopProductsDeleteImage(this, ` + pf_id + `, \'` + target_file_name + `\');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>');`)
 								}
 							}
 						}

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