Skip to content

Commit

Permalink
added autocomplete to Import CSV show name
Browse files Browse the repository at this point in the history
see #383
  • Loading branch information
RocketMan committed Jan 30, 2023
1 parent 9b2cc66 commit 5fd2c85
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
48 changes: 46 additions & 2 deletions js/playlists.import.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Zookeeper Online
//
// @author Jim Mason <jmason@ibinx.com>
// @copyright Copyright (C) 1997-2022 Jim Mason <jmason@ibinx.com>
// @copyright Copyright (C) 1997-2023 Jim Mason <jmason@ibinx.com>
// @link https://zookeeper.ibinx.com/
// @license GPL-3.0
//
Expand All @@ -20,9 +20,11 @@
// http://www.gnu.org/licenses/
//

/*! Zookeeper Online (C) 1997-2022 Jim Mason <jmason@ibinx.com> | @source: https://zookeeper.ibinx.com/ | @license: magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3.0 */
/*! Zookeeper Online (C) 1997-2023 Jim Mason <jmason@ibinx.com> | @source: https://zookeeper.ibinx.com/ | @license: magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3.0 */

$().ready(function() {
var shownames = null;

/**
* @param time string formatted 'hhmm'
*/
Expand Down Expand Up @@ -50,6 +52,48 @@ $().ready(function() {
$(this).fxtime('seg', 3, hour < 11 || hour > 22 ? 'AM' : 'PM').select();
});

$("#description").on('click', function() {
$(this).autocomplete('search', '');
}).autocomplete({
minLength: 0,
source: function(rq, rs) {
var term = rq.term.toLowerCase();
if(shownames) {
rs(shownames.filter(function(show) {
return show.name.toLowerCase().startsWith(term);
}).map(show => show.name));
return;
}

$.ajax({
type: 'GET',
accept: 'application/json; charset=utf-8',
url: 'api/v1/playlist?filter[user]=self&fields[show]=name,airname,rebroadcast',
}).done(function(response) {
shownames = response.data.map(show => show.attributes)
.sort((a, b) => Intl.Collator().compare(a.name, b.name))
.filter(function(show, pos, shows) {
return !pos ||
show.name.localeCompare(shows[pos - 1].name,
undefined,
{ sensitivity: 'base' });
})
.filter(function(show) {
return !show.rebroadcast;
});

rs(shownames.filter(function(show) {
return show.name.toLowerCase().startsWith(term);
}).map(show => show.name));
});
},
select: function(event, ui) {
var name = ui.item.value;
var show = shownames.find(show => show.name == name);
$("#airname").val(show.airname);
}
});

$("#airname").on('click', function() {
$(this).autocomplete('search', '');
}).autocomplete({
Expand Down
4 changes: 2 additions & 2 deletions ui/Playlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <jmason@ibinx.com>
* @copyright Copyright (C) 1997-2022 Jim Mason <jmason@ibinx.com>
* @copyright Copyright (C) 1997-2023 Jim Mason <jmason@ibinx.com>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -959,7 +959,7 @@ public function emitImportList() {
</div>
<div>
<label>Show Name:</label>
<input type='text' name='description' value='<?php echo stripslashes($description);?>' maxlength='<?php echo IPlaylist::MAX_DESCRIPTION_LENGTH;?>' required>
<input type='text' id='description' name='description' value='<?php echo stripslashes($description);?>' maxlength='<?php echo IPlaylist::MAX_DESCRIPTION_LENGTH;?>' required>
</div>
<div>
<label>DJ:</label>
Expand Down

0 comments on commit 5fd2c85

Please sign in to comment.