diff --git a/src/assets/js/parts/wishlist-filter.js b/src/assets/js/parts/wishlist-filter.js new file mode 100644 index 00000000..51430141 --- /dev/null +++ b/src/assets/js/parts/wishlist-filter.js @@ -0,0 +1,52 @@ +$(function () { + + /** + * Filter wishes + */ + $('.ui.dropdown.filter.priority') + .dropdown({ + match : 'text', + fullTextSearch : true, + onChange : function() { + $(this).addClass('disabled loading'); + + var wishlist_id; + var wistlist_cards_data = $('.wishlist-cards').attr('data-wishlist') + var dropdown_wishlists = $('.dropdown.wishlists'); + + if (dropdown_wishlists.length) { + wishlist_id = $('.dropdown.wishlists').dropdown('get value'); + } + + if (typeof wistlist_cards_data !== 'undefined') { + wishlist_id = wistlist_cards_data; + } + + if (!Number.isInteger(parseInt(wishlist_id))) { + $(this).removeClass('disabled loading'); + + return false; + } + + var paramater = new URLSearchParams({ + wishlist : wishlist_id, + priority : $(this).dropdown('get value'), + }); + + fetch('/src/api/wishlists.php?' + paramater, { + method : 'GET', + }) + .then(handleFetchError) + .then(handleFetchResponse) + .then(function(response) { + var html = response.results ? response.results : ''; + + $('.wishlist-cards').html(html); + }) + .finally(() => { + $(this).removeClass('disabled loading'); + }); + } + }); + +}); diff --git a/src/assets/js/wishlists.js b/src/assets/js/wishlists.js index 2659a8e1..6edf5341 100644 --- a/src/assets/js/wishlists.js +++ b/src/assets/js/wishlists.js @@ -440,42 +440,4 @@ $(function () { }); }); - /** - * Filter wishes - */ - $('.ui.dropdown.filter.priority') - .dropdown({ - match : 'text', - fullTextSearch : true, - onChange : function() { - $(this).addClass('disabled loading'); - - var wishlist_id = $('.dropdown.wishlists').dropdown('get value'); - - if (!Number.isInteger(parseInt(wishlist_id))) { - $(this).removeClass('disabled loading'); - return false; - } - - var paramater = new URLSearchParams({ - wishlist : wishlist_id, - priority : $(this).dropdown('get value'), - }); - - fetch('/src/api/wishlists.php?' + paramater, { - method : 'GET', - }) - .then(handleFetchError) - .then(handleFetchResponse) - .then(function(response) { - var html = response.results ? response.results : ''; - - $('.wishlist-cards').html(html); - }) - .finally(() => { - $(this).removeClass('disabled loading'); - }); - } - }); - }); diff --git a/src/pages/parts/wishlist-filter.php b/src/pages/parts/wishlist-filter.php new file mode 100644 index 00000000..36771847 --- /dev/null +++ b/src/pages/parts/wishlist-filter.php @@ -0,0 +1,54 @@ + + */ + +use wishthis\Wish; + +$scriptPart = '/src/assets/js/parts/wishlist-filter.js'; +?> + + +
+ +
+
diff --git a/src/pages/wishlist.php b/src/pages/wishlist.php index af7895ae..e1a5665d 100644 --- a/src/pages/wishlist.php +++ b/src/pages/wishlist.php @@ -60,7 +60,9 @@ $page->navigation();

-
+ + +
getCards( array( diff --git a/src/pages/wishlists.php b/src/pages/wishlists.php index 3b6acb4c..d8fb76ef 100644 --- a/src/pages/wishlists.php +++ b/src/pages/wishlists.php @@ -6,7 +6,7 @@ * @author Jay Trees */ -use wishthis\{Page, User, Wishlist, Wish}; +use wishthis\{Page, User, Wishlist}; $page = new Page(__FILE__, __('My lists')); $page->header(); @@ -96,48 +96,7 @@ $page->navigation();
-
- -
-
+