lokesh341 commited on
Commit
3535091
·
verified ·
1 Parent(s): 701d127

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +130 -10
templates/menu.html CHANGED
@@ -174,6 +174,23 @@
174
  background-color: #ffe4c4;
175
  color: #333;
176
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  .fixed-top-bar {
178
  position: relative;
179
  top: 0;
@@ -830,12 +847,26 @@
830
 
831
  <div class="fixed-top-bar">
832
  <div class="avatar-dropdown-container">
833
- <div class="avatar-icon">
834
- <span>{{ first_letter }}</span>
 
 
 
 
 
835
  </div>
836
- <div class="dropdown-menu">
837
  <a href="{{ url_for('user_details.customer_details') }}" class="dropdown-item">View Profile</a>
838
  <a href="{{ url_for('orderhistory.order_history') }}" class="dropdown-item">Order History</a>
 
 
 
 
 
 
 
 
 
839
  <a href="{{ url_for('logout') }}" class="dropdown-item">Logout</a>
840
  </div>
841
  </div>
@@ -1208,22 +1239,111 @@
1208
  document.addEventListener('DOMContentLoaded', function () {
1209
  const avatarContainer = document.querySelector('.avatar-dropdown-container');
1210
  const dropdownMenu = document.querySelector('.dropdown-menu');
1211
- avatarContainer.addEventListener('click', function (event) {
 
 
 
 
 
1212
  event.stopPropagation();
1213
  dropdownMenu.style.display = dropdownMenu.style.display === 'block' ? 'none' : 'block';
1214
  });
1215
- document.addEventListener('click', function (event) {
 
 
1216
  if (!avatarContainer.contains(event.target)) {
1217
  dropdownMenu.style.display = 'none';
1218
  }
1219
  });
1220
- const dropdownItems = document.querySelectorAll('.dropdown-item');
1221
- dropdownItems.forEach(item => {
1222
- item.addEventListener('click', function () {
1223
- dropdownMenu.style.display = 'none';
1224
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1225
  });
1226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1227
  const menuCards = document.querySelectorAll('.menu-card');
1228
  const menuVideos = document.querySelectorAll('.menu-video');
1229
  const cardObserver = new IntersectionObserver((entries, observer) => {
 
174
  background-color: #ffe4c4;
175
  color: #333;
176
  }
177
+ /* Added styles for upload/delete options */
178
+ .upload-item:hover,
179
+ .delete-item:hover {
180
+ background-color: #ffe4c4;
181
+ color: #333;
182
+ }
183
+ .upload-item,
184
+ .delete-item {
185
+ padding: 12px 16px;
186
+ text-decoration: none;
187
+ color: #333;
188
+ border-bottom: 1px solid #ffd8b1;
189
+ display: block;
190
+ font-size: 15px;
191
+ transition: background-color 0.2s ease;
192
+ cursor: pointer;
193
+ }
194
  .fixed-top-bar {
195
  position: relative;
196
  top: 0;
 
847
 
848
  <div class="fixed-top-bar">
849
  <div class="avatar-dropdown-container">
850
+ <div class="avatar-icon" id="avatarIcon">
851
+ {% if user_image %}
852
+ <img src="{{ user_image }}" alt="User Avatar" class="avatar-image"
853
+ style="width: 100%; height: 100%; object-fit: cover; border-radius: 50%;">
854
+ {% else %}
855
+ <span>{{ first_letter }}</span>
856
+ {% endif %}
857
  </div>
858
+ <div class="dropdown-menu" id="avatarDropdown">
859
  <a href="{{ url_for('user_details.customer_details') }}" class="dropdown-item">View Profile</a>
860
  <a href="{{ url_for('orderhistory.order_history') }}" class="dropdown-item">Order History</a>
861
+ <div class="dropdown-item upload-item">
862
+ <label for="avatarUpload" style="cursor: pointer; margin: 0; width: 100%;">
863
+ Upload Image
864
+ </label>
865
+ <input type="file" id="avatarUpload" accept="image/*" style="display: none;">
866
+ </div>
867
+ {% if user_image %}
868
+ <div class="dropdown-item delete-item" id="deleteAvatar">Delete Image</div>
869
+ {% endif %}
870
  <a href="{{ url_for('logout') }}" class="dropdown-item">Logout</a>
871
  </div>
872
  </div>
 
1239
  document.addEventListener('DOMContentLoaded', function () {
1240
  const avatarContainer = document.querySelector('.avatar-dropdown-container');
1241
  const dropdownMenu = document.querySelector('.dropdown-menu');
1242
+ const avatarIcon = document.getElementById('avatarIcon');
1243
+ const avatarUpload = document.getElementById('avatarUpload');
1244
+ const deleteAvatar = document.getElementById('deleteAvatar');
1245
+
1246
+ // Avatar click handler
1247
+ avatarIcon.addEventListener('click', function(event) {
1248
  event.stopPropagation();
1249
  dropdownMenu.style.display = dropdownMenu.style.display === 'block' ? 'none' : 'block';
1250
  });
1251
+
1252
+ // Close dropdown when clicking outside
1253
+ document.addEventListener('click', function(event) {
1254
  if (!avatarContainer.contains(event.target)) {
1255
  dropdownMenu.style.display = 'none';
1256
  }
1257
  });
1258
+
1259
+ // Handle image upload
1260
+ avatarUpload.addEventListener('change', function(event) {
1261
+ const file = event.target.files[0];
1262
+ if (file) {
1263
+ const reader = new FileReader();
1264
+ reader.onload = function(e) {
1265
+ const base64Image = e.target.result;
1266
+
1267
+ fetch('/upload_avatar', {
1268
+ method: 'POST',
1269
+ headers: {
1270
+ 'Content-Type': 'application/json',
1271
+ },
1272
+ body: JSON.stringify({ image: base64Image })
1273
+ })
1274
+ .then(response => response.json())
1275
+ .then(data => {
1276
+ if (data.success) {
1277
+ // Update avatar image
1278
+ const avatarImg = avatarIcon.querySelector('.avatar-image');
1279
+ if (avatarImg) {
1280
+ avatarImg.src = data.image;
1281
+ } else {
1282
+ const img = document.createElement('img');
1283
+ img.src = data.image;
1284
+ img.alt = 'User Avatar';
1285
+ img.className = 'avatar-image';
1286
+ img.style.cssText = 'width: 100%; height: 100%; object-fit: cover; border-radius: 50%;';
1287
+ avatarIcon.innerHTML = '';
1288
+ avatarIcon.appendChild(img);
1289
+ }
1290
+ // Add delete option if not present
1291
+ if (!document.getElementById('deleteAvatar')) {
1292
+ const deleteItem = document.createElement('div');
1293
+ deleteItem.className = 'dropdown-item delete-item';
1294
+ deleteItem.id = 'deleteAvatar';
1295
+ deleteItem.innerText = 'Delete Image';
1296
+ dropdownMenu.insertBefore(deleteItem, dropdownMenu.querySelector('.dropdown-item:last-child'));
1297
+ addDeleteListener(deleteItem);
1298
+ }
1299
+ dropdownMenu.style.display = 'none';
1300
+ } else {
1301
+ alert('Failed to upload image: ' + (data.error || 'Unknown error'));
1302
+ }
1303
+ })
1304
+ .catch(error => {
1305
+ console.error('Upload error:', error);
1306
+ alert('Error uploading image');
1307
+ });
1308
+ };
1309
+ reader.readAsDataURL(file);
1310
+ }
1311
  });
1312
 
1313
+ // Handle image deletion
1314
+ function addDeleteListener(deleteElement) {
1315
+ deleteElement.addEventListener('click', function() {
1316
+ fetch('/delete_avatar', {
1317
+ method: 'POST',
1318
+ headers: {
1319
+ 'Content-Type': 'application/json'
1320
+ }
1321
+ })
1322
+ .then(response => response.json())
1323
+ .then(data => {
1324
+ if (data.success) {
1325
+ // Replace image with first letter
1326
+ const firstLetter = "{{ first_letter }}";
1327
+ avatarIcon.innerHTML = `<span>${firstLetter}</span>`;
1328
+ // Remove delete option
1329
+ deleteElement.remove();
1330
+ dropdownMenu.style.display = 'none';
1331
+ } else {
1332
+ alert('Failed to delete image: ' + (data.error || 'Unknown error'));
1333
+ }
1334
+ })
1335
+ .catch(error => {
1336
+ console.error('Delete error:', error);
1337
+ alert('Error deleting image');
1338
+ });
1339
+ });
1340
+ }
1341
+
1342
+ // Add delete listener if delete option exists
1343
+ if (deleteAvatar) {
1344
+ addDeleteListener(deleteAvatar);
1345
+ }
1346
+
1347
  const menuCards = document.querySelectorAll('.menu-card');
1348
  const menuVideos = document.querySelectorAll('.menu-video');
1349
  const cardObserver = new IntersectionObserver((entries, observer) => {