mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Added possibility to track who did a habit (this implements and closes #21)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
Grocy.Components.ProductPicker = { };
|
||||
|
||||
Grocy.Components.ProductPicker.GetPicker = function ()
|
||||
Grocy.Components.ProductPicker.GetPicker = function()
|
||||
{
|
||||
return $('#product_id');
|
||||
}
|
||||
@@ -43,7 +43,7 @@ Grocy.Components.ProductPicker.HideCustomError = function()
|
||||
$("#custom-productpicker-error").addClass("d-none");
|
||||
}
|
||||
|
||||
$('.combobox').combobox({
|
||||
$('.product-combobox').combobox({
|
||||
appendId: '_text_input',
|
||||
bsVersion: '4'
|
||||
});
|
||||
|
62
public/viewjs/components/userpicker.js
Normal file
62
public/viewjs/components/userpicker.js
Normal file
@@ -0,0 +1,62 @@
|
||||
Grocy.Components.UserPicker = { };
|
||||
|
||||
Grocy.Components.UserPicker.GetPicker = function()
|
||||
{
|
||||
return $('#user_id');
|
||||
}
|
||||
|
||||
Grocy.Components.UserPicker.GetInputElement = function()
|
||||
{
|
||||
return $('#user_id_text_input');
|
||||
}
|
||||
|
||||
Grocy.Components.UserPicker.GetValue = function()
|
||||
{
|
||||
return $('#user_id').val();
|
||||
}
|
||||
|
||||
Grocy.Components.UserPicker.SetValue = function(value)
|
||||
{
|
||||
Grocy.Components.UserPicker.GetInputElement().val(value);
|
||||
Grocy.Components.UserPicker.GetInputElement().trigger('change');
|
||||
}
|
||||
|
||||
$('.user-combobox').combobox({
|
||||
appendId: '_text_input',
|
||||
bsVersion: '4'
|
||||
});
|
||||
|
||||
var prefillUser = Grocy.Components.UserPicker.GetPicker().parent().data('prefill-by-username').toString();
|
||||
if (typeof prefillUser !== "undefined")
|
||||
{
|
||||
var possibleOptionElement = $("#user_id option[data-additional-searchdata*='" + prefillUser + "']").first();
|
||||
if (possibleOptionElement.length === 0)
|
||||
{
|
||||
possibleOptionElement = $("#user_id option:contains('" + prefillUser + "')").first();
|
||||
}
|
||||
|
||||
if (possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#user_id').val(possibleOptionElement.val());
|
||||
$('#user_id').data('combobox').refresh();
|
||||
$('#user_id').trigger('change');
|
||||
|
||||
var nextInputElement = $(Grocy.Components.UserPicker.GetPicker().parent().data('next-input-selector').toString());
|
||||
nextInputElement.focus();
|
||||
}
|
||||
}
|
||||
|
||||
var prefillUserId = Grocy.Components.UserPicker.GetPicker().parent().data('prefill-by-user-id').toString();
|
||||
if (typeof prefillUserId !== "undefined")
|
||||
{
|
||||
var possibleOptionElement = $("#user_id option[value='" + prefillUserId + "']").first();
|
||||
if (possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#user_id').val(possibleOptionElement.val());
|
||||
$('#user_id').data('combobox').refresh();
|
||||
$('#user_id').trigger('change');
|
||||
|
||||
var nextInputElement = $(Grocy.Components.UserPicker.GetPicker().parent().data('next-input-selector').toString());
|
||||
nextInputElement.focus();
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@
|
||||
Grocy.Api.Get('habits/get-habit-details/' + jsonForm.habit_id,
|
||||
function (habitDetails)
|
||||
{
|
||||
Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + Grocy.Components.DateTimePicker.GetValue(),
|
||||
Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(),
|
||||
function(result)
|
||||
{
|
||||
toastr.success(L('Tracked execution of habit #1 on #2', habitDetails.habit.name, Grocy.Components.DateTimePicker.GetValue()));
|
||||
|
Reference in New Issue
Block a user