@@ -25,22 +25,22 @@ enum AdvancedsearchModalAction: string
2525
2626class Modal extends Component
2727{
28- public $showModal = false;
28+ public $showModal= false;
2929 public AdvancedsearchModalAction $modalActionType;
3030
3131 #[Validate("required")]
3232 public FilterVisibility $visibility = FilterVisibility::Private;
3333
3434 #[Validate("required")]
35- public ?string $name = "";
35+ public ?string $name= "";
3636
3737 #[Validate("sometimes")]
38- public $groupSelect = [];
38+ public $groupSelect= [];
3939
4040 #[Validate("sometimes")]
41- public array $groupSelectOtherOptions = [];
41+ public array $groupSelectOtherOptions= [];
4242
43- protected $listeners = ["groupSelect"];
43+ protected $listeners= ["groupSelect"];
4444
4545 public ?int $filterId;
4646
@@ -75,42 +75,45 @@ public function openPredefinedFiltersModal(
7575 }
7676
7777 if (
78- $this->modalActionType === AdvancedsearchModalAction::Edit &&
79- $predefinedFilterId !== null
78+ $this->modalActionType === AdvancedsearchModalAction::Edit
79+ && $predefinedFilterId !== null
8080 ) {
81- $predefinedFilter = $predefinedFilterService->getFilterWithOptionalPermissionsById(
82- $predefinedFilterId
83- );
81+ $this->openPredefinedFiltersEditModal($predefinedFilterId);
82+ }
83+
84+ $this->dispatch("openPredefinedFiltersModalEvent");
85+ }
86+
87+ private function openPredefinedFiltersEditModal($predefinedFilterId) {
88+ $predefinedFilter = $predefinedFilterService->getFilterWithOptionalPermissionsById(
89+ $predefinedFilterId
90+ );
8491
85- if ($predefinedFilter === null) {
86- $this->showModal = false;
87- $this->dispatchNotFoundNotification();
88- return;
89- }
92+ if ($predefinedFilter === null) {
93+ $this->showModal = false;
94+ $this->dispatchNotFoundNotification();
95+ return;
96+ }
9097
91- $this->name = $predefinedFilter["name"];
92-
93- if ($predefinedFilter["is_public"] == 1) {
94- $this->visibility = FilterVisibility::Public;
95- } else {
96- $this->visibility = FilterVisibility::Private;
97- }
98+ $this->name = $predefinedFilter["name"];
9899
99- foreach ($predefinedFilter["permissions"] as $permission) {
100- array_push(
101- $this->groupSelect,
102- $permission->permission_group_id
103- );
104- }
100+ if ($predefinedFilter["is_public"] == 1) {
101+ $this->visibility = FilterVisibility::Public;
102+ } else {
103+ $this->visibility = FilterVisibility::Private;
104+ }
105105
106- $this->groupSelectOtherOptions = array_diff(
107- $this->groupSelectOtherOptions,
108- $this->groupSelect
106+ foreach ($predefinedFilter["permissions"] as $permission) {
107+ array_push(
108+ $this->groupSelect,
109+ $permission->permission_group_id
109110 );
110111 }
111- // end if
112112
113- $this->dispatch("openPredefinedFiltersModalEvent");
113+ $this->groupSelectOtherOptions = array_diff(
114+ $this->groupSelectOtherOptions,
115+ $this->groupSelect
116+ );
114117 }
115118
116119 #[On("closePredefinedFiltersModal")]
@@ -131,13 +134,7 @@ public function savePredefinedFiltersModal(
131134 ) {
132135 $this->validate();
133136
134- if ($this->validateMaxLenghtForFiltername()) {
135- $this->dispatch('showNotificationInFrontend', [
136- 'type' => 'error',
137- 'title' => trans('general.notification_error'),
138- 'message' => trans('admin/predefinedFilters/message.name_too_long'),
139- 'tag' => 'predefinedFilter',
140- ]);
137+ if(!$this->validateMaxLenghtForFiltername()) {
141138 return;
142139 }
143140
@@ -210,13 +207,7 @@ public function updatePredefinedFiltersModal(
210207 'groupSelect.*' => 'required|integer|exists:permission_groups,id',
211208 ]);
212209
213- if($this->validateMaxLenghtForFiltername()) {
214- $this->dispatch('showNotificationInFrontend', [
215- 'type' => 'error',
216- 'title' => trans('general.notification_error'),
217- 'message' => trans('admin/predefinedFilters/message.name_too_long'),
218- 'tag' => 'predefinedFilter',
219- ]);
210+ if(!$this->validateMaxLenghtForFiltername()) {
220211 return;
221212 }
222213
@@ -316,7 +307,7 @@ public function deletePredefinedFiltersModal(
316307
317308 $predefinedFilter = $predefinedFilterService->getFilterWithOptionalPermissionsById($this->filterId);
318309
319- if ($predefinedFilter === null){
310+ if ($predefinedFilter === null) {
320311 $this->dispatchNotFoundNotification();
321312 return;
322313 }
@@ -414,6 +405,16 @@ private function dispatchNotFoundNotification()
414405 }
415406
416407 private function validateMaxLenghtForFiltername(): bool {
417- return mb_strlen($this->name) > 190;
408+ if (mb_strlen($this->name) > 190) {
409+ $this->dispatch('showNotificationInFrontend', [
410+ 'type' => 'error',
411+ 'title' => trans('general.notification_error'),
412+ 'message' => trans('admin/predefinedFilters/message.name_too_long'),
413+ 'tag' => 'predefinedFilter',
414+ ]);
415+ return false;
416+ }
417+ return true;
418418 }
419+
419420}
0 commit comments