From 6d75a545c1bcb3d7ae8ef537ceb5666ba0a75fb5 Mon Sep 17 00:00:00 2001 From: doremon04 Date: Tue, 12 Jul 2022 16:09:00 +0700 Subject: [PATCH 1/4] Update jquery validation for crud --- .../service/impl/CategoryServiceImpl.java | 2 +- .../static/backend/assets/js/custom.js | 50 +++ .../templates/backend/category/create.html | 53 ++- .../templates/backend/category/edit.html | 48 ++- .../templates/backend/customer/create.html | 49 ++- .../templates/backend/customer/edit.html | 49 ++- .../templates/backend/payment/create.html | 32 +- .../templates/backend/payment/edit.html | 28 +- .../templates/backend/product/create.html | 345 ++++++++++++------ .../templates/backend/product/edit.html | 338 +++++++++++------ .../templates/backend/supplier/create.html | 35 +- .../templates/backend/supplier/edit.html | 36 +- .../templates/backend/transport/create.html | 32 +- .../templates/backend/transport/edit.html | 32 +- .../templates/backend/unit/create.html | 32 +- .../templates/backend/unit/edit.html | 32 +- .../templates/backend/user/create.html | 51 ++- .../templates/backend/user/edit.html | 43 ++- .../resources/templates/frontend/cart.html | 2 +- .../resources/templates/frontend/product.html | 2 +- .../templates/layouts/backend/layout.html | 3 + .../templates/layouts/backend/sidebar.html | 41 ++- .../templates/layouts/frontend/header.html | 16 +- .../templates/layouts/frontend/layout.html | 3 + 24 files changed, 1020 insertions(+), 334 deletions(-) create mode 100644 src/main/resources/static/backend/assets/js/custom.js diff --git a/src/main/java/com/example/multikart/service/impl/CategoryServiceImpl.java b/src/main/java/com/example/multikart/service/impl/CategoryServiceImpl.java index c7f108a..b558ed1 100644 --- a/src/main/java/com/example/multikart/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/example/multikart/service/impl/CategoryServiceImpl.java @@ -53,7 +53,7 @@ public String storeCategory(CategoryRequestDTO input, BindingResult result, Mode return "backend/category/create"; } - var count = categoryRepository.findBySlugAndStatusNot(input.getSlug(), DefaultStatus.DELETED); + var count = categoryRepository.countBySlugAndStatusNot(input.getSlug(), DefaultStatus.DELETED); if (count > 0) { result.rejectValue("slug", "", "Đường dẫn đã được sử dụng"); } diff --git a/src/main/resources/static/backend/assets/js/custom.js b/src/main/resources/static/backend/assets/js/custom.js new file mode 100644 index 0000000..19289cc --- /dev/null +++ b/src/main/resources/static/backend/assets/js/custom.js @@ -0,0 +1,50 @@ +function convertToSlug(text) { + text = text.toString().toLowerCase().trim(); + + const sets = [ + {to: 'a', from: '[ÀÁÂÃÄÅÆĀĂĄẠẢẤẦẨẪẬẮẰẲẴẶἀ]'}, + {to: 'c', from: '[ÇĆĈČ]'}, + {to: 'd', from: '[ÐĎĐÞ]'}, + {to: 'e', from: '[ÈÉÊËĒĔĖĘĚẸẺẼẾỀỂỄỆ]'}, + {to: 'g', from: '[ĜĞĢǴ]'}, + {to: 'h', from: '[ĤḦ]'}, + {to: 'i', from: '[ÌÍÎÏĨĪĮİỈỊ]'}, + {to: 'j', from: '[Ĵ]'}, + {to: 'ij', from: '[IJ]'}, + {to: 'k', from: '[Ķ]'}, + {to: 'l', from: '[ĹĻĽŁ]'}, + {to: 'm', from: '[Ḿ]'}, + {to: 'n', from: '[ÑŃŅŇ]'}, + {to: 'o', from: '[ÒÓÔÕÖØŌŎŐỌỎỐỒỔỖỘỚỜỞỠỢǪǬƠ]'}, + {to: 'oe', from: '[Œ]'}, + {to: 'p', from: '[ṕ]'}, + {to: 'r', from: '[ŔŖŘ]'}, + {to: 's', from: '[ߌŜŞŠȘ]'}, + {to: 't', from: '[ŢŤ]'}, + {to: 'u', from: '[ÙÚÛÜŨŪŬŮŰŲỤỦỨỪỬỮỰƯ]'}, + {to: 'w', from: '[ẂŴẀẄ]'}, + {to: 'x', from: '[ẍ]'}, + {to: 'y', from: '[ÝŶŸỲỴỶỸ]'}, + {to: 'z', from: '[ŹŻŽ]'}, + {to: '-', from: '[·/_,:;\']'} + ]; + + sets.forEach(set => { + text = text.replace(new RegExp(set.from, 'gi'), set.to) + }); + + return text + .replace(/\s+/g, '-') // Replace spaces with - + .replace(/[^-a-z0-9а-я\u0370-\u03ff\u1f00-\u1fff]+/g, '') // Remove all non-word chars + .replace(/--+/g, '-') // Replace multiple - with single - + .replace(/^-+/, '') // Trim - from start of text + .replace(/-+$/, '') // Trim - from end of text +} + +//Add new method for jquery validate to check regex +$.validator.addMethod('regex', function (value, element, parameter) { + var re = new RegExp(parameter); + return this.optional(element) || re.test(value); +}, ''); + + diff --git a/src/main/resources/templates/backend/category/create.html b/src/main/resources/templates/backend/category/create.html index 44d42ca..15a307a 100644 --- a/src/main/resources/templates/backend/category/create.html +++ b/src/main/resources/templates/backend/category/create.html @@ -55,31 +55,31 @@

Thêm danh mục
+ method="post" id="form-input">
-
- +
-
+
- +
+
+ +
+ \ No newline at end of file diff --git a/src/main/resources/templates/backend/category/edit.html b/src/main/resources/templates/backend/category/edit.html index 596f0ef..0a1fcbb 100644 --- a/src/main/resources/templates/backend/category/edit.html +++ b/src/main/resources/templates/backend/category/edit.html @@ -56,7 +56,7 @@

Sửa danh mục + method="post" id="form-input">
@@ -65,17 +65,17 @@

Sửa danh mục Tên
-
+ placeholder="Tên danh mục..." th:field="*{name}"> +

-
+
@@ -112,5 +112,41 @@

Sửa danh mục

+
+ +
\ No newline at end of file diff --git a/src/main/resources/templates/backend/customer/create.html b/src/main/resources/templates/backend/customer/create.html index 061dd61..54b91fb 100644 --- a/src/main/resources/templates/backend/customer/create.html +++ b/src/main/resources/templates/backend/customer/create.html @@ -55,7 +55,7 @@

Create User + method="post" id="form-input">
@@ -66,7 +66,9 @@

Account Details

Name
+ placeholder="Name..." th:field="*{name}"> +
@@ -74,8 +76,8 @@

Account Details

-
+
@@ -119,5 +121,44 @@

Account Details

+
+ +
\ No newline at end of file diff --git a/src/main/resources/templates/backend/customer/edit.html b/src/main/resources/templates/backend/customer/edit.html index b2c366b..aa80ede 100644 --- a/src/main/resources/templates/backend/customer/edit.html +++ b/src/main/resources/templates/backend/customer/edit.html @@ -56,7 +56,7 @@

Edit User + method="post" id="form-input">
@@ -67,16 +67,18 @@

Account Details

Name
+ placeholder="Name..." th:field="*{name}"> +
-
+ placeholder="Email..."> +
@@ -120,5 +122,42 @@

Account Details

+
+ +
\ No newline at end of file diff --git a/src/main/resources/templates/backend/payment/create.html b/src/main/resources/templates/backend/payment/create.html index d2dc746..dab9f45 100644 --- a/src/main/resources/templates/backend/payment/create.html +++ b/src/main/resources/templates/backend/payment/create.html @@ -56,7 +56,7 @@

Thêm phương thức thanh toán + method="post" id="form-input">
@@ -65,10 +65,10 @@

Thêm phương thức thanh toán Tên
-
+

@@ -104,5 +104,29 @@

Thêm phương thức thanh toán

+
+ +
\ No newline at end of file diff --git a/src/main/resources/templates/backend/payment/edit.html b/src/main/resources/templates/backend/payment/edit.html index c4d0cfa..d1b1531 100644 --- a/src/main/resources/templates/backend/payment/edit.html +++ b/src/main/resources/templates/backend/payment/edit.html @@ -57,7 +57,7 @@

Sửa phương thức thanh toán + method="post" id="form-input">
@@ -66,7 +66,7 @@

Sửa phương thức thanh toán Tên
@@ -105,5 +105,29 @@

Sửa phương thức thanh toán

+
+ +
\ No newline at end of file diff --git a/src/main/resources/templates/backend/product/create.html b/src/main/resources/templates/backend/product/create.html index bd14316..110ef86 100644 --- a/src/main/resources/templates/backend/product/create.html +++ b/src/main/resources/templates/backend/product/create.html @@ -1,13 +1,14 @@ - + Thêm sản phẩm -
@@ -15,7 +16,8 @@
-

Thêm sản phẩm +

+ Thêm sản phẩm Multikart Admin panel

@@ -24,9 +26,18 @@

Thêm sản phẩm