1import { Controller } from "@hotwired/stimulus"; 2import SimplyDropdown from 'libs/simply-dropdown'; 3 4export default class extends Controller { 5 createCourseDropdown(event) { 6 new SimplyDropdown(Hub.$('#search_edition'), 7 `<turbo-frame id='courses-simply-dropdown'> 8 <span class='spinner spinner-right'></span> 9 </turbo-frame>`, { 10 onSelect: (dropdown) => { 11 // Update input text 12 const courseName = dropdown.selected().querySelector('.course-name').innerText 13 dropdown.input.value = courseName 14 15 // Update hidden field 16 const courseId = dropdown.selected().querySelector('.course-id').innerText 17 const hiddenField = Hub.$("#search-editions-course-id") 18 hiddenField.value = courseId 19 20 // Let the field's own turbo-visit action refresh the fields derived from the course 21 hiddenField.dispatchEvent(new Event("change", { bubbles: true })) 22 }, 23 onSearch: (dropdown) => { 24 Turbo.visit('/admin/master_courses/search?q=' + dropdown.input.value, { frame: 'courses-simply-dropdown' }) 25 dropdown.highlight() 26 }, 27 }) 28 } 29 30 createInstructorDropdown(event) { 31 new SimplyDropdown(Hub.$('#search_instructor'), 32 `<turbo-frame id='instructors-simply-dropdown'> 33 <span class='spinner spinner-right'></span> 34 </turbo-frame>`, { 35 onSelect: (dropdown) => { 36 // Update input text 37 const instructorName = dropdown.selected().querySelector('.instructor-name').innerText 38 dropdown.input.value = instructorName 39 40 // Update hidden field 41 const instructorId = dropdown.selected().querySelector('.instructor-id').innerText 42 const hiddenField = Hub.$("#search-editions-instructor-id") 43 hiddenField.value = instructorId 44 }, 45 onSearch: (dropdown) => { 46 Turbo.visit('/admin/users/search?q=' + dropdown.input.value, { frame: 'instructors-simply-dropdown' }) 47 dropdown.highlight() 48 }, 49 }) 50 } 51}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.