mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 12:26:15 +02:00
This *absolute commit monster* does the following things: - Introduce gulp to build javascript and css files. This includes moving node_modules out of the public/ folder. Use `gulp --tasks` to get a list of all tasks; however some of them are automatically generated. Use `gulp live` to watch for changes and automatically recompile what's needed. - Upgrade to yarn2 - Upgrade FullCalendar to 4.4.2 I know that 5.x is the current version, but two major version upgrades are too much right now. Also v5 would break any custom css as they renamed a bunch of classes. - Move Styles to sass (Most) global styles are now included in one sass file. This also means that we now compile our own bootstrap. - Javascript is now in strict mode Because everything is a module now, `use strict` is now in effect for all javascript files. There are probably still some parts left where implicit variable declarations were used. - grocy*.js were split up in modules. `window.Grocy` is now an instance of GrocyClass. API-wise nothing has changed (albeit some functions were added regarding Undo actions) At the Moment, this leaks a whole bunch of functions into window (that was easier than tracking those down). - FindObjectIn... style functions were removed. Array.prototype.find and Array.prototype.filter suffice. - Use babel to preprocess javascript. - Use rollup to bundle javascript. rollup bundles and tree-shakes es6 javascript bundles. It also allows to "import" css files and generate css files specific to this javascript file. This is used in viewjs scripts, for example when importing FullCalendar, to generate an associated viewcss file. - Use postcss to post-process css files. postcss uses autoprefixer to handle browser compatiblity. Internally this uses the package `browserslist`; and is currently configured to the default setting. - Minify assets when building in production `gulp publish` builds all assets in production mode, that is, the assets get minified. This includes javascript as well as css files. - css bundling concatCss is used to pull @imports of non-sass-files into one grocy.css - animate.css is now in the main bundle animate.css was used in so many places that it is now located in the main style bundle.
240 lines
7.7 KiB
JavaScript
240 lines
7.7 KiB
JavaScript
$('#save-chore-button').on('click', function(e)
|
|
{
|
|
e.preventDefault();
|
|
|
|
if ($(".combobox-menu-visible").length)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var jsonData = $('#chore-form').serializeJSON();
|
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_CHORES_ASSIGNMENTS)
|
|
{
|
|
jsonData.assignment_config = $("#assignment_config").val().join(",");
|
|
}
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("chore-form");
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
{
|
|
Grocy.Api.Post('objects/chores', jsonData,
|
|
function(result)
|
|
{
|
|
Grocy.EditObjectId = result.created_object_id;
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
{
|
|
Grocy.Api.Post('chores/executions/calculate-next-assignments', { "chore_id": Grocy.EditObjectId },
|
|
function(result)
|
|
{
|
|
window.location.href = U('/chores');
|
|
},
|
|
function(xhr)
|
|
{
|
|
Grocy.FrontendHelpers.EndUiBusy();
|
|
console.error(xhr);
|
|
}
|
|
);
|
|
});
|
|
},
|
|
function(xhr)
|
|
{
|
|
Grocy.FrontendHelpers.EndUiBusy("chore-form");
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
}
|
|
);
|
|
}
|
|
else
|
|
{
|
|
Grocy.Api.Put('objects/chores/' + Grocy.EditObjectId, jsonData,
|
|
function(result)
|
|
{
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
{
|
|
Grocy.Api.Post('chores/executions/calculate-next-assignments', { "chore_id": Grocy.EditObjectId },
|
|
function(result)
|
|
{
|
|
window.location.href = U('/chores');
|
|
},
|
|
function(xhr)
|
|
{
|
|
Grocy.FrontendHelpers.EndUiBusy();
|
|
console.error(xhr);
|
|
}
|
|
);
|
|
});
|
|
},
|
|
function(xhr)
|
|
{
|
|
Grocy.FrontendHelpers.EndUiBusy("chore-form");
|
|
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
|
|
{
|
|
event.preventDefault();
|
|
|
|
if (document.getElementById('chore-form').checkValidity() === false) //There is at least one validation error
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
$('#save-chore-button').click();
|
|
}
|
|
}
|
|
});
|
|
|
|
var checkboxValues = $("#period_config").val().split(",");
|
|
for (var i = 0; i < checkboxValues.length; i++)
|
|
{
|
|
if (!checkboxValues[i].isEmpty())
|
|
{
|
|
$("#" + checkboxValues[i]).prop('checked', true);
|
|
}
|
|
}
|
|
|
|
Grocy.Components.UserfieldsForm.Load();
|
|
$('#name').focus();
|
|
Grocy.FrontendHelpers.ValidateForm('chore-form');
|
|
|
|
setTimeout(function()
|
|
{
|
|
$(".input-group-chore-period-type").trigger("change");
|
|
$(".input-group-chore-assignment-type").trigger("change");
|
|
|
|
// Click twice to trigger on-click but not change the actual checked state
|
|
$("#consume_product_on_execution").click();
|
|
$("#consume_product_on_execution").click();
|
|
|
|
Grocy.Components.ProductPicker.GetPicker().trigger('change');
|
|
}, 100);
|
|
|
|
$('.input-group-chore-period-type').on('change', function(e)
|
|
{
|
|
var periodType = $('#period_type').val();
|
|
var periodDays = $('#period_days').val();
|
|
var periodInterval = $('#period_interval').val();
|
|
|
|
$(".period-type-input").addClass("d-none");
|
|
$(".period-type-" + periodType).removeClass("d-none");
|
|
$('#chore-period-type-info').attr("data-original-title", "");
|
|
$("#period_config").val("");
|
|
|
|
if (periodType === 'manually')
|
|
{
|
|
$('#chore-period-type-info').attr("data-original-title", __t('This means the next execution of this chore is not scheduled'));
|
|
}
|
|
else if (periodType === 'dynamic-regular')
|
|
{
|
|
$("label[for='period_days']").text(__t("Period days"));
|
|
$("#period_days").attr("min", "0");
|
|
$("#period_days").removeAttr("max");
|
|
$('#chore-period-type-info').attr("data-original-title", __t('This means the next execution of this chore is scheduled %s days after the last execution', periodDays.toString()));
|
|
}
|
|
else if (periodType === 'daily')
|
|
{
|
|
$('#chore-period-type-info').attr("data-original-title", __t('This means the next execution of this chore is scheduled 1 day after the last execution'));
|
|
$('#chore-period-interval-info').attr("data-original-title", __t('This means the next execution of this chore should only be scheduled every %s days', periodInterval.toString()));
|
|
}
|
|
else if (periodType === 'weekly')
|
|
{
|
|
$('#chore-period-type-info').attr("data-original-title", __t('This means the next execution of this chore is scheduled 1 day after the last execution, but only for the weekdays selected below'));
|
|
$("#period_config").val($(".period-type-weekly input:checkbox:checked").map(function() { return this.value; }).get().join(","));
|
|
$('#chore-period-interval-info').attr("data-original-title", __t('This means the next execution of this chore should only be scheduled every %s weeks', periodInterval.toString()));
|
|
}
|
|
else if (periodType === 'monthly')
|
|
{
|
|
$('#chore-period-type-info').attr("data-original-title", __t('This means the next execution of this chore is scheduled on the below selected day of each month'));
|
|
$("label[for='period_days']").text(__t("Day of month"));
|
|
$("#period_days").attr("min", "1");
|
|
$("#period_days").attr("max", "31");
|
|
$('#chore-period-interval-info').attr("data-original-title", __t('This means the next execution of this chore should only be scheduled every %s months', periodInterval.toString()));
|
|
}
|
|
else if (periodType === 'yearly')
|
|
{
|
|
$('#chore-period-type-info').attr("data-original-title", __t('This means the next execution of this chore is scheduled 1 year after the last execution'));
|
|
$('#chore-period-interval-info').attr("data-original-title", __t('This means the next execution of this chore should only be scheduled every %s years', periodInterval.toString()));
|
|
}
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('chore-form');
|
|
});
|
|
|
|
$('.input-group-chore-assignment-type').on('change', function(e)
|
|
{
|
|
var assignmentType = $('#assignment_type').val();
|
|
|
|
$('#chore-period-assignment-info').text("");
|
|
$("#assignment_config").removeAttr("required");
|
|
$("#assignment_config").attr("disabled", "");
|
|
|
|
if (assignmentType === 'no-assignment')
|
|
{
|
|
$('#chore-assignment-type-info').attr("data-original-title", __t('This means the next execution of this chore will not be assigned to anyone'));
|
|
}
|
|
else if (assignmentType === 'who-least-did-first')
|
|
{
|
|
$('#chore-assignment-type-info').attr("data-original-title", __t('This means the next execution of this chore will be assigned to the one who executed it least'));
|
|
$("#assignment_config").attr("required", "");
|
|
$("#assignment_config").removeAttr("disabled");
|
|
}
|
|
else if (assignmentType === 'random')
|
|
{
|
|
$('#chore-assignment-type-info').attr("data-original-title", __t('This means the next execution of this chore will be assigned randomly'));
|
|
$("#assignment_config").attr("required", "");
|
|
$("#assignment_config").removeAttr("disabled");
|
|
}
|
|
else if (assignmentType === 'in-alphabetical-order')
|
|
{
|
|
$('#chore-assignment-type-info').attr("data-original-title", __t('This means the next execution of this chore will be assigned to the next one in alphabetical order'));
|
|
$("#assignment_config").attr("required", "");
|
|
$("#assignment_config").removeAttr("disabled");
|
|
}
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('chore-form');
|
|
});
|
|
|
|
$("#consume_product_on_execution").on("click", function()
|
|
{
|
|
if (this.checked)
|
|
{
|
|
Grocy.Components.ProductPicker.Enable();
|
|
$("#product_amount").removeAttr("disabled");
|
|
}
|
|
else
|
|
{
|
|
Grocy.Components.ProductPicker.Disable();
|
|
$("#product_amount").attr("disabled", "");
|
|
}
|
|
|
|
Grocy.FrontendHelpers.ValidateForm("chore-form");
|
|
});
|
|
|
|
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
|
{
|
|
var productId = $(e.target).val();
|
|
|
|
if (productId)
|
|
{
|
|
Grocy.Api.Get('stock/products/' + productId,
|
|
function(productDetails)
|
|
{
|
|
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
|
},
|
|
function(xhr)
|
|
{
|
|
console.error(xhr);
|
|
}
|
|
);
|
|
}
|
|
});
|