diff --git a/src/api/wishlists.php b/src/api/wishlists.php index 5900919f..5c44a1b3 100644 --- a/src/api/wishlists.php +++ b/src/api/wishlists.php @@ -135,19 +135,22 @@ switch ($_SERVER['REQUEST_METHOD']) { */ $user = isset($_GET['userid']) ? User::getFromID($_GET['userid']) : $_SESSION['user']; - $wishlists = array(); + $wishlists = array(); + $wishlists_items = array(); foreach ($user->getWishlists() as $wishlist_result) { $wishlist = new Wishlist($wishlist_result['id']); - $wishlists[$wishlist->id] = array( + $wishlists[$wishlist->id] = $wishlist; + $wishlists_items[$wishlist->id] = array( 'name' => $wishlist->name, 'value' => $wishlist->id, 'text' => $wishlist->name, ); } - $response['results'] = $wishlists; + $response['wishlists'] = $wishlists; + $response['wishlists_items'] = $wishlists_items; } break; diff --git a/src/assets/js/parts/wishlists.js b/src/assets/js/parts/wishlists.js index d1f69852..7fa844fc 100644 --- a/src/assets/js/parts/wishlists.js +++ b/src/assets/js/parts/wishlists.js @@ -1,18 +1,21 @@ +var wishlists = []; + $(function () { /** * Get Wishlists */ - var wishlists = []; - var wishlists_api = { + var wishlists_items = []; + var wishlists_api = { 'action' : 'get wishlists', 'onSuccess' : function(response, dropdown_wishlists, xhr) { /** Save response for later use */ - wishlists = response.results; + wishlists = response.wishlists; + wishlists_items = response.wishlists_items; /** Setup and populate dropdown */ var dropdown_values = { - 'values' : wishlists, + 'values' : wishlists_items, }; dropdown_wishlists.dropdown('setup menu', dropdown_values); @@ -704,17 +707,21 @@ $(function () { */ function setDropdownWishlistsSelection() { var dropdown_wishlists = $('.ui.dropdown.wishlists'); + var wishlist_id; if (!dropdown_wishlists.dropdown('get value')) { if (wishthis.$_GET.id) { - dropdown_wishlists.dropdown('set selected', wishthis.$_GET.id); + wishlist_id = wishthis.$_GET.id; } else { if (Object.keys(wishlists).length >= 1) { var first_wishlist_id = Object.keys(wishlists)[0]; - dropdown_wishlists.dropdown('set selected', first_wishlist_id); + wishlist_id = first_wishlist_id; } } + + wishlist = wishlists[wishlist_id]; + dropdown_wishlists.dropdown('set selected', wishlist.id); } }