mirror of
https://github.com/grocy/grocy.git
synced 2025-08-28 09:01:14 +00:00
Optimize user settings
This commit is contained in:
@@ -41,3 +41,16 @@ IsTouchInputDevice = function()
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
BoolVal = function(test)
|
||||
{
|
||||
var anything = test.toString().toLowerCase();
|
||||
if (anything === true || anything === "true" || anything === "1" || anything === "on")
|
||||
{
|
||||
return true
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.log(xhr)
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -216,3 +216,35 @@ $("form").on("click", "select", function()
|
||||
{
|
||||
$(this).closest("form").addClass("is-dirty");
|
||||
});
|
||||
|
||||
// Auto saving user setting controls
|
||||
$(".user-setting-control").on("change", function()
|
||||
{
|
||||
var element = $(this);
|
||||
var inputType = element.attr("type").toLowerCase();
|
||||
var settingKey = element.attr("data-setting-key");
|
||||
|
||||
if (inputType === "checkbox")
|
||||
{
|
||||
value = element.is(":checked");
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = element.val();
|
||||
}
|
||||
|
||||
Grocy.UserSettings[settingKey] = value;
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/' + settingKey, jsonData,
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do...
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@@ -22,7 +22,7 @@ setInterval(function()
|
||||
{
|
||||
if (Grocy.IdleTime >= 50)
|
||||
{
|
||||
if (Grocy.AutoReloadOnDatabaseChangeEnabled && $("form.is-dirty").length === 0)
|
||||
if (BoolVal(Grocy.UserSettings.auto_reload_on_db_change) && $("form.is-dirty").length === 0)
|
||||
{
|
||||
window.location.reload();
|
||||
}
|
||||
@@ -56,27 +56,7 @@ setInterval(function()
|
||||
Grocy.IdleTime += 1;
|
||||
}, 1000);
|
||||
|
||||
$("#auto-reload-enabled").on("change", function()
|
||||
{
|
||||
var value = $(this).is(":checked");
|
||||
|
||||
Grocy.AutoReloadOnDatabaseChangeEnabled = value;
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/auto_reload_on_db_change', jsonData,
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do...
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (Grocy.AutoReloadOnDatabaseChangeEnabled)
|
||||
if (BoolVal(Grocy.UserSettings.auto_reload_on_db_change))
|
||||
{
|
||||
$("#auto-reload-enabled").prop("checked", true);
|
||||
}
|
||||
|
@@ -1,20 +1,6 @@
|
||||
$("#night-mode-enabled").on("change", function()
|
||||
{
|
||||
var value = $(this).is(":checked");
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/night_mode_enabled', jsonData,
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do...
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
|
||||
if (value)
|
||||
{
|
||||
$("body").addClass("night-mode");
|
||||
@@ -28,67 +14,9 @@
|
||||
$("#auto-night-mode-enabled").on("change", function()
|
||||
{
|
||||
var value = $(this).is(":checked");
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/auto_night_mode_enabled', jsonData,
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do...
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
|
||||
if (value)
|
||||
{
|
||||
$("#auto-night-mode-time-range-from").prop("readonly", false);
|
||||
$("#auto-night-mode-time-range-to").prop("readonly", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#auto-night-mode-time-range-from").prop("readonly", true);
|
||||
$("#auto-night-mode-time-range-to").prop("readonly", true);
|
||||
}
|
||||
});
|
||||
|
||||
$("#auto-night-mode-time-range-from").on("blur", function()
|
||||
{
|
||||
var value = $(this).val();
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/auto_night_mode_time_range_from', jsonData,
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do...
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("#auto-night-mode-time-range-to").on("blur", function()
|
||||
{
|
||||
var value = $(this).val();
|
||||
|
||||
jsonData = { };
|
||||
jsonData.value = value;
|
||||
Grocy.Api.Post('user/settings/auto_night_mode_time_range_to', jsonData,
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do...
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
$("#auto-night-mode-time-range-from").prop("readonly", !value);
|
||||
$("#auto-night-mode-time-range-to").prop("readonly", !value);
|
||||
});
|
||||
|
||||
$("#night-mode-enabled").prop("checked", Grocy.NightModeEnabled);
|
||||
$("#auto-night-mode-enabled").prop("checked", Grocy.AutoNightModeEnabled);
|
||||
$("#auto-night-mode-enabled").prop("checked", Grocy.UserSettings.auto_night_mode_enabled);
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
var jsonData = $('#recipe-pos-form').serializeJSON({ checkboxUncheckedValue: "0" });
|
||||
jsonData.recipe_id = Grocy.EditObjectParentId;
|
||||
console.log(jsonData);
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('add-object/recipes_pos', jsonData,
|
||||
|
Reference in New Issue
Block a user