Update templates/customer_details.html
Browse files- templates/customer_details.html +175 -199
templates/customer_details.html
CHANGED
@@ -7,255 +7,231 @@
|
|
7 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
8 |
<style>
|
9 |
body {
|
10 |
-
background-color: #
|
|
|
|
|
|
|
11 |
}
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
padding: 10px 20px;
|
17 |
-
background-color: #ff5722;
|
18 |
-
color: #ffffff;
|
19 |
-
border: none;
|
20 |
-
border-radius: 25px;
|
21 |
-
font-size: 1rem;
|
22 |
-
font-weight: bold;
|
23 |
-
text-align: center;
|
24 |
-
text-decoration: none;
|
25 |
-
width: 100%;
|
26 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
27 |
-
transition: background-color 0.3s ease;
|
28 |
}
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
text-decoration: none;
|
|
|
|
|
|
|
33 |
}
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
}
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
position: relative;
|
41 |
}
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
transform: translateY(-50%);
|
48 |
-
background-color: #ffffff;
|
49 |
-
color: #0FAA39;
|
50 |
-
border: none;
|
51 |
-
border-radius: 5px;
|
52 |
-
padding: 5px 10px;
|
53 |
-
cursor: pointer;
|
54 |
-
font-size: 0.9rem;
|
55 |
}
|
56 |
-
|
57 |
-
.
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
-
|
62 |
-
|
|
|
|
|
63 |
position: absolute;
|
64 |
right: 10px;
|
65 |
top: 50%;
|
66 |
transform: translateY(-50%);
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
font-size: 1.2rem;
|
71 |
-
cursor: pointer;
|
72 |
-
}
|
73 |
-
|
74 |
-
.update-btn {
|
75 |
-
background-color: #0FAA39;
|
76 |
-
color: white;
|
77 |
-
border: none;
|
78 |
-
border-radius: 5px;
|
79 |
-
padding: 10px 20px;
|
80 |
-
font-size: 1rem;
|
81 |
cursor: pointer;
|
82 |
-
|
83 |
-
|
|
|
84 |
}
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
}
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
color:
|
93 |
-
border:
|
94 |
-
|
95 |
-
|
|
|
96 |
font-size: 1rem;
|
|
|
97 |
cursor: pointer;
|
98 |
-
width: 20%;
|
99 |
-
font-weight: bold; /* Making the button text bold */
|
100 |
-
}
|
101 |
-
|
102 |
-
.edit-btn:hover {
|
103 |
-
background-color: #0f8e29;
|
104 |
-
}
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
/* Button container adjustments */
|
109 |
-
.button-container {
|
110 |
-
display: flex;
|
111 |
-
justify-content: space-between;
|
112 |
-
gap: 10px; /* Add space between buttons */
|
113 |
-
}
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
/* Flexbox for equally spaced buttons */
|
120 |
-
.button-container {
|
121 |
-
display: flex;
|
122 |
-
justify-content: space-between;
|
123 |
margin-top: 20px;
|
124 |
}
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
150 |
}
|
151 |
</style>
|
152 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
153 |
<script>
|
154 |
-
function enableEditField(fieldId) {
|
155 |
var field = document.getElementById(fieldId);
|
156 |
-
|
157 |
-
field.
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
}
|
160 |
-
|
161 |
function updateProfile(event) {
|
162 |
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
var formData = $('#profileForm').serialize();
|
164 |
-
|
165 |
$.ajax({
|
166 |
type: "POST",
|
167 |
-
url: "/user/update_profile",
|
168 |
data: formData,
|
|
|
169 |
success: function(response) {
|
170 |
if (response.status === "success") {
|
171 |
-
alert(response.message);
|
172 |
location.reload();
|
173 |
} else {
|
174 |
-
alert(response.message);
|
175 |
}
|
176 |
},
|
177 |
-
error: function() {
|
178 |
-
|
|
|
179 |
}
|
180 |
});
|
181 |
}
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
var referralCode = document.getElementById('referralCode');
|
194 |
-
referralCode.select();
|
195 |
-
document.execCommand('copy');
|
196 |
-
alert('Referral Code Copied!');
|
197 |
-
}
|
198 |
</script>
|
199 |
</head>
|
200 |
<body>
|
201 |
-
<div class="container
|
202 |
-
<
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
{% endwith %}
|
211 |
-
|
212 |
-
<div class="card">
|
213 |
-
<div class="card-body">
|
214 |
-
<form id="profileForm" method="POST" onsubmit="updateProfile(event)">
|
215 |
-
<div class="mb-3">
|
216 |
-
<label for="customerName" class="form-label"><strong>Name:</strong></label>
|
217 |
-
<div class="input-group">
|
218 |
-
<input type="text" id="customerName" name="customerName" class="form-control" value="{{ customer['name'] }}" readonly>
|
219 |
-
</div>
|
220 |
-
</div>
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
</div>
|
227 |
-
</div>
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
</div>
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
</div>
|
242 |
-
</div>
|
243 |
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
248 |
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
<button type="submit" class="update-btn">Update Profile</button>
|
253 |
-
</div>
|
254 |
-
</form>
|
255 |
</div>
|
256 |
-
</div>
|
257 |
|
258 |
-
|
|
|
259 |
</div>
|
260 |
</body>
|
261 |
-
</html>
|
|
|
7 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
8 |
<style>
|
9 |
body {
|
10 |
+
background-color: #F5F7FA;
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
margin: 0;
|
13 |
+
padding: 0;
|
14 |
}
|
15 |
+
.container {
|
16 |
+
max-width: 90%;
|
17 |
+
margin: 20px auto;
|
18 |
+
padding: 15px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
+
.header {
|
21 |
+
display: flex;
|
22 |
+
align-items: center;
|
23 |
+
margin-bottom: 20px;
|
24 |
+
}
|
25 |
+
.back-btn {
|
26 |
+
font-size: 1.5rem;
|
27 |
+
color: #1C1C1C;
|
28 |
text-decoration: none;
|
29 |
+
margin-right: 10px;
|
30 |
+
display: inline-flex;
|
31 |
+
align-items: center;
|
32 |
}
|
33 |
+
.back-btn svg {
|
34 |
+
width: 24px;
|
35 |
+
height: 24px;
|
36 |
}
|
37 |
+
.header h1 {
|
38 |
+
font-size: 1.25rem;
|
39 |
+
font-weight: bold;
|
40 |
+
color: #1C1C1C;
|
41 |
+
margin: 0;
|
42 |
+
}
|
43 |
+
.form-group {
|
44 |
+
margin-bottom: 15px;
|
45 |
position: relative;
|
46 |
}
|
47 |
+
.form-group label {
|
48 |
+
font-size: 0.875rem;
|
49 |
+
color: #6C757D;
|
50 |
+
margin-bottom: 5px;
|
51 |
+
display: block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
+
.form-group input,
|
54 |
+
.form-group select {
|
55 |
+
width: 100%;
|
56 |
+
padding: 10px;
|
57 |
+
border: 1px solid #E0E0E0;
|
58 |
+
border-radius: 10px;
|
59 |
+
font-size: 1rem;
|
60 |
+
color: #1C1C1C;
|
61 |
+
background-color: #FFFFFF;
|
62 |
+
box-sizing: border-box;
|
63 |
}
|
64 |
+
.form-group input[readonly] {
|
65 |
+
background-color: #F5F7FA;
|
66 |
+
}
|
67 |
+
.change-btn {
|
68 |
position: absolute;
|
69 |
right: 10px;
|
70 |
top: 50%;
|
71 |
transform: translateY(-50%);
|
72 |
+
color: #FF0000;
|
73 |
+
font-size: 0.75rem;
|
74 |
+
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
cursor: pointer;
|
76 |
+
text-transform: uppercase;
|
77 |
+
padding: 2px 5px;
|
78 |
+
display: inline-block;
|
79 |
}
|
80 |
+
.change-btn.disabled {
|
81 |
+
color: #A9A9A9;
|
82 |
+
cursor: not-allowed;
|
83 |
}
|
84 |
+
.update-btn {
|
85 |
+
width: 100%;
|
86 |
+
padding: 12px;
|
87 |
+
background-color: #FFA07A;
|
88 |
+
border-color: #FFA07A;
|
89 |
+
color: #6C757D;
|
90 |
+
border: 1px solid;
|
91 |
+
border-radius: 10px;
|
92 |
font-size: 1rem;
|
93 |
+
font-weight: bold;
|
94 |
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
margin-top: 20px;
|
96 |
}
|
97 |
+
.update-btn:hover {
|
98 |
+
background-color: #FF7F50;
|
99 |
+
border-color: #FF7F50;
|
100 |
+
}
|
101 |
+
|
102 |
+
/* Media Queries for Smaller Screens */
|
103 |
+
@media (max-width: 576px) {
|
104 |
+
.container {
|
105 |
+
padding: 10px;
|
106 |
+
}
|
107 |
+
.header h1 {
|
108 |
+
font-size: 1.1rem;
|
109 |
+
}
|
110 |
+
.back-btn svg {
|
111 |
+
width: 20px;
|
112 |
+
height: 20px;
|
113 |
+
}
|
114 |
+
.form-group input,
|
115 |
+
.form-group select {
|
116 |
+
font-size: 0.9rem;
|
117 |
+
padding: 8px;
|
118 |
+
}
|
119 |
+
.update-btn {
|
120 |
+
padding: 10px;
|
121 |
+
font-size: 0.9rem;
|
122 |
+
}
|
123 |
}
|
124 |
</style>
|
125 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
126 |
<script>
|
127 |
+
function enableEditField(fieldId, flagId) {
|
128 |
var field = document.getElementById(fieldId);
|
129 |
+
var flagField = document.getElementById(flagId);
|
130 |
+
var changeBtn = $(field).siblings('.change-btn');
|
131 |
+
changeBtn.hide();
|
132 |
+
if (flagField.value === "false") {
|
133 |
+
field.removeAttribute("readonly");
|
134 |
+
field.focus();
|
135 |
+
$(field).on('input', function() {
|
136 |
+
flagField.value = "true";
|
137 |
+
});
|
138 |
+
}
|
139 |
+
}
|
140 |
+
function onFocusNext(inputField) {
|
141 |
+
var changeBtn = $(inputField).siblings('.change-btn');
|
142 |
+
changeBtn.show();
|
143 |
}
|
|
|
144 |
function updateProfile(event) {
|
145 |
event.preventDefault();
|
146 |
+
var phone = $('#phone').val().trim();
|
147 |
+
var email = $('#email').val().trim();
|
148 |
+
var referralCode = $('#referralCode').val().trim();
|
149 |
+
if (!phone && !email && !referralCode) {
|
150 |
+
alert("Please enter at least one field to update (Phone, Email, or Referral Code).");
|
151 |
+
return;
|
152 |
+
}
|
153 |
+
if (phone && !/^\d{10}$/.test(phone)) {
|
154 |
+
alert("Please enter a valid 10-digit phone number.");
|
155 |
+
return;
|
156 |
+
}
|
157 |
+
if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
158 |
+
alert("Please enter a valid email address.");
|
159 |
+
return;
|
160 |
+
}
|
161 |
var formData = $('#profileForm').serialize();
|
|
|
162 |
$.ajax({
|
163 |
type: "POST",
|
164 |
+
url: "/user/update_profile",
|
165 |
data: formData,
|
166 |
+
dataType: 'json',
|
167 |
success: function(response) {
|
168 |
if (response.status === "success") {
|
169 |
+
alert(response.message || "Profile updated successfully!");
|
170 |
location.reload();
|
171 |
} else {
|
172 |
+
alert(response.message || "Failed to update profile.");
|
173 |
}
|
174 |
},
|
175 |
+
error: function(xhr, status, error) {
|
176 |
+
console.error("Error:", error);
|
177 |
+
alert("An error occurred while updating the profile. Please try again.");
|
178 |
}
|
179 |
});
|
180 |
}
|
181 |
+
$(document).ready(function() {
|
182 |
+
if ($('#nameEdited').val() === "true") {
|
183 |
+
$('#customerName').siblings('.change-btn').addClass('disabled').off('click');
|
184 |
+
}
|
185 |
+
if ($('#phoneEdited').val() === "true") {
|
186 |
+
$('#phone').siblings('.change-btn').addClass('disabled').off('click');
|
187 |
+
}
|
188 |
+
if ($('#emailEdited').val() === "true") {
|
189 |
+
$('#email').siblings('.change-btn').addClass('disabled').off('click');
|
190 |
+
}
|
191 |
+
});
|
|
|
|
|
|
|
|
|
|
|
192 |
</script>
|
193 |
</head>
|
194 |
<body>
|
195 |
+
<div class="container">
|
196 |
+
<div class="header">
|
197 |
+
<a href="/menu" class="back-btn">
|
198 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
199 |
+
<path d="M15 18l-6-6 6-6"/>
|
200 |
+
</svg>
|
201 |
+
</a>
|
202 |
+
<h1>Your Profile</h1>
|
203 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
+
<form id="profileForm" method="POST" onsubmit="updateProfile(event)">
|
206 |
+
<input type="hidden" id="nameEdited" name="nameEdited" value="{{ 'true' if customer['name_edited'] else 'false' }}">
|
207 |
+
<input type="hidden" id="phoneEdited" name="phoneEdited" value="{{ 'true' if customer['phone_edited'] else 'false' }}">
|
208 |
+
<input type="hidden" id="emailEdited" name="emailEdited" value="{{ 'true' if customer['email_edited'] else 'false' }}">
|
|
|
|
|
209 |
|
210 |
+
<div class="form-group">
|
211 |
+
<label for="customerName">Name</label>
|
212 |
+
<input type="text" id="customerName" name="customerName" value="{{ customer['name'] }}" readonly>
|
213 |
+
<span class="change-btn" onclick="enableEditField('customerName', 'nameEdited')">CHANGE</span>
|
214 |
+
</div>
|
|
|
215 |
|
216 |
+
<div class="form-group">
|
217 |
+
<label for="phone">Mobile</label>
|
218 |
+
<input type="text" id="phone" name="phone" value="{{ customer['phone'] }}" readonly onfocus="onFocusNext(this)">
|
219 |
+
<span class="change-btn" onclick="enableEditField('phone', 'phoneEdited')">CHANGE</span>
|
220 |
+
</div>
|
|
|
|
|
221 |
|
222 |
+
<div class="form-group">
|
223 |
+
<label for="email">Email</label>
|
224 |
+
<input type="email" id="email" name="email" value="{{ customer['email'] }}" readonly onfocus="onFocusNext(this)">
|
225 |
+
<span class="change-btn" onclick="enableEditField('email', 'emailEdited')">CHANGE</span>
|
226 |
+
</div>
|
227 |
|
228 |
+
<div class="form-group">
|
229 |
+
<label for="referralCode">Referral Code</label>
|
230 |
+
<input type="text" id="referralCode" name="referralCode" value="{{ customer['referral_code'] }}">
|
|
|
|
|
|
|
231 |
</div>
|
|
|
232 |
|
233 |
+
<button type="submit" class="update-btn">Update profile</button>
|
234 |
+
</form>
|
235 |
</div>
|
236 |
</body>
|
237 |
+
</html>
|