2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 21:15:41 +00:00

Simplify process for marking a part as "starred"

This commit is contained in:
Oliver Walters
2021-02-25 23:27:27 +11:00
parent 35b9b17167
commit f2da1c990b
5 changed files with 59 additions and 44 deletions

View File

@ -50,8 +50,11 @@
<link rel="stylesheet" href="{% get_color_theme_css user.get_username %}">
{% block css %}
{% endblock %}
<style>
{% block css %}
<!-- Custom CSS style goes here -->
{% endblock %}
</style>
{% block head %}
{% endblock %}

View File

@ -14,50 +14,30 @@ function toggleStar(options) {
* - user: pk of the user
*/
var url = '/api/part/star/';
var url = `/api/part/${options.part}/`;
inventreeGet(
url,
{
part: options.part,
user: options.user,
},
{
success: function(response) {
if (response.length == 0) {
// Zero length response = star does not exist
// So let's add one!
inventreePut(
url,
{
part: options.part,
user: options.user,
},
{
method: 'POST',
success: function(response, status) {
$(options.button).addClass('icon-yellow');
},
inventreeGet(url, {}, {
success: function(response) {
var starred = response.starred;
inventreePut(
url,
{
starred: !starred,
},
{
method: 'PATCH',
success: function(response) {
if (response.starred) {
$(options.button).addClass('icon-yellow');
} else {
$(options.button).removeClass('icon-yellow');
}
);
} else {
var pk = response[0].pk;
// There IS a star (delete it!)
inventreePut(
url + pk + "/",
{
},
{
method: 'DELETE',
success: function(response, status) {
$(options.button).removeClass('icon-yellow');
},
}
);
}
}
},
);
}
);
});
}