2022-02-08 18:08:26 +01:00
|
|
|
|
$('.save-choretracking-button').on('click', function(e)
|
2018-09-22 13:26:58 +02:00
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2022-03-26 10:34:00 +01:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm("choretracking-form", true))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 13:45:14 +01:00
|
|
|
|
if ($(".combobox-menu-visible").length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 18:08:26 +01:00
|
|
|
|
var skipped = $(e.currentTarget).hasClass("skip");
|
|
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
|
var jsonForm = $('#choretracking-form').serializeJSON();
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("choretracking-form");
|
2018-09-22 13:26:58 +02:00
|
|
|
|
|
2019-01-19 00:37:21 -07:00
|
|
|
|
Grocy.Api.Get('chores/' + jsonForm.chore_id,
|
2020-08-30 12:18:16 +02:00
|
|
|
|
function(choreDetails)
|
2018-09-22 13:26:58 +02:00
|
|
|
|
{
|
2022-02-08 18:08:26 +01:00
|
|
|
|
Grocy.Api.Post('chores/' + jsonForm.chore_id + '/execute', { 'tracked_time': Grocy.Components.DateTimePicker.GetValue(), 'done_by': $("#user_id").val(), 'skipped': skipped },
|
2018-09-22 13:26:58 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2021-07-11 19:44:06 +02:00
|
|
|
|
Grocy.EditObjectId = result.id;
|
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
|
2022-04-04 20:10:29 +02:00
|
|
|
|
toastr.success(__t('Tracked execution of chore %1$s on %2$s', choreDetails.chore.name, Grocy.Components.DateTimePicker.GetValue()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoChoreExecution(' + result.id + ')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>');
|
2021-07-11 19:44:06 +02:00
|
|
|
|
Grocy.Components.ChoreCard.Refresh($('#chore_id').val());
|
2018-09-22 13:26:58 +02:00
|
|
|
|
|
2021-07-11 19:44:06 +02:00
|
|
|
|
$('#chore_id').val('');
|
|
|
|
|
$('#chore_id_text_input').focus();
|
|
|
|
|
$('#chore_id_text_input').val('');
|
|
|
|
|
Grocy.Components.DateTimePicker.SetValue(moment().format('YYYY-MM-DD HH:mm:ss'));
|
|
|
|
|
$('#chore_id_text_input').trigger('change');
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
|
|
|
|
|
});
|
2018-09-22 13:26:58 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
|
2018-09-22 13:26:58 +02:00
|
|
|
|
console.error(xhr);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
|
2018-09-22 13:26:58 +02:00
|
|
|
|
console.error(xhr);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#chore_id').on('change', function(e)
|
|
|
|
|
{
|
|
|
|
|
var input = $('#chore_id_text_input').val().toString();
|
|
|
|
|
$('#chore_id_text_input').val(input);
|
|
|
|
|
$('#chore_id').data('combobox').refresh();
|
|
|
|
|
|
|
|
|
|
var choreId = $(e.target).val();
|
|
|
|
|
if (choreId)
|
|
|
|
|
{
|
2019-05-04 16:13:05 +02:00
|
|
|
|
Grocy.Api.Get('objects/chores/' + choreId,
|
|
|
|
|
function(chore)
|
|
|
|
|
{
|
2022-02-08 18:08:26 +01:00
|
|
|
|
|
2019-05-04 16:13:05 +02:00
|
|
|
|
if (chore.track_date_only == 1)
|
|
|
|
|
{
|
|
|
|
|
Grocy.Components.DateTimePicker.ChangeFormat("YYYY-MM-DD");
|
|
|
|
|
Grocy.Components.DateTimePicker.SetValue(moment().format("YYYY-MM-DD"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Grocy.Components.DateTimePicker.ChangeFormat("YYYY-MM-DD HH:mm:ss");
|
|
|
|
|
Grocy.Components.DateTimePicker.SetValue(moment().format("YYYY-MM-DD HH:mm:ss"));
|
|
|
|
|
}
|
2022-02-08 18:08:26 +01:00
|
|
|
|
|
|
|
|
|
if (chore.period_type == "manually")
|
|
|
|
|
{
|
2022-03-26 11:06:03 +01:00
|
|
|
|
$(".save-choretracking-button.skip").addClass("disabled");
|
2022-02-08 18:08:26 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-03-26 11:06:03 +01:00
|
|
|
|
$(".save-choretracking-button.skip").removeClass("disabled");
|
2022-02-08 18:08:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
|
2019-05-04 16:13:05 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
console.error(xhr);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
|
Grocy.Components.ChoreCard.Refresh(choreId);
|
2021-08-27 20:54:27 +02:00
|
|
|
|
|
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
|
|
|
|
Grocy.Components.DateTimePicker.GetInputElement().focus();
|
|
|
|
|
}, 200);
|
|
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.combobox').combobox({
|
2018-09-24 16:50:30 +02:00
|
|
|
|
appendId: '_text_input',
|
2021-07-13 19:29:23 +02:00
|
|
|
|
bsVersion: '4',
|
|
|
|
|
clearIfNoMatch: false
|
2018-09-22 13:26:58 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#chore_id_text_input').focus();
|
|
|
|
|
$('#chore_id_text_input').trigger('change');
|
2019-03-04 17:43:12 +01:00
|
|
|
|
Grocy.Components.DateTimePicker.GetInputElement().trigger('input');
|
2018-09-22 13:26:58 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
|
|
|
|
|
|
2019-03-04 17:43:12 +01:00
|
|
|
|
$('#choretracking-form input').keyup(function(event)
|
2018-09-22 13:26:58 +02:00
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#choretracking-form input').keydown(function(event)
|
|
|
|
|
{
|
2022-03-30 18:00:28 +02:00
|
|
|
|
if (event.keyCode === 13) // Enter
|
2018-09-22 13:26:58 +02:00
|
|
|
|
{
|
2018-09-29 13:41:56 +02:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
2022-03-30 18:00:28 +02:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm('choretracking-form'))
|
2018-09-22 13:26:58 +02:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-08 18:08:26 +01:00
|
|
|
|
$('.save-choretracking-button').first().click();
|
2018-09-22 13:26:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-07-13 19:29:23 +02:00
|
|
|
|
$(document).on("Grocy.BarcodeScanned", function(e, barcode, target)
|
|
|
|
|
{
|
|
|
|
|
if (!(target == "@chorepicker" || target == "undefined" || target == undefined)) // Default target
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 17:48:45 +02:00
|
|
|
|
// Don't know why the blur event does not fire immediately ... this works...
|
|
|
|
|
$("#chore_id_text_input").focusout();
|
|
|
|
|
$("#chore_id_text_input").focus();
|
|
|
|
|
$("#chore_id_text_input").blur();
|
|
|
|
|
|
|
|
|
|
$("#chore_id_text_input").val(barcode);
|
|
|
|
|
|
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
|
|
|
|
$("#chore_id_text_input").focusout();
|
|
|
|
|
$("#chore_id_text_input").focus();
|
|
|
|
|
$("#chore_id_text_input").blur();
|
2021-08-27 20:54:27 +02:00
|
|
|
|
$('#tracked_time').find('input').focus();
|
2021-08-17 17:48:45 +02:00
|
|
|
|
}, 200);
|
2021-07-13 19:29:23 +02:00
|
|
|
|
});
|
|
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
|
Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
|
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
|
|
|
|
|
});
|
2018-10-27 17:26:00 +02:00
|
|
|
|
|
|
|
|
|
function UndoChoreExecution(executionId)
|
|
|
|
|
{
|
2020-08-30 12:18:16 +02:00
|
|
|
|
Grocy.Api.Post('chores/executions/' + executionId.toString() + '/undo', {},
|
2018-10-27 17:26:00 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2019-05-01 20:19:18 +02:00
|
|
|
|
toastr.success(__t("Chore execution successfully undone"));
|
2018-10-27 17:26:00 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
console.error(xhr);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
2021-07-13 19:29:23 +02:00
|
|
|
|
|
|
|
|
|
$('#chore_id_text_input').on('blur', function(e)
|
|
|
|
|
{
|
|
|
|
|
if ($('#chore_id').hasClass("combobox-menu-visible"))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var input = $('#chore_id_text_input').val().toString();
|
|
|
|
|
var possibleOptionElement = [];
|
|
|
|
|
|
|
|
|
|
// grocycode handling
|
|
|
|
|
if (input.startsWith("grcy"))
|
|
|
|
|
{
|
|
|
|
|
var gc = input.split(":");
|
|
|
|
|
if (gc[1] == "c")
|
|
|
|
|
{
|
|
|
|
|
possibleOptionElement = $("#chore_id option[value=\"" + gc[2] + "\"]").first();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 17:06:40 +02:00
|
|
|
|
if (possibleOptionElement.length > 0)
|
|
|
|
|
{
|
|
|
|
|
$('#chore_id').val(possibleOptionElement.val());
|
|
|
|
|
$('#chore_id').data('combobox').refresh();
|
|
|
|
|
$('#chore_id').trigger('change');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$('#chore_id').val(null);
|
|
|
|
|
$('#chore_id_text_input').val("");
|
|
|
|
|
$('#chore_id').data('combobox').refresh();
|
|
|
|
|
$('#chore_id').trigger('change');
|
|
|
|
|
}
|
2021-07-13 19:29:23 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2021-08-27 20:54:27 +02:00
|
|
|
|
|
|
|
|
|
$("#tracked_time").find("input").on("focus", function(e)
|
|
|
|
|
{
|
|
|
|
|
$(this).select();
|
|
|
|
|
});
|