Skip to content

A free open source IT asset/license management system

Merge branch 'develop' into Label_customization

Godfrey Mac8f0390205f
diff --cc app/Models/Setting.php
index f3d4e84025,9bcade4d69..0f72831ddf
--- a/app/Models/Setting.php
+++ b/app/Models/Setting.php
@@@ -3,9 -3,9 +3,11 @@@
namespace App\Models;
use App\Helpers\Helper;
+ use App\Rules\CssColor;
+use App\Models\Labels\CustomUserLabel;
+use App\Models\Labels\Label;
use Carbon\Carbon;
+ use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
diff --cc app/Presenters/LabelPresenter.php
index 89628c9c12,78505d90eb..0f9825d75b
--- a/app/Presenters/LabelPresenter.php
+++ b/app/Presenters/LabelPresenter.php
@@@ -26,9 -28,9 +28,10 @@@ class LabelPresenter extends Presente
'switchable' => true,
'title' => trans('general.name'),
'visible' => true,
+ 'formatter' => 'labelNameFormatter',
], [
'field' => 'size',
+ 'scope' => 'col',
'searchable' => false,
'sortable' => false,
'switchable' => true,
diff --cc resources/assets/js/snipeit.js
index 5a30a04cab,af4c4d83ca..ded0350d3b
--- a/resources/assets/js/snipeit.js
+++ b/resources/assets/js/snipeit.js
@@@ -137,11 -139,23 +139,23 @@@ $(function ()
return false;
});
+ // Mark-a-maintenance-complete modal (green checkmark button in the
+ // maintenances table actions column). Sets the modal form's action to
+ // the row's completion URL and opens it.
+ $el.on('click', '.complete-maintenance', function () {
+ var url = $(this).data('url');
+ $('#completeMaintenanceForm').attr('action', url);
+ $('#completionNote').val('');
+ $('#completeMaintenanceModal').modal('show');
+ });
+
// confirm delete modal
- $el.on('click', '.delete-asset', function (evnt) {
+ $el.on('click', '.delete-asset, .delete-custom-label', function (evnt) {
var $context = $(this);
var $dataConfirmModal = $('#dataConfirmModal');
- var href = $context.attr('href');
+ // Anchors keep the URL in href; buttons keep it in data-href
+ // (buttons don't semantically support href per HTML5).
+ var href = $context.attr('data-href') || $context.attr('href');
var message = $context.attr('data-content');
var headericon = $context.attr('data-icon');
var title = $context.attr('data-title');
diff --cc resources/lang/en-US/general.php
index bc697c2ab6,81335fdbc3..ecb4281d48
--- a/resources/lang/en-US/general.php
+++ b/resources/lang/en-US/general.php
@@@ -89,9 -96,9 +96,10 @@@ return
'component' => 'Component',
'components' => 'Components',
'complete' => 'Complete',
+ 'completed' => 'completed',
'consumable' => 'Consumable',
'consumables' => 'Consumables',
+ 'continue' => 'Continue',
'country' => 'Country',
'could_not_restore' => 'Error restoring :item_type: :error',
'not_deleted' => 'The :item_type was not deleted and therefore cannot be restored',
diff --cc resources/views/partials/bootstrap-table.blade.php
index 10678c5ac6,0b9d4fc29e..9be1558381
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@@ -2372,79 -3139,10 +3153,84 @@@
return linkToUserSectionBasedOnCount(value, row.id, 'managed-locations');
}
+ function linkNumberToUserAssignedMaintenancesFormatter(value, row) {
+ return linkToUserSectionBasedOnCount(value, row.id, 'maintenances');
+ }
+
+ function labelActionsFormatter(value, row) {
+ if (!row.name) return '';
+
+ const createUrl = '{{ route('settings.labels.create') }}';
+ // Clone Button
+ let cloneHref;
-
++
+ if (row.source === 'custom') {
+ cloneHref = createUrl + '?custom_label_id=' + row.custom_label_id;
+ } else {
+ cloneHref = createUrl + '?label=' + encodeURIComponent(row.name);
+ }
+
+ let actions = '<a href="' + cloneHref + '" '
+ + 'class="actions btn btn-sm btn-primary hidden-print" '
+ + 'data-tooltip="true" '
+ + 'title="{{ trans('general.clone') }}">'
+ + '<i class="fa-regular fa-clone"></i>'
+ + '<span class="sr-only">{{ trans('general.clone') }}</span>'
+ + '</a>&nbsp;';
+ // Only allow delete, share or edit for custom labels
+ if (row.source === 'custom') {
+ // Update Button
+ var editUrl = editLabelUrlTemplate.replace('label_id', row.custom_label_id);
+
+ actions += '<a href="' + editUrl + '" '
+ + 'class="actions btn btn-sm btn-warning hidden-print" '
+ + 'data-tooltip="true" '
+ + 'title="{{ trans('general.update') }}">'
+ + '<x-icon type="edit" class="fa-fw" />'
+ + '<span class="sr-only">{{ trans('general.update') }}</span>'
+ + '</a>&nbsp;';
+ // Share button
+ var encodedJson = encodeURIComponent(JSON.stringify(row.config_snapshot || {}, null, 2));
+
+ actions += '<button type="button" '
+ + 'class="btn btn-primary btn-sm export-label-json hidden-print" '
+ + 'data-json="' + encodedJson + '" '
+ + 'data-name="' + encodeURIComponent(row.name || "label") + '" '
+ + 'title="Export Label" '
+ + 'data-tooltip="true">'
+ + '<i class="fa-solid fa-file-export"></i>'
+ + '<span class="sr-only">Export Label</span>'
+ + '</button>&nbsp;';
+
+ // Delete button
+ var safeName = $('<div>').text(row.name || 'this label').html();
+ var deleteUrl = deleteLabelUrlTemplate.replace('label_id', row.custom_label_id);
+
+ actions += '<a href="' + deleteUrl + '" '
+ + 'class="actions btn btn-danger btn-sm delete-custom-label hidden-print" '
+ + 'data-tooltip="true" '
+ + 'data-icon="fa-trash" '
+ + 'data-content="{{ trans('general.sure_to_delete') }}: ' + safeName + '?" '
+ + 'data-title="{{ trans('general.delete') }}">'
+ + '<x-icon type="delete" class="fa-fw" />'
+ + '<span class="sr-only">{{ trans('general.delete') }}</span>'
+ + '</a>&nbsp;';
+ }
+
+
+ return actions;
+ }
+
+ function labelNameFormatter(value) {
+ if (!value) return '';
+
+ // Normalize slashes just in case
+ value = value.replace(/\//g, '\\');
+
+ // Remove "Sheets\" or "Tapes\" from the beginning
+ return value.replace(/^(Sheets|Tapes)\\/, '');
+ }
++
function labelPerPageFormatter(value, row, index, field) {
if (row) {
if (!row.hasOwnProperty('sheet_info')) { return 1; }
diff --cc resources/views/settings/labels.blade.php
index 9e8ef4e775,db655180f8..60c1fbdce5
--- a/resources/views/settings/labels.blade.php
+++ b/resources/views/settings/labels.blade.php
@@@ -80,434 -49,9 +73,127 @@@
</div>
</div>
-
@if ($setting->label2_enable)
- <!-- Import Label -->
- <div class="form-group">
- <div class="col-md-3 text-right">
- <label for="config_snapshot" class="control-label">
- Import Label Config
- </label>
- </div>
++ <!-- Import Label -->
++ <div class="form-group">
++ <div class="col-md-3 text-right">
++ <label for="config_snapshot" class="control-label">
++ Import Label Config
++ </label>
++ </div>
+
- <div class="col-md-7">
- <input
- type="hidden"
- name="import_method"
- id="import_method"
- value="json"
- form="import-label-form"
- >
-
- <div class="btn-group import-toggle" role="group">
- <button
- type="button"
- class="btn btn-primary import-toggle-btn active"
- data-method="json"
++ <div class="col-md-7">
++ <input
++ type="hidden"
++ name="import_method"
++ id="import_method"
++ value="json"
++ form="import-label-form"
+ >
- JSON
- </button>
+
- <button
- type="button"
- class="btn btn-default import-toggle-btn"
- data-method="text"
- >
- Text
- </button>
- </div>
++ <div class="btn-group import-toggle" role="group">
++ <button
++ type="button"
++ class="btn btn-primary import-toggle-btn active"
++ data-method="json"
++ >
++ JSON
++ </button>
++
++ <button
++ type="button"
++ class="btn btn-default import-toggle-btn"
++ data-method="text"
++ >
++ Text
++ </button>
++ </div>
+
- <div id="text-input-group" style="display:none; margin-top:10px;">
- <div class="import-inline-row">
++ <div id="text-input-group" style="display:none; margin-top:10px;">
++ <div class="import-inline-row">
+ <textarea
+ name="config_snapshot"
+ form="import-label-form"
+ id="config_snapshot"
+ class="form-control"
+ rows="4"
+ placeholder="Paste label config JSON here"
+ >{{ old('config_snapshot') }}</textarea>
+
- <button
- type="submit"
- form="import-label-form"
- id="import-text-button"
- class="btn btn-primary"
- disabled
- >
- Import
- </button>
- </div>
-
- <p id="json-validation-message" class="help-block" style="display:none;"></p>
- </div>
-
- <div id="json-input-group" style="margin-top:10px; margin-bottom:15px;">
- <div class="input-group">
- <input
- type="file"
- name="config_file"
- form="import-label-form"
- id="config_file"
- class="form-control"
- accept=".json,application/json"
- >
-
- <span class="input-group-btn">
+ <button
+ type="submit"
+ form="import-label-form"
- id="import-file-button"
++ id="import-text-button"
+ class="btn btn-primary"
+ disabled
+ >
+ Import
+ </button>
- </span>
- </div>
- </div>
++ </div>
+
- @if ($errors->has('config_snapshot'))
- <ul class="alert-msg list-unstyled" style="margin-top: 10px;">
- @foreach ((array) $errors->get('config_snapshot') as $message)
- @if (is_array($message))
- @foreach ($message as $line)
- <li>{!! $line !!}</li>
- @endforeach
- @else
- <li>{!! $message !!}</li>
- @endif
- @endforeach
- </ul>
- @endif
- </div>
- </div>
- <!-- New Settings -->
- <fieldset name="select-template">
- <x-form.legend>
- {{ trans('admin/settings/general.select_template') }}
- </x-form.legend>
-
- <!-- Template -->
- <div class="form-group{{ $errors->has('label2_template') ? ' has-error' : '' }}">
-
- <div class="col-md-12">
- <x-container>
- <x-box name="label-templates">
- <x-table.labels/>
- </x-box>
- </x-container>
- </div>
- </div>
- </fieldset>
-
- <fieldset name="label-preview">
- <x-form.legend>
- {{ trans('admin/settings/general.label2_label_preview') }}: <code
- id="selected-template-display">{{ $setting->label2_template_display }}</code>
- </x-form.legend>
- <div class="col-md-12" style="margin-bottom: 10px;">
- <input type="hidden" name="label2_template" id="label2_template"
- value="{{ old('label2_template', $setting->label2_template) }}">
- @include('partials.label2-preview')
- </div>
- </fieldset>
-
-
- <fieldset name="label-settings">
- <x-form.legend help_text="{{ trans('admin/settings/general.labels_title_help') }}">
- {{ trans('admin/settings/general.labels_title') }}
- </x-form.legend>
-
- <!-- Title -->
- <div class="form-group{{ $errors->has('label2_title') ? ' has-error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="label2_title" class="control-label">{{trans('admin/settings/general.label2_title')}}</label>
- </div>
- <div class="col-md-7">
- <input class="form-control" aria-label="label2_title" name="label2_title" type="text" id="label2_title" value="{{ old('label2_title', $setting->label2_title) }}">
- {!! $errors->first('label2_title', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
- <p class="help-block">{!! trans('admin/settings/general.label2_title_help') !!}</p>
- <p class="help-block">
- {!! trans('admin/settings/general.label2_title_help_phold') !!}.<br />
- {!! trans('admin/settings/general.help_asterisk_bold') !!}.<br />
- {!!
- trans('admin/settings/general.help_blank_to_use', [
- 'setting_name' => trans('admin/settings/general.barcodes').' &gt; '.trans('admin/settings/general.qr_text')
- ])
- !!}
- </p>
- </div>
- </div>
-
- <!-- Use Asset Logo -->
- <div class="form-group" {{ $errors->has('label2_asset_logo') ? 'error' : '' }}">
- <div class="col-md-7 col-md-offset-3">
-
- <label class="form-control">
- <input type="checkbox" value="1" name="label2_asset_logo"{{ ((old('label2_asset_logo') == '1') || ($setting->label2_asset_logo) == '1') ? ' checked="checked"' : '' }} aria-label="label2_asset_logo">
- <label for="label2_asset_logo">{{ trans('admin/settings/general.label2_asset_logo') }}</label>
- </label>
- <p class="help-block">
- {!! trans('admin/settings/general.label2_asset_logo_help', ['setting_name' => trans('admin/settings/general.brand').' &gt; '.trans('admin/settings/general.logo_labels.logo')]) !!}
- </p>
-
- </div>
- </div>
- @endif
- @if($setting->label2_enable == 0)
- @if ($is_gd_installed)
- <!-- barcode -->
- <div class="form-group">
- <div class="col-md-9 col-md-offset-3">
- <label class="form-control">
- <input type="checkbox" name="alt_barcode_enabled" value="1" @checked(old('alt_barcode_enabled', $setting->alt_barcode_enabled)) aria-label="alt_barcode_enabled"/>
- {{ trans('admin/settings/general.display_alt_barcode') }}
- </label>
- </div>
- </div>
- @endif
- @endif
-
- <!-- 1D Barcode Type -->
- <div class="form-group{{ $errors->has('label2_1d_type') ? ' has-error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="label2_1d_type" class="control-label">{{ trans('admin/settings/general.label2_1d_type') }}</label>
- </div>
- <div class="col-md-7">
- @php
- $select1DValues = [
- 'C128' => 'C128',
- 'C39' => 'C39',
- 'EAN5' => 'EAN5',
- 'EAN13' => 'EAN13',
- 'UPCA' => 'UPCA',
- 'UPCE' => 'UPCE',
- 'none' => trans('admin/settings/general.none'),
- ];
- @endphp
- <x-input.select
- name="label2_1d_type"
- id="label2_1d_type"
- :options="$select1DValues"
- :selected="old('label2_1d_type', $setting->label2_1d_type)"
- class="col-md-4"
- aria-label="label2_1d_type"
- />
- {!! $errors->first('label2_1d_type', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
- <p class="help-block">
- {{ trans('admin/settings/general.label2_1d_type_help') }}.
- {!!
- trans('admin/settings/general.help_default_will_use', [
- 'default' => trans('admin/settings/general.default'),
- 'setting_name' => trans('admin/settings/general.barcodes').' &gt; '.trans('admin/settings/general.alt_barcode_type'),
- ])
- !!}
- </p>
- </div>
- </div>
-
- @if($setting->label2_enable == 0)
-
- <!-- qr code -->
- <div class="form-group">
- <div class="col-md-9 col-md-offset-3">
- <label class="form-control">
- <input type="checkbox" name="qr_code" value="1" @checked(old('qr_code', $setting->qr_code)) aria-label="qr_code" />
- {{ trans('admin/settings/general.display_qr') }}
- </label>
- </div>
- </div>
- @endif
- <!-- 2D Barcode Type -->
- <div class="form-group{{ $errors->has('label2_2d_type') ? ' has-error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="label2_2d_type" class="control-label">{{ trans('admin/settings/general.label2_2d_type') }}</label>
++ <p id="json-validation-message" class="help-block" style="display:none;"></p>
+ </div>
- <div class="col-md-7">
- @php
- $select2DValues = [
- 'QRCODE' => 'QRCODE',
- ];
- if ($setting->label2_enable == 1) {
- $select2DValues['PDF417'] = 'PDF417';
- }
- $select2DValues = array_merge($select2DValues, [
- 'DATAMATRIX' => 'DATAMATRIX',
- 'none' => trans('admin/settings/general.none'),
- ]);
- @endphp
- <x-input.select
- name="label2_2d_type"
- id="label2_2d_type"
- :options="$select2DValues"
- :selected="old('label2_2d_type', $setting->label2_2d_type)"
- class="col-md-4"
- aria-label="label2_2d_type"
- />
- {!! $errors->first('label2_2d_type', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
- <p class="help-block">
- {{ trans('admin/settings/general.label2_2d_type_help', ['current' => $setting->barcode_type]) }}.
- {!! trans('admin/settings/general.help_default_will_use') !!}
- </p>
- </div>
- </div>
+
- @if($setting->label2_enable == 0)
- <!-- QR Text -->
- <div class="form-group{{ $errors->has('qr_text') ? ' has-error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="qr_text" class="control-label">{{ trans('admin/settings/general.qr_text') }}</label>
- </div>
- <div class="col-md-7">
- @if ($setting->qr_code == 1)
++ <div id="json-input-group" style="margin-top:10px; margin-bottom:15px;">
++ <div class="input-group">
+ <input
- class="form-control"
- placeholder="Property of Your Company"
- rel="txtTooltip"
- title="Extra text that you would like to display on your labels."
- data-toggle="tooltip"
- data-placement="top"
- name="qr_text"
- type="text"
- id="qr_text"
- value="{{ old('qr_text', $setting->qr_text) }}"
- >
- @else
- <input
- class="form-control"
- disabled="disabled"
- placeholder="Property of Your Company"
- name="qr_text"
- type="text"
- id="qr_text"
- value="{{ old('qr_text', $setting->qr_text) }}"
++ type="file"
++ name="config_file"
++ form="import-label-form"
++ id="config_file"
++ class="form-control"
++ accept=".json,application/json"
+ >
- <p class="help-block">{{ trans('admin/settings/general.qr_help') }}</p>
- @endif
- {!! $errors->first('qr_text', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
- </div>
- </div>
+
- <!-- Nuke barcode cache -->
- <div class="form-group">
- <div class="col-md-3 text-right">
- <label for="purge_barcodes" class="control-label">{{ trans('admin/settings/general.purge_barcodes') }}</label>
- </div>
- <div class="col-md-7">
- <a class="btn btn-theme btn-sm pull-left" id="purgebarcodes" style="margin-right: 10px;">
- {{ trans('admin/settings/general.barcode_delete_cache') }}
- </a>
- <span id="purgebarcodesicon"></span>
- <span id="purgebarcodesresult"></span>
- <span id="purgebarcodesstatus"></span>
- {!! $errors->first('purgebarcodes', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
- <p class="help-block">{{ trans('admin/settings/general.barcodes_help') }}</p>
++ <span class="input-group-btn">
++ <button
++ type="submit"
++ form="import-label-form"
++ id="import-file-button"
++ class="btn btn-primary"
++ disabled
++ >
++ Import
++ </button>
++ </span>
++ </div>
+ </div>
- </div>
- @endif
- @if ($setting->label2_enable)
-
- <!-- 2D prefix -->
- <div class="form-group{{ $errors->has('label2_2d_prefix') ? ' has-error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="label2_2d_prefix" class="control-label">{{trans('admin/settings/general.label2_2d_prefix')}}</label>
- </div>
- <div class="col-md-7">
- <input class="form-control" aria-label="label2_2d_prefix" name="label2_2d_prefix" type="text" id="label2_2d_prefix" value="{{ old('label2_2d_prefix', $setting->label2_2d_prefix) }}">
- {!! $errors->first('label2_2d_prefix', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
- <p class="help-block">{!! trans('admin/settings/general.label2_2d_prefix_help') !!}</p>
- </div>
- </div>
+
-
- <!-- 2D Barcode Target -->
- <div class="form-group{{ $errors->has('label2_2d_target') ? ' has-error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="label2_2d_target" class="control-label">{{ trans('admin/settings/general.label2_2d_target') }}</label>
- </div>
- <div class="col-md-9">
- <x-input.select
- name="label2_2d_target"
- id="label2_2d_target"
- style="min-width:50%"
- :options="[
- 'hardware_id'=> config('app.url').'/hardware/{id} ('.trans('admin/settings/general.default').')',
- 'ht_tag'=> config('app.url').'/ht/{asset_tag}',
- 'location' => config('app.url').'/locations/{location_id}',
- 'plain_asset_id'=> trans('admin/settings/general.asset_id'),
- 'plain_asset_tag'=> trans('general.asset_tag'),
- 'plain_serial_number'=> trans('general.serial_number'),
- 'plain_model_number'=> trans('general.model_no'),
- 'plain_model_name'=> trans('general.asset_model'),
- 'plain_manufacturer_name'=> trans('general.manufacturer'),
- 'plain_location_name'=> trans('general.location'),
- ]"
- :selected="old('label2_2d_target', $setting->label2_2d_target)"
- class="col-md-4"
- aria-label="label2_2d_target"
- />
- {!! $errors->first('label2_2d_target', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
- <p class="help-block">{{ trans('admin/settings/general.label2_2d_target_help') }}</p>
++ @if ($errors->has('config_snapshot'))
++ <ul class="alert-msg list-unstyled" style="margin-top: 10px;">
++ @foreach ((array) $errors->get('config_snapshot') as $message)
++ @if (is_array($message))
++ @foreach ($message as $line)
++ <li>{!! $line !!}</li>
++ @endforeach
++ @else
++ <li>{!! $message !!}</li>
++ @endif
++ @endforeach
++ </ul>
++ @endif
+ </div>
+ </div>
- <!-- Field offset -->
- <div class="form-group{{ $errors->has('label2_empty_row_count') ? ' has-error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="label2_empty_row_count" class="control-label">{{ trans('admin/settings/general.empty_row_count') }}</label>
- </div>
- <div class="col-md-9 col-xl-2 col-lg-2">
- <input
- class="form-control"
- aria-label="Empty Row Count"
- name="label2_empty_row_count"
- type="number"
- id="label2_empty_row_count"
- min="0"
- max="5"
- value="{{ old('label2_empty_row_count', $setting->label2_empty_row_count) }}"
- >
- </div>
-
- <div class="col-md-9 col-md-offset-3">
- <p class="help-block">{!! trans('admin/settings/general.empty_row_count_help') !!}</p>
- {!! $errors->first('label2_empty_row_count', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
- </div>
- </div>
- </fieldset>
-
-
- <fieldset name="field-definitions">
- <x-form.legend help_text="{!! trans('admin/settings/general.label2_fields_help') !!}">
- Label Fields
- </x-form.legend>
- <!-- Fields -->
- <div class="form-group {{ $errors->has('label2_fields') ? 'error' : '' }}">
- <div class="col-md-12">
- @include('partials.label2-field-definitions', [ 'name' => 'label2_fields', 'value' => old('label2_fields', $setting->label2_fields), 'customFields' => $customFields, 'template' => $setting->label2_template])
- {!! $errors->first('label2_fields', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
++ <!-- New Settings -->
++ <fieldset name="select-template">
++ <x-form.legend>
++ {{ trans('admin/settings/general.select_template') }}
++ </x-form.legend>
++
++ <!-- Template -->
++ <div class="form-group{{ $errors->has('label2_template') ? ' has-error' : '' }}">
++
++ <div class="col-md-12">
++ <x-container>
++ <x-box name="label-templates">
++ <x-table.labels/>
++ </x-box>
++ </x-container>
++ </div>
+ </div>
- </div>
-
- </fieldset>
-
- {{-- <fieldset name="label-preview">--}}
- {{-- <x-form.legend>--}}
- {{-- {{ trans('admin/settings/general.label2_label_preview') }}: <code--}}
- {{-- id="selected-template-display">{{ $setting->label2_template_display }}</code>--}}
- {{-- </x-form.legend>--}}
- {{-- <div class="col-md-12" style="margin-bottom: 10px;">--}}
- {{-- <input type="hidden" name="label2_template" id="label2_template"--}}
- {{-- value="{{ old('label2_template', $setting->label2_template) }}">--}}
- {{-- @include('partials.label2-preview')--}}
- {{-- </div>--}}
- {{-- </fieldset>--}}
-
- @include('partials.bootstrap-table')
-
++ </fieldset>
+ @include('partials.labels-new-engine')
@else
-
- <!-- Hidden version of new settings -->
<input name="label2_template" type="hidden" value="{{ old('label2_template', $setting->label2_template) }}" />
<input name="label2_title" type="hidden" value="{{ old('label2_title', $setting->label2_title) }}" />
<input name="label2_asset_logo" type="hidden" value="{{ old('label2_asset_logo', $setting->label2_asset_logo) }}" />
@@@ -770,160 -127,9 +278,161 @@@
});
- });
+ });
+ }
+ $(function () {
+ let isPreselecting = false;
+
+ $('#label2TemplateTable').on('check.bs.table', function (e, row) {
+ if (isPreselecting) {
+ return;
+ }
+
+ const value = row.source === 'custom'
+ ? 'custom:' + row.custom_label_id
+ : row.name;
+
+ $('#label2_template').val(value);
+ $('#selected-template-display').text(row.name || value);
+
+ document.getElementById('settingsForm')?.dispatchEvent(new Event('change'));
+ });
+
+ $('#label2TemplateTable').on('load-success.bs.table', function () {
+ const selected = $('#label2_template').val();
+
+ isPreselecting = true;
+
+ $('#label2TemplateTable').bootstrapTable('getData').forEach((row, index) => {
+ const value = row.source === 'custom'
+ ? 'custom:' + row.custom_label_id
+ : row.name;
+
+ if (value === selected) {
+ $('#label2TemplateTable').bootstrapTable('check', index);
+ }
+ });
+
+ isPreselecting = false;
+
+ document.getElementById('settingsForm')?.dispatchEvent(new Event('change'));
+ });
+ });
+
+
+ const deleteLabelUrlTemplate = "{{ route('settings.labels.destroy', ['label' => 'label_id']) }}";
+ const editLabelUrlTemplate = "{{ route('settings.labels.edit', ['label' => 'label_id']) }}";
+
+ $(document).on('click', '.copy-label-json', async function (e) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ const $btn = $(this);
+ const originalHtml = $btn.html();
+
+ try {
+ const json = decodeURIComponent($btn.data('json'));
+
+ await navigator.clipboard.writeText(json);
+
+ $btn
+ .removeClass('btn-primary')
+ .addClass('btn-success')
+ .html('<i class="fa fa-check"></i>');
+
+ setTimeout(() => {
+ $btn
+ .removeClass('btn-success')
+ .addClass('btn-primary')
+ .html(originalHtml);
+ }, 1500);
+ } catch (e) {
+ console.error(e);
+
+ $btn
+ .removeClass('btn-primary')
+ .addClass('btn-danger')
+ .html('<i class="fa fa-times"></i>');
+
+ setTimeout(() => {
+ $btn
+ .removeClass('btn-danger')
+ .addClass('btn-primary')
+ .html(originalHtml);
+ }, 1500);
+ }
+ });
+ $(document).on('click', '.export-label-json', function () {
+
+ const json = decodeURIComponent($(this).data('json'));
+ const name = decodeURIComponent($(this).data('name'));
+
+ const blob = new Blob([json], {
+ type: 'application/json;charset=utf-8'
+ });
+
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ const safeName = name.replace(/[^\w\-]+/g, '_');
+
+ a.href = url;
+ a.download = `${safeName}.json`;
+
+ document.body.appendChild(a);
+ a.click();
+
+ document.body.removeChild(a);
+ window.URL.revokeObjectURL(url);
+ });
+
+ $('.import-toggle-btn').on('click', function () {
+ const method = $(this).data('method');
+
+ $('.import-toggle-btn')
+ .removeClass('btn-primary active')
+ .addClass('btn-default');
+
+ $(this)
+ .addClass('btn-primary active')
+ .removeClass('btn-default');
+
+ $('#import_method').val(method);
+
+ $('#text-input-group').toggle(method === 'text');
+ $('#json-input-group').toggle(method === 'json');
+ });
+
+ $('#config_file').on('change', function () {
+ const hasFile = this.files && this.files.length > 0;
+
+ $('#import-file-button').prop('disabled', !hasFile);
+ });
+
+ $('#config_snapshot').on('input', function () {
+
+ const value = $(this).val().trim();
+
+ try {
+ JSON.parse(value);
+
+ $('#import-text-button').prop('disabled', false);
+
+ $('#json-validation-message')
+ .hide()
+ .text('');
+
+ } catch (e) {
+
+ $('#import-text-button').prop('disabled', true);
+
+ $('#json-validation-message')
+ .show()
+ .addClass('text-danger')
+ .text('Invalid JSON');
+ }
+ });
+
</script>
{{-- Can't use @script here because we're not in a livewire component so let's manually load --}}
@livewireScripts