Renamed habits to chores as this is more what it is about

This commit is contained in:
Bernd Bestel
2018-09-22 13:26:58 +02:00
parent bd3c63218b
commit 4075067a10
31 changed files with 653 additions and 622 deletions

View File

@@ -0,0 +1,71 @@
$('#save-chore-button').on('click', function(e)
{
e.preventDefault();
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('add-object/chores', $('#chore-form').serializeJSON(),
function(result)
{
window.location.href = U('/chores');
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
}
);
}
else
{
Grocy.Api.Post('edit-object/chores/' + Grocy.EditObjectId, $('#chore-form').serializeJSON(),
function(result)
{
window.location.href = U('/chores');
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
}
);
}
});
$('#chore-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('chore-form');
});
$('#chore-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('chore-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-chore-button').click();
}
}
});
$('#name').focus();
Grocy.FrontendHelpers.ValidateForm('chore-form');
$('.input-group-chore-period-type').on('change', function(e)
{
var periodType = $('#period_type').val();
var periodDays = $('#period_days').val();
if (periodType === 'dynamic-regular')
{
$('#chore-period-type-info').text(L('This means it is estimated that a new execution of this chore is tracked #1 days after the last was tracked', periodDays.toString()));
$('#chore-period-type-info').removeClass('d-none');
}
else
{
$('#chore-period-type-info').addClass('d-none');
}
});

View File

@@ -1,4 +1,4 @@
var habitsTable = $('#habits-table').DataTable({
var choresTable = $('#chores-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
@@ -22,16 +22,16 @@ $("#search").on("keyup", function()
value = "";
}
habitsTable.search(value).draw();
choresTable.search(value).draw();
});
$(document).on('click', '.habit-delete-button', function (e)
$(document).on('click', '.chore-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-habit-name');
var objectId = $(e.currentTarget).attr('data-habit-id');
var objectName = $(e.currentTarget).attr('data-chore-name');
var objectId = $(e.currentTarget).attr('data-chore-id');
bootbox.confirm({
message: L('Are you sure to delete habit "#1"?', objectName),
message: L('Are you sure to delete chore "#1"?', objectName),
buttons: {
confirm: {
label: L('Yes'),
@@ -46,10 +46,10 @@ $(document).on('click', '.habit-delete-button', function (e)
{
if (result === true)
{
Grocy.Api.Get('delete-object/habits/' + objectId,
Grocy.Api.Get('delete-object/chores/' + objectId,
function(result)
{
window.location.href = U('/habits');
window.location.href = U('/chores');
},
function(xhr)
{

View File

@@ -1,4 +1,4 @@
var habitsAnalysisTable = $('#habits-analysis-table').DataTable({
var choresAnalysisTable = $('#chores-analysis-table').DataTable({
'paginate': false,
'order': [[1, 'desc']],
'language': JSON.parse(L('datatables_localization')),
@@ -11,16 +11,16 @@
}
});
$("#habit-filter").on("change", function()
$("#chore-filter").on("change", function()
{
var value = $(this).val();
var text = $("#habit-filter option:selected").text();
var text = $("#chore-filter option:selected").text();
if (value === "all")
{
text = "";
}
habitsAnalysisTable.column(0).search(text).draw();
choresAnalysisTable.column(0).search(text).draw();
});
$("#search").on("keyup", function()
@@ -31,11 +31,11 @@ $("#search").on("keyup", function()
value = "";
}
habitsAnalysisTable.search(value).draw();
choresAnalysisTable.search(value).draw();
});
if (typeof GetUriParam("habit") !== "undefined")
if (typeof GetUriParam("chore") !== "undefined")
{
$("#habit-filter").val(GetUriParam("habit"));
$("#habit-filter").trigger("change");
$("#chore-filter").val(GetUriParam("chore"));
$("#chore-filter").trigger("change");
}

View File

@@ -1,4 +1,4 @@
var habitsOverviewTable = $('#habits-overview-table').DataTable({
var choresOverviewTable = $('#chores-overview-table').DataTable({
'paginate': false,
'order': [[2, 'desc']],
'columnDefs': [
@@ -22,55 +22,55 @@ $("#search").on("keyup", function()
value = "";
}
habitsOverviewTable.search(value).draw();
choresOverviewTable.search(value).draw();
});
$(document).on('click', '.track-habit-button', function(e)
$(document).on('click', '.track-chore-button', function(e)
{
var habitId = $(e.currentTarget).attr('data-habit-id');
var habitName = $(e.currentTarget).attr('data-habit-name');
var choreId = $(e.currentTarget).attr('data-chore-id');
var choreName = $(e.currentTarget).attr('data-chore-name');
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Get('habits/track-habit-execution/' + habitId + '?tracked_time=' + trackedTime,
Grocy.Api.Get('chores/track-chore-execution/' + choreId + '?tracked_time=' + trackedTime,
function()
{
Grocy.Api.Get('habits/get-habit-details/' + habitId,
Grocy.Api.Get('chores/get-chore-details/' + choreId,
function(result)
{
var habitRow = $('#habit-' + habitId + '-row');
var nextXDaysThreshold = moment().add($("#info-due-habits").data("next-x-days"), "days");
var choreRow = $('#chore-' + choreId + '-row');
var nextXDaysThreshold = moment().add($("#info-due-chores").data("next-x-days"), "days");
var now = moment();
var nextExecutionTime = moment(result.next_estimated_execution_time);
habitRow.removeClass("table-warning");
habitRow.removeClass("table-danger");
choreRow.removeClass("table-warning");
choreRow.removeClass("table-danger");
if (nextExecutionTime.isBefore(now))
{
habitRow.addClass("table-danger");
choreRow.addClass("table-danger");
}
else if (nextExecutionTime.isBefore(nextXDaysThreshold))
{
habitRow.addClass("table-warning");
choreRow.addClass("table-warning");
}
$('#habit-' + habitId + '-last-tracked-time').parent().effect('highlight', { }, 500);
$('#habit-' + habitId + '-last-tracked-time').fadeOut(500, function()
$('#chore-' + choreId + '-last-tracked-time').parent().effect('highlight', { }, 500);
$('#chore-' + choreId + '-last-tracked-time').fadeOut(500, function()
{
$(this).text(trackedTime).fadeIn(500);
});
$('#habit-' + habitId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
$('#chore-' + choreId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
if (result.habit.period_type == "dynamic-regular")
if (result.chore.period_type == "dynamic-regular")
{
$('#habit-' + habitId + '-next-execution-time').parent().effect('highlight', { }, 500);
$('#habit-' + habitId + '-next-execution-time').fadeOut(500, function()
$('#chore-' + choreId + '-next-execution-time').parent().effect('highlight', { }, 500);
$('#chore-' + choreId + '-next-execution-time').fadeOut(500, function()
{
$(this).text(result.next_estimated_execution_time).fadeIn(500);
});
$('#habit-' + habitId + '-next-execution-time-timeago').attr('datetime', result.next_estimated_execution_time);
$('#chore-' + choreId + '-next-execution-time-timeago').attr('datetime', result.next_estimated_execution_time);
}
toastr.success(L('Tracked execution of habit #1 on #2', habitName, trackedTime));
toastr.success(L('Tracked execution of chore #1 on #2', choreName, trackedTime));
RefreshContextualTimeago();
RefreshStatistics();
},
@@ -89,8 +89,8 @@ $(document).on('click', '.track-habit-button', function(e)
function RefreshStatistics()
{
var nextXDays = $("#info-due-habits").data("next-x-days");
Grocy.Api.Get('habits/get-current',
var nextXDays = $("#info-due-chores").data("next-x-days");
Grocy.Api.Get('chores/get-current',
function(result)
{
var dueCount = 0;
@@ -109,8 +109,8 @@ function RefreshStatistics()
}
});
$("#info-due-habits").text(Pluralize(dueCount, L('#1 habit is due to be done within the next #2 days', dueCount, nextXDays), L('#1 habits are due to be done within the next #2 days', dueCount, nextXDays)));
$("#info-overdue-habits").text(Pluralize(overdueCount, L('#1 habit is overdue to be done', overdueCount), L('#1 habits are overdue to be done', overdueCount)));
$("#info-due-chores").text(Pluralize(dueCount, L('#1 chore is due to be done within the next #2 days', dueCount, nextXDays), L('#1 chores are due to be done within the next #2 days', dueCount, nextXDays)));
$("#info-overdue-chores").text(Pluralize(overdueCount, L('#1 chore is overdue to be done', overdueCount), L('#1 chores are overdue to be done', overdueCount)));
},
function(xhr)
{

View File

@@ -0,0 +1,82 @@
$('#save-choretracking-button').on('click', function(e)
{
e.preventDefault();
var jsonForm = $('#choretracking-form').serializeJSON();
Grocy.Api.Get('chores/get-chore-details/' + jsonForm.chore_id,
function (choreDetails)
{
Grocy.Api.Get('chores/track-chore-execution/' + jsonForm.chore_id + '?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(),
function(result)
{
toastr.success(L('Tracked execution of chore #1 on #2', choreDetails.chore.name, Grocy.Components.DateTimePicker.GetValue()));
$('#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');
},
function(xhr)
{
console.error(xhr);
}
);
},
function(xhr)
{
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)
{
Grocy.Components.ChoreCard.Refresh(choreId);
Grocy.Components.DateTimePicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
}
});
$('.combobox').combobox({
appendId: '_text_input'
});
$('#chore_id_text_input').focus();
$('#chore_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
$('#choretracking-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
});
$('#choretracking-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('choretracking-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-choretracking-button').click();
}
}
});
Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
{
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
});

View File

@@ -0,0 +1,21 @@
Grocy.Components.ChoreCard = { };
Grocy.Components.ChoreCard.Refresh = function(choreId)
{
Grocy.Api.Get('chores/get-chore-details/' + choreId,
function(choreDetails)
{
$('#chorecard-chore-name').text(choreDetails.chore.name);
$('#chorecard-chore-last-tracked').text((choreDetails.last_tracked || L('never')));
$('#chorecard-chore-last-tracked-timeago').text($.timeago(choreDetails.last_tracked || ''));
$('#chorecard-chore-tracked-count').text((choreDetails.tracked_count || '0'));
$('#chorecard-chore-last-done-by').text((choreDetails.last_done_by.display_name || L('Unknown')));
EmptyElementWhenMatches('#chorecard-chore-last-tracked-timeago', L('timeago_nan'));
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -1,21 +0,0 @@
Grocy.Components.HabitCard = { };
Grocy.Components.HabitCard.Refresh = function(habitId)
{
Grocy.Api.Get('habits/get-habit-details/' + habitId,
function(habitDetails)
{
$('#habitcard-habit-name').text(habitDetails.habit.name);
$('#habitcard-habit-last-tracked').text((habitDetails.last_tracked || L('never')));
$('#habitcard-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || ''));
$('#habitcard-habit-tracked-count').text((habitDetails.tracked_count || '0'));
$('#habitcard-habit-last-done-by').text((habitDetails.last_done_by.display_name || L('Unknown')));
EmptyElementWhenMatches('#habitcard-habit-last-tracked-timeago', L('timeago_nan'));
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -1,71 +0,0 @@
$('#save-habit-button').on('click', function(e)
{
e.preventDefault();
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('add-object/habits', $('#habit-form').serializeJSON(),
function(result)
{
window.location.href = U('/habits');
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
}
);
}
else
{
Grocy.Api.Post('edit-object/habits/' + Grocy.EditObjectId, $('#habit-form').serializeJSON(),
function(result)
{
window.location.href = U('/habits');
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
}
);
}
});
$('#habit-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('habit-form');
});
$('#habit-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('habit-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-habit-button').click();
}
}
});
$('#name').focus();
Grocy.FrontendHelpers.ValidateForm('habit-form');
$('.input-group-habit-period-type').on('change', function(e)
{
var periodType = $('#period_type').val();
var periodDays = $('#period_days').val();
if (periodType === 'dynamic-regular')
{
$('#habit-period-type-info').text(L('This means it is estimated that a new execution of this habit is tracked #1 days after the last was tracked', periodDays.toString()));
$('#habit-period-type-info').removeClass('d-none');
}
else
{
$('#habit-period-type-info').addClass('d-none');
}
});

View File

@@ -1,82 +0,0 @@
$('#save-habittracking-button').on('click', function(e)
{
e.preventDefault();
var jsonForm = $('#habittracking-form').serializeJSON();
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() + "&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()));
$('#habit_id').val('');
$('#habit_id_text_input').focus();
$('#habit_id_text_input').val('');
Grocy.Components.DateTimePicker.SetValue(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#habit_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
},
function(xhr)
{
console.error(xhr);
}
);
},
function(xhr)
{
console.error(xhr);
}
);
});
$('#habit_id').on('change', function(e)
{
var input = $('#habit_id_text_input').val().toString();
$('#habit_id_text_input').val(input);
$('#habit_id').data('combobox').refresh();
var habitId = $(e.target).val();
if (habitId)
{
Grocy.Components.HabitCard.Refresh(habitId);
Grocy.Components.DateTimePicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
}
});
$('.combobox').combobox({
appendId: '_text_input'
});
$('#habit_id_text_input').focus();
$('#habit_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
$('#habittracking-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
});
$('#habittracking-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('habittracking-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-habittracking-button').click();
}
}
});
Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
{
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
});