-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04582f7
commit 1f07e21
Showing
4 changed files
with
197 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
function initializeShirts() { | ||
loadShirts(); | ||
setupShirtToggler(); | ||
setupShirtEditModal(); | ||
} | ||
|
||
function loadShirts() { | ||
const token = localStorage.getItem('token'); | ||
$.ajax({ | ||
url: '/api/shirts/user', | ||
method: 'GET', | ||
headers: { | ||
'Authorization': `Bearer ${token}` | ||
}, | ||
success: function(shirts) { | ||
displayShirts(shirts); | ||
}, | ||
error: function(xhr, status, error) { | ||
console.error('Error fetching shirts:', error); | ||
} | ||
}); | ||
} | ||
|
||
function displayShirts(shirts) { | ||
const shirtsContainer = $('#shirts-container'); | ||
shirtsContainer.empty(); | ||
|
||
if (shirts.length === 0) { | ||
shirtsContainer.append('<p>You have not created any shirts yet.</p>'); | ||
return; | ||
} | ||
|
||
shirts.forEach(shirt => { | ||
const shirtElement = $(` | ||
<div class="list-group-item"> | ||
<h4 class="list-group-item-heading">${shirt.title}</h4> | ||
<p class="list-group-item-text">${shirt.description}</p> | ||
<img src="${shirt.thumbnailUrl}" alt="${shirt.title}" style="max-width: 100px; max-height: 100px;"> | ||
<p>Asset ID: ${shirt.assetId}</p> | ||
<button class="btn btn-primary edit-shirt" data-shirt-id="${shirt._id}">Edit</button> | ||
</div> | ||
`); | ||
shirtsContainer.append(shirtElement); | ||
}); | ||
} | ||
|
||
function setupShirtToggler() { | ||
$('#list-tab a').on('click', function (e) { | ||
e.preventDefault(); | ||
$(this).tab('show'); | ||
}); | ||
|
||
$('#list-shirts-list').on('shown.bs.tab', function (e) { | ||
loadShirts(); | ||
}); | ||
} | ||
|
||
function setupShirtEditModal() { | ||
$(document).on('click', '.edit-shirt', function() { | ||
const shirtId = $(this).data('shirt-id'); | ||
openShirtEditModal(shirtId); | ||
}); | ||
|
||
$('#save-shirt-changes').on('click', function() { | ||
saveShirtChanges(); | ||
}); | ||
} | ||
|
||
function openShirtEditModal(shirtId) { | ||
const token = localStorage.getItem('token'); | ||
$.ajax({ | ||
url: `/api/shirts/${shirtId}`, | ||
method: 'GET', | ||
headers: { | ||
'Authorization': `Bearer ${token}` | ||
}, | ||
success: function(shirt) { | ||
$('#edit-shirt-id').val(shirt._id); | ||
$('#edit-shirt-title').val(shirt.title); | ||
$('#edit-shirt-description').val(shirt.description); | ||
$('#current-shirt-thumbnail').attr('src', shirt.thumbnailUrl); | ||
$('#editShirtModal').modal('show'); | ||
}, | ||
error: function(xhr, status, error) { | ||
console.error('Error fetching shirt details:', error); | ||
} | ||
}); | ||
} | ||
|
||
function saveShirtChanges() { | ||
const token = localStorage.getItem('token'); | ||
const shirtId = $('#edit-shirt-id').val(); | ||
const title = $('#edit-shirt-title').val(); | ||
const description = $('#edit-shirt-description').val(); | ||
|
||
const formData = new FormData(); | ||
formData.append('title', title); | ||
formData.append('description', description); | ||
|
||
$.ajax({ | ||
url: `/api/shirts/${shirtId}`, | ||
method: 'PUT', | ||
data: formData, | ||
processData: false, | ||
contentType: false, | ||
headers: { | ||
'Authorization': `Bearer ${token}` | ||
}, | ||
success: function(updatedShirt) { | ||
$('#editShirtModal').modal('hide'); | ||
loadShirts(); | ||
}, | ||
error: function(xhr, status, error) { | ||
console.error('Error updating shirt:', error); | ||
$('#shirt-error-message').text('Error updating shirt: ' + error).removeClass('hidden'); | ||
} | ||
}); | ||
} | ||
|
||
$(document).ready(function() { | ||
initializeShirts(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+74.3 KB
uploads/1728183299927-89437201_10216152954596170_8517994551216963584_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.