Update Items JavaScript Code Documentation

Function: window.onload

Sets up the initial state of the page when it loads. Calls the 'changeCategory' function to set the category to 'piadas' on page load.

Parameters:


window.onload = function() {
    // run change category to be set to piadas when page loads
    changeCategory('piadas');
};
        

Variable: selected_item_id

Keeps track of the identifier of the selected item.


var selected_item_id = -1
        

Variable: selected_mode

Keeps track of the selected mode (0 for delete, 1 for edit).


var selected_mode = -1
        

Function: changeCategory

Changes the displayed items based on the selected category. Hides all items that do not belong to the selected category and shows those that do.

Parameters:


function changeCategory(category) {
    // ... Function code ...
}
        

Function: deleteItem

Deletes the selected item after confirming with the user. Makes an AJAX request to delete the item and reloads the page on success. Logs an error message on failure.

Parameters:


function deleteItem(itemID) {
    // ... Function code ...
}
        

Function: select_item

Selects an item by highlighting it and updating the selected_item_id. Resets the style of the previously selected item.

Parameters:


function select_item(itemID) {
    // ... Function code ...
}
        

Function: select_delete

Sets the selected_mode to 'delete' and deletes the selected item.


function select_delete() {
    // ... Function code ...
}
        

Function: select_edit

Sets the selected_mode to 'edit' and redirects to the edit page for the selected item.


function select_edit() {
    // ... Function code ...
}
        

Function: editItem

Redirects to the edit page for the selected item.

Parameters:


function editItem(itemID) {
    // ... Function code ...
}