Improve wishlist view
This commit is contained in:
parent
1a08996c96
commit
6a13151c36
4 changed files with 131 additions and 43 deletions
|
@ -21,13 +21,13 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
$user = isset($_GET['userid']) ? new User($_GET['userid']) : new User();
|
||||
$wishlists = $user->getWishlists();
|
||||
$wishlists = array_map(function ($wishlist) {
|
||||
return array(
|
||||
'name' => $wishlist['name'],
|
||||
'value' => $wishlist['id'],
|
||||
'text' => $wishlist['name'],
|
||||
);
|
||||
}, $wishlists);
|
||||
$newFormat = $wishlist;
|
||||
// $newFormat['name'] = $wishlist['name'];
|
||||
$newFormat['value'] = $wishlist['id'];
|
||||
$newFormat['text'] = $wishlist['name'];
|
||||
|
||||
return $newFormat;
|
||||
}, $wishlists);
|
||||
$response['results'] = $wishlists;
|
||||
$response['success'] = true;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,90 @@ $(function() {
|
|||
'delete product' : '/src/api/products.php',
|
||||
};
|
||||
|
||||
/** Default callbacks */
|
||||
$.fn.api.settings.onResponse = function(response) {
|
||||
return response;
|
||||
}
|
||||
$.fn.api.settings.successTest = function(response) {
|
||||
return response.status == 'OK' || response.success || false;
|
||||
}
|
||||
$.fn.api.settings.onComplete = function(response, element, xhr) {
|
||||
element.removeClass('loading');
|
||||
}
|
||||
$.fn.api.settings.onSuccess = function(response, element, xhr) {
|
||||
element.dropdown({
|
||||
values: response.results,
|
||||
placeholder: 'No wishlist selected.'
|
||||
})
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
if (urlParams.has('wishlist')) {
|
||||
element.dropdown('set selected', urlParams.get('wishlist'));
|
||||
} else {
|
||||
if (response.results[0]) {
|
||||
element.dropdown('set selected', response.results[0].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$.fn.api.settings.onFailure = function(response, element, xhr) {
|
||||
console.log(response);
|
||||
console.log(element);
|
||||
console.log(xhr);
|
||||
|
||||
$('body')
|
||||
.modal({
|
||||
title: 'Failure',
|
||||
content: 'The process has failed.',
|
||||
class: '',
|
||||
actions: [
|
||||
{
|
||||
text: 'Oh well',
|
||||
class: 'primary'
|
||||
}
|
||||
]
|
||||
})
|
||||
.modal('show');
|
||||
}
|
||||
$.fn.api.settings.onError = function(response, element, xhr) {
|
||||
console.log(response);
|
||||
console.log(element);
|
||||
console.log(xhr);
|
||||
|
||||
$('body')
|
||||
.modal({
|
||||
title: 'Error',
|
||||
content: 'There has been an error.',
|
||||
class: '',
|
||||
actions: [
|
||||
{
|
||||
text: 'Oh well',
|
||||
class: 'primary'
|
||||
}
|
||||
]
|
||||
})
|
||||
.modal('show');
|
||||
}
|
||||
$.fn.api.settings.onAbort = function(response, element, xhr) {
|
||||
console.log(response);
|
||||
console.log(element);
|
||||
console.log(xhr);
|
||||
|
||||
$('body')
|
||||
.modal({
|
||||
title: 'Interrupted',
|
||||
content: 'The process was interrupted.',
|
||||
class: '',
|
||||
actions: [
|
||||
{
|
||||
text: 'Oh well',
|
||||
class: 'primary'
|
||||
}
|
||||
]
|
||||
})
|
||||
.modal('show');
|
||||
}
|
||||
|
||||
$('.ui.dropdown.wishlists').dropdown({
|
||||
filterRemoteData: true
|
||||
});
|
||||
|
@ -16,7 +100,7 @@ $(function() {
|
|||
/**
|
||||
* Refresh Wishlist
|
||||
*/
|
||||
wishlistRefresh();
|
||||
// wishlistRefresh();
|
||||
|
||||
/**
|
||||
* Commit to Product
|
||||
|
@ -151,41 +235,6 @@ function wishlistRefresh() {
|
|||
$('.ui.dropdown.wishlists').api({
|
||||
action: 'get wishlists',
|
||||
method: 'GET',
|
||||
on: 'now',
|
||||
onResponse: function(response) {
|
||||
return response;
|
||||
},
|
||||
successTest: function(response) {
|
||||
return response.success || false;
|
||||
},
|
||||
onComplete: function(response, element, xhr) {
|
||||
$('.ui.dropdown.wishlists').removeClass('loading');
|
||||
},
|
||||
onSuccess: function(response, element, xhr) {
|
||||
$('.ui.dropdown.wishlists').dropdown({
|
||||
values: response.results,
|
||||
placeholder: 'No wishlist selected.'
|
||||
})
|
||||
|
||||
if (urlParams.has('wishlist')) {
|
||||
$('.ui.dropdown.wishlists').dropdown('set selected', urlParams.get('wishlist'));
|
||||
} else {
|
||||
if (response.results[0]) {
|
||||
$('.ui.dropdown.wishlists').dropdown('set selected', response.results[0].value);
|
||||
}
|
||||
}
|
||||
},
|
||||
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
|
||||
}
|
||||
on: 'now'
|
||||
});
|
||||
}
|
||||
|
|
7
src/assets/js/wishlist-product-add.js
Normal file
7
src/assets/js/wishlist-product-add.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
$(function() {
|
||||
$('.ui.dropdown.wishlists').api({
|
||||
action: 'get wishlists',
|
||||
method: 'GET',
|
||||
on: 'now'
|
||||
});
|
||||
});
|
|
@ -1,9 +1,39 @@
|
|||
$(function() {
|
||||
/**
|
||||
* Get Wishlists
|
||||
*/
|
||||
var wishlists = [];
|
||||
|
||||
$('.ui.dropdown.wishlists').api({
|
||||
action: 'get wishlists',
|
||||
method: 'GET',
|
||||
on: 'now',
|
||||
onSuccess: function(response, element, xhr) {
|
||||
wishlists = response.results;
|
||||
|
||||
element.dropdown({
|
||||
values: wishlists,
|
||||
placeholder: 'No wishlist selected.'
|
||||
})
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
if (urlParams.has('wishlist')) {
|
||||
element.dropdown('set selected', urlParams.get('wishlist'));
|
||||
} else {
|
||||
if (wishlists[0]) {
|
||||
element.dropdown('set selected', wishlists[0].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Selection
|
||||
*/
|
||||
$('.ui.dropdown.wishlists').on('change', function() {
|
||||
var wishlistValue = $('.ui.dropdown.wishlists').dropdown('get value');
|
||||
var wishlistIndex = $('.ui.dropdown.wishlists select').prop('selectedIndex') - 1;
|
||||
|
||||
$('[name="wishlist_delete_id"]').val(wishlistValue);
|
||||
|
||||
|
@ -14,6 +44,8 @@ $(function() {
|
|||
urlParams.set('wishlist', wishlistValue);
|
||||
window.history.pushState({}, '', '/?' + urlParams.toString());
|
||||
|
||||
$('.wishlist-share').attr('href', '/?wishlist=' + wishlists[wishlistIndex].hash);
|
||||
|
||||
$('.wishlist-share').removeClass('disabled');
|
||||
$('.wishlist-delete button').removeClass('disabled');
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue