* @param xmlTvFile XML file path to get EPG from. * @param currentXmlTvId Current XMLTV ID to set initial input value to. * @returns Array of, sequentially: * 1) Container of the picker. * 2) Input field to type at and get choice from. * 3) Datalist containing every option.
(xmlTvFile, currentXmlTvId)
| 1770 | * 3) Datalist containing every option. |
| 1771 | */ |
| 1772 | newXmlTvIdPicker(xmlTvFile, currentXmlTvId) { |
| 1773 | const container = document.createElement('div'); |
| 1774 | const input = document.createElement('input'); |
| 1775 | input.setAttribute('type', 'text'); |
| 1776 | // Initially, set value to '-' if input is empty |
| 1777 | input.value = (currentXmlTvId) ? currentXmlTvId : '-'; |
| 1778 | // When input is focused, remove '-' from it |
| 1779 | input.addEventListener('focus', (evt) => { |
| 1780 | const target = evt.target; |
| 1781 | target.value = (target.value === '-') ? '' : target.value; |
| 1782 | }); |
| 1783 | // When input lose focus or take a value, if it's empty, set value to '-' |
| 1784 | input.addEventListener('blur', setFallbackValue); |
| 1785 | input.addEventListener('change', setFallbackValue); |
| 1786 | function setFallbackValue(evt) { |
| 1787 | const target = evt.target; |
| 1788 | target.value = (target.value) ? target.value : '-'; |
| 1789 | } |
| 1790 | container.appendChild(input); |
| 1791 | const datalist = document.createElement('datalist'); |
| 1792 | const option = document.createElement('option'); |
| 1793 | option.setAttribute('value', '-'); |
| 1794 | option.innerText = '-'; |
| 1795 | datalist.appendChild(option); |
| 1796 | const epg = SERVER['xepg']['xmltvMap'][xmlTvFile]; |
| 1797 | if (epg) { |
| 1798 | const programIds = getOwnObjProps(epg); |
| 1799 | programIds.forEach((programId) => { |
| 1800 | const program = epg[programId]; |
| 1801 | if (program.hasOwnProperty('display-name')) { |
| 1802 | const option = document.createElement('option'); |
| 1803 | option.setAttribute('value', programId); |
| 1804 | option.innerText = program["display-name"]; |
| 1805 | datalist.appendChild(option); |
| 1806 | } |
| 1807 | else { |
| 1808 | const option = document.createElement('option'); |
| 1809 | option.setAttribute('value', programId); |
| 1810 | option.innerText = '-'; |
| 1811 | datalist.appendChild(option); |
| 1812 | } |
| 1813 | }); |
| 1814 | } |
| 1815 | container.appendChild(datalist); |
| 1816 | return [container, input, datalist]; |
| 1817 | } |
| 1818 | newM3uPicker(xmlTvFile, currentXmlTvId) { |
| 1819 | const container = document.createElement('div'); |
| 1820 | const input = document.createElement('input'); |
no test coverage detected