Browse Source

CP shop product images on edit

Vova Tkach 5 years ago
parent
commit
95c33e794e

+ 1 - 1
modules/module_settings_act_thumbnails.go

@@ -101,7 +101,7 @@ func (this *Modules) RegisterAction_SettingsThumbnails() *Action {
 		if files, err := filepath.Glob(pattern); err == nil {
 			for _, file := range files {
 				if err := os.Remove(file); err != nil {
-					wrap.LogError("Thumbnail file (%s) delete error: %s", file, err.Error())
+					wrap.LogError("[settings save] Thumbnail file (%s) delete error: %s", file, err.Error())
 				}
 			}
 		}

+ 1 - 1
modules/module_shop.go

@@ -241,7 +241,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])) + `" target="_blank">` + html.EscapeString(string(values[1])) + `</a>, <a href="javascript:fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[0])) + `, '` + html.EscapeString(string(values[1])) + `');">Delete</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 src="/api/product-image/thumb-0/` + string(values[0]) + `/` + string(values[1]) + `" /></a>, <a href="javascript:fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[0])) + `, '` + html.EscapeString(string(values[1])) + `');">Delete</a></div>`
 			}
 		}
 	}

+ 12 - 1
modules/module_shop_act_upload_delete.go

@@ -2,6 +2,7 @@ package modules
 
 import (
 	"os"
+	"path/filepath"
 
 	"golang-fave/engine/wrapper"
 	"golang-fave/utils"
@@ -44,12 +45,22 @@ func (this *Modules) RegisterAction_ShopUploadDelete() *Action {
 			target_file_full := wrap.DHtdocs + string(os.PathSeparator) + "products" + string(os.PathSeparator) + "images" + string(os.PathSeparator) + pf_id + string(os.PathSeparator) + pf_file
 			os.Remove(target_file_full)
 
+			// Delete thumbnails
+			pattern := wrap.DHtdocs + string(os.PathSeparator) + "products" + string(os.PathSeparator) + "images" + string(os.PathSeparator) + pf_id + string(os.PathSeparator) + "thumb-*-" + pf_file
+			if files, err := filepath.Glob(pattern); err == nil {
+				for _, file := range files {
+					if err := os.Remove(file); err != nil {
+						wrap.LogError("[upload delete] Thumbnail file (%s) delete error: %s", file, err.Error())
+					}
+				}
+			}
+
 			return nil
 		}); err != nil {
 			wrap.MsgError(err.Error())
 			return
 		}
 
-		wrap.Write(`$('#list-images a').each(function(i, e) { if(e.innerHTML == '` + pf_file + `') { $(e).parent().remove(); return; } });`)
+		wrap.Write(`$('#list-images a').each(function(i, e) { if($(e).attr('title') == '` + pf_file + `') { $(e).parent().remove(); return; } });`)
 	})
 }

+ 1 - 1
modules/module_shop_act_upload_image.go

@@ -92,6 +92,6 @@ func (this *Modules) RegisterAction_ShopUploadImage() *Action {
 			return
 		}
 
-		wrap.Write(`$('#list-images').append('<div class="attached-img"><a href="/products/images/` + pf_id + `/` + target_file_name + `" target="_blank">` + target_file_name + `</a>, <a href="javascript:fave.ShopProductsDeleteImage(this, ` + pf_id + `, \'` + target_file_name + `\');">Delete</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 src="/api/product-image/thumb-0/` + pf_id + `/` + target_file_name + `" /></a>, <a href="javascript:fave.ShopProductsDeleteImage(this, ` + pf_id + `, \'` + target_file_name + `\');">Delete</a></div>');`)
 	})
 }