mirror of
https://github.com/grocy/grocy.git
synced 2025-08-16 02:34:44 +00:00
Started working on user-defined-fields for all entities (references #176)
This commit is contained in:
86
public/viewjs/userfields.js
Normal file
86
public/viewjs/userfields.js
Normal file
@@ -0,0 +1,86 @@
|
||||
var userfieldsTable = $('#userfields-table').DataTable({
|
||||
'paginate': false,
|
||||
'order': [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 }
|
||||
],
|
||||
'language': JSON.parse(L('datatables_localization')),
|
||||
'scrollY': false,
|
||||
'colReorder': true,
|
||||
'stateSave': true,
|
||||
'stateSaveParams': function(settings, data)
|
||||
{
|
||||
data.search.search = "";
|
||||
|
||||
data.columns.forEach(column =>
|
||||
{
|
||||
column.search.search = "";
|
||||
});
|
||||
}
|
||||
});
|
||||
$('#userfields-table tbody').removeClass("d-none");
|
||||
userfieldsTable.columns.adjust().draw();
|
||||
|
||||
$("#search").on("keyup", function()
|
||||
{
|
||||
var value = $(this).val();
|
||||
if (value === "all")
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
|
||||
userfieldsTable.search(value).draw();
|
||||
});
|
||||
|
||||
$("#entity-filter").on("change", function()
|
||||
{
|
||||
var value = $("#entity-filter option:selected").text();
|
||||
if (value === L("All"))
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
|
||||
userfieldsTable.column(1).search(value).draw();
|
||||
});
|
||||
|
||||
$(document).on('click', '.userfield-delete-button', function (e)
|
||||
{
|
||||
var objectName = $(e.currentTarget).attr('data-userfield-name');
|
||||
var objectId = $(e.currentTarget).attr('data-userfield-id');
|
||||
|
||||
bootbox.confirm({
|
||||
message: L('Are you sure to delete user field "#1"?', objectName),
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: L('Yes'),
|
||||
className: 'btn-success'
|
||||
},
|
||||
cancel: {
|
||||
label: L('No'),
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function(result)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('objects/userfields/' + objectId, {},
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/userfields');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (typeof GetUriParam("entity") !== "undefined")
|
||||
{
|
||||
$("#entity-filter").val(GetUriParam("entity"));
|
||||
$("#entity-filter").trigger("change");
|
||||
}
|
Reference in New Issue
Block a user