diff --git a/app/Events/NoteAdded.php b/app/Events/NoteAdded.php deleted file mode 100644 index de5f91ce78..0000000000 --- a/app/Events/NoteAdded.php +++ /dev/null @@ -1,28 +0,0 @@ -itemNoteAddedOn = $itemNoteAddedOn; - $this->note = $note; - $this->noteAddedBy = $noteAddedBy; - } -} \ No newline at end of file diff --git a/app/Http/Controllers/Api/NotesController.php b/app/Http/Controllers/Api/NotesController.php deleted file mode 100644 index 97b7ca4134..0000000000 --- a/app/Http/Controllers/Api/NotesController.php +++ /dev/null @@ -1,43 +0,0 @@ -validate([ - 'note' => 'required|string|max:500', - 'type' => [ - 'required', - Rule::in(['asset']), - ], - ]); - - // This can be made dynamic by using $request->input('type') to determine which model type to add the note to. - // For now, we are only placing this on Assets - $item = Asset::findOrFail($request->input("id")); - $this->authorize('update', $item); - - event(new NoteAdded($item, Auth::user(), $validated['note'])); - - return response()->json(Helper::formatStandardApiResponse('success')); - } - - public function update(Request $request) - { - - } - public function destroy(Request $request) - { - - } -} diff --git a/app/Http/Controllers/NotesController.php b/app/Http/Controllers/NotesController.php new file mode 100644 index 0000000000..ecac627c0f --- /dev/null +++ b/app/Http/Controllers/NotesController.php @@ -0,0 +1,42 @@ +authorize('update', Asset::class); + + $validated = $request->validate([ + 'id' => 'required', + 'note' => 'required|string|max:500', + 'type' => [ + 'required', + Rule::in(['asset']), + ], + ]); + + $item = Asset::findOrFail($validated['id']); + + $this->authorize('update', $item); + + $logaction = new Actionlog; + $logaction->item_id = $item->id; + $logaction->item_type = get_class($item); + $logaction->note = $validated['note']; + $logaction->created_by = Auth::id(); + $logaction->logaction('note added'); + + return redirect() + ->route('hardware.show', $validated['id']) + ->withFragment('history') + ->with('success', trans('general.note_added')); + } +} diff --git a/app/Listeners/LogListener.php b/app/Listeners/LogListener.php index d0da80614c..27a9168484 100644 --- a/app/Listeners/LogListener.php +++ b/app/Listeners/LogListener.php @@ -17,7 +17,6 @@ use App\Events\ItemAccepted; use App\Events\ItemDeclined; use App\Events\LicenseCheckedIn; use App\Events\LicenseCheckedOut; -use App\Events\NoteAdded; use App\Models\Actionlog; use App\Models\User; use App\Models\LicenseSeat; @@ -129,23 +128,6 @@ class LogListener } - - /** - * Note is added to action log - * - */ - public function onNoteAdded(NoteAdded $event) - { - $logaction = new Actionlog(); - $logaction->item_id = $event->itemNoteAddedOn->id; - $logaction->item_type = get_class($event->itemNoteAddedOn); - $logaction->note = $event->note; //this is the received alphanumeric text from the box - $logaction->created_by = $event->noteAddedBy->id; - $logaction->action_type = 'note_added'; - $logaction->save(); - } - - /** * Register the listeners for the subscriber. * diff --git a/resources/assets/js/snipeit_modals.js b/resources/assets/js/snipeit_modals.js index 250868bbbb..cea79e1141 100644 --- a/resources/assets/js/snipeit_modals.js +++ b/resources/assets/js/snipeit_modals.js @@ -28,7 +28,7 @@ $(function () { var baseUrl = $('meta[name="baseUrl"]').attr('content'); //handle modal-add-interstitial calls - var model, select, refreshSelector, hasnopayload; + var model, select, refreshSelector; if($('#createModal').length == 0) { $('body').append('
'); @@ -40,8 +40,6 @@ $(function () { select = link.data("select"); refreshSelector = link.data("refresh"); - hasnopayload = link.data("hasnopayload"); - $('#createModal').load(link.attr('href'),function () { // this sets the focus to be the name field @@ -123,13 +121,12 @@ $(function () { $('#modal_error_msg').html(error_message).show(); return false; } - if(!hasnopayload) { - var id = result.payload.id; - var name = result.payload.name || (result.payload.first_name + " " + result.payload.last_name); - if (!id || !name) { - console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id); - return false; - } + + var id = result.payload.id; + var name = result.payload.name || (result.payload.first_name + " " + result.payload.last_name); + if (!id || !name) { + console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id); + return false; } $('#createModal').modal('hide'); $('#createModal').html(""); diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index a6197f5971..531bfa63f6 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -217,14 +217,13 @@ @can('update', \App\Models\Asset::class) - @endcan diff --git a/resources/views/modals/add-note.blade.php b/resources/views/modals/add-note.blade.php index 9c14098f06..8208fc36a9 100644 --- a/resources/views/modals/add-note.blade.php +++ b/resources/views/modals/add-note.blade.php @@ -1,28 +1,35 @@ {{-- See snipeit_modals.js for what powers this --}} -