-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7b6f27
commit 34eb928
Showing
9 changed files
with
194 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,50 @@ | ||
const speciesAutoComplete = (inputDiv, additionalFilters = "") => { | ||
return new Promise(function (resolve, reject) { | ||
inputDiv.autocomplete({ | ||
source: function (request, response) { | ||
$.ajax({ | ||
url: ( | ||
`/species-autocomplete/?` + | ||
`term=${encodeURIComponent(request.term)}` + | ||
`${additionalFilters}` | ||
), | ||
type: 'get', | ||
dataType: 'json', | ||
success: function (data) { | ||
response($.map(data, function (item) { | ||
return { | ||
label: item.species, | ||
value: item.id | ||
} | ||
})); | ||
} | ||
}); | ||
|
||
const parseAdditionalFilters = (filterString) => { | ||
const params = new URLSearchParams(filterString); | ||
let filterObject = {}; | ||
for (const [key, value] of params.entries()) { | ||
filterObject[key] = value; | ||
} | ||
return filterObject; | ||
}; | ||
return new Promise((resolve, reject) => { | ||
// Ensure inputDiv is a jQuery object | ||
const $inputDiv = $(inputDiv); | ||
|
||
if (typeof $inputDiv.select2 !== 'function') { | ||
console.error('Select2 is not loaded.'); | ||
return reject(new Error('Select2 is not loaded.')); | ||
} | ||
|
||
const filters = parseAdditionalFilters(additionalFilters); | ||
|
||
$inputDiv.select2({ | ||
ajax: { | ||
url: '/species-autocomplete/', | ||
dataType: 'json', | ||
delay: 250, | ||
data: (params) => ({ | ||
term: params.term, | ||
...filters | ||
}), | ||
processResults: (data) => ({ | ||
results: data.map(item => ({ | ||
id: item.id, | ||
text: item.species | ||
})) | ||
}), | ||
cache: true | ||
}, | ||
minLength: 3, | ||
open: function (event, ui) { | ||
setTimeout(function () { | ||
$('.ui-autocomplete').css('z-index', 9999) | ||
}, 0); | ||
}, | ||
select: function (e, u) { | ||
e.preventDefault(); | ||
console.log('clicked'); | ||
inputDiv.val(u.item.label) | ||
resolve(u.item.value) | ||
} | ||
}) | ||
}) | ||
} | ||
minimumInputLength: 3, | ||
templateResult: (item) => item.text, | ||
templateSelection: (item) => item.text | ||
}).on('select2:select', (e) => { | ||
resolve(e.params.data.id); | ||
}).on('select2:open', () => { | ||
setTimeout(() => { | ||
$('.select2-results').css('z-index', 9999); | ||
}, 0); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,9 +411,13 @@ <h5 class="modal-title">Add New Taxon</h5> | |
</thead> | ||
<tbody> | ||
<tr> | ||
<td><input type="text" class="form-control new-taxon-family-name" placeholder="Family"> | ||
<input type="hidden" class="new-taxon-family-id"></td> | ||
<td><input type="text" class="form-control" placeholder="Taxon Name" id="new-taxon-name"></td> | ||
<td> | ||
<select name="newTaxonFamilyName" class="new-taxon-family-name form-control" data-add-new-tag="false" style="width: 100%"></select> | ||
<input type="hidden" class="new-taxon-family-id"> | ||
</td> | ||
<td> | ||
<input type="text" class="form-control" placeholder="Taxon Name" id="new-taxon-name"> | ||
</td> | ||
<td> | ||
|
||
<div> | ||
|
@@ -773,7 +777,7 @@ <h5 class="modal-title" id="statusModalLabel">Status</h5> | |
</script> | ||
<script src="{% static "js/libs/jquery/jquery-3.3.1.min.js" %}"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/underscore-umd-min.js"></script> | ||
<script src="{% static "js/libs/jquery-ui-1.12.1/jquery-ui.min.js" %}"></script> | ||
<script src="https://code.jquery.com/ui/1.13.3/jquery-ui.js"></script> | ||
|
||
<script src="https://cdn.datatables.net/v/dt/jq-3.7.0/dt-2.0.8/fc-5.0.1/fh-4.0.1/datatables.min.js"></script> | ||
<script src="{% static "library/popper.js/1.11.0/popper.min.js" %}" crossorigin="anonymous"></script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.