@@ -886,4 +886,84 @@ public function handleShowDeleteModal(array $data): void
886
886
$ this ->mountAction ('deleteMenuItem ' , ['itemId ' => $ itemId ]);
887
887
}
888
888
}
889
+
890
+ #[On('move-item-up ' )]
891
+ public function handleMoveItemUp (array $ data ): void
892
+ {
893
+ $ itemId = $ data ['itemId ' ] ?? null ;
894
+ if ($ itemId ) {
895
+ $ this ->moveItemUp ($ itemId );
896
+ }
897
+ }
898
+
899
+ #[On('move-item-down ' )]
900
+ public function handleMoveItemDown (array $ data ): void
901
+ {
902
+ $ itemId = $ data ['itemId ' ] ?? null ;
903
+ if ($ itemId ) {
904
+ $ this ->moveItemDown ($ itemId );
905
+ }
906
+ }
907
+
908
+ public function moveItemUp (int $ itemId ): void
909
+ {
910
+ try {
911
+ $ item = $ this ->getMenuItemSecurely ($ itemId );
912
+ if (!$ item ) {
913
+ Notification::make ()
914
+ ->title (flexiblePagesTrans ('menu_items.errors.item_not_found ' ))
915
+ ->danger ()
916
+ ->send ();
917
+ return ;
918
+ }
919
+
920
+ // Move up means move to previous sibling
921
+ $ previousSibling = $ item ->getPrevSibling ();
922
+ if ($ previousSibling ) {
923
+ $ item ->beforeNode ($ previousSibling )->save ();
924
+ $ this ->refreshTree ();
925
+
926
+ Notification::make ()
927
+ ->title ('Menu item moved up successfully. ' )
928
+ ->success ()
929
+ ->send ();
930
+ }
931
+ } catch (Exception $ e ) {
932
+ Notification::make ()
933
+ ->title ('Failed to move menu item: ' . $ e ->getMessage ())
934
+ ->danger ()
935
+ ->send ();
936
+ }
937
+ }
938
+
939
+ public function moveItemDown (int $ itemId ): void
940
+ {
941
+ try {
942
+ $ item = $ this ->getMenuItemSecurely ($ itemId );
943
+ if (!$ item ) {
944
+ Notification::make ()
945
+ ->title (flexiblePagesTrans ('menu_items.errors.item_not_found ' ))
946
+ ->danger ()
947
+ ->send ();
948
+ return ;
949
+ }
950
+
951
+ // Move down means move to next sibling
952
+ $ nextSibling = $ item ->getNextSibling ();
953
+ if ($ nextSibling ) {
954
+ $ item ->afterNode ($ nextSibling )->save ();
955
+ $ this ->refreshTree ();
956
+
957
+ Notification::make ()
958
+ ->title ('Menu item moved down successfully. ' )
959
+ ->success ()
960
+ ->send ();
961
+ }
962
+ } catch (Exception $ e ) {
963
+ Notification::make ()
964
+ ->title ('Failed to move menu item: ' . $ e ->getMessage ())
965
+ ->danger ()
966
+ ->send ();
967
+ }
968
+ }
889
969
}
0 commit comments