mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Added userfield default values for userfield types date & datetime (closes #1166)
This commit is contained in:
parent
3efecb8bed
commit
97626b4a59
@ -63,8 +63,8 @@
|
||||
- This period type scheduled chores `n` days _after the last execution_ before, which is also possible by using the `Hourly` period type and a corresponding period interval; all existing `Daily` schedules will be converted to that on migration
|
||||
- It's now possible to manually reschedule / assign chores
|
||||
- New entry "Reschedule next execution" in the context/more menu on the chores overview page
|
||||
- If you have rescheduled a chore and want to continue the normal schedule instead, use the "Clear" button in the dialog
|
||||
- Rescheduled chores will be highlighted with an corresponding icon next to the "next estiamted tracking date"
|
||||
- If you have rescheduled a chore and want to continue the normal schedule/assignment instead, use the "Clear" button in the dialog
|
||||
- Rescheduled/reassigned chores will be highlighted with an corresponding icon next to the "Next estimated tracking date" / "Assigned to"
|
||||
- Optimized that when skipping chores via the chore tracking page, the given time is used as the "skipped time", not the scheduled next estimated tracking time of the corresponding chore (essentially making it possible to skip more then one schedule at once)
|
||||
- Fixed that when consuming a parent product on chore execution (chore option "Consume product on chore execution"), no child products were used if the parent product itself is not in-stock
|
||||
- Fixed that the upgrade to v3.2.0 failed when having any former "Dynamic Regular" chore with a "Period interval" of `0` (which makes absolutely no sense in reality)
|
||||
@ -91,13 +91,13 @@
|
||||
|
||||
### Userfields
|
||||
|
||||
- xxx
|
||||
- Userfields of type "Date & time" and "Date (without time)" have now the option to default to now / today for new objects (new Userfield option "Default value")
|
||||
|
||||
### General
|
||||
|
||||
- Optimized form validation: Save / submit buttons are now not disabled when the form is invalid, the invalid / missing fields are instead highlighted when trying to submit / save the form (making it more obvious which fields are invalid / missing exactly)
|
||||
- Night mode can now use / follow the system preferred color scheme
|
||||
- The user setting `night_mode_enabled` has been removed and replaced by `night_mode` which now defaults to `follow-system` (which uses the system preferred color scheme)
|
||||
- The view/user setting "Enable night mode" has been removed and replaced by "Night mode" which now defaults to "Use system setting" (which uses the system preferred color scheme, "On" and "Off" are other possible options to always enable/disable night mode)
|
||||
- Fixed an server error (on every page) when not having any quantity unit
|
||||
|
||||
### API
|
||||
|
@ -2356,3 +2356,9 @@ msgstr ""
|
||||
|
||||
msgid "Reassigned"
|
||||
msgstr ""
|
||||
|
||||
msgid "Default value"
|
||||
msgstr ""
|
||||
|
||||
msgid "Now / today"
|
||||
msgstr ""
|
||||
|
2
migrations/0186.sql
Normal file
2
migrations/0186.sql
Normal file
@ -0,0 +1,2 @@
|
||||
ALTER TABLE userfields
|
||||
ADD default_value TEXT;
|
@ -89,86 +89,123 @@ Grocy.Components.UserfieldsForm.Save = function(success, error)
|
||||
|
||||
Grocy.Components.UserfieldsForm.Load = function()
|
||||
{
|
||||
if (!$("#userfields-form").length || typeof Grocy.EditObjectId == "undefined")
|
||||
if (!$("#userfields-form").length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Grocy.Api.Get('userfields/' + $("#userfields-form").data("entity") + '/' + Grocy.EditObjectId,
|
||||
function(result)
|
||||
{
|
||||
$.each(result, function(key, value)
|
||||
if (typeof Grocy.EditObjectId == "undefined")
|
||||
{
|
||||
// Init fields by configured default values
|
||||
|
||||
Grocy.Api.Get("objects/userfields?query[]=entity=" + $("#userfields-form").data("entity"),
|
||||
function(result)
|
||||
{
|
||||
var input = $(".userfield-input[data-userfield-name='" + key + "']");
|
||||
$.each(result, function(key, userfield)
|
||||
{
|
||||
var input = $(".userfield-input[data-userfield-name='" + userfield.name + "']");
|
||||
|
||||
if (input.attr("type") == "checkbox" && value == 1)
|
||||
{
|
||||
input.prop("checked", true);
|
||||
}
|
||||
else if (input.hasAttr("multiple"))
|
||||
{
|
||||
input.val(value.split(","));
|
||||
$(".selectpicker").selectpicker("render");
|
||||
}
|
||||
else if (input.attr('type') == "file")
|
||||
{
|
||||
if (value != null && !value.isEmpty())
|
||||
if (userfield.type == "datetime" && userfield.default_value == "now")
|
||||
{
|
||||
var fileName = atob(value.split('_')[1]);
|
||||
var fileSrc = value.split('_')[0];
|
||||
var formGroup = input.parent().parent().parent();
|
||||
|
||||
formGroup.find("label.custom-file-label").text(fileName);
|
||||
formGroup.find(".userfield-file-show").attr('href', U('/files/userfiles/' + value));
|
||||
formGroup.find('.userfield-file-show').removeClass('d-none');
|
||||
formGroup.find('img.userfield-current-file')
|
||||
.attr('src', U('/files/userfiles/' + value + '?force_serve_as=picture&best_fit_width=250&best_fit_height=250'));
|
||||
LoadImagesLazy();
|
||||
|
||||
formGroup.find('.userfield-file-delete').click(
|
||||
function()
|
||||
{
|
||||
formGroup.find("label.custom-file-label").text(__t("No file selected"));
|
||||
formGroup.find(".userfield-file-show").addClass('d-none');
|
||||
input.attr('data-old-file', fileSrc);
|
||||
}
|
||||
);
|
||||
|
||||
input.on("change", function(e)
|
||||
{
|
||||
formGroup.find(".userfield-file-show").addClass('d-none');
|
||||
});
|
||||
input.val(moment().format("YYYY-MM-DD HH:mm:ss"))
|
||||
}
|
||||
}
|
||||
else if (input.attr("data-userfield-type") == "link")
|
||||
{
|
||||
if (!value.isEmpty())
|
||||
else if (userfield.type == "date" && userfield.default_value == "now")
|
||||
{
|
||||
var data = JSON.parse(value);
|
||||
input.val(moment().format("YYYY-MM-DD"))
|
||||
}
|
||||
});
|
||||
|
||||
var formRow = input.parent().parent();
|
||||
formRow.find(".userfield-link-title").val(data.title);
|
||||
formRow.find(".userfield-link-link").val(data.link);
|
||||
$("form").each(function()
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm(this.id);
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Load object field values
|
||||
|
||||
Grocy.Api.Get('userfields/' + $("#userfields-form").data("entity") + '/' + Grocy.EditObjectId,
|
||||
function(result)
|
||||
{
|
||||
$.each(result, function(key, value)
|
||||
{
|
||||
var input = $(".userfield-input[data-userfield-name='" + key + "']");
|
||||
|
||||
if (input.attr("type") == "checkbox" && value == 1)
|
||||
{
|
||||
input.prop("checked", true);
|
||||
}
|
||||
else if (input.hasAttr("multiple"))
|
||||
{
|
||||
input.val(value.split(","));
|
||||
$(".selectpicker").selectpicker("render");
|
||||
}
|
||||
else if (input.attr('type') == "file")
|
||||
{
|
||||
if (value != null && !value.isEmpty())
|
||||
{
|
||||
var fileName = atob(value.split('_')[1]);
|
||||
var fileSrc = value.split('_')[0];
|
||||
var formGroup = input.parent().parent().parent();
|
||||
|
||||
formGroup.find("label.custom-file-label").text(fileName);
|
||||
formGroup.find(".userfield-file-show").attr('href', U('/files/userfiles/' + value));
|
||||
formGroup.find('.userfield-file-show').removeClass('d-none');
|
||||
formGroup.find('img.userfield-current-file')
|
||||
.attr('src', U('/files/userfiles/' + value + '?force_serve_as=picture&best_fit_width=250&best_fit_height=250'));
|
||||
LoadImagesLazy();
|
||||
|
||||
formGroup.find('.userfield-file-delete').click(
|
||||
function()
|
||||
{
|
||||
formGroup.find("label.custom-file-label").text(__t("No file selected"));
|
||||
formGroup.find(".userfield-file-show").addClass('d-none');
|
||||
input.attr('data-old-file', fileSrc);
|
||||
}
|
||||
);
|
||||
|
||||
input.on("change", function(e)
|
||||
{
|
||||
formGroup.find(".userfield-file-show").addClass('d-none');
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (input.attr("data-userfield-type") == "link")
|
||||
{
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
var data = JSON.parse(value);
|
||||
|
||||
var formRow = input.parent().parent();
|
||||
formRow.find(".userfield-link-title").val(data.title);
|
||||
formRow.find(".userfield-link-link").val(data.link);
|
||||
|
||||
input.val(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
input.val(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
input.val(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("form").each(function()
|
||||
$("form").each(function()
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm(this.id);
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm(this.id);
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Grocy.Components.UserfieldsForm.Clear = function()
|
||||
|
@ -106,6 +106,9 @@ $("#type").on("change", function(e)
|
||||
$("#config").parent().addClass("d-none");
|
||||
$("#config-hint").text("");
|
||||
}
|
||||
|
||||
$("#default-value-group").addClass("d-none");
|
||||
$("#default-value-group.userfield-type-" + value).removeClass("d-none");
|
||||
});
|
||||
|
||||
$('#entity').focus();
|
||||
|
@ -118,6 +118,20 @@
|
||||
name="config">@if($mode == 'edit'){{ $userfield->config }}@endif</textarea>
|
||||
</div>
|
||||
|
||||
<div id="default-value-group"
|
||||
class="form-group d-none userfield-type-date userfield-type-datetime">
|
||||
<label for="entity">{{ $__t('Default value') }}</label>
|
||||
<select class="custom-control custom-select"
|
||||
id="default_value"
|
||||
name="default_value">
|
||||
<option></option>
|
||||
<option value="now"
|
||||
@if($mode=='edit'
|
||||
&&
|
||||
$userfield->default_value == 'now') selected="selected" @endif>{{ $__t('Now / today') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input @if($mode=='edit'
|
||||
|
Loading…
x
Reference in New Issue
Block a user