diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index 7256b72..9b2ea2d 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -62,8 +62,11 @@ class FacultyController extends Controller public function PublicationsForm() { + $organisingInstitutes = Publication::select('organizing_institute') + ->distinct() + ->pluck('organizing_institute'); // Logic to show the response form - return view('faculty.publications-form'); + return view('faculty.publications-form', compact('organisingInstitutes')); } public function viewPublicationsResponses() diff --git a/app/Http/Controllers/PublicationsController.php b/app/Http/Controllers/PublicationsController.php index de8fd4b..2abd6fe 100644 --- a/app/Http/Controllers/PublicationsController.php +++ b/app/Http/Controllers/PublicationsController.php @@ -12,8 +12,11 @@ class PublicationsController extends Controller public function edit($id) { $publication = Publication::findOrFail($id); + $organisingInstitutes = Publication::select('organizing_institute') + ->distinct() + ->pluck('organizing_institute'); - return view('pages.publications.edit', compact('publication')); + return view('pages.publications.edit', compact('publication', 'organisingInstitutes')); } public function update(Request $request, $id) diff --git a/resources/views/faculty/publications-form.blade.php b/resources/views/faculty/publications-form.blade.php index 6dc561e..41e1ce7 100644 --- a/resources/views/faculty/publications-form.blade.php +++ b/resources/views/faculty/publications-form.blade.php @@ -21,11 +21,13 @@
- + +
- + +
@@ -42,9 +44,14 @@
- - -
+ + +
@@ -162,5 +169,64 @@ document.getElementById('num_days').value = numDays; } } + + document.addEventListener('DOMContentLoaded', function() { + // Initialize Select2 for first_author_name + $('#first_author_name').select2({ + tags: true, + tokenSeparators: [','], + ajax: { + url: '{{ route('api.users.index') }}', // Adjust this route to fetch user names + dataType: 'json', + delay: 250, + processResults: function(data) { + return { + results: data.map(user => ({ + id: user.name, + text: user.name + })) + }; + }, + cache: true + } + }); + + $('#first_author_name').on('change', function() { + const selectedValues = $(this).val(); + document.getElementById('first_author_name_hidden').value = selectedValues.join(', '); + }); + + // Initialize Select2 for co_authors + $('#co_authors').select2({ + tags: true, + tokenSeparators: [','], + ajax: { + url: '{{ route('api.users.index') }}', // Adjust this route to fetch user names + dataType: 'json', + delay: 250, + processResults: function(data) { + return { + results: data.map(user => ({ + id: user.name, + text: user.name + })) + }; + }, + cache: true + } + }); + + $('#co_authors').on('change', function() { + const selectedValues = $(this).val(); + document.getElementById('co_authors_hidden').value = selectedValues.join(', '); + }); + + $('#organizing_institute').select2({ + tags: true, + placeholder: "Select or type...", + allowClear: true + }); + + }); @endsection \ No newline at end of file diff --git a/resources/views/pages/publications/edit.blade.php b/resources/views/pages/publications/edit.blade.php index 99ff791..d5a3485 100644 --- a/resources/views/pages/publications/edit.blade.php +++ b/resources/views/pages/publications/edit.blade.php @@ -28,11 +28,13 @@
- + +
- + +
@@ -49,9 +51,14 @@
- - -
+ + +
@@ -184,6 +191,99 @@ // Calculate days on page load document.addEventListener('DOMContentLoaded', function() { calculateDays(); + + const OldFirstAuthorNameData = {!! json_encode(explode(', ', old('first_author_name', $publication->first_author_name))) !!}; + + $('#first_author_name').select2({ + tags: true, + tokenSeparators: [','], + ajax: { + url: '{{ route('api.users.index') }}', + dataType: 'json', + delay: 250, + processResults: function (data) { + return { + results: data.map(user => ({ id: user.name, text: user.name })) + }; + }, + cache: true + } + }); + + $('#organizing_institute').select2({ + tags: true, + placeholder: "Select or Type...", + allowClear: true + }); + + // Prepopulate with old data + OldFirstAuthorNameData.forEach(function (item) { + const option = new Option(item, item, true, true); + $('#first_author_name').append(option).trigger('change'); + }); + + $('#first_author_name').on('change', function () { + const selectedValues = $(this).val(); + document.getElementById('first_author_name_hidden').value = selectedValues.join(', '); + }); + const OldCoAuthorData = {!! json_encode(explode(', ', old('co_authors', $publication->co_authors))) !!}; + + $('#co_authors').select2({ + tags: true, + tokenSeparators: [','], + ajax: { + url: '{{ route('api.users.index') }}', + dataType: 'json', + delay: 250, + processResults: function (data) { + return { + results: data.map(user => ({ id: user.name, text: user.name })) + }; + }, + cache: true + } + }); + + // Prepopulate with old data + OldCoAuthorData.forEach(function (item) { + const option = new Option(item, item, true, true); + $('#co_authors').append(option).trigger('change'); + }); + + $('#co_authors').on('change', function () { + const selectedValues = $(this).val(); + document.getElementById('co_authors_hidden').value = selectedValues.join(', '); + }); + }); + + document.addEventListener('DOMContentLoaded', function () { + const firstAuthorNameSelect = document.getElementById('first_author_name'); + const firstAuthorNameHidden = document.getElementById('first_author_name_hidden'); + const CoAuthorsNameSelect = document.getElementById('co_authors'); + const CoAuthorsNameHidden = document.getElementById('co_authors_hidden'); + + // Populate hidden input with existing values on page load + if (firstAuthorNameSelect) { + const existingValues = $(firstAuthorNameSelect).val(); + firstAuthorNameHidden.value = existingValues ? existingValues.join(', ') : ''; + } + + if (CoAuthorsNameSelect) { + const existingValues = $(CoAuthorsNameSelect).val(); + CoAuthorsNameHidden.value = existingValues ? existingValues.join(', ') : ''; + } + + const form = document.querySelector('form'); + form.addEventListener('submit', function () { + if (firstAuthorNameSelect) { + const selectedValues = $(firstAuthorNameSelect).val(); + firstAuthorNameHidden.value = selectedValues ? selectedValues.join(', ') : ''; + } + if (CoAuthorsNameSelect) { + const selectedValues = $(CoAuthorsNameSelect).val(); + CoAuthorsNameHidden.value = selectedValues ? selectedValues.join(', ') : ''; + } + }); }); @endsection \ No newline at end of file