Fix delete not working
This commit is contained in:
parent
aa551dfe12
commit
909859ad01
4 changed files with 96 additions and 127 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
/**
|
/**
|
||||||
* Fomantic UI
|
* Fomantic UI
|
||||||
|
@ -25,8 +27,6 @@ $(function() {
|
||||||
placeholder: 'No wishlist selected.'
|
placeholder: 'No wishlist selected.'
|
||||||
})
|
})
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
|
|
||||||
if (urlParams.has('wishlist')) {
|
if (urlParams.has('wishlist')) {
|
||||||
element.dropdown('set selected', urlParams.get('wishlist'));
|
element.dropdown('set selected', urlParams.get('wishlist'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,25 +81,7 @@ $(function() {
|
||||||
})
|
})
|
||||||
.modal('show');
|
.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: 'Thanks for nothing',
|
|
||||||
class: 'primary'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
.modal('show');
|
|
||||||
}
|
|
||||||
|
|
||||||
$('.ui.dropdown.wishlists').dropdown({
|
$('.ui.dropdown.wishlists').dropdown({
|
||||||
filterRemoteData: true
|
filterRemoteData: true
|
||||||
|
@ -113,7 +95,7 @@ $(function() {
|
||||||
/**
|
/**
|
||||||
* Commit to Product
|
* Commit to Product
|
||||||
*/
|
*/
|
||||||
$('.ui.button.commit').on('click', function() {
|
$(document).on('click', '.ui.button.commit', function() {
|
||||||
var button = $(this);
|
var button = $(this);
|
||||||
var card = button.closest('.ui.card');
|
var card = button.closest('.ui.card');
|
||||||
var column = card.closest('.column');
|
var column = card.closest('.column');
|
||||||
|
@ -145,27 +127,9 @@ $(function() {
|
||||||
productStatus: 'unavailable'
|
productStatus: 'unavailable'
|
||||||
},
|
},
|
||||||
on: 'now',
|
on: 'now',
|
||||||
onResponse: function(response) {
|
|
||||||
return response;
|
|
||||||
},
|
|
||||||
successTest: function(response) {
|
|
||||||
return response.success || false;
|
|
||||||
},
|
|
||||||
onComplete: function(response, element, xhr) {
|
|
||||||
|
|
||||||
},
|
|
||||||
onSuccess: function(response, element, xhr) {
|
onSuccess: function(response, element, xhr) {
|
||||||
column.fadeOut();
|
column.fadeOut();
|
||||||
},
|
},
|
||||||
onFailure: function(response, element, xhr) {
|
|
||||||
|
|
||||||
},
|
|
||||||
onError: function(errorMessage, element, xhr) {
|
|
||||||
|
|
||||||
},
|
|
||||||
onAbort: function(errorMessage, element, xhr) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -175,7 +139,7 @@ $(function() {
|
||||||
/**
|
/**
|
||||||
* Delete Product
|
* Delete Product
|
||||||
*/
|
*/
|
||||||
$('.ui.button.delete').on('click', function() {
|
$(document).on('click', '.ui.button.delete', function() {
|
||||||
var button = $(this);
|
var button = $(this);
|
||||||
var card = button.closest('.ui.card');
|
var card = button.closest('.ui.card');
|
||||||
var column = card.closest('.column');
|
var column = card.closest('.column');
|
||||||
|
@ -191,8 +155,7 @@ $(function() {
|
||||||
class: 'approve primary'
|
class: 'approve primary'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'Cancel',
|
text: 'Cancel'
|
||||||
class: ''
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
onApprove: function() {
|
onApprove: function() {
|
||||||
|
@ -200,33 +163,15 @@ $(function() {
|
||||||
* Delete product
|
* Delete product
|
||||||
*/
|
*/
|
||||||
button.api({
|
button.api({
|
||||||
action: 'delete product',
|
action: 'delete product',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
data: {
|
data: {
|
||||||
productID: card.data('id'),
|
productID: card.data('id'),
|
||||||
},
|
},
|
||||||
on: 'now',
|
on: 'now',
|
||||||
onResponse: function(response) {
|
onSuccess: function() {
|
||||||
return response;
|
|
||||||
},
|
|
||||||
successTest: function(response) {
|
|
||||||
return response.success || false;
|
|
||||||
},
|
|
||||||
onComplete: function(response, element, xhr) {
|
|
||||||
|
|
||||||
},
|
|
||||||
onSuccess: function(response, element, xhr) {
|
|
||||||
column.fadeOut();
|
column.fadeOut();
|
||||||
},
|
},
|
||||||
onFailure: function(response, element, xhr) {
|
|
||||||
|
|
||||||
},
|
|
||||||
onError: function(errorMessage, element, xhr) {
|
|
||||||
|
|
||||||
},
|
|
||||||
onAbort: function(errorMessage, element, xhr) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -238,8 +183,6 @@ function wishlistRefresh() {
|
||||||
/**
|
/**
|
||||||
* URL Parameter
|
* URL Parameter
|
||||||
*/
|
*/
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
|
|
||||||
$('.ui.dropdown.wishlists').api({
|
$('.ui.dropdown.wishlists').api({
|
||||||
action: 'get wishlists',
|
action: 'get wishlists',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
|
@ -10,15 +10,12 @@ $(function() {
|
||||||
on: 'now',
|
on: 'now',
|
||||||
onSuccess: function(response, element, xhr) {
|
onSuccess: function(response, element, xhr) {
|
||||||
wishlists = response.results;
|
wishlists = response.results;
|
||||||
console.log(wishlists);
|
|
||||||
|
|
||||||
element.dropdown({
|
element.dropdown({
|
||||||
values: wishlists,
|
values: wishlists,
|
||||||
placeholder: 'No wishlist selected.'
|
placeholder: 'No wishlist selected.'
|
||||||
})
|
})
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
|
|
||||||
if (urlParams.has('wishlist')) {
|
if (urlParams.has('wishlist')) {
|
||||||
element.dropdown('set selected', urlParams.get('wishlist'));
|
element.dropdown('set selected', urlParams.get('wishlist'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,14 +29,13 @@ $(function() {
|
||||||
/**
|
/**
|
||||||
* Selection
|
* Selection
|
||||||
*/
|
*/
|
||||||
$('.ui.dropdown.wishlists').on('change', function() {
|
$(document).on('change', '.ui.dropdown.wishlists', function() {
|
||||||
var wishlistValue = $('.ui.dropdown.wishlists').dropdown('get value');
|
var wishlistValue = $('.ui.dropdown.wishlists').dropdown('get value');
|
||||||
var wishlistIndex = $('.ui.dropdown.wishlists select').prop('selectedIndex') - 1;
|
var wishlistIndex = $('.ui.dropdown.wishlists select').prop('selectedIndex') - 1;
|
||||||
|
|
||||||
$('[name="wishlist_delete_id"]').val(wishlistValue);
|
$('[name="wishlist_delete_id"]').val(wishlistValue);
|
||||||
|
|
||||||
if (wishlistValue) {
|
if (wishlistValue) {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
urlParams.set('wishlist', wishlistValue);
|
urlParams.set('wishlist', wishlistValue);
|
||||||
window.history.pushState({}, '', '/?' + urlParams.toString());
|
window.history.pushState({}, '', '/?' + urlParams.toString());
|
||||||
|
|
||||||
|
@ -61,7 +57,7 @@ $(function() {
|
||||||
/**
|
/**
|
||||||
* Delete Wishlist
|
* Delete Wishlist
|
||||||
*/
|
*/
|
||||||
$('.wishlist-delete').on('submit', function(event) {
|
$(document).on('submit', '.wishlist-delete', function(event) {
|
||||||
var wishlistValue = $('.ui.dropdown.wishlists').dropdown('get value');
|
var wishlistValue = $('.ui.dropdown.wishlists').dropdown('get value');
|
||||||
|
|
||||||
if (wishlistValue) {
|
if (wishlistValue) {
|
||||||
|
@ -84,30 +80,23 @@ $(function() {
|
||||||
$('.ui.dropdown.wishlists').api({
|
$('.ui.dropdown.wishlists').api({
|
||||||
action: 'delete wishlist',
|
action: 'delete wishlist',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
data: {
|
data: {
|
||||||
wishlistID: wishlistValue
|
wishlistID: wishlistValue
|
||||||
},
|
},
|
||||||
on: 'now',
|
on: 'now',
|
||||||
onResponse: function(response) {
|
onSuccess: function(response, wishlists) {
|
||||||
return response;
|
$('.wishlist-cards .column').fadeOut();
|
||||||
},
|
|
||||||
successTest: function(response) {
|
|
||||||
return response.success || false;
|
|
||||||
},
|
|
||||||
onComplete: function(response, element, xhr) {
|
|
||||||
|
|
||||||
},
|
wishlists.dropdown('clear');
|
||||||
onSuccess: function(response, element, xhr) {
|
|
||||||
wishlistRefresh();
|
|
||||||
},
|
|
||||||
onFailure: function(response, element, xhr) {
|
|
||||||
|
|
||||||
},
|
urlParams.delete('wishlist');
|
||||||
onError: function(errorMessage, element, xhr) {
|
window.history.pushState({}, '', '/?' + urlParams.toString());
|
||||||
|
|
||||||
},
|
|
||||||
onAbort: function(errorMessage, element, xhr) {
|
|
||||||
|
|
||||||
|
$('.ui.dropdown.wishlists').api({
|
||||||
|
action: 'get wishlists',
|
||||||
|
method: 'GET',
|
||||||
|
on: 'now'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ class EmbedCache
|
||||||
$info = null;
|
$info = null;
|
||||||
$identifier = md5($url);
|
$identifier = md5($url);
|
||||||
$filepath = $this->directory . '/' . $identifier;
|
$filepath = $this->directory . '/' . $identifier;
|
||||||
$age = time() - filemtime($filepath);
|
|
||||||
$maxAge = 2592000; // 30 days
|
$maxAge = 2592000; // 30 days
|
||||||
|
$age = file_exists($filepath) ? time() - filemtime($filepath) : $maxAge;
|
||||||
|
|
||||||
if (file_exists($filepath) && $age <= $maxAge) {
|
if (file_exists($filepath) && $age <= $maxAge) {
|
||||||
$info = json_decode(file_get_contents($filepath));
|
$info = json_decode(file_get_contents($filepath));
|
||||||
|
@ -33,28 +33,54 @@ class EmbedCache
|
||||||
* @link https://github.com/oscarotero/Embed
|
* @link https://github.com/oscarotero/Embed
|
||||||
*/
|
*/
|
||||||
$embed = new \Embed\Embed();
|
$embed = new \Embed\Embed();
|
||||||
$info = $embed->get($url);
|
|
||||||
|
|
||||||
$info_simplified = new \stdClass();
|
$info_simplified = new \stdClass();
|
||||||
$info_simplified->authorName = (string) $info->authorName;
|
$info_simplified->authorName = '';
|
||||||
$info_simplified->authorUrl = (string) $info->authorUrl;
|
$info_simplified->authorUrl = '';
|
||||||
$info_simplified->cms = (string) $info->cms;
|
$info_simplified->cms = '';
|
||||||
$info_simplified->code = (string) $info->code;
|
$info_simplified->code = '';
|
||||||
$info_simplified->description = (string) $info->description;
|
$info_simplified->description = '';
|
||||||
$info_simplified->favicon = (string) $info->favicon;
|
$info_simplified->favicon = '';
|
||||||
$info_simplified->feeds = (array) $info->feeds;
|
$info_simplified->feeds = array();
|
||||||
$info_simplified->icon = (string) $info->icon;
|
$info_simplified->icon = '';
|
||||||
$info_simplified->image = (string) $info->image;
|
$info_simplified->image = '';
|
||||||
$info_simplified->keywords = (array) $info->keywords;
|
$info_simplified->keywords = array();
|
||||||
$info_simplified->language = (string) $info->language;
|
$info_simplified->language = '';
|
||||||
$info_simplified->languages = (array) $info->languages;
|
$info_simplified->languages = array();
|
||||||
$info_simplified->license = (string) $info->license;
|
$info_simplified->license = '';
|
||||||
$info_simplified->providerName = (string) $info->providerName;
|
$info_simplified->providerName = '';
|
||||||
$info_simplified->providerUrl = (string) $info->providerUrl;
|
$info_simplified->providerUrl = '';
|
||||||
$info_simplified->publishedTime = $info->publishedTime ? $info->publishedTime->format('d.m.Y') : '';
|
$info_simplified->publishedTime = '';
|
||||||
$info_simplified->redirect = (string) $info->redirect;
|
$info_simplified->redirect = '';
|
||||||
$info_simplified->title = (string) $info->title;
|
$info_simplified->title = '';
|
||||||
$info_simplified->url = (string) $info->url;
|
$info_simplified->url = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$info = $embed->get($url);
|
||||||
|
|
||||||
|
$info_simplified->authorName = (string) $info->authorName;
|
||||||
|
$info_simplified->authorUrl = (string) $info->authorUrl;
|
||||||
|
$info_simplified->cms = (string) $info->cms;
|
||||||
|
$info_simplified->code = (string) $info->code;
|
||||||
|
$info_simplified->description = (string) $info->description;
|
||||||
|
$info_simplified->favicon = (string) $info->favicon;
|
||||||
|
$info_simplified->feeds = (array) $info->feeds;
|
||||||
|
$info_simplified->icon = (string) $info->icon;
|
||||||
|
$info_simplified->image = (string) $info->image;
|
||||||
|
$info_simplified->keywords = (array) $info->keywords;
|
||||||
|
$info_simplified->language = (string) $info->language;
|
||||||
|
$info_simplified->languages = (array) $info->languages;
|
||||||
|
$info_simplified->license = (string) $info->license;
|
||||||
|
$info_simplified->providerName = (string) $info->providerName;
|
||||||
|
$info_simplified->providerUrl = (string) $info->providerUrl;
|
||||||
|
$info_simplified->publishedTime = $info->publishedTime ? $info->publishedTime->format('d.m.Y') : '';
|
||||||
|
$info_simplified->redirect = (string) $info->redirect;
|
||||||
|
$info_simplified->title = (string) $info->title;
|
||||||
|
$info_simplified->url = (string) $info->url;
|
||||||
|
} catch (\Throwable $ex) {
|
||||||
|
$info_simplified->title = (string) $ex->getMessage();
|
||||||
|
$info_simplified->url = (string) $url;
|
||||||
|
}
|
||||||
|
|
||||||
$info = $info_simplified;
|
$info = $info_simplified;
|
||||||
|
|
||||||
|
|
|
@ -189,26 +189,37 @@ class Page
|
||||||
<div class="ui hidden divider"></div>
|
<div class="ui hidden divider"></div>
|
||||||
<div class="ui inverted vertical footer segment">
|
<div class="ui inverted vertical footer segment">
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
<div class="ui stackable inverted divided equal height stackable grid">
|
<div class="ui stackable inverted divided equal height stackable grid">
|
||||||
<div class="sixteen wide column">
|
|
||||||
<h4 class="ui inverted header">wishthis</h4>
|
|
||||||
|
|
||||||
<div class="ui inverted link list">
|
<div class="eight wide column">
|
||||||
<?php
|
<h4 class="ui inverted header">wishthis</h4>
|
||||||
global $options;
|
|
||||||
|
|
||||||
echo 'v' . $options->version;
|
<div class="ui inverted link list">
|
||||||
?>
|
<?php
|
||||||
|
global $options;
|
||||||
|
|
||||||
|
echo 'v' . $options->version;
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ui inverted link list">
|
||||||
|
<a class="item" href="https://github.com/grandeljay/wishthis" target="_blank">
|
||||||
|
<i class="big github icon"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ui inverted link list">
|
<div class="eight wide column">
|
||||||
<a class="item" href="https://github.com/grandeljay/wishthis" target="_blank">
|
<h4 class="ui inverted header">Preferences</h4>
|
||||||
<i class="big github icon"></i>
|
|
||||||
</a>
|
<div class="ui inverted link list">
|
||||||
|
<div class="dnt">Do Not Track</div>
|
||||||
|
<div class="prefers-color-scheme">Prefers color scheme</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue