2022-01-13 15:43:07 +00:00
|
|
|
$(function() {
|
2022-01-17 14:33:11 +00:00
|
|
|
/**
|
|
|
|
* URL Parameter
|
|
|
|
*/
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fomantic UI
|
|
|
|
*/
|
2022-01-17 11:40:53 +00:00
|
|
|
$.fn.api.settings.api = {
|
|
|
|
'get wishlists' : '/includes/api/wishlists.php'
|
|
|
|
};
|
2022-01-13 15:43:07 +00:00
|
|
|
|
2022-01-17 11:40:53 +00:00
|
|
|
$('.ui.dropdown.wishlists').dropdown({
|
|
|
|
filterRemoteData: true
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.ui.dropdown.wishlists').api({
|
|
|
|
action: 'get wishlists',
|
|
|
|
method: 'GET',
|
|
|
|
on: 'now',
|
|
|
|
onResponse: function(response) {
|
|
|
|
console.log('onResponse');
|
|
|
|
// make some adjustments to response
|
|
|
|
return response;
|
|
|
|
},
|
|
|
|
successTest: function(response) {
|
|
|
|
console.log('successTest');
|
|
|
|
return response.success || false;
|
|
|
|
},
|
|
|
|
onComplete: function(response, element, xhr) {
|
|
|
|
$('.ui.dropdown.wishlists').removeClass('loading');
|
|
|
|
},
|
|
|
|
onSuccess: function(response, element, xhr) {
|
2022-01-17 12:51:49 +00:00
|
|
|
$('.ui.dropdown.wishlists').dropdown({
|
2022-01-17 14:21:38 +00:00
|
|
|
values: response.results,
|
|
|
|
placeholder: 'No wishlist selected.'
|
2022-01-17 11:40:53 +00:00
|
|
|
})
|
2022-01-17 14:33:11 +00:00
|
|
|
|
|
|
|
if (urlParams.has('wishlist')) {
|
|
|
|
$('.ui.dropdown.wishlists').dropdown('set selected', urlParams.get('wishlist'));
|
|
|
|
}
|
2022-01-17 11:40:53 +00:00
|
|
|
},
|
|
|
|
onFailure: function(response, element, xhr) {
|
|
|
|
console.log('onFailure');
|
|
|
|
// request failed, or valid response but response.success = false
|
|
|
|
},
|
|
|
|
onError: function(errorMessage, element, xhr) {
|
|
|
|
console.log('onError');
|
|
|
|
// invalid response
|
|
|
|
},
|
|
|
|
onAbort: function(errorMessage, element, xhr) {
|
|
|
|
console.log('onAbort');
|
|
|
|
// navigated to a new page, CORS issue, or user canceled request
|
|
|
|
}
|
|
|
|
});
|
2022-01-13 15:43:07 +00:00
|
|
|
});
|