Desabilitando ou excluindo botões no Grocy
Link: https://www.reddit.com/r/grocy/comments/1987cf1/how_to_remove_consume_all_button/
Grocy Developer
It's kind of impossible to have a configuration option for each and every single detail, unless having a trillion of them at the end.
A very practically oriented advice of mine (I know, always unpopular here): Just don't click that button if it doesn't make sense. And if it happened accidentally, it's even just one more click to undo the corresponding transaction.
If that's not the way to go for you, custom JS gives you the opportunity to customize everything to your very end without having to maintain a complete own fork or something like that.
So imagine you've added a Userfield named "disableconsumeall" to the entity "products" (demo), this snippet (for data/custom_js.html) would disable the "consume all button" on the stock overview page when this Userfield is set for the corresponding product:
<script>
if (Grocy.View == "stockoverview")
{
$("[id$=consume-all-button]").each(function()
{
var button = $(this);
Grocy.Api.Get("objects/products/" + button.attr("data-product-id"),
function(product)
{
if (product.userfields.disableconsumeall == 1)
{
button.addClass("disabled");
}
}
);
});
}
</script>
1y ago
Awesome! Thank you. I am going to work on this.
I'm with you on the just don't click the button. Lol.
I am implementing this for the entire house. Trying my best to make sure that every option that is available is actually used. Make it as clutter-free as possible.
Next step is to get a laser barcode going with some kind of tablet/PC in the basement to check things in/out.
1y ago
Well, I'm struggling to get this to work. I did do the 2 steps mentioned:
I did add the Userfield exactly as described.
I did create data/custom_js.html which is exactly:
<html>
<head></head>
<body>
<script>
if (Grocy.View == "stockoverview")
{
$("[id$=consume-all-button]").each(function()
{
var button = $(this);
Grocy.Api.Get("objects/products/" + button.attr("data-product-id"),
function(product)
{
if (product.userfields.disableconsumeall == 1)
{
button.addClass("disabled");
}
}
);
});
}
</script>
</body>
</html>
Any ideas on what I could be missing? The custom_js.html didn't exist, so I created it myself. I am running this in Docker on unRAID. Have restarted the container several times.
Thank you.
Grocy Developer
Simply compare my posted snippet above with what you've put into the mentioned file again.
Especially "<html><head></head><body>" at the beginning and "</body></html>" at the end - that wasn't part of my posted snippet, make sure exactly only the snippet is in the file, nothing more or less.
Okay. I am still struggling.
I did try the code exactly how you gave the first time, no luck. The reason I put in the other tags, was because I saw this on the github page:
Adding your own CSS or JS without to have to modify the application itself
When the file data/custom_js.html exists, the contents of the file will be added just before </body> (end of body) on every page
When the file data/custom_css.html exists, the contents of the file will be added just before </head> (end of head) on every page
I'll do some more work on my side to see what the deal is. It seems like this should be super easy, so I'm sure it's something with me. Awesome software btw.
1y ago
Grocy Developer
There is stated that those snippets will be included in the HTML markup of the page at the mentioned places. When you introduce a whole other HTML document there, of course the whole page is kind of broken then.
Not interpreting that much into something, reading twice and just doing exactly what is mentioned is the key most of the time I guess...
1y ago
You know what, I'm dumb.
This actually did work. I did not realize that once you complete these steps, you must go into and edit the product itself and check "disable consume all"
This is awesome. It does only just disable the "Consume All" button but does not hide it.
Grocy Developer
It does only just disable the "Consume All" button but does not hide it.
No Comments