Skip to content

A free open source IT asset/license management system

toggle supported inputs in label editor

Godfrey Md5fc871043dc
diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
index 5abe0b18f8..8b7c043a28 100644
--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
@@ -102,26 +102,30 @@ trait HasCustomLabelEditorSections
'title' => [
'label' => 'admin/labels/general.groups.title',
'toggle' => 'supports.title',
- 'fields' => [
- 'title_font' => ['type' => 'select',
+ 'fields' => array_filter([
+ 'title_font' => [
+ 'type' => 'select',
'options' => [
'freemono' => 'admin/labels/general.options.freemono',
'freesans' => 'admin/labels/general.options.freesans',
'dejavusans' => 'admin/labels/general.options.dejavusans',
],
],
+
'title_font_size' => ['type' => 'number'],
'title_margin' => ['type' => 'number'],
'title_offset_x' => ['type' => 'number'],
- 'title_position' => [
- 'type' => 'select',
- 'options' => [
- 'inline' => 'admin/labels/general.options.inline',
- 'top' => 'admin/labels/general.options.top',
- ],
- ],
- ],
+ 'title_position' => !$this->isTapeLabel()
+ ? [
+ 'type' => 'select',
+ 'options' => [
+ 'inline' => 'admin/labels/general.options.inline',
+ 'top' => 'admin/labels/general.options.top',
+ ],
+ ]
+ : null,
+ ]),
],
'field_labels' => [
diff --git a/resources/views/partials/label-editor-section.blade.php b/resources/views/partials/label-editor-section.blade.php
index 44fe33b1fc..a5b74e8d62 100644
--- a/resources/views/partials/label-editor-section.blade.php
+++ b/resources/views/partials/label-editor-section.blade.php
@@ -63,7 +63,22 @@
@elseif (isset($section['groups']))
<div class="label-content-groups">
@foreach ($section['groups'] as $groupKey => $group)
- <div class="panel panel-default">
+ @php
+ $toggle = $group['toggle'] ?? null;
+ $isSupported = $toggle
+ ? (bool) data_get($config, $toggle, false)
+ : true;
+ @endphp
+
+ <div
+ class="panel panel-default label-editor-group"
+ @if($toggle)
+ data-support-toggle="{{ $toggle }}"
+ @endif
+ @if(!$isSupported)
+ style="display:none;"
+ @endif
+ >
<div class="panel-heading">
<strong>{{ trans($group['label']) }}</strong>
</div>
diff --git a/resources/views/settings/label-edit.blade.php b/resources/views/settings/label-edit.blade.php
index e08f45e3fa..8c66ca4dec 100644
--- a/resources/views/settings/label-edit.blade.php
+++ b/resources/views/settings/label-edit.blade.php
@@ -226,6 +226,40 @@
.val(value === 'L' ? 'R' : 'L');
}
});
+
+ function syncContentSupportGroups() {
+ $('.label-editor-group[data-support-toggle]').each(function () {
+ const $group = $(this);
+ const toggle = $group.data('support-toggle');
+
+ const parts = toggle.split('.');
+
+ if (parts.length !== 2) {
+ return;
+ }
+
+ const inputName = `${parts[0]}[${parts[1]}]`;
+ const $input = $(`[name="${inputName}"]`);
+
+ let enabled = false;
+
+ if ($input.is(':checkbox')) {
+ enabled = $input.is(':checked');
+ } else {
+ enabled = parseInt($input.val(), 10) > 0;
+ }
+
+ $group.toggle(enabled);
+ });
+ }
+
+ $(document).on(
+ 'change',
+ 'input[name^="supports["][type="checkbox"]',
+ syncContentSupportGroups
+ );
+
+ $(syncContentSupportGroups);
</script>
@livewireScripts
@endpush
\ No newline at end of file