mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-30 18:58:39 -04:00
- Implemented `planting_alternate_name.js` to load alternate names for crops in the planting form based on user input. - Added `tab_navigation.js` to manage tab navigation and update the URL hash accordingly. Update map rendering in member and place views - Modified `_map.html.haml` to include a custom marker icon for member maps. - Updated `index.html.haml` and `show.html.haml` to pass `places_map_data` to the map sections. Refactor asset management in Rails application - Removed Sprockets from the application configuration and adjusted asset paths. - Updated asset precompilation settings and removed deprecated asset configurations from environment files. - Added new build scripts for CSS and updated package dependencies in `package.json` for Bootstrap, Chart.js, and others. Ensure React and CSS bundles are built before running tests - Updated `react_bundle.rb` to check for the existence of both JavaScript and CSS bundles and build them if missing.
58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
// The full screen search a phone gets from the magnifier in the top bar: put
|
|
// the cursor in the field when it opens, and list the crops that match as the
|
|
// member types.
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
var panel = document.getElementById('phoneSearch');
|
|
if (!panel) return;
|
|
|
|
var field = document.getElementById('phone-term');
|
|
var results = panel.querySelector('.phone-search-results');
|
|
var list = results.querySelector('.phone-search-list');
|
|
var all = results.querySelector('.phone-search-all');
|
|
var template = document.getElementById('phone-search-row');
|
|
var searchUrl = results.getAttribute('data-url');
|
|
var allLabel = results.getAttribute('data-all-label');
|
|
var allUrl = panel.querySelector('form').getAttribute('action');
|
|
var timer;
|
|
var latest = 0;
|
|
|
|
function show(term, crops) {
|
|
list.replaceChildren();
|
|
crops.slice(0, 8).forEach(function(crop) {
|
|
var row = template.content.firstElementChild.cloneNode(true);
|
|
row.href = '/crops/' + encodeURIComponent(crop.slug);
|
|
row.querySelector('span').textContent = crop.name;
|
|
list.appendChild(row);
|
|
});
|
|
all.href = allUrl + '?term=' + encodeURIComponent(term);
|
|
all.querySelector('span').textContent = allLabel.replace('__term__', term);
|
|
results.hidden = false;
|
|
}
|
|
|
|
function search(term) {
|
|
var request = ++latest;
|
|
if (!term) {
|
|
results.hidden = true;
|
|
return;
|
|
}
|
|
fetch(searchUrl + '?term=' + encodeURIComponent(term), {headers: {Accept: 'application/json'}})
|
|
.then(function(response) { return response.json(); })
|
|
.then(function(crops) {
|
|
if (request === latest) show(term, crops);
|
|
})
|
|
.catch(function() {});
|
|
}
|
|
|
|
field.addEventListener('input', function() {
|
|
clearTimeout(timer);
|
|
var term = field.value.trim();
|
|
timer = setTimeout(function() { search(term); }, 200);
|
|
});
|
|
|
|
panel.addEventListener('shown.bs.offcanvas', function() { field.focus(); });
|
|
panel.addEventListener('hidden.bs.offcanvas', function() {
|
|
field.value = '';
|
|
search('');
|
|
});
|
|
});
|