MCPcopy Create free account
hub / github.com/Threadfin/Threadfin / newXmlTvIdPicker

Method newXmlTvIdPicker

ts/menu_ts.ts:2161–2216  ·  view source on GitHub ↗

* @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: string, currentXmlTvId: string)

Source from the content-addressed store, hash-verified

2159 * 3) Datalist containing every option.
2160 */
2161 newXmlTvIdPicker(xmlTvFile: string, currentXmlTvId: string): [HTMLDivElement, HTMLInputElement, HTMLDataListElement] {
2162 const container = document.createElement('div');
2163 const input = document.createElement('input');
2164 input.setAttribute('type', 'text');
2165
2166 // Initially, set value to '-' if input is empty
2167 input.value = (currentXmlTvId) ? currentXmlTvId : '-';
2168
2169 // When input is focused, remove '-' from it
2170 input.addEventListener('focus', (evt) => {
2171 const target = evt.target as HTMLInputElement;
2172 target.value = (target.value === '-') ? '' : target.value;
2173 });
2174
2175 // When input lose focus or take a value, if it's empty, set value to '-'
2176 input.addEventListener('blur', setFallbackValue);
2177 input.addEventListener('change', setFallbackValue);
2178 function setFallbackValue(evt: Event) {
2179 const target = evt.target as HTMLInputElement;
2180 target.value = (target.value) ? target.value : '-';
2181 }
2182
2183 container.appendChild(input);
2184
2185 const datalist = document.createElement('datalist');
2186
2187 const option = document.createElement('option');
2188 option.setAttribute('value', '-');
2189 option.innerText = '-';
2190 datalist.appendChild(option);
2191
2192 const epg: Object = SERVER['xepg']['xmltvMap'][xmlTvFile];
2193
2194 if (epg) {
2195 const programIds = getOwnObjProps(epg);
2196
2197 programIds.forEach((programId) => {
2198 const program: Object = epg[programId];
2199 if (program.hasOwnProperty('display-name')) {
2200 const option = document.createElement('option');
2201 option.setAttribute('value', programId);
2202 option.innerText = program["display-name"];
2203 datalist.appendChild(option);
2204 } else {
2205 const option = document.createElement('option');
2206 option.setAttribute('value', programId);
2207 option.innerText = '-';
2208 datalist.appendChild(option);
2209 }
2210 });
2211 }
2212
2213 container.appendChild(datalist);
2214
2215 return [container, input, datalist];
2216 }
2217
2218 newM3uPicker(xmlTvFile: string, currentXmlTvId: string): [HTMLDivElement, HTMLInputElement, HTMLDataListElement] {

Callers 2

openPopUpFunction · 0.95
setXmltvChannelFunction · 0.95

Calls 1

getOwnObjPropsFunction · 0.70

Tested by

no test coverage detected