mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Move public stuff into subdirectory
This commit is contained in:
@@ -1,146 +0,0 @@
|
||||
body {
|
||||
padding-top: 50px;
|
||||
font-family: 'Noto Sans', sans-serif;
|
||||
}
|
||||
|
||||
.navbar-fixed-top {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 51px;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 1000;
|
||||
display: block;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background-color: #f5f5f5;
|
||||
border-right: 1px solid #5e5e5e;
|
||||
min-width: 220px;
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
#navbar-mobile {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-sidebar {
|
||||
margin-right: -21px;
|
||||
margin-bottom: 20px;
|
||||
margin-left: -20px;
|
||||
}
|
||||
|
||||
.nav-sidebar > li > a {
|
||||
padding-right: 20px;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.nav-sidebar > .active > a,
|
||||
.nav-sidebar > .active > a:hover,
|
||||
.nav-sidebar > .active > a:focus {
|
||||
color: #fff;
|
||||
background-color: #5e5e5e;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.main {
|
||||
padding-right: 40px;
|
||||
padding-left: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.main .page-header {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.nav-copyright {
|
||||
color: #b3b3b1;
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
font-family: 'Arial', sans-serif;
|
||||
}
|
||||
|
||||
.discrete-link {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
a.discrete-link:hover {
|
||||
color: #5cb85c;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.discrete-link:focus {
|
||||
color: #337ab7;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.navbar-fixed-top {
|
||||
border-bottom: solid;
|
||||
border-color: #5e5e5e;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: bold;
|
||||
letter-spacing: -2px;
|
||||
font-size: 2.2em;
|
||||
font-family: 'Arial', sans-serif;
|
||||
}
|
||||
|
||||
.table td.fit-content,
|
||||
.table th.fit-content {
|
||||
white-space: nowrap;
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
.dataTables_info,
|
||||
.dataTables_length,
|
||||
.dataTables_filter {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.timeago-contextual {
|
||||
font-style: italic;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.disabled,
|
||||
.no-real-button {
|
||||
pointer-events: none;
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.warning-bg {
|
||||
background-color: #fcf8e3 !important;
|
||||
}
|
||||
|
||||
.error-bg {
|
||||
background-color: #f2dede !important;
|
||||
}
|
||||
|
||||
.info-bg {
|
||||
background-color: #afd9ee !important;
|
||||
}
|
||||
|
||||
.discrete-content-separator {
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.discrete-content-separator-2x {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 5.2 KiB |
@@ -1,103 +0,0 @@
|
||||
var Grocy = { };
|
||||
|
||||
$(function()
|
||||
{
|
||||
var menuItem = $('.nav').find("[data-nav-for-page='" + Grocy.ContentPage + "']");
|
||||
menuItem.addClass('active');
|
||||
|
||||
$.timeago.settings.allowFuture = true;
|
||||
$('time.timeago').timeago();
|
||||
});
|
||||
|
||||
Grocy.FetchJson = function(url, success, error)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
error(xhr);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open('GET', url, true);
|
||||
xhr.send();
|
||||
};
|
||||
|
||||
Grocy.PostJson = function(url, jsonData, success, error)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
{
|
||||
if (xhr.status === 200)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
success(JSON.parse(xhr.responseText));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
error(xhr);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open('POST', url, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
Grocy.EmptyElementWhenMatches = function(selector, text)
|
||||
{
|
||||
if ($(selector).text() === text)
|
||||
{
|
||||
$(selector).text('');
|
||||
}
|
||||
};
|
||||
|
||||
String.prototype.contains = function(search)
|
||||
{
|
||||
return this.toLowerCase().indexOf(search.toLowerCase()) !== -1;
|
||||
};
|
||||
|
||||
Grocy.GetUriParam = function(key)
|
||||
{
|
||||
var currentUri = decodeURIComponent(window.location.search.substring(1));
|
||||
var vars = currentUri.split('&');
|
||||
|
||||
for (i = 0; i < vars.length; i++)
|
||||
{
|
||||
var currentParam = vars[i].split('=');
|
||||
|
||||
if (currentParam[0] === key)
|
||||
{
|
||||
return currentParam[1] === undefined ? true : currentParam[1];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Grocy.Wait = function(ms)
|
||||
{
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
@@ -16,7 +16,7 @@ $applicationService = new ApplicationService();
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
|
||||
<meta name="author" content="Bernd Bestel (bernd@berrnd.de)">
|
||||
<link rel="icon" type="image/png" sizes="200x200" href="/views/img/grocy.png">
|
||||
<link rel="icon" type="image/png" sizes="200x200" href="/img/grocy.png">
|
||||
|
||||
<title><?php echo $title; ?> | grocy</title>
|
||||
|
||||
@@ -30,10 +30,10 @@ $applicationService = new ApplicationService();
|
||||
<link href="/bower_components/tagmanager/tagmanager.css?v=<?php echo $applicationService->GetInstalledVersion(); ?>" rel="stylesheet">
|
||||
<link href="/bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css?v=<?php echo $applicationService->GetInstalledVersion(); ?>" rel="stylesheet">
|
||||
<link href="/vendor_unmanaged/noto-sans-v6-latin/noto-sans-v6-latin.css?v=<?php echo $applicationService->GetInstalledVersion(); ?>" rel="stylesheet">
|
||||
<link href="/views/css/grocy.css?v=<?php echo $applicationService->GetInstalledVersion(); ?>" rel="stylesheet">
|
||||
<link href="/css/grocy.css?v=<?php echo $applicationService->GetInstalledVersion(); ?>" rel="stylesheet">
|
||||
|
||||
<script src="/bower_components/jquery/dist/jquery.min.js?v=<?php echo $applicationService->GetInstalledVersion(); ?>"></script>
|
||||
<script src="/views/js/grocy.js?v=<?php echo $applicationService->GetInstalledVersion(); ?>"></script>
|
||||
<script src="/js/grocy.js?v=<?php echo $applicationService->GetInstalledVersion(); ?>"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -234,8 +234,8 @@ $applicationService = new ApplicationService();
|
||||
<script src="/bower_components/tagmanager/tagmanager.js?v=<?php echo $applicationService->GetInstalledVersion(); ?>"></script>
|
||||
<script src="/bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js?v=<?php echo $applicationService->GetInstalledVersion(); ?>"></script>
|
||||
|
||||
<?php if (file_exists(__DIR__ . '/../../views/viewjs/' . str_replace('.php', '.js', $contentPage))) : ?>
|
||||
<script src="/views/viewjs/<?php echo str_replace('.php', '.js', $contentPage) . '?v=' . $applicationService->GetInstalledVersion(); ?>"></script>
|
||||
<?php if (file_exists(__DIR__ . '/../../public/viewjs/' . str_replace('.php', '.js', $contentPage))) : ?>
|
||||
<script src="/viewjs/<?php echo str_replace('.php', '.js', $contentPage) . '?v=' . $applicationService->GetInstalledVersion(); ?>"></script>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (file_exists(__DIR__ . '/../data/add_before_end_body.html')) include __DIR__ . '/../data/add_before_end_body.html' ?>
|
||||
|
@@ -1,43 +0,0 @@
|
||||
$(document).on('click', '.battery-delete-button', function(e)
|
||||
{
|
||||
bootbox.confirm({
|
||||
message: 'Delete battery <strong>' + $(e.target).attr('data-battery-name') + '</strong>?',
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: 'Yes',
|
||||
className: 'btn-success'
|
||||
},
|
||||
cancel: {
|
||||
label: 'No',
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function(result)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.FetchJson('/api/delete-object/batteries/' + $(e.target).attr('data-battery-id'),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/batteries';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#batteries-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 }
|
||||
]
|
||||
});
|
||||
});
|
@@ -1,7 +0,0 @@
|
||||
$(function()
|
||||
{
|
||||
$('#batteries-overview-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'desc']]
|
||||
});
|
||||
});
|
@@ -1,38 +0,0 @@
|
||||
$('#save-battery-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.PostJson('/api/add-object/batteries', $('#battery-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/batteries';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.PostJson('/api/edit-object/batteries/' + Grocy.EditObjectId, $('#battery-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/batteries';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#name').focus();
|
||||
$('#battery-form').validator();
|
||||
$('#battery-form').validator('validate');
|
||||
});
|
@@ -1,167 +0,0 @@
|
||||
$('#save-batterytracking-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonForm = $('#batterytracking-form').serializeJSON();
|
||||
|
||||
Grocy.FetchJson('/api/batteries/get-battery-details/' + jsonForm.battery_id,
|
||||
function (batteryDetails)
|
||||
{
|
||||
Grocy.FetchJson('/api/batteries/track-charge-cycle/' + jsonForm.battery_id + '?tracked_time=' + $('#tracked_time').val(),
|
||||
function(result)
|
||||
{
|
||||
toastr.success('Tracked charge cylce of battery ' + batteryDetails.battery.name + ' on ' + $('#tracked_time').val());
|
||||
|
||||
$('#battery_id').val('');
|
||||
$('#battery_id_text_input').focus();
|
||||
$('#battery_id_text_input').val('');
|
||||
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
||||
$('#tracked_time').trigger('change');
|
||||
$('#battery_id_text_input').trigger('change');
|
||||
$('#batterytracking-form').validator('validate');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#battery_id').on('change', function(e)
|
||||
{
|
||||
var batteryId = $(e.target).val();
|
||||
|
||||
if (batteryId)
|
||||
{
|
||||
Grocy.FetchJson('/api/batteries/get-battery-details/' + batteryId,
|
||||
function(batteryDetails)
|
||||
{
|
||||
$('#selected-battery-name').text(batteryDetails.battery.name);
|
||||
$('#selected-battery-last-charged').text((batteryDetails.last_charged || 'never'));
|
||||
$('#selected-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || ''));
|
||||
$('#selected-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0'));
|
||||
|
||||
$('#tracked_time').focus();
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-battery-last-charged-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('.datetimepicker').datetimepicker(
|
||||
{
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
showTodayButton: true,
|
||||
calendarWeeks: true,
|
||||
maxDate: moment()
|
||||
});
|
||||
|
||||
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
||||
$('#tracked_time').trigger('change');
|
||||
|
||||
$('#tracked_time').on('focus', function(e)
|
||||
{
|
||||
if ($('#battery_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#battery_id_text_input').focus();
|
||||
}
|
||||
});
|
||||
|
||||
$('.combobox').combobox({
|
||||
appendId: '_text_input'
|
||||
});
|
||||
|
||||
$('#battery_id').val('');
|
||||
$('#battery_id_text_input').focus();
|
||||
$('#battery_id_text_input').val('');
|
||||
$('#battery_id_text_input').trigger('change');
|
||||
|
||||
$('#batterytracking-form').validator();
|
||||
$('#batterytracking-form').validator('validate');
|
||||
|
||||
$('#batterytracking-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
if ($('#batterytracking-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
|
||||
{
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#tracked_time').on('change', function(e)
|
||||
{
|
||||
var value = $('#tracked_time').val();
|
||||
var now = new Date();
|
||||
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
|
||||
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
|
||||
|
||||
if (value === 'x' || value === 'X') {
|
||||
value = '29991231';
|
||||
}
|
||||
|
||||
if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
|
||||
{
|
||||
value = (new Date()).getFullYear().toString() + value;
|
||||
}
|
||||
|
||||
if (value.length === 8 && $.isNumeric(value))
|
||||
{
|
||||
value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
|
||||
$('#tracked_time').val(value);
|
||||
$('#batterytracking-form').validator('validate');
|
||||
}
|
||||
});
|
||||
|
||||
$('#tracked_time').on('keypress', function(e)
|
||||
{
|
||||
var element = $(e.target);
|
||||
var value = element.val();
|
||||
var dateObj = moment(element.val(), 'YYYY-MM-DD', true);
|
||||
|
||||
$('.datepicker').datepicker('hide');
|
||||
|
||||
//If input is empty and any arrow key is pressed, set date to today
|
||||
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
|
||||
{
|
||||
dateObj = moment(new Date(), 'YYYY-MM-DD', true);
|
||||
}
|
||||
|
||||
if (dateObj.isValid())
|
||||
{
|
||||
if (e.keyCode === 38) //Up
|
||||
{
|
||||
element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 40) //Down
|
||||
{
|
||||
element.val(dateObj.add(1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 37) //Left
|
||||
{
|
||||
element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 39) //Right
|
||||
{
|
||||
element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
}
|
||||
|
||||
$('#batterytracking-form').validator('validate');
|
||||
});
|
@@ -1,144 +0,0 @@
|
||||
$('#save-consume-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonForm = $('#consume-form').serializeJSON();
|
||||
|
||||
var spoiled = 0;
|
||||
if ($('#spoiled').is(':checked'))
|
||||
{
|
||||
spoiled = 1;
|
||||
}
|
||||
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + jsonForm.product_id,
|
||||
function (productDetails)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/consume-product/' + jsonForm.product_id + '/' + jsonForm.amount + '?spoiled=' + spoiled,
|
||||
function(result)
|
||||
{
|
||||
toastr.success('Removed ' + jsonForm.amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' from stock');
|
||||
|
||||
$('#amount').val(1);
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').focus();
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').trigger('change');
|
||||
$('#consume-form').validator('validate');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#product_id').on('change', function(e)
|
||||
{
|
||||
var productId = $(e.target).val();
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function (productDetails)
|
||||
{
|
||||
$('#selected-product-name').text(productDetails.product.name);
|
||||
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#amount').attr('max', productDetails.stock_amount);
|
||||
$('#consume-form').validator('update');
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
|
||||
if ((productDetails.stock_amount || 0) === 0)
|
||||
{
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').addClass('has-error');
|
||||
$('#product_id_text_input').parent('.input-group').addClass('has-error');
|
||||
$('#product_id_text_input').closest('.form-group').addClass('has-error');
|
||||
$('#product-error').text('This product is not in stock.');
|
||||
$('#product-error').show();
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#product_id_text_input').removeClass('has-error');
|
||||
$('#product_id_text_input').parent('.input-group').removeClass('has-error');
|
||||
$('#product_id_text_input').closest('.form-group').removeClass('has-error');
|
||||
$('#product-error').hide();
|
||||
$('#amount').focus();
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('.combobox').combobox({
|
||||
appendId: '_text_input'
|
||||
});
|
||||
|
||||
$('#product_id_text_input').on('change', function(e)
|
||||
{
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||
|
||||
if (possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
$('#amount').val(1);
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').focus();
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').trigger('change');
|
||||
|
||||
$('#consume-form').validator();
|
||||
$('#consume-form').validator('validate');
|
||||
|
||||
$('#amount').on('focus', function(e)
|
||||
{
|
||||
if ($('#product_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
$(this).select();
|
||||
}
|
||||
});
|
||||
|
||||
$('#consume-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
if ($('#consume-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
|
||||
{
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
@@ -1,54 +0,0 @@
|
||||
$('#save-habit-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.PostJson('/api/add-object/habits', $('#habit-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/habits';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.PostJson('/api/edit-object/habits/' + Grocy.EditObjectId, $('#habit-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/habits';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#name').focus();
|
||||
$('#habit-form').validator();
|
||||
$('#habit-form').validator('validate');
|
||||
});
|
||||
|
||||
$('.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('This means it is estimated that a new "execution" of this habit is tracked ' + periodDays.toString() + ' days after the last was tracked.');
|
||||
$('#habit-period-type-info').show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#habit-period-type-info').hide();
|
||||
}
|
||||
});
|
@@ -1,43 +0,0 @@
|
||||
$(document).on('click', '.habit-delete-button', function(e)
|
||||
{
|
||||
bootbox.confirm({
|
||||
message: 'Delete habit <strong>' + $(e.target).attr('data-habit-name') + '</strong>?',
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: 'Yes',
|
||||
className: 'btn-success'
|
||||
},
|
||||
cancel: {
|
||||
label: 'No',
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function(result)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.FetchJson('/api/delete-object/habits/' + $(e.target).attr('data-habit-id'),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/habits';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#habits-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 }
|
||||
]
|
||||
});
|
||||
});
|
@@ -1,7 +0,0 @@
|
||||
$(function()
|
||||
{
|
||||
$('#habits-overview-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'desc']]
|
||||
});
|
||||
});
|
@@ -1,167 +0,0 @@
|
||||
$('#save-habittracking-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonForm = $('#habittracking-form').serializeJSON();
|
||||
|
||||
Grocy.FetchJson('/api/habits/get-habit-details/' + jsonForm.habit_id,
|
||||
function (habitDetails)
|
||||
{
|
||||
Grocy.FetchJson('/api/habits/track-habit-exeuction/' + jsonForm.habit_id + '?tracked_time=' + $('#tracked_time').val(),
|
||||
function(result)
|
||||
{
|
||||
toastr.success('Tracked execution of habit ' + habitDetails.habit.name + ' on ' + $('#tracked_time').val());
|
||||
|
||||
$('#habit_id').val('');
|
||||
$('#habit_id_text_input').focus();
|
||||
$('#habit_id_text_input').val('');
|
||||
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
||||
$('#tracked_time').trigger('change');
|
||||
$('#habit_id_text_input').trigger('change');
|
||||
$('#habittracking-form').validator('validate');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#habit_id').on('change', function(e)
|
||||
{
|
||||
var habitId = $(e.target).val();
|
||||
|
||||
if (habitId)
|
||||
{
|
||||
Grocy.FetchJson('/api/habits/get-habit-details/' + habitId,
|
||||
function(habitDetails)
|
||||
{
|
||||
$('#selected-habit-name').text(habitDetails.habit.name);
|
||||
$('#selected-habit-last-tracked').text((habitDetails.last_tracked || 'never'));
|
||||
$('#selected-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || ''));
|
||||
$('#selected-habit-tracked-count').text((habitDetails.tracked_count || '0'));
|
||||
|
||||
$('#tracked_time').focus();
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-habit-last-tracked-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('.datetimepicker').datetimepicker(
|
||||
{
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
showTodayButton: true,
|
||||
calendarWeeks: true,
|
||||
maxDate: moment()
|
||||
});
|
||||
|
||||
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
||||
$('#tracked_time').trigger('change');
|
||||
|
||||
$('#tracked_time').on('focus', function(e)
|
||||
{
|
||||
if ($('#habit_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#habit_id_text_input').focus();
|
||||
}
|
||||
});
|
||||
|
||||
$('.combobox').combobox({
|
||||
appendId: '_text_input'
|
||||
});
|
||||
|
||||
$('#habit_id').val('');
|
||||
$('#habit_id_text_input').focus();
|
||||
$('#habit_id_text_input').val('');
|
||||
$('#habit_id_text_input').trigger('change');
|
||||
|
||||
$('#habittracking-form').validator();
|
||||
$('#habittracking-form').validator('validate');
|
||||
|
||||
$('#habittracking-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
if ($('#habittracking-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
|
||||
{
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#tracked_time').on('change', function(e)
|
||||
{
|
||||
var value = $('#tracked_time').val();
|
||||
var now = new Date();
|
||||
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
|
||||
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
|
||||
|
||||
if (value === 'x' || value === 'X') {
|
||||
value = '29991231';
|
||||
}
|
||||
|
||||
if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
|
||||
{
|
||||
value = (new Date()).getFullYear().toString() + value;
|
||||
}
|
||||
|
||||
if (value.length === 8 && $.isNumeric(value))
|
||||
{
|
||||
value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
|
||||
$('#tracked_time').val(value);
|
||||
$('#habittracking-form').validator('validate');
|
||||
}
|
||||
});
|
||||
|
||||
$('#tracked_time').on('keypress', function(e)
|
||||
{
|
||||
var element = $(e.target);
|
||||
var value = element.val();
|
||||
var dateObj = moment(element.val(), 'YYYY-MM-DD', true);
|
||||
|
||||
$('.datepicker').datepicker('hide');
|
||||
|
||||
//If input is empty and any arrow key is pressed, set date to today
|
||||
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
|
||||
{
|
||||
dateObj = moment(new Date(), 'YYYY-MM-DD', true);
|
||||
}
|
||||
|
||||
if (dateObj.isValid())
|
||||
{
|
||||
if (e.keyCode === 38) //Up
|
||||
{
|
||||
element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 40) //Down
|
||||
{
|
||||
element.val(dateObj.add(1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 37) //Left
|
||||
{
|
||||
element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 39) //Right
|
||||
{
|
||||
element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
}
|
||||
|
||||
$('#habittracking-form').validator('validate');
|
||||
});
|
@@ -1,402 +0,0 @@
|
||||
$('#save-inventory-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonForm = $('#inventory-form').serializeJSON();
|
||||
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + jsonForm.product_id,
|
||||
function (productDetails)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||
function(result)
|
||||
{
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
if (existingBarcodes.length === 0)
|
||||
{
|
||||
productDetails.product.barcode = addBarcode;
|
||||
}
|
||||
else
|
||||
{
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
|
||||
Grocy.PostJson('/api/edit-object/products/' + productDetails.product.id, productDetails.product,
|
||||
function (result) { },
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
toastr.success('Stock amount of ' + productDetails.product.name + ' is now ' + jsonForm.new_amount.toString() + ' ' + productDetails.quantity_unit_stock.name);
|
||||
Grocy.Wait(1000);
|
||||
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
window.location.href = '/inventory';
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#inventory-change-info').hide();
|
||||
$('#new_amount').val('');
|
||||
$('#best_before_date').val('');
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').focus();
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').trigger('change');
|
||||
$('#inventory-form').validator('validate');
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#product_id').on('change', function(e)
|
||||
{
|
||||
var productId = $(e.target).val();
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#selected-product-name').text(productDetails.product.name);
|
||||
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name);
|
||||
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#new_amount').attr('not-equal', productDetails.stock_amount);
|
||||
$('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
||||
|
||||
$('#new_amount').focus();
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('.datepicker').datepicker(
|
||||
{
|
||||
format: 'yyyy-mm-dd',
|
||||
startDate: '+0d',
|
||||
todayHighlight: true,
|
||||
autoclose: true,
|
||||
calendarWeeks: true,
|
||||
orientation: 'bottom auto',
|
||||
weekStart: 1,
|
||||
showOnFocus: false
|
||||
});
|
||||
$('.datepicker').trigger('change');
|
||||
|
||||
$('.combobox').combobox({
|
||||
appendId: '_text_input'
|
||||
});
|
||||
|
||||
$('#product_id_text_input').on('change', function(e)
|
||||
{
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||
|
||||
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
}
|
||||
else
|
||||
{
|
||||
var optionElement = $("#product_id option:contains('" + input + "')").first();
|
||||
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
|
||||
{
|
||||
bootbox.dialog({
|
||||
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
|
||||
title: 'Create or assign product',
|
||||
onEscape: function() { },
|
||||
size: 'large',
|
||||
backdrop: true,
|
||||
buttons: {
|
||||
cancel: {
|
||||
label: 'Cancel',
|
||||
className: 'btn-default',
|
||||
callback: function() { }
|
||||
},
|
||||
addnewproduct: {
|
||||
label: 'Add as new <u><strong>p</strong></u>roduct',
|
||||
className: 'btn-success add-new-product-dialog-button',
|
||||
callback: function()
|
||||
{
|
||||
window.location.href = '/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname);
|
||||
}
|
||||
},
|
||||
addbarcode: {
|
||||
label: 'Add as <u><strong>b</strong></u>arcode to existing product',
|
||||
className: 'btn-info add-new-barcode-dialog-button',
|
||||
callback: function()
|
||||
{
|
||||
window.location.href = '/inventory?addbarcodetoselection=' + encodeURIComponent(input);
|
||||
}
|
||||
},
|
||||
addnewproductwithbarcode: {
|
||||
label: '<u><strong>A</strong></u>dd as new product + prefill barcode',
|
||||
className: 'btn-warning add-new-product-with-barcode-dialog-button',
|
||||
callback: function()
|
||||
{
|
||||
window.location.href = '/product/new?prefillbarcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).on('keypress', function(e)
|
||||
{
|
||||
if (e.key === 'B' || e.key === 'b')
|
||||
{
|
||||
$('.add-new-barcode-dialog-button').click();
|
||||
}
|
||||
if (e.key === 'p' || e.key === 'P')
|
||||
{
|
||||
$('.add-new-product-dialog-button').click();
|
||||
}
|
||||
if (e.key === 'a' || e.key === 'A')
|
||||
{
|
||||
$('.add-new-product-with-barcode-dialog-button').click();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#new_amount').val('');
|
||||
$('#best_before_date').val('');
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').focus();
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').trigger('change');
|
||||
|
||||
$('#inventory-form').validator({
|
||||
custom: {
|
||||
'isodate': function($el)
|
||||
{
|
||||
if ($el.val().length !== 0 && !moment($el.val(), 'YYYY-MM-DD', true).isValid())
|
||||
{
|
||||
return 'Wrong date format, needs to be YYYY-MM-DD';
|
||||
}
|
||||
else if (moment($el.val()).isValid())
|
||||
{
|
||||
if (moment($el.val()).isBefore(moment(), 'day'))
|
||||
{
|
||||
return 'This value cannot be before today.';
|
||||
}
|
||||
}
|
||||
},
|
||||
'notequal': function($el)
|
||||
{
|
||||
if ($el.val().length !== 0 && $el.val().toString() === $el.attr('not-equal').toString())
|
||||
{
|
||||
return 'This value cannot be equal to ' + $el.attr('not-equal').toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$('#inventory-form').validator('validate');
|
||||
|
||||
$('#new_amount').on('focus', function(e)
|
||||
{
|
||||
if ($('#product_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
$(this).select();
|
||||
}
|
||||
});
|
||||
|
||||
$('#inventory-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
if ($('#inventory-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
|
||||
{
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var prefillProduct = Grocy.GetUriParam('createdproduct');
|
||||
if (prefillProduct !== undefined)
|
||||
{
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
|
||||
if (possibleOptionElement.length === 0)
|
||||
{
|
||||
possibleOptionElement = $("#product_id option:contains('" + prefillProduct + "')").first();
|
||||
}
|
||||
|
||||
if (possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
$('#new_amount').focus();
|
||||
}
|
||||
}
|
||||
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
$('#addbarcodetoselection').text(addBarcode);
|
||||
$('#flow-info-addbarcodetoselection').removeClass('hide');
|
||||
$('#barcode-lookup-disabled-hint').removeClass('hide');
|
||||
}
|
||||
});
|
||||
|
||||
$('#best_before_date-datepicker-button').on('click', function(e)
|
||||
{
|
||||
$('.datepicker').datepicker('show');
|
||||
});
|
||||
|
||||
$('#new_amount').on('keypress', function(e)
|
||||
{
|
||||
$('#new_amount').trigger('change');
|
||||
});
|
||||
|
||||
$('#best_before_date').on('change', function(e)
|
||||
{
|
||||
var value = $('#best_before_date').val();
|
||||
var now = new Date();
|
||||
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
|
||||
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
|
||||
|
||||
if (value === 'x' || value === 'X')
|
||||
{
|
||||
value = '29991231';
|
||||
}
|
||||
|
||||
if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
|
||||
{
|
||||
value = (new Date()).getFullYear().toString() + value;
|
||||
}
|
||||
|
||||
if (value.length === 8 && $.isNumeric(value))
|
||||
{
|
||||
value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
|
||||
$('#best_before_date').val(value);
|
||||
$('#inventory-form').validator('validate');
|
||||
}
|
||||
});
|
||||
|
||||
$('#best_before_date').on('keypress', function(e)
|
||||
{
|
||||
var element = $(e.target);
|
||||
var value = element.val();
|
||||
var dateObj = moment(element.val(), 'YYYY-MM-DD', true);
|
||||
|
||||
$('.datepicker').datepicker('hide');
|
||||
|
||||
//If input is empty and any arrow key is pressed, set date to today
|
||||
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
|
||||
{
|
||||
dateObj = moment(new Date(), 'YYYY-MM-DD', true);
|
||||
}
|
||||
|
||||
if (dateObj.isValid())
|
||||
{
|
||||
if (e.keyCode === 38) //Up
|
||||
{
|
||||
element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 40) //Down
|
||||
{
|
||||
element.val(dateObj.add(1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 37) //Left
|
||||
{
|
||||
element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 39) //Right
|
||||
{
|
||||
element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
}
|
||||
|
||||
$('#inventory-form').validator('validate');
|
||||
});
|
||||
|
||||
$('#best_before_date').on('keydown', function(e)
|
||||
{
|
||||
if (e.keyCode === 13) //Enter
|
||||
{
|
||||
$('#best_before_date').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
$('#new_amount').on('change', function(e)
|
||||
{
|
||||
if ($('#product_id').parent().hasClass('has-error'))
|
||||
{
|
||||
$('#inventory-change-info').hide();
|
||||
return;
|
||||
}
|
||||
|
||||
var productId = $('#product_id').val();
|
||||
var newAmount = $('#new_amount').val();
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
var productStockAmount = productDetails.stock_amount || '0';
|
||||
|
||||
if (newAmount > productStockAmount)
|
||||
{
|
||||
var amountToAdd = newAmount - productDetails.stock_amount;
|
||||
$('#inventory-change-info').text('This means ' + amountToAdd.toString() + ' ' + productDetails.quantity_unit_stock.name + ' will be added to stock');
|
||||
$('#inventory-change-info').show();
|
||||
$('#best_before_date').attr('required', 'required');
|
||||
}
|
||||
else if (newAmount < productStockAmount)
|
||||
{
|
||||
var amountToRemove = productStockAmount - newAmount;
|
||||
$('#inventory-change-info').text('This means ' + amountToRemove.toString() + ' ' + productDetails.quantity_unit_stock.name + ' will be removed from stock');
|
||||
$('#inventory-change-info').show();
|
||||
$('#best_before_date').removeAttr('required');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#inventory-change-info').hide();
|
||||
}
|
||||
|
||||
$('#inventory-form').validator('update');
|
||||
$('#inventory-form').validator('validate');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
@@ -1,38 +0,0 @@
|
||||
$('#save-location-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.PostJson('/api/add-object/locations', $('#location-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/locations';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.PostJson('/api/edit-object/locations/' + Grocy.EditObjectId, $('#location-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/locations';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#name').focus();
|
||||
$('#location-form').validator();
|
||||
$('#location-form').validator('validate');
|
||||
});
|
@@ -1,43 +0,0 @@
|
||||
$(document).on('click', '.location-delete-button', function(e)
|
||||
{
|
||||
bootbox.confirm({
|
||||
message: 'Delete location <strong>' + $(e.target).attr('data-location-name') + '</strong>?',
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: 'Yes',
|
||||
className: 'btn-success'
|
||||
},
|
||||
cancel: {
|
||||
label: 'No',
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function(result)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.FetchJson('/api/delete-object/locations/' + $(e.target).attr('data-location-id'),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/locations';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#locations-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 }
|
||||
]
|
||||
});
|
||||
});
|
@@ -1,12 +0,0 @@
|
||||
$(function()
|
||||
{
|
||||
$('.logout-button').hide();
|
||||
|
||||
$('#username').focus();
|
||||
|
||||
if (Grocy.GetUriParam('invalid') === 'true')
|
||||
{
|
||||
$('#login-error').text('Invalid credentials, please try again.');
|
||||
$('#login-error').show();
|
||||
}
|
||||
});
|
@@ -1,99 +0,0 @@
|
||||
$('#save-product-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var redirectDestination = '/products';
|
||||
var returnTo = Grocy.GetUriParam('returnto');
|
||||
if (returnTo !== undefined)
|
||||
{
|
||||
redirectDestination = returnTo + '?createdproduct=' + encodeURIComponent($('#name').val());
|
||||
}
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.PostJson('/api/add-object/products', $('#product-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.PostJson('/api/edit-object/products/' + Grocy.EditObjectId, $('#product-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#barcode-taginput').tagsManager({
|
||||
'hiddenTagListName': 'barcode',
|
||||
'tagsContainer': '#barcode-taginput-container'
|
||||
});
|
||||
|
||||
if (Grocy.EditMode === 'edit')
|
||||
{
|
||||
Grocy.FetchJson('/api/get-object/products/' + Grocy.EditObjectId,
|
||||
function (product)
|
||||
{
|
||||
if (product.barcode !== null && product.barcode.length > 0)
|
||||
{
|
||||
product.barcode.split(',').forEach(function(item)
|
||||
{
|
||||
$('#barcode-taginput').tagsManager('pushTag', item);
|
||||
});
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$('#qu_factor_purchase_to_stock').trigger('change');
|
||||
$('#name').focus();
|
||||
$('#product-form').validator();
|
||||
$('#product-form').validator('validate');
|
||||
|
||||
var prefillName = Grocy.GetUriParam('prefillname');
|
||||
if (prefillName !== undefined)
|
||||
{
|
||||
$('#name').val(prefillName);
|
||||
$('#name').focus();
|
||||
}
|
||||
|
||||
var prefillBarcode = Grocy.GetUriParam('prefillbarcode');
|
||||
if (prefillBarcode !== undefined)
|
||||
{
|
||||
$('#barcode-taginput').tagsManager('pushTag', prefillBarcode);
|
||||
$('#name').focus();
|
||||
}
|
||||
});
|
||||
|
||||
$('.input-group-qu').on('change', function(e)
|
||||
{
|
||||
var factor = $('#qu_factor_purchase_to_stock').val();
|
||||
if (factor > 1)
|
||||
{
|
||||
$('#qu-conversion-info').text('This means 1 ' + $("#qu_id_purchase option:selected").text() + ' purchased will be converted into ' + (1 * factor).toString() + ' ' + $("#qu_id_stock option:selected").text() + ' in stock.');
|
||||
$('#qu-conversion-info').show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#qu-conversion-info').hide();
|
||||
}
|
||||
});
|
@@ -1,43 +0,0 @@
|
||||
$(document).on('click', '.product-delete-button', function(e)
|
||||
{
|
||||
bootbox.confirm({
|
||||
message: 'Delete product <strong>' + $(e.target).attr('data-product-name') + '</strong>?',
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: 'Yes',
|
||||
className: 'btn-success'
|
||||
},
|
||||
cancel: {
|
||||
label: 'No',
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function(result)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.FetchJson('/api/delete-object/products/' + $(e.target).attr('data-product-id'),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/products';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#products-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 }
|
||||
]
|
||||
});
|
||||
});
|
@@ -1,363 +0,0 @@
|
||||
$('#save-purchase-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonForm = $('#purchase-form').serializeJSON();
|
||||
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + jsonForm.product_id,
|
||||
function (productDetails)
|
||||
{
|
||||
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||
function(result)
|
||||
{
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
if (existingBarcodes.length === 0)
|
||||
{
|
||||
productDetails.product.barcode = addBarcode;
|
||||
}
|
||||
else
|
||||
{
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
|
||||
Grocy.PostJson('/api/edit-object/products/' + productDetails.product.id, productDetails.product,
|
||||
function (result) { },
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
toastr.success('Added ' + amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock');
|
||||
Grocy.Wait(1000);
|
||||
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
window.location.href = '/purchase';
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#amount').val(0);
|
||||
$('#best_before_date').val('');
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').focus();
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').trigger('change');
|
||||
$('#purchase-form').validator('validate');
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#product_id').on('change', function(e)
|
||||
{
|
||||
var productId = $(e.target).val();
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#selected-product-name').text(productDetails.product.name);
|
||||
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name);
|
||||
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
|
||||
if (productDetails.product.default_best_before_days.toString() !== '0')
|
||||
{
|
||||
$('#best_before_date').val(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD'));
|
||||
$('#best_before_date').trigger('change');
|
||||
$('#amount').focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#best_before_date').focus();
|
||||
}
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('.datepicker').datepicker(
|
||||
{
|
||||
format: 'yyyy-mm-dd',
|
||||
startDate: '+0d',
|
||||
todayHighlight: true,
|
||||
autoclose: true,
|
||||
calendarWeeks: true,
|
||||
orientation: 'bottom auto',
|
||||
weekStart: 1,
|
||||
showOnFocus: false
|
||||
});
|
||||
$('.datepicker').trigger('change');
|
||||
|
||||
$('.combobox').combobox({
|
||||
appendId: '_text_input'
|
||||
});
|
||||
|
||||
$('#product_id_text_input').on('change', function(e)
|
||||
{
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||
|
||||
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
}
|
||||
else
|
||||
{
|
||||
var optionElement = $("#product_id option:contains('" + input + "')").first();
|
||||
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
|
||||
{
|
||||
bootbox.dialog({
|
||||
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
|
||||
title: 'Create or assign product',
|
||||
onEscape: function() { },
|
||||
size: 'large',
|
||||
backdrop: true,
|
||||
buttons: {
|
||||
cancel: {
|
||||
label: 'Cancel',
|
||||
className: 'btn-default',
|
||||
callback: function() { }
|
||||
},
|
||||
addnewproduct: {
|
||||
label: 'Add as new <u><strong>p</strong></u>roduct',
|
||||
className: 'btn-success add-new-product-dialog-button',
|
||||
callback: function()
|
||||
{
|
||||
window.location.href = '/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname);
|
||||
}
|
||||
},
|
||||
addbarcode: {
|
||||
label: 'Add as <u><strong>b</strong></u>arcode to existing product',
|
||||
className: 'btn-info add-new-barcode-dialog-button',
|
||||
callback: function()
|
||||
{
|
||||
window.location.href = '/purchase?addbarcodetoselection=' + encodeURIComponent(input);
|
||||
}
|
||||
},
|
||||
addnewproductwithbarcode: {
|
||||
label: '<u><strong>A</strong></u>dd as new product + prefill barcode',
|
||||
className: 'btn-warning add-new-product-with-barcode-dialog-button',
|
||||
callback: function()
|
||||
{
|
||||
window.location.href = '/product/new?prefillbarcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).on('keypress', function(e)
|
||||
{
|
||||
if (e.key === 'B' || e.key === 'b')
|
||||
{
|
||||
$('.add-new-barcode-dialog-button').click();
|
||||
}
|
||||
if (e.key === 'p' || e.key === 'P')
|
||||
{
|
||||
$('.add-new-product-dialog-button').click();
|
||||
}
|
||||
if (e.key === 'a' || e.key === 'A')
|
||||
{
|
||||
$('.add-new-product-with-barcode-dialog-button').click();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#amount').val(0);
|
||||
$('#best_before_date').val('');
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').focus();
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').trigger('change');
|
||||
|
||||
$('#purchase-form').validator({
|
||||
custom: {
|
||||
'isodate': function($el)
|
||||
{
|
||||
if ($el.val().length !== 0 && !moment($el.val(), 'YYYY-MM-DD', true).isValid())
|
||||
{
|
||||
return 'Wrong date format, needs to be YYYY-MM-DD';
|
||||
}
|
||||
else if (moment($el.val()).isValid())
|
||||
{
|
||||
if (moment($el.val()).isBefore(moment(), 'day'))
|
||||
{
|
||||
return 'This value cannot be before today.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$('#purchase-form').validator('validate');
|
||||
|
||||
$('#best_before_date').on('focus', function(e)
|
||||
{
|
||||
if ($('#product_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
});
|
||||
|
||||
$('#amount').on('focus', function(e)
|
||||
{
|
||||
if ($('#product_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
$(this).select();
|
||||
}
|
||||
});
|
||||
|
||||
$('#purchase-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
if ($('#purchase-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
|
||||
{
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var prefillProduct = Grocy.GetUriParam('createdproduct');
|
||||
if (prefillProduct !== undefined)
|
||||
{
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
|
||||
if (possibleOptionElement.length === 0)
|
||||
{
|
||||
possibleOptionElement = $("#product_id option:contains('" + prefillProduct + "')").first();
|
||||
}
|
||||
|
||||
if (possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
$('#best_before_date').focus();
|
||||
}
|
||||
}
|
||||
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
$('#addbarcodetoselection').text(addBarcode);
|
||||
$('#flow-info-addbarcodetoselection').removeClass('hide');
|
||||
$('#barcode-lookup-disabled-hint').removeClass('hide');
|
||||
}
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
|
||||
});
|
||||
|
||||
$('#best_before_date-datepicker-button').on('click', function(e)
|
||||
{
|
||||
$('.datepicker').datepicker('show');
|
||||
});
|
||||
|
||||
$('#best_before_date').on('change', function(e)
|
||||
{
|
||||
var value = $('#best_before_date').val();
|
||||
var now = new Date();
|
||||
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
|
||||
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
|
||||
|
||||
if (value === 'x' || value === 'X') {
|
||||
value = '29991231';
|
||||
}
|
||||
|
||||
if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
|
||||
{
|
||||
value = (new Date()).getFullYear().toString() + value;
|
||||
}
|
||||
|
||||
if (value.length === 8 && $.isNumeric(value))
|
||||
{
|
||||
value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
|
||||
$('#best_before_date').val(value);
|
||||
$('#purchase-form').validator('validate');
|
||||
}
|
||||
|
||||
$('#best-before-timeago').text($.timeago($('#best_before_date').val()));
|
||||
Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
|
||||
});
|
||||
|
||||
$('#best_before_date').on('keydown', function(e)
|
||||
{
|
||||
if (e.keyCode === 13) //Enter
|
||||
{
|
||||
$('#best_before_date').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
$('#best_before_date').on('keypress', function(e)
|
||||
{
|
||||
var element = $(e.target);
|
||||
var value = element.val();
|
||||
var dateObj = moment(element.val(), 'YYYY-MM-DD', true);
|
||||
|
||||
$('.datepicker').datepicker('hide');
|
||||
|
||||
//If input is empty and any arrow key is pressed, set date to today
|
||||
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
|
||||
{
|
||||
dateObj = moment(new Date(), 'YYYY-MM-DD', true);
|
||||
}
|
||||
|
||||
if (dateObj.isValid())
|
||||
{
|
||||
if (e.keyCode === 38) //Up
|
||||
{
|
||||
element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 40) //Down
|
||||
{
|
||||
element.val(dateObj.add(1, 'days').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 37) //Left
|
||||
{
|
||||
element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
else if (e.keyCode === 39) //Right
|
||||
{
|
||||
element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD'));
|
||||
}
|
||||
}
|
||||
|
||||
$('#purchase-form').validator('validate');
|
||||
});
|
@@ -1,38 +0,0 @@
|
||||
$('#save-quantityunit-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.PostJson('/api/add-object/quantity_units', $('#quantityunit-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/quantityunits';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.PostJson('/api/edit-object/quantity_units/' + Grocy.EditObjectId, $('#quantityunit-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/quantityunits';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#name').focus();
|
||||
$('#quantityunit-form').validator();
|
||||
$('#quantityunit-form').validator('validate');
|
||||
});
|
@@ -1,43 +0,0 @@
|
||||
$(document).on('click', '.quantityunit-delete-button', function(e)
|
||||
{
|
||||
bootbox.confirm({
|
||||
message: 'Delete quantity unit <strong>' + $(e.target).attr('data-quantityunit-name') + '</strong>?',
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: 'Yes',
|
||||
className: 'btn-success'
|
||||
},
|
||||
cancel: {
|
||||
label: 'No',
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function(result)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.FetchJson('/api/delete-object/quantity_units/' + $(e.target).attr('data-quantityunit-id'),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/quantityunits';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#quantityunits-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 }
|
||||
]
|
||||
});
|
||||
});
|
@@ -1,38 +0,0 @@
|
||||
$(document).on('click', '.shoppinglist-delete-button', function(e)
|
||||
{
|
||||
Grocy.FetchJson('/api/delete-object/shopping_list/' + $(e.target).attr('data-shoppinglist-id'),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/shoppinglist';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on('click', '#add-products-below-min-stock-amount', function(e)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/add-missing-products-to-shoppinglist',
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/shoppinglist';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('#shoppinglist-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 }
|
||||
]
|
||||
});
|
||||
});
|
@@ -1,149 +0,0 @@
|
||||
$('#save-shoppinglist-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.PostJson('/api/add-object/shopping_list', $('#shoppinglist-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/shoppinglist';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.PostJson('/api/edit-object/shopping_list/' + Grocy.EditObjectId, $('#shoppinglist-form').serializeJSON(),
|
||||
function(result)
|
||||
{
|
||||
window.location.href = '/shoppinglist';
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$('#product_id').on('change', function(e)
|
||||
{
|
||||
var productId = $(e.target).val();
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function (productDetails)
|
||||
{
|
||||
$('#selected-product-name').text(productDetails.product.name);
|
||||
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
|
||||
if ($('#product_id').hasClass('suppress-next-custom-validate-event'))
|
||||
{
|
||||
$('#product_id').removeClass('suppress-next-custom-validate-event');
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.FetchJson('/api/get-objects/shopping_list',
|
||||
function (currentShoppingListItems)
|
||||
{
|
||||
if (currentShoppingListItems.filter(function (e) { return e.product_id === productId; }).length > 0)
|
||||
{
|
||||
$('#product_id').val('');
|
||||
$('#product_id_text_input').val('');
|
||||
$('#product_id_text_input').addClass('has-error');
|
||||
$('#product_id_text_input').parent('.input-group').addClass('has-error');
|
||||
$('#product_id_text_input').closest('.form-group').addClass('has-error');
|
||||
$('#product-error').text('This product is already on the shopping list.');
|
||||
$('#product-error').show();
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#product_id_text_input').removeClass('has-error');
|
||||
$('#product_id_text_input').parent('.input-group').removeClass('has-error');
|
||||
$('#product_id_text_input').closest('.form-group').removeClass('has-error');
|
||||
$('#product-error').hide();
|
||||
|
||||
$('#amount').focus();
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$(function()
|
||||
{
|
||||
$('.combobox').combobox({
|
||||
appendId: '_text_input'
|
||||
});
|
||||
|
||||
$('#product_id_text_input').on('change', function(e)
|
||||
{
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||
|
||||
if (possibleOptionElement.length > 0 && possibleOptionElement.text().length > 0) {
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
$('#product_id_text_input').focus();
|
||||
$('#product_id_text_input').trigger('change');
|
||||
|
||||
if (Grocy.EditMode === 'edit')
|
||||
{
|
||||
$('#product_id').addClass('suppress-next-custom-validate-event');
|
||||
$('#product_id').trigger('change');
|
||||
}
|
||||
|
||||
$('#shoppinglist-form').validator();
|
||||
$('#shoppinglist-form').validator('validate');
|
||||
|
||||
$('#amount').on('focus', function(e)
|
||||
{
|
||||
if ($('#product_id_text_input').val().length === 0)
|
||||
{
|
||||
$('#product_id_text_input').focus();
|
||||
}
|
||||
});
|
||||
|
||||
$('#shoppinglist-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
if ($('#shoppinglist-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
|
||||
{
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
@@ -1,7 +0,0 @@
|
||||
$(function()
|
||||
{
|
||||
$('#stock-overview-table').DataTable({
|
||||
'pageLength': 50,
|
||||
'order': [[2, 'asc']]
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user