A free open source IT asset/license management system
Moved btn methods closer to the BS table
snipe3f69b70367aa
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.phpindex 2120a6529d..ab789d6c1a 100644--- a/resources/views/partials/bootstrap-table.blade.php+++ b/resources/views/partials/bootstrap-table.blade.php@@ -196,493 +196,1022 @@});+ // User table buttons+ window.userButtons = () => ({+ @can('create', \App\Models\User::class)+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('users.create') }}';+ },+ attributes: {+ title: '{{ trans('general.create') }}',+ class: 'btn btn-primary',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ @endcan+ btnExport: {+ text: '{{ trans('general.export_all_to_csv') }}',+ icon: 'fa-solid fa-file-csv',+ event () {+ window.location.href = '{{ route('users.export') }}';+ },+ attributes: {+ title: '{{ trans('general.export_all_to_csv') }}',+ }+ },+ btnShowAdmins: {+ text: '{{ trans('general.show_admins') }}',+ icon: 'fa-solid fa-crown{{ (request()->input('admins') == "true") ? ' text-danger' : '' }}',+ event () {+ window.location.href = '{{ (request()->input('admins') == "true") ? route('users.index') : route('users.index', ['admins' => 'true']) }}';+ },+ attributes: {+ title: '{{ trans('general.show_admins') }}',+ }+ },- function dateRowCheckStyle(value) {- if ((value.days_to_next_audit) && (value.days_to_next_audit < {{ $snipeSettings->audit_warning_days ?: 0 }})) {- return { classes : "danger" }- }- return {};- }+ btnShowDeleted: {+ text: '{{ (request()->input('status') == "deleted") ?trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',+ icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : ' fa-user-trash' }}',+ event () {+ window.location.href = '{{ (request()->input('status') == "deleted") ? route('users.index') : route('users.index', ['status' => 'deleted']) }}';+ },+ attributes: {+ title: '{{ (request()->input('status') == "deleted") ? trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',+ }+ },- // These methods dynamically add/remove hidden input values in the bulk actions form- $('.snipe-table').on('check.bs.table .btSelectItem', function (row, $element) {- var buttonName = $(this).data('bulk-button-id');- var tableId = $(this).data('id-table');+ }); // end user table buttons- $(buttonName).removeAttr('disabled');- $(buttonName).after('<input id="' + tableId + '_checkbox_' + $element.id + '" type="hidden" name="ids[]" value="' + $element.id + '">');- });- $('.snipe-table').on('check-all.bs.table', function (event, rowsAfter) {+ @can('create', \App\Models\Company::class)+ // Company table buttons+ window.companyButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('companies.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },- var buttonName = $(this).data('bulk-button-id');- $(buttonName).removeAttr('disabled');- var tableId = $(this).data('id-table');+ }); // End company table buttons+ @endcan- for (var i in rowsAfter) {- // Do not select things that were already selected- if($('#'+ tableId + '_checkbox_' + rowsAfter[i].id).length == 0) {- $(buttonName).after('<input id="' + tableId + '_checkbox_' + rowsAfter[i].id + '" type="hidden" name="ids[]" value="' + rowsAfter[i].id + '">');- }- }- });+ // Asset table buttons+ window.assetButtons = () => ({+ @can('create', \App\Models\Asset::class)+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('hardware.create') }}';+ },+ attributes: {+ title: '{{ trans('general.create') }}',+ class: 'btn btn-primary',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ @endcan- $('.snipe-table').on('uncheck.bs.table .btSelectItem', function (row, $element) {- var tableId = $(this).data('id-table');- $( "#" + tableId + "_checkbox_" + $element.id).remove();- });+ @can('update', \App\Models\Asset::class)+ btnAddMaintenance: {+ text: '{{ trans('button.add_maintenance') }}',+ icon: 'fa-solid fa-screwdriver-wrench',+ event () {+ window.location.href = '{{ route('maintenances.create', ['asset_id' => (isset($asset)) ? $asset->id :'' ]) }}';+ },+ attributes: {+ title: '{{ trans('button.add_maintenance') }}',+ }+ },+ @endcan- // Handle whether the edit button should be disabled- $('.snipe-table').on('uncheck.bs.table', function () {- var buttonName = $(this).data('bulk-button-id');+ btnExport: {+ text: '{{ trans('admin/hardware/general.custom_export') }}',+ icon: 'fa-solid fa-file-csv',+ event () {+ window.location.href = '{{ route('reports/custom') }}';+ },+ attributes: {+ title: '{{ trans('admin/hardware/general.custom_export') }}',+ }+ },- if ($(this).bootstrapTable('getSelections').length == 0) {+ btnShowDeleted: {+ text: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',+ icon: 'fa-solid fa-trash {{ (request()->input('status') == "Deleted") ? ' text-danger' : '' }}',+ event () {+ window.location.href = '{{ (request()->input('status') == "Deleted") ? route('hardware.index') : route('hardware.index', ['status' => 'Deleted']) }}';+ },+ attributes: {+ title: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',- $(buttonName).attr('disabled', 'disabled');- }+ }+ },});- $('.snipe-table').on('uncheck-all.bs.table', function (event, rowsAfter, rowsBefore) {-- var buttonName = $(this).data('bulk-button-id');- $(buttonName).attr('disabled', 'disabled');- var tableId = $(this).data('id-table');+ @can('create', \App\Models\Location::class)+ // Location table buttons+ window.locationButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('locations.create') }}';+ },+ attributes: {+ class: 'btn btn-default',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },- for (var i in rowsBefore) {- $('#' + tableId + "_checkbox_" + rowsBefore[i].id).remove();- }+ btnShowDeleted: {+ text: '{{ (request()->input('status') == "deleted") ? trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',+ icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : ' fa-user-trash' }}',+ event () {+ window.location.href = '{{ (request()->input('status') == "deleted") ? route('locations.index') : route('locations.index', ['status' => 'deleted']) }}';+ },+ attributes: {+ title: '{{ (request()->input('status') == "deleted") ? trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',+ }+ },});+ @endcan- // Initialize sort-order for bulk actions (label-generation) for snipe-tables- $('.snipe-table').each(function (i, table) {- table_cookie_segment = $(table).data('cookie-id-table');- sort = '';- order = '';- cookies = document.cookie.split(";");- for(i in cookies) {- cookiedef = cookies[i].split("=", 2);- cookiedef[0] = cookiedef[0].trim();- if (cookiedef[0] == table_cookie_segment + ".bs.table.sortOrder") {- order = cookiedef[1];- }- if (cookiedef[0] == table_cookie_segment + ".bs.table.sortName") {- sort = cookiedef[1];- }- }- if (sort && order) {- domnode = $($(this).data('bulk-form-id')).get(0);- if ( domnode && domnode.elements && domnode.elements.sort ) {- domnode.elements.sort.value = sort;- domnode.elements.order.value = order;+ @can('create', \App\Models\Accessory::class)+ // Accessory table buttons+ window.accessoryButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('accessories.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif}- }+ },});+ @endcan- // If sort order changes, update the sort-order for bulk-actions (for label-generation)- $('.snipe-table').on('sort.bs.table', function (event, name, order) {- domnode = $($(this).data('bulk-form-id')).get(0);- // make safe in case there isn't a bulk-form-id, or it's not found, or has no 'sort' element- if ( domnode && domnode.elements && domnode.elements.sort ) {- domnode.elements.sort.value = name;- domnode.elements.order.value = order;- }+ @can('create', \App\Models\Depreciation::class)+ // Accessory table buttons+ window.depreciationButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('depreciations.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },});+ @endcan--- // This specifies the footer columns that should have special styles associated- // (usually numbers)- window.footerStyle = column => ({- remaining: {- classes: 'text-padding-number-footer-cell'- },- qty: {- classes: 'text-padding-number-footer-cell',- },- purchase_cost: {- classes: 'text-padding-number-footer-cell'- },- checkouts_count: {- classes: 'text-padding-number-footer-cell'- },- assets_count: {- classes: 'text-padding-number-footer-cell'- },- seats: {- classes: 'text-padding-number-footer-cell'- },- free_seats_count: {- classes: 'text-padding-number-footer-cell'+ @can('create', \App\Models\CustomField::class)+ // Accessory table buttons+ window.customFieldButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('fields.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }},- }[column.field]);--+ });+ @endcan- // This only works for model index pages because it uses the row's model ID- function genericRowLinkFormatter(destination) {- return function (value,row) {- if (value) {- return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '">' + value + '</a>';+ @can('create', \App\Models\CustomFieldset::class)+ // Accessory table buttons+ window.customFieldsetButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('fieldsets.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif}- };- }---- // This is a special formatter that will indicate whether a user is an admin or superadmin- function usernameRoleLinkFormatter(value, row) {-- if ((value) && (row)) {-- if (row.role === 'superadmin') {- return '<span style="white-space: nowrap" data-tooltip="true" title="{{ trans('general.superuser_tooltip') }}"><x-icon type="superadmin" title="{{ trans('general.superuser') }}" class="text-danger" /> <a href="{{ config('app.url') }}/users/' + row.id + '">' + value + '</a></span>';- } else if (row.role === 'admin') {- return '<span style="white-space: nowrap" data-tooltip="true" title="{{ trans('general.admin_tooltip') }}"><x-icon type="superadmin" title="{{ trans('general.admin_user') }}" class="text-warning" /> <a href="{{ config('app.url') }}/users/' + row.id + '">' + value + '</a></span>';- }+ },+ });+ @endcan- // Regular user- return '<a href="{{ config('app.url') }}/users/' + row.id + '">' + value + '</a>';+ @can('create', \App\Models\Component::class)+ // Compoment table buttons+ window.componentButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('components.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif}+ },+ });+ @endcan- }+ @can('create', \App\Models\Consumable::class)+ // Consumable table buttons+ window.consumableButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('consumables.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ });+ @endcan- // Use this when we're introspecting into a column object and need to link- function genericColumnObjLinkFormatter(destination) {- return function (value,row) {- if ((value) && (value.status_meta)) {+ @can('create', \App\Models\Manufacturer::class)+ // Consumable table buttons+ window.manufacturerButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('manufacturers.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ },- var text_color;- var icon_style;- var text_help;- var status_meta = {- 'deployed': '{{ strtolower(trans('general.deployed')) }}',- 'deployable': '{{ strtolower(trans('admin/hardware/general.deployable')) }}',- 'archived': '{{ strtolower(trans('general.archived')) }}',- 'undeployable': '{{ strtolower(trans('general.undeployable')) }}',- 'pending': '{{ strtolower(trans('general.pending')) }}'- }+ btnShowDeleted: {+ text: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',+ icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : '' }}',+ event () {+ window.location.href = '{{ (request()->input('status') == "deleted") ? route('manufacturers.index') : route('manufacturers.index', ['status' => 'deleted']) }}';+ },+ attributes: {+ title: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',- switch (value.status_meta) {- case 'deployed':- text_color = 'blue';- icon_style = 'fa-circle';- text_help = '<label class="label label-default">{{ trans('general.deployed') }}</label>';- break;- case 'deployable':- text_color = 'green';- icon_style = 'fa-circle';- text_help = '';- break;- case 'pending':- text_color = 'orange';- icon_style = 'fa-circle';- text_help = '';- break;- default:- text_color = 'red';- icon_style = 'fa-times';- text_help = '';}+ },+ },+ });+ @endcan- return '<nobr><a href="{{ config('app.url') }}/' + destination + '/' + value.id + '" data-tooltip="true" title="'+ status_meta[value.status_meta] + '"> <i class="fa ' + icon_style + ' text-' + text_color + '"></i> ' + value.name + ' ' + text_help + ' </a> </nobr>';- } else if ((value) && (value.name)) {-- // Add some overrides for any funny urls we have- var dest = destination;- var polymorphicItemFormatterDest = '';- if (destination == 'fieldsets') {- var polymorphicItemFormatterDest = 'fields/';- }-- return '<nobr><a href="{{ config('app.url') }}/' + polymorphicItemFormatterDest + dest + '/' + value.id + '">' + value.name + '</a></span>';+ @can('create', \App\Models\Supplier::class)+ // Consumable table buttons+ window.supplierButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('suppliers.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif}- };- }-+ },+ });+ @endcan- function licenseKeyFormatter(value, row) {- if (value) {- return '<code class="single-line"><span class="js-copy-link" data-clipboard-target=".js-copy-key-' + row.id + '" aria-hidden="true" data-tooltip="true" data-placement="top" title="{{ trans('general.copy_to_clipboard') }}"><span class="js-copy-key-' + row.id + '">' + value + '</span></span></code>';- }- }+ @can('create', \App\Models\Department::class)+ // Department table buttons+ window.departmentButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('departments.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ });+ @endcan+ @can('create', \App\Models\CustomField::class)+ // Custom Field table buttons+ window.departmentButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('departments.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ });+ @endcan+ @can('update', \App\Models\Asset::class)+ // Custom Field table buttons+ window.maintenanceButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('maintenances.create', ['asset_id' => (isset($asset)) ? $asset->id :'' ]) }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ });+ @endcan- function hardwareAuditFormatter(value, row) {- return '<a href="{{ config('app.url') }}/hardware/' + row.id + '/audit" class="actions btn btn-sm btn-primary" data-tooltip="true" title="{{ trans('general.audit') }}"><x-icon type="audit" /><span class="sr-only">{{ trans('general.audit') }}</span></a> ';- }+ @can('create', \App\Models\Category::class)+ // Custom Field table buttons+ window.categoryButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('categories.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ });+ @endcan+ @can('create', \App\Models\AssetModel::class)+ // Custom Field table buttons+ window.modelButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('models.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ btnShowDeleted: {+ text: '{{ (request()->input('status') == "deleted") ? trans('general.list_all') : trans('general.deleted') }}',+ icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : '' }}',+ event () {+ window.location.href = '{{ (request()->input('status') == "deleted") ? route('models.index') : route('models.index', ['status' => 'deleted']) }}';+ },+ attributes: {+ title: '{{ (request()->input('status') == "deleted") ? trans('general.list_all') : trans('general.deleted') }}',+ }+ },+ });+ @endcan+ @can('create', \App\Models\Statuslabel::class)+ // Status label table buttons+ window.statuslabelButtons = () => ({+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('statuslabels.create') }}';+ },+ attributes: {+ class: 'btn btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ }+ },+ });+ @endcan- // Make the edit/delete buttons- function genericActionsFormatter(owner_name, element_name) {- if (!element_name) {- element_name = '';- }+ // License table buttons+ window.licenseButtons = () => ({+ @can('create', \App\Models\License::class)+ btnAdd: {+ text: '{{ trans('general.create') }}',+ icon: 'fa fa-plus',+ event () {+ window.location.href = '{{ route('licenses.create') }}';+ },+ attributes: {+ class: 'btn-primary',+ title: '{{ trans('general.create') }}',+ @if ($snipeSettings->shortcuts_enabled == 1)+ accesskey: 'n'+ @endif+ },+ },+ @endcan- return function (value,row) {- var actions = '<nobr>';+ btnExport: {+ text: '{{ trans('general.export_all_to_csv') }}',+ icon: 'fa-solid fa-file-csv',+ event () {+ window.location.href = '{{ route('licenses.export', ['category_id' => (isset($category)) ? $category->id :'' ]) }}';+ },+ attributes: {+ class: 'btn-primary',+ title: '{{ trans('general.export_all_to_csv') }}',+ }+ },- // Add some overrides for any funny urls we have- var dest = owner_name;+ btnShowExpiring: {+ text: '{{ (request()->input('status') == "expiring") ? trans('general.list_all') : trans('general.show_expiring') }}',+ icon: 'fas fa-clock {{ (request()->input('status') == "expiring") ? ' text-danger' : '' }}',+ event () {+ window.location.href = '{{ (request()->input('status') == "expiring") ? route('licenses.index') : route('licenses.index', ['status' => 'expiring']) }}';+ },+ attributes: {+ title: '{{ (request()->input('status') == "expiring") ? trans('general.list_all') : trans('general.show_expiring') }}',- if (dest =='groups') {- var dest = 'admin/groups';}+ },+ btnShowInactive: {+ text: '{{ (request()->input('status') == "inactive") ? trans('general.list_all') : trans('general.show_inactive') }}',+ icon: 'fas fa-history {{ (request()->input('status') == "inactive") ? ' text-danger' : '' }}',+ event () {+ window.location.href = '{{ (request()->input('status') == "inactive") ? route('licenses.index') : route('licenses.index', ['status' => 'inactive']) }}';+ },+ attributes: {+ title: '{{ (request()->input('status') == "inactive") ? trans('general.list_all') : trans('general.show_inactive') }}',- if(element_name != '') {- dest = dest + '/' + row.owner_id + '/' + element_name;}+ },+ });- if ((row.available_actions) && (row.available_actions.clone === true)) {- actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '/clone" class="actions btn btn-sm btn-info" data-tooltip="true" title="{{ trans('general.clone_item') }}"><x-icon type="clone" /><span class="sr-only">{{ trans('general.clone_item') }}</span></a> ';- }- if ((row.available_actions) && (row.available_actions.audit === true)) {- actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '/audit" class="actions btn btn-sm btn-primary" data-tooltip="true" title="{{ trans('general.audit') }}"><x-icon type="audit" /><span class="sr-only">{{ trans('general.audit') }}</span></a> ';- }- if ((row.available_actions) && (row.available_actions.update === true)) {- actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '/edit" class="actions btn btn-sm btn-warning" data-tooltip="true" title="{{ trans('general.update') }}"><x-icon type="edit" /><span class="sr-only">{{ trans('general.update') }}</span></a> ';- } else {- if ((row.available_actions) && (row.available_actions.update != true)) {- actions += '<span data-tooltip="true" title="{{ trans('general.cannot_be_edited') }}"><a class="btn btn-warning btn-sm disabled" onClick="return false;"><x-icon type="edit" /></a></span> ';- }- }- if ((row.available_actions) && (row.available_actions.delete === true)) {- // use the asset tag if no name is provided+ function dateRowCheckStyle(value) {+ if ((value.days_to_next_audit) && (value.days_to_next_audit < {{ $snipeSettings->audit_warning_days ?: 0 }})) {+ return { classes : "danger" }+ }+ return {};+ }- if (row.name) {- var name_for_box = row.name- } else if (row.asset_tag) {- var name_for_box = row.asset_tag- }+ // These methods dynamically add/remove hidden input values in the bulk actions form+ $('.snipe-table').on('check.bs.table .btSelectItem', function (row, $element) {+ var buttonName = $(this).data('bulk-button-id');+ var tableId = $(this).data('id-table');-- actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '" '- + ' class="actions btn btn-danger btn-sm delete-asset" data-tooltip="true" '- + ' data-toggle="modal" data-icon="fa-trash"'- + ' data-content="{{ trans('general.sure_to_delete') }}: ' + name_for_box + '?" '- + ' data-title="{{ trans('general.delete') }}" onClick="return false;">'- + '<x-icon type="delete" /><span class="sr-only">{{ trans('general.delete') }}</span></a> ';- } else {- // Do not show the delete button on things that are already deleted- if ((row.available_actions) && (row.available_actions.restore != true)) {- actions += '<span data-tooltip="true" title="{{ trans('general.cannot_be_deleted') }}"><a class="btn btn-danger btn-sm delete-asset disabled" onClick="return false;"><x-icon type="delete" /><span class="sr-only">{{ trans('general.cannot_be_deleted') }}</span></a></span> ';- }+ $(buttonName).removeAttr('disabled');+ $(buttonName).after('<input id="' + tableId + '_checkbox_' + $element.id + '" type="hidden" name="ids[]" value="' + $element.id + '">');+ });- }+ $('.snipe-table').on('check-all.bs.table', function (event, rowsAfter) {+ var buttonName = $(this).data('bulk-button-id');+ $(buttonName).removeAttr('disabled');+ var tableId = $(this).data('id-table');- if ((row.available_actions) && (row.available_actions.restore === true)) {- actions += '<form style="display: inline;" method="POST" action="{{ config('app.url') }}/' + dest + '/' + row.id + '/restore"> ';- actions += '@csrf';- actions += '<button class="btn btn-sm btn-warning" data-tooltip="true" title="{{ trans('general.restore') }}"><x-icon type="restore" /><span class="sr-only">{{ trans('general.restore') }}</span></button> ';+ for (var i in rowsAfter) {+ // Do not select things that were already selected+ if($('#'+ tableId + '_checkbox_' + rowsAfter[i].id).length == 0) {+ $(buttonName).after('<input id="' + tableId + '_checkbox_' + rowsAfter[i].id + '" type="hidden" name="ids[]" value="' + rowsAfter[i].id + '">');}+ }+ });- actions +='</nobr>';- return actions;- };- }+ $('.snipe-table').on('uncheck.bs.table .btSelectItem', function (row, $element) {+ var tableId = $(this).data('id-table');+ $( "#" + tableId + "_checkbox_" + $element.id).remove();+ });- // This handles the icons and display of polymorphic entries- function polymorphicItemFormatter(value) {+ // Handle whether the edit button should be disabled+ $('.snipe-table').on('uncheck.bs.table', function () {+ var buttonName = $(this).data('bulk-button-id');- var item_destination = '';- var item_icon;+ if ($(this).bootstrapTable('getSelections').length == 0) {- if ((value) && (value.type)) {+ $(buttonName).attr('disabled', 'disabled');+ }+ });- if (value.type == 'asset') {- item_destination = 'hardware';- item_icon = 'fas fa-barcode';- } else if (value.type == 'accessory') {- item_destination = 'accessories';- item_icon = 'far fa-keyboard';- } else if (value.type == 'component') {- item_destination = 'components';- item_icon = 'far fa-hdd';- } else if (value.type == 'consumable') {- item_destination = 'consumables';- item_icon = 'fas fa-tint';- } else if (value.type == 'license') {- item_destination = 'licenses';- item_icon = 'far fa-save';- } else if (value.type == 'user') {- item_destination = 'users';- item_icon = 'fas fa-user';- } else if (value.type == 'location') {- item_destination = 'locations'- item_icon = 'fas fa-map-marker-alt';- } else if (value.type == 'maintenance') {- item_destination = 'maintenances'- item_icon = 'fa-solid fa-screwdriver-wrench';- } else if (value.type == 'model') {- item_destination = 'models'- item_icon = '';- }-- // display the username if it's checked out to a user, but don't do it if the username's there already- if (value.username && !value.name.match('\\(') && !value.name.match('\\)')) {- value.name = value.name + ' (' + value.username + ')';- }+ $('.snipe-table').on('uncheck-all.bs.table', function (event, rowsAfter, rowsBefore) {- return '<nobr><a href="{{ config('app.url') }}/' + item_destination +'/' + value.id + '" data-tooltip="true" title="' + value.type + '"><i class="' + item_icon + ' text-{{ $snipeSettings->skin!='' ? $snipeSettings->skin : 'blue' }} "></i> ' + value.name + '</a></nobr>';+ var buttonName = $(this).data('bulk-button-id');+ $(buttonName).attr('disabled', 'disabled');+ var tableId = $(this).data('id-table');- } else {- return '';+ for (var i in rowsBefore) {+ $('#' + tableId + "_checkbox_" + rowsBefore[i].id).remove();}+ });- }-- // This just prints out the item type in the activity report- function itemTypeFormatter(value, row) {-- if ((row) && (row.item) && (row.item.type)) {- return row.item.type;+ // Initialize sort-order for bulk actions (label-generation) for snipe-tables+ $('.snipe-table').each(function (i, table) {+ table_cookie_segment = $(table).data('cookie-id-table');+ sort = '';+ order = '';+ cookies = document.cookie.split(";");+ for(i in cookies) {+ cookiedef = cookies[i].split("=", 2);+ cookiedef[0] = cookiedef[0].trim();+ if (cookiedef[0] == table_cookie_segment + ".bs.table.sortOrder") {+ order = cookiedef[1];+ }+ if (cookiedef[0] == table_cookie_segment + ".bs.table.sortName") {+ sort = cookiedef[1];+ }}- }+ if (sort && order) {+ domnode = $($(this).data('bulk-form-id')).get(0);+ if ( domnode && domnode.elements && domnode.elements.sort ) {+ domnode.elements.sort.value = sort;+ domnode.elements.order.value = order;+ }+ }+ });+ // If sort order changes, update the sort-order for bulk-actions (for label-generation)+ $('.snipe-table').on('sort.bs.table', function (event, name, order) {+ domnode = $($(this).data('bulk-form-id')).get(0);+ // make safe in case there isn't a bulk-form-id, or it's not found, or has no 'sort' element+ if ( domnode && domnode.elements && domnode.elements.sort ) {+ domnode.elements.sort.value = name;+ domnode.elements.order.value = order;+ }+ });- // Convert line breaks to <br>- function notesFormatter(value) {- if (value) {- return value.replace(/(?:\r\n|\r|\n)/g, '<br />');- }- }- // Check if checkbox should be selectable- // Selectability is determined by the API field "selectable" which is set at the Presenter/API Transformer- // However since different bulk actions have different requirements, we have to walk through the available_actions object- // to determine whether to disable it- function checkboxEnabledFormatter (value, row) {- // add some stuff to get the value of the select2 option here?+ // This specifies the footer columns that should have special styles associated+ // (usually numbers)+ window.footerStyle = column => ({+ remaining: {+ classes: 'text-padding-number-footer-cell'+ },+ qty: {+ classes: 'text-padding-number-footer-cell',+ },+ purchase_cost: {+ classes: 'text-padding-number-footer-cell'+ },+ checkouts_count: {+ classes: 'text-padding-number-footer-cell'+ },+ assets_count: {+ classes: 'text-padding-number-footer-cell'+ },+ seats: {+ classes: 'text-padding-number-footer-cell'+ },+ free_seats_count: {+ classes: 'text-padding-number-footer-cell'+ },+ }[column.field]);- if ((row.available_actions) && (row.available_actions.bulk_selectable) && (row.available_actions.bulk_selectable.delete !== true)) {- return {- disabled:true,- //checked: false, <-- not sure this will work the way we want?- }- }- }- function licenseInOutFormatter(value, row) {- // check that checkin is not disabled- if (row.user_can_checkout === false) {- return '<span class="btn btn-sm bg-maroon disabled" data-tooltip="true" title="{{ trans('admin/licenses/message.checkout.unavailable') }}">{{ trans('general.checkout') }}</span>';- } else if (row.disabled === true) {- return '<span class="btn btn-sm bg-maroon disabled" data-tooltip="true" title="{{ trans('admin/licenses/message.checkout.license_is_inactive') }}">{{ trans('general.checkout') }}</span>';- } else- // The user is allowed to check the license seat out and it's available- if ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && (row.disabled === false)) {- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkout/" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';- }+ // This only works for model index pages because it uses the row's model ID+ function genericRowLinkFormatter(destination) {+ return function (value,row) {+ if (value) {+ return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '">' + value + '</a>';+ }+ };}- // We need a special formatter for license seats, since they don't work exactly the same- // Checkouts need the license ID, checkins need the specific seat ID- function licenseSeatInOutFormatter(value, row) {- if (row.disabled && (row.assigned_user || row.assigned_asset)) {- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';- }- if (row.disabled) {- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-maroon disabled" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkout') }}</a>';- }- // The user is allowed to check the license seat out and it's available- if ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && ((!row.assigned_asset) && (!row.assigned_user))) {- return '<a href="{{ config('app.url') }}/licenses/' + row.license_id + '/checkout/'+row.id+'" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';- }- // The user is allowed to check the license seat in and it's available- if ((row.available_actions.checkin === true) && ((row.assigned_asset) || (row.assigned_user))) {- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin/" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';- }- }+ // This is a special formatter that will indicate whether a user is an admin or superadmin+ function usernameRoleLinkFormatter(value, row) {- function genericCheckinCheckoutFormatter(destination) {- return function (value, row) {+ if ((value) && (row)) {- // The user is allowed to check items out, AND the item is deployable- if ((row.available_actions.checkout == true) && (row.user_can_checkout == true) && ((!row.asset_id) && (!row.assigned_to))) {+ if (row.role === 'superadmin') {+ return '<span style="white-space: nowrap" data-tooltip="true" title="{{ trans('general.superuser_tooltip') }}"><x-icon type="superadmin" title="{{ trans('general.superuser') }}" class="text-danger" /> <a href="{{ config('app.url') }}/users/' + row.id + '">' + value + '</a></span>';+ } else if (row.role === 'admin') {+ return '<span style="white-space: nowrap" data-tooltip="true" title="{{ trans('general.admin_tooltip') }}"><x-icon type="superadmin" title="{{ trans('general.admin_user') }}" class="text-warning" /> <a href="{{ config('app.url') }}/users/' + row.id + '">' + value + '</a></span>';+ }- return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '/checkout" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';+ // Regular user+ return '<a href="{{ config('app.url') }}/users/' + row.id + '">' + value + '</a>';+ }- // The user is allowed to check items out, but the item is not able to be checked out- } else if (((row.user_can_checkout == false)) && (row.available_actions.checkout == true) && (!row.assigned_to)) {+ }- // We use slightly different language for assets versus other things, since they are the only- // item that has a status label- if (destination =='hardware') {- return '<span data-tooltip="true" title="{{ trans('admin/hardware/general.undeployable_tooltip') }}"><a class="btn btn-sm bg-maroon disabled">{{ trans('general.checkout') }}</a></span>';- } else {- return '<span data-tooltip="true" title="{{ trans('general.undeployable_tooltip') }}"><a class="btn btn-sm bg-maroon disabled">{{ trans('general.checkout') }}</a></span>';+ // Use this when we're introspecting into a column object and need to link+ function genericColumnObjLinkFormatter(destination) {+ return function (value,row) {+ if ((value) && (value.status_meta)) {++ var text_color;+ var icon_style;+ var text_help;+ var status_meta = {+ 'deployed': '{{ strtolower(trans('general.deployed')) }}',+ 'deployable': '{{ strtolower(trans('admin/hardware/general.deployable')) }}',+ 'archived': '{{ strtolower(trans('general.archived')) }}',+ 'undeployable': '{{ strtolower(trans('general.undeployable')) }}',+ 'pending': '{{ strtolower(trans('general.pending')) }}'}- // The user is allowed to check items in- } else if (row.available_actions.checkin == true) {- if (row.assigned_to) {- return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';- } else if (row.assigned_pivot_id) {- return '<a href="{{ config('app.url') }}/' + destination + '/' + row.assigned_pivot_id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';+ switch (value.status_meta) {+ case 'deployed':+ text_color = 'blue';+ icon_style = 'fa-circle';+ text_help = '<label class="label label-default">{{ trans('general.deployed') }}</label>';+ break;+ case 'deployable':+ text_color = 'green';+ icon_style = 'fa-circle';+ text_help = '';+ break;+ case 'pending':+ text_color = 'orange';+ icon_style = 'fa-circle';+ text_help = '';+ break;+ default:+ text_color = 'red';+ icon_style = 'fa-times';+ text_help = '';}+ return '<nobr><a href="{{ config('app.url') }}/' + destination + '/' + value.id + '" data-tooltip="true" title="'+ status_meta[value.status_meta] + '"> <i class="fa ' + icon_style + ' text-' + text_color + '"></i> ' + value.name + ' ' + text_help + ' </a> </nobr>';+ } else if ((value) && (value.name)) {++ // Add some overrides for any funny urls we have+ var dest = destination;+ var polymorphicItemFormatterDest = '';+ if (destination == 'fieldsets') {+ var polymorphicItemFormatterDest = 'fields/';+ }++ return '<nobr><a href="{{ config('app.url') }}/' + polymorphicItemFormatterDest + dest + '/' + value.id + '">' + value.name + '</a></span>';}+ };+ }++ function licenseKeyFormatter(value, row) {+ if (value) {+ return '<code class="single-line"><span class="js-copy-link" data-clipboard-target=".js-copy-key-' + row.id + '" aria-hidden="true" data-tooltip="true" data-placement="top" title="{{ trans('general.copy_to_clipboard') }}"><span class="js-copy-key-' + row.id + '">' + value + '</span></span></code>';}+ }++ function hardwareAuditFormatter(value, row) {+ return '<a href="{{ config('app.url') }}/hardware/' + row.id + '/audit" class="actions btn btn-sm btn-primary" data-tooltip="true" title="{{ trans('general.audit') }}"><x-icon type="audit" /><span class="sr-only">{{ trans('general.audit') }}</span></a> ';}- // This is only used by the requestable assets section- function assetRequestActionsFormatter (row, value) {- if (value.assigned_to_self == true){- return '<button class="btn btn-danger btn-sm btn-block disabled" data-tooltip="true" title="{{ trans('admin/hardware/message.requests.cancel') }}">{{ trans('button.cancel') }}</button>';- } else if (value.available_actions.cancel == true) {- return '<form action="{{ config('app.url') }}/account/request-asset/' + value.id + '/cancel" method="POST">@csrf<button class="btn btn-danger btn-block btn-sm" data-tooltip="true" title="{{ trans('admin/hardware/message.requests.cancel') }}">{{ trans('button.cancel') }}</button></form>';- } else if (value.available_actions.request == true) {- return '<form action="{{ config('app.url') }}/account/request-asset/'+ value.id + '" method="POST">@csrf<button class="btn btn-block btn-primary btn-sm" data-tooltip="true" title="{{ trans('general.request_item') }}">{{ trans('button.request') }}</button></form>';+++ // Make the edit/delete buttons+ function genericActionsFormatter(owner_name, element_name) {+ if (!element_name) {+ element_name = '';}- }+ return function (value,row) {+ var actions = '<nobr>';+ // Add some overrides for any funny urls we have+ var dest = owner_name;- var formatters = [- 'accessories',- 'categories',- 'companies',- 'components',- 'consumables',- 'departments',- 'depreciations',- 'fieldsets',- 'groups',- 'hardware',- 'kits',- 'licenses',- 'locations',- 'maintenances',+ if (dest =='groups') {+ var dest = 'admin/groups';+ }+++ if(element_name != '') {+ dest = dest + '/' + row.owner_id + '/' + element_name;+ }++ if ((row.available_actions) && (row.available_actions.clone === true)) {+ actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '/clone" class="actions btn btn-sm btn-info" data-tooltip="true" title="{{ trans('general.clone_item') }}"><x-icon type="clone" /><span class="sr-only">{{ trans('general.clone_item') }}</span></a> ';+ }++ if ((row.available_actions) && (row.available_actions.audit === true)) {+ actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '/audit" class="actions btn btn-sm btn-primary" data-tooltip="true" title="{{ trans('general.audit') }}"><x-icon type="audit" /><span class="sr-only">{{ trans('general.audit') }}</span></a> ';+ }++ if ((row.available_actions) && (row.available_actions.update === true)) {+ actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '/edit" class="actions btn btn-sm btn-warning" data-tooltip="true" title="{{ trans('general.update') }}"><x-icon type="edit" /><span class="sr-only">{{ trans('general.update') }}</span></a> ';+ } else {+ if ((row.available_actions) && (row.available_actions.update != true)) {+ actions += '<span data-tooltip="true" title="{{ trans('general.cannot_be_edited') }}"><a class="btn btn-warning btn-sm disabled" onClick="return false;"><x-icon type="edit" /></a></span> ';+ }+ }++ if ((row.available_actions) && (row.available_actions.delete === true)) {++ // use the asset tag if no name is provided++ if (row.name) {+ var name_for_box = row.name+ } else if (row.asset_tag) {+ var name_for_box = row.asset_tag+ }++++ actions += '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '" '+ + ' class="actions btn btn-danger btn-sm delete-asset" data-tooltip="true" '+ + ' data-toggle="modal" data-icon="fa-trash"'+ + ' data-content="{{ trans('general.sure_to_delete') }}: ' + name_for_box + '?" '+ + ' data-title="{{ trans('general.delete') }}" onClick="return false;">'+ + '<x-icon type="delete" /><span class="sr-only">{{ trans('general.delete') }}</span></a> ';+ } else {+ // Do not show the delete button on things that are already deleted+ if ((row.available_actions) && (row.available_actions.restore != true)) {+ actions += '<span data-tooltip="true" title="{{ trans('general.cannot_be_deleted') }}"><a class="btn btn-danger btn-sm delete-asset disabled" onClick="return false;"><x-icon type="delete" /><span class="sr-only">{{ trans('general.cannot_be_deleted') }}</span></a></span> ';+ }++ }+++ if ((row.available_actions) && (row.available_actions.restore === true)) {+ actions += '<form style="display: inline;" method="POST" action="{{ config('app.url') }}/' + dest + '/' + row.id + '/restore"> ';+ actions += '@csrf';+ actions += '<button class="btn btn-sm btn-warning" data-tooltip="true" title="{{ trans('general.restore') }}"><x-icon type="restore" /><span class="sr-only">{{ trans('general.restore') }}</span></button> ';+ }++ actions +='</nobr>';+ return actions;++ };+ }+++ // This handles the icons and display of polymorphic entries+ function polymorphicItemFormatter(value) {++ var item_destination = '';+ var item_icon;++ if ((value) && (value.type)) {++ if (value.type == 'asset') {+ item_destination = 'hardware';+ item_icon = 'fas fa-barcode';+ } else if (value.type == 'accessory') {+ item_destination = 'accessories';+ item_icon = 'far fa-keyboard';+ } else if (value.type == 'component') {+ item_destination = 'components';+ item_icon = 'far fa-hdd';+ } else if (value.type == 'consumable') {+ item_destination = 'consumables';+ item_icon = 'fas fa-tint';+ } else if (value.type == 'license') {+ item_destination = 'licenses';+ item_icon = 'far fa-save';+ } else if (value.type == 'user') {+ item_destination = 'users';+ item_icon = 'fas fa-user';+ } else if (value.type == 'location') {+ item_destination = 'locations'+ item_icon = 'fas fa-map-marker-alt';+ } else if (value.type == 'maintenance') {+ item_destination = 'maintenances'+ item_icon = 'fa-solid fa-screwdriver-wrench';+ } else if (value.type == 'model') {+ item_destination = 'models'+ item_icon = '';+ }++ // display the username if it's checked out to a user, but don't do it if the username's there already+ if (value.username && !value.name.match('\\(') && !value.name.match('\\)')) {+ value.name = value.name + ' (' + value.username + ')';+ }++ return '<nobr><a href="{{ config('app.url') }}/' + item_destination +'/' + value.id + '" data-tooltip="true" title="' + value.type + '"><i class="' + item_icon + ' text-{{ $snipeSettings->skin!='' ? $snipeSettings->skin : 'blue' }} "></i> ' + value.name + '</a></nobr>';++ } else {+ return '';+ }+++ }++ // This just prints out the item type in the activity report+ function itemTypeFormatter(value, row) {++ if ((row) && (row.item) && (row.item.type)) {+ return row.item.type;+ }+ }+++ // Convert line breaks to <br>+ function notesFormatter(value) {+ if (value) {+ return value.replace(/(?:\r\n|\r|\n)/g, '<br />');+ }+ }++ // Check if checkbox should be selectable+ // Selectability is determined by the API field "selectable" which is set at the Presenter/API Transformer+ // However since different bulk actions have different requirements, we have to walk through the available_actions object+ // to determine whether to disable it+ function checkboxEnabledFormatter (value, row) {++ // add some stuff to get the value of the select2 option here?++ if ((row.available_actions) && (row.available_actions.bulk_selectable) && (row.available_actions.bulk_selectable.delete !== true)) {+ return {+ disabled:true,+ //checked: false, <-- not sure this will work the way we want?+ }+ }+ }++ function licenseInOutFormatter(value, row) {++ // check that checkin is not disabled+ if (row.user_can_checkout === false) {+ return '<span class="btn btn-sm bg-maroon disabled" data-tooltip="true" title="{{ trans('admin/licenses/message.checkout.unavailable') }}">{{ trans('general.checkout') }}</span>';+ } else if (row.disabled === true) {+ return '<span class="btn btn-sm bg-maroon disabled" data-tooltip="true" title="{{ trans('admin/licenses/message.checkout.license_is_inactive') }}">{{ trans('general.checkout') }}</span>';++ } else+ // The user is allowed to check the license seat out and it's available+ if ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && (row.disabled === false)) {+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkout/" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';+ }+ }+ // We need a special formatter for license seats, since they don't work exactly the same+ // Checkouts need the license ID, checkins need the specific seat ID++ function licenseSeatInOutFormatter(value, row) {+ if (row.disabled && (row.assigned_user || row.assigned_asset)) {+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';+ }+ if (row.disabled) {+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-maroon disabled" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkout') }}</a>';+ }+ // The user is allowed to check the license seat out and it's available+ if ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && ((!row.assigned_asset) && (!row.assigned_user))) {+ return '<a href="{{ config('app.url') }}/licenses/' + row.license_id + '/checkout/'+row.id+'" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';+ }++ // The user is allowed to check the license seat in and it's available+ if ((row.available_actions.checkin === true) && ((row.assigned_asset) || (row.assigned_user))) {+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin/" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';+ }++ }++ function genericCheckinCheckoutFormatter(destination) {+ return function (value, row) {++ // The user is allowed to check items out, AND the item is deployable+ if ((row.available_actions.checkout == true) && (row.user_can_checkout == true) && ((!row.asset_id) && (!row.assigned_to))) {++ return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '/checkout" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';++ // The user is allowed to check items out, but the item is not able to be checked out+ } else if (((row.user_can_checkout == false)) && (row.available_actions.checkout == true) && (!row.assigned_to)) {++ // We use slightly different language for assets versus other things, since they are the only+ // item that has a status label+ if (destination =='hardware') {+ return '<span data-tooltip="true" title="{{ trans('admin/hardware/general.undeployable_tooltip') }}"><a class="btn btn-sm bg-maroon disabled">{{ trans('general.checkout') }}</a></span>';+ } else {+ return '<span data-tooltip="true" title="{{ trans('general.undeployable_tooltip') }}"><a class="btn btn-sm bg-maroon disabled">{{ trans('general.checkout') }}</a></span>';+ }++ // The user is allowed to check items in+ } else if (row.available_actions.checkin == true) {+ if (row.assigned_to) {+ return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';+ } else if (row.assigned_pivot_id) {+ return '<a href="{{ config('app.url') }}/' + destination + '/' + row.assigned_pivot_id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';+ }++ }++ }+++ }+++ // This is only used by the requestable assets section+ function assetRequestActionsFormatter (row, value) {+ if (value.assigned_to_self == true){+ return '<button class="btn btn-danger btn-sm btn-block disabled" data-tooltip="true" title="{{ trans('admin/hardware/message.requests.cancel') }}">{{ trans('button.cancel') }}</button>';+ } else if (value.available_actions.cancel == true) {+ return '<form action="{{ config('app.url') }}/account/request-asset/' + value.id + '/cancel" method="POST">@csrf<button class="btn btn-danger btn-block btn-sm" data-tooltip="true" title="{{ trans('admin/hardware/message.requests.cancel') }}">{{ trans('button.cancel') }}</button></form>';+ } else if (value.available_actions.request == true) {+ return '<form action="{{ config('app.url') }}/account/request-asset/'+ value.id + '" method="POST">@csrf<button class="btn btn-block btn-primary btn-sm" data-tooltip="true" title="{{ trans('general.request_item') }}">{{ trans('button.request') }}</button></form>';+ }++ }++++ var formatters = [+ 'accessories',+ 'categories',+ 'companies',+ 'components',+ 'consumables',+ 'departments',+ 'depreciations',+ 'fieldsets',+ 'groups',+ 'hardware',+ 'kits',+ 'licenses',+ 'locations',+ 'maintenances','manufacturers','models','statuslabels',@@ -1132,696 +1661,163 @@if (value) {if ((value.file) && (value.file.filename) && (value.file.url)) {- if (value.file.exists_on_disk === true) {- return '<a href="' + value.file.url + '">' + value.file.filename + '</a>';- }-- return '<span class="text-danger" style="text-decoration: line-through;" data-tooltip="true" title="{{ trans('general.file_does_not_exist') }}"><x-icon type="x" /> ' + value.file.filename + '</span>';-- } else if ((value.filename) && (value.url)) {- if (value.exists_on_disk === true) {- return '<a href="' + value.url + '">' + value.filename + '</a>';- }- return '<span class="text-danger" style="text-decoration: line-through;" data-tooltip="true" title="{{ trans('general.file_does_not_exist') }}"><x-icon type="x" /> ' + value.filename + '</span>';- }- }-- }--- function linkToUserSectionBasedOnCount (count, id, section) {- if (count) {- return '<a href="{{ config('app.url') }}/users/' + id + '#' + section +'">' + count + '</a>';- }-- return count;- }-- function linkNumberToUserAssetsFormatter(value, row) {- return linkToUserSectionBasedOnCount(value, row.id, 'asset');- }-- function linkNumberToUserLicensesFormatter(value, row) {- return linkToUserSectionBasedOnCount(value, row.id, 'licenses');- }-- function linkNumberToUserConsumablesFormatter(value, row) {- return linkToUserSectionBasedOnCount(value, row.id, 'consumables');- }-- function linkNumberToUserAccessoriesFormatter(value, row) {- return linkToUserSectionBasedOnCount(value, row.id, 'accessories');- }-- function linkNumberToUserManagedUsersFormatter(value, row) {- return linkToUserSectionBasedOnCount(value, row.id, 'managed-users');- }-- function linkNumberToUserManagedLocationsFormatter(value, row) {- return linkToUserSectionBasedOnCount(value, row.id, 'managed-locations');- }-- function labelPerPageFormatter(value, row, index, field) {- if (row) {- if (!row.hasOwnProperty('sheet_info')) { return 1; }- else { return row.sheet_info.labels_per_page; }- }- }-- function labelRadioFormatter(value, row, index, field) {- if (row) {- return row.name == '{{ str_replace("\\", "\\\\", $snipeSettings->label2_template) }}';- }- }-- function labelSizeFormatter(value, row) {- if (row) {- return row.width + ' x ' + row.height + ' ' + row.unit;- }- }-- function cleanFloat(number) {- if(!number) { // in a JavaScript context, meaning, if it's null or zero or unset- return 0.0;- }- if ("{{$snipeSettings->digit_separator}}" == "1.234,56") {- // yank periods, change commas to periods- periodless = number.toString().replace(/\./g,"");- decimalfixed = periodless.replace(/,/g,".");- } else {- // yank commas, that's it.- decimalfixed = number.toString().replace(/\,/g,"");- }- return parseFloat(decimalfixed);- }--- function qtySumFormatter(data) {- var currentField = this.field;- var total = 0;- var fieldname = this.field;-- $.each(data, function() {- var r = this;- total += this[currentField];- });- return total;- }-- function sumFormatter(data) {- if (Array.isArray(data)) {- var field = this.field;- var total_sum = data.reduce(function(sum, row) {-- return (sum) + (cleanFloat(row[field]) || 0);- }, 0);-- return numberWithCommas(total_sum.toFixed(2));- }- return 'not an array';- }-- function sumFormatterQuantity(data){- if(Array.isArray(data)) {-- // Prevents issues on page load where data is an empty array- if(data[0] == undefined){- return 0.00- }- // Check that we are actually trying to sum cost from a table- // that has a quantity column. We must perform this check to- // support licences which use seats instead of qty- if('qty' in data[0]) {- var multiplier = 'qty';- } else if('seats' in data[0]) {- var multiplier = 'seats';- } else {- return 'no quantity';- }- var total_sum = data.reduce(function(sum, row) {- return (sum) + (cleanFloat(row["purchase_cost"])*row[multiplier] || 0);- }, 0);- return numberWithCommas(total_sum.toFixed(2));- }- return 'not an array';- }-- function numberWithCommas(value) {-- if ((value) && ("{{$snipeSettings->digit_separator}}" == "1.234,56")){- var parts = value.toString().split(".");- parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");- return parts.join(",");- } else {- var parts = value.toString().split(",");- parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");- return parts.join(".");- }- return value- }-- $(function () {- $('#bulkEdit').click(function () {- var selectedIds = $('.snipe-table').bootstrapTable('getSelections');- $.each(selectedIds, function(key,value) {- $( "#bulkForm" ).append($('<input type="hidden" name="ids[' + value.id + ']" value="' + value.id + '">' ));- });-- });- });--- // User table buttons- window.userButtons = () => ({- @can('create', \App\Models\User::class)- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('users.create') }}';- },- attributes: {- title: '{{ trans('general.create') }}',- class: 'btn btn-primary',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- @endcan-- btnExport: {- text: '{{ trans('general.export_all_to_csv') }}',- icon: 'fa-solid fa-file-csv',- event () {- window.location.href = '{{ route('users.export') }}';- },- attributes: {- title: '{{ trans('general.export_all_to_csv') }}',- }- },-- btnShowAdmins: {- text: '{{ trans('general.show_admins') }}',- icon: 'fa-solid fa-crown{{ (request()->input('admins') == "true") ? ' text-danger' : '' }}',- event () {- window.location.href = '{{ (request()->input('admins') == "true") ? route('users.index') : route('users.index', ['admins' => 'true']) }}';- },- attributes: {- title: '{{ trans('general.show_admins') }}',- }- },-- btnShowDeleted: {- text: '{{ (request()->input('status') == "deleted") ?trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',- icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : ' fa-user-trash' }}',- event () {- window.location.href = '{{ (request()->input('status') == "deleted") ? route('users.index') : route('users.index', ['status' => 'deleted']) }}';- },- attributes: {- title: '{{ (request()->input('status') == "deleted") ? trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',-- }- },-- }); // end user table buttons--- @can('create', \App\Models\Company::class)- // Company table buttons- window.companyButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('companies.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },-- }); // End company table buttons- @endcan--- // Asset table buttons- window.assetButtons = () => ({- @can('create', \App\Models\Asset::class)- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('hardware.create') }}';- },- attributes: {- title: '{{ trans('general.create') }}',- class: 'btn btn-primary',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- @endcan-- @can('update', \App\Models\Asset::class)- btnAddMaintenance: {- text: '{{ trans('button.add_maintenance') }}',- icon: 'fa-solid fa-screwdriver-wrench',- event () {- window.location.href = '{{ route('maintenances.create', ['asset_id' => (isset($asset)) ? $asset->id :'' ]) }}';- },- attributes: {- title: '{{ trans('button.add_maintenance') }}',- }- },- @endcan--- btnExport: {- text: '{{ trans('admin/hardware/general.custom_export') }}',- icon: 'fa-solid fa-file-csv',- event () {- window.location.href = '{{ route('reports/custom') }}';- },- attributes: {- title: '{{ trans('admin/hardware/general.custom_export') }}',- }- },-- btnShowDeleted: {- text: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',- icon: 'fa-solid fa-trash {{ (request()->input('status') == "Deleted") ? ' text-danger' : '' }}',- event () {- window.location.href = '{{ (request()->input('status') == "Deleted") ? route('hardware.index') : route('hardware.index', ['status' => 'Deleted']) }}';- },- attributes: {- title: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',-- }- },- });-- @can('create', \App\Models\Location::class)- // Location table buttons- window.locationButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('locations.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },-- btnShowDeleted: {- text: '{{ (request()->input('status') == "deleted") ? trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',- icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : ' fa-user-trash' }}',- event () {- window.location.href = '{{ (request()->input('status') == "deleted") ? route('locations.index') : route('locations.index', ['status' => 'deleted']) }}';- },- attributes: {- title: '{{ (request()->input('status') == "deleted") ? trans('admin/users/table.show_current') : trans('admin/users/table.show_deleted') }}',-- }- },- });- @endcan-- @can('create', \App\Models\Accessory::class)- // Accessory table buttons- window.accessoryButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('accessories.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('create', \App\Models\Depreciation::class)- // Accessory table buttons- window.depreciationButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('depreciations.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('create', \App\Models\CustomField::class)- // Accessory table buttons- window.customFieldButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('fields.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan--- @can('create', \App\Models\CustomFieldset::class)- // Accessory table buttons- window.customFieldsetButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('fieldsets.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('create', \App\Models\Component::class)- // Compoment table buttons- window.componentButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('components.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('create', \App\Models\Consumable::class)- // Consumable table buttons- window.consumableButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('consumables.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('create', \App\Models\Manufacturer::class)- // Consumable table buttons- window.manufacturerButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('manufacturers.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- },-- btnShowDeleted: {- text: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',- icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : '' }}',- event () {- window.location.href = '{{ (request()->input('status') == "deleted") ? route('manufacturers.index') : route('manufacturers.index', ['status' => 'deleted']) }}';- },- attributes: {- title: '{{ (request()->input('status') == "Deleted") ? trans('general.list_all') : trans('general.deleted') }}',-- }- },- },- });- @endcan-- @can('create', \App\Models\Supplier::class)- // Consumable table buttons- window.supplierButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('suppliers.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('create', \App\Models\Department::class)- // Department table buttons- window.departmentButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('departments.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('create', \App\Models\CustomField::class)- // Custom Field table buttons- window.departmentButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('departments.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan-- @can('update', \App\Models\Asset::class)- // Custom Field table buttons- window.maintenanceButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('maintenances.create', ['asset_id' => (isset($asset)) ? $asset->id :'' ]) }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan+ if (value.file.exists_on_disk === true) {+ return '<a href="' + value.file.url + '">' + value.file.filename + '</a>';+ }- @can('create', \App\Models\Category::class)- // Custom Field table buttons- window.categoryButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('categories.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan+ return '<span class="text-danger" style="text-decoration: line-through;" data-tooltip="true" title="{{ trans('general.file_does_not_exist') }}"><x-icon type="x" /> ' + value.file.filename + '</span>';- @can('create', \App\Models\AssetModel::class)- // Custom Field table buttons- window.modelButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('models.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif+ } else if ((value.filename) && (value.url)) {+ if (value.exists_on_disk === true) {+ return '<a href="' + value.url + '">' + value.filename + '</a>';+ }+ return '<span class="text-danger" style="text-decoration: line-through;" data-tooltip="true" title="{{ trans('general.file_does_not_exist') }}"><x-icon type="x" /> ' + value.filename + '</span>';}- },- btnShowDeleted: {- text: '{{ (request()->input('status') == "deleted") ? trans('general.list_all') : trans('general.deleted') }}',- icon: 'fa-solid fa-trash {{ (request()->input('status') == "deleted") ? ' text-danger' : '' }}',- event () {- window.location.href = '{{ (request()->input('status') == "deleted") ? route('models.index') : route('models.index', ['status' => 'deleted']) }}';- },- attributes: {- title: '{{ (request()->input('status') == "deleted") ? trans('general.list_all') : trans('general.deleted') }}',+ }- }- },- });- @endcan+ }- @can('create', \App\Models\Statuslabel::class)- // Status label table buttons- window.statuslabelButtons = () => ({- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('statuslabels.create') }}';- },- attributes: {- class: 'btn btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- }- },- });- @endcan+ function linkToUserSectionBasedOnCount (count, id, section) {+ if (count) {+ return '<a href="{{ config('app.url') }}/users/' + id + '#' + section +'">' + count + '</a>';+ }- // License table buttons- window.licenseButtons = () => ({- @can('create', \App\Models\License::class)- btnAdd: {- text: '{{ trans('general.create') }}',- icon: 'fa fa-plus',- event () {- window.location.href = '{{ route('licenses.create') }}';- },- attributes: {- class: 'btn-primary',- title: '{{ trans('general.create') }}',- @if ($snipeSettings->shortcuts_enabled == 1)- accesskey: 'n'- @endif- },- },- @endcan+ return count;+ }- btnExport: {- text: '{{ trans('general.export_all_to_csv') }}',- icon: 'fa-solid fa-file-csv',- event () {- window.location.href = '{{ route('licenses.export', ['category_id' => (isset($category)) ? $category->id :'' ]) }}';- },- attributes: {- class: 'btn-primary',- title: '{{ trans('general.export_all_to_csv') }}',- }- },+ function linkNumberToUserAssetsFormatter(value, row) {+ return linkToUserSectionBasedOnCount(value, row.id, 'asset');+ }- btnShowExpiring: {- text: '{{ (request()->input('status') == "expiring") ? trans('general.list_all') : trans('general.show_expiring') }}',- icon: 'fas fa-clock {{ (request()->input('status') == "expiring") ? ' text-danger' : '' }}',- event () {- window.location.href = '{{ (request()->input('status') == "expiring") ? route('licenses.index') : route('licenses.index', ['status' => 'expiring']) }}';- },- attributes: {- title: '{{ (request()->input('status') == "expiring") ? trans('general.list_all') : trans('general.show_expiring') }}',+ function linkNumberToUserLicensesFormatter(value, row) {+ return linkToUserSectionBasedOnCount(value, row.id, 'licenses');+ }- }- },+ function linkNumberToUserConsumablesFormatter(value, row) {+ return linkToUserSectionBasedOnCount(value, row.id, 'consumables');+ }- btnShowInactive: {- text: '{{ (request()->input('status') == "inactive") ? trans('general.list_all') : trans('general.show_inactive') }}',- icon: 'fas fa-history {{ (request()->input('status') == "inactive") ? ' text-danger' : '' }}',- event () {- window.location.href = '{{ (request()->input('status') == "inactive") ? route('licenses.index') : route('licenses.index', ['status' => 'inactive']) }}';- },- attributes: {- title: '{{ (request()->input('status') == "inactive") ? trans('general.list_all') : trans('general.show_inactive') }}',+ function linkNumberToUserAccessoriesFormatter(value, row) {+ return linkToUserSectionBasedOnCount(value, row.id, 'accessories');+ }- }- },- });+ function linkNumberToUserManagedUsersFormatter(value, row) {+ return linkToUserSectionBasedOnCount(value, row.id, 'managed-users');+ }++ function linkNumberToUserManagedLocationsFormatter(value, row) {+ return linkToUserSectionBasedOnCount(value, row.id, 'managed-locations');+ }++ function labelPerPageFormatter(value, row, index, field) {+ if (row) {+ if (!row.hasOwnProperty('sheet_info')) { return 1; }+ else { return row.sheet_info.labels_per_page; }+ }+ }++ function labelRadioFormatter(value, row, index, field) {+ if (row) {+ return row.name == '{{ str_replace("\\", "\\\\", $snipeSettings->label2_template) }}';+ }+ }++ function labelSizeFormatter(value, row) {+ if (row) {+ return row.width + ' x ' + row.height + ' ' + row.unit;+ }+ }++ function cleanFloat(number) {+ if(!number) { // in a JavaScript context, meaning, if it's null or zero or unset+ return 0.0;+ }+ if ("{{$snipeSettings->digit_separator}}" == "1.234,56") {+ // yank periods, change commas to periods+ periodless = number.toString().replace(/\./g,"");+ decimalfixed = periodless.replace(/,/g,".");+ } else {+ // yank commas, that's it.+ decimalfixed = number.toString().replace(/\,/g,"");+ }+ return parseFloat(decimalfixed);+ }+++ function qtySumFormatter(data) {+ var currentField = this.field;+ var total = 0;+ var fieldname = this.field;++ $.each(data, function() {+ var r = this;+ total += this[currentField];+ });+ return total;+ }++ function sumFormatter(data) {+ if (Array.isArray(data)) {+ var field = this.field;+ var total_sum = data.reduce(function(sum, row) {++ return (sum) + (cleanFloat(row[field]) || 0);+ }, 0);++ return numberWithCommas(total_sum.toFixed(2));+ }+ return 'not an array';+ }+ function sumFormatterQuantity(data){+ if(Array.isArray(data)) {++ // Prevents issues on page load where data is an empty array+ if(data[0] == undefined){+ return 0.00+ }+ // Check that we are actually trying to sum cost from a table+ // that has a quantity column. We must perform this check to+ // support licences which use seats instead of qty+ if('qty' in data[0]) {+ var multiplier = 'qty';+ } else if('seats' in data[0]) {+ var multiplier = 'seats';+ } else {+ return 'no quantity';+ }+ var total_sum = data.reduce(function(sum, row) {+ return (sum) + (cleanFloat(row["purchase_cost"])*row[multiplier] || 0);+ }, 0);+ return numberWithCommas(total_sum.toFixed(2));+ }+ return 'not an array';+ }+ function numberWithCommas(value) {++ if ((value) && ("{{$snipeSettings->digit_separator}}" == "1.234,56")){+ var parts = value.toString().split(".");+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");+ return parts.join(",");+ } else {+ var parts = value.toString().split(",");+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");+ return parts.join(".");+ }+ return value+ }+ $(function () {+ $('#bulkEdit').click(function () {+ var selectedIds = $('.snipe-table').bootstrapTable('getSelections');+ $.each(selectedIds, function(key,value) {+ $( "#bulkForm" ).append($('<input type="hidden" name="ids[' + value.id + ']" value="' + value.id + '">' ));+ });+ });+ });$(function() {