Refactor seasonal rule HTML generation for improved maintainability
This commit is contained in:
@@ -685,108 +685,84 @@
|
|||||||
var endMonth = data ? (data.EndMonth !== undefined ? data.EndMonth : (data.endMonth !== undefined ? data.endMonth : 1)) : 1;
|
var endMonth = data ? (data.EndMonth !== undefined ? data.EndMonth : (data.endMonth !== undefined ? data.endMonth : 1)) : 1;
|
||||||
var theme = data ? (data.Theme || data.theme || 'none') : 'none';
|
var theme = data ? (data.Theme || data.theme || 'none') : 'none';
|
||||||
|
|
||||||
// Helper to generate options
|
|
||||||
function getOptions(items, selected) {
|
|
||||||
var html = '';
|
|
||||||
items.forEach(function(item) {
|
|
||||||
var val = item.val || item;
|
|
||||||
var txt = item.name || item;
|
|
||||||
var isSelected = val == selected ? 'selected' : '';
|
|
||||||
html += '<option value="' + val + '" ' + isSelected + '>' + txt + '</option>';
|
|
||||||
});
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
|
|
||||||
var days = [];
|
var days = [];
|
||||||
for (var i = 1; i <= 31; i++) days.push(i);
|
for (var i = 1; i <= 31; i++) days.push(i);
|
||||||
|
|
||||||
var months = [
|
var months = [
|
||||||
{ val: 1, name: 'Jan' },
|
{ v: 1, n: 'Jan' }, { v: 2, n: 'Feb' }, { v: 3, n: 'Mar' }, { v: 4, n: 'Apr' },
|
||||||
{ val: 2, name: 'Feb' },
|
{ v: 5, n: 'May' }, { v: 6, n: 'Jun' }, { v: 7, n: 'Jul' }, { v: 8, n: 'Aug' },
|
||||||
{ val: 3, name: 'Mar' },
|
{ v: 9, n: 'Sep' }, { v: 10, n: 'Oct' }, { v: 11, n: 'Nov' }, { v: 12, n: 'Dec' }
|
||||||
{ val: 4, name: 'Apr' },
|
|
||||||
{ val: 5, name: 'May' },
|
|
||||||
{ val: 6, name: 'Jun' },
|
|
||||||
{ val: 7, name: 'Jul' },
|
|
||||||
{ val: 8, name: 'Aug' },
|
|
||||||
{ val: 9, name: 'Sep' },
|
|
||||||
{ val: 10, name: 'Oct' },
|
|
||||||
{ val: 11, name: 'Nov' },
|
|
||||||
{ val: 12, name: 'Dec' }
|
|
||||||
];
|
];
|
||||||
|
|
||||||
div.innerHTML = `
|
// Build select HTML via string concatenation to avoid Jellyfin's ${} localization processing
|
||||||
<div class="seasonal-rule-header">
|
function mkSelect(val, opts, cls) {
|
||||||
<div style="font-weight: bold; font-size: 1.1em;" class="rule-title"></div>
|
var h = '<select class="emby-select emby-select-withcolor ' + cls + '" style="width: 100%; -webkit-appearance: menulist; appearance: menulist;">';
|
||||||
<div class="rule-actions">
|
opts.forEach(function(o) {
|
||||||
<button type="button" is="paper-icon-button-light" class="btn-move-up" title="Move Up"><i class="material-icons">arrow_upward</i></button>
|
var v = o.v || o;
|
||||||
<button type="button" is="paper-icon-button-light" class="btn-move-down" title="Move Down"><i class="material-icons">arrow_downward</i></button>
|
var n = o.n || o;
|
||||||
<button type="button" is="paper-icon-button-light" class="btn-remove" title="Remove"><i class="material-icons">delete</i></button>
|
h += '<option value="' + v + '" ' + (v == val ? 'selected' : '') + '>' + n + '</option>';
|
||||||
</div>
|
});
|
||||||
</div>
|
h += '</select>';
|
||||||
<div class="seasonal-rule-content">
|
return h;
|
||||||
<div class="inputContainer" style="margin:0;">
|
}
|
||||||
<label class="inputLabel">Name</label>
|
|
||||||
<input is="emby-input" class="rule-name" onchange="SeasonalsConfigPage.updateRuleTitles();" />
|
|
||||||
</div>
|
|
||||||
<div class="date-range-group">
|
|
||||||
<div class="selectContainer" style="margin:0; flex: 1;">
|
|
||||||
<label class="selectLabel">Start Day</label>
|
|
||||||
<select class="emby-select emby-select-withcolor rule-start-day" style="width: 100%; -webkit-appearance: menulist; appearance: menulist;">
|
|
||||||
${getOptions(days, startDay)}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="selectContainer" style="margin:0; flex: 1;">
|
|
||||||
<label class="selectLabel">Month</label>
|
|
||||||
<select class="emby-select emby-select-withcolor rule-start-month" style="width: 100%; -webkit-appearance: menulist; appearance: menulist;">
|
|
||||||
${getOptions(months, startMonth)}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="date-range-group">
|
|
||||||
<div class="selectContainer" style="margin:0; flex: 1;">
|
|
||||||
<label class="selectLabel">End Day</label>
|
|
||||||
<select class="emby-select emby-select-withcolor rule-end-day" style="width: 100%; -webkit-appearance: menulist; appearance: menulist;">
|
|
||||||
${getOptions(days, endDay)}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="selectContainer" style="margin:0; flex: 1;">
|
|
||||||
<label class="selectLabel">Month</label>
|
|
||||||
<select class="emby-select emby-select-withcolor rule-end-month" style="width: 100%; -webkit-appearance: menulist; appearance: menulist;">
|
|
||||||
${getOptions(months, endMonth)}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="selectContainer" style="margin:0;">
|
div.innerHTML =
|
||||||
<label class="selectLabel">Theme</label>
|
'<div class="seasonal-rule-header">' +
|
||||||
<select is="emby-select" class="rule-theme" style="width: 100%;">
|
' <div style="font-weight: bold; font-size: 1.1em;" class="rule-title"></div>' +
|
||||||
<option value="none">None</option>
|
' <div class="rule-actions">' +
|
||||||
<option value="snowflakes">Snowflakes</option>
|
' <button type="button" is="paper-icon-button-light" class="btn-move-up" title="Move Up"><i class="material-icons">arrow_upward</i></button>' +
|
||||||
<option value="snowfall">Snowfall</option>
|
' <button type="button" is="paper-icon-button-light" class="btn-move-down" title="Move Down"><i class="material-icons">arrow_downward</i></button>' +
|
||||||
<option value="snowstorm">Snowstorm</option>
|
' <button type="button" is="paper-icon-button-light" class="btn-remove" title="Remove"><i class="material-icons">delete</i></button>' +
|
||||||
<option value="fireworks">Fireworks</option>
|
' </div>' +
|
||||||
<option value="halloween">Halloween</option>
|
'</div>' +
|
||||||
<option value="hearts">Hearts</option>
|
'<div class="seasonal-rule-content">' +
|
||||||
<option value="christmas">Christmas</option>
|
' <div class="inputContainer" style="margin:0;">' +
|
||||||
<option value="santa">Santa</option>
|
' <label class="inputLabel">Name</label>' +
|
||||||
<option value="autumn">Autumn</option>
|
' <input is="emby-input" class="rule-name" onchange="SeasonalsConfigPage.updateRuleTitles();" />' +
|
||||||
<option value="easter">Easter</option>
|
' </div>' +
|
||||||
<option value="resurrection">Resurrection</option>
|
' <div class="date-range-group">' +
|
||||||
</select>
|
' <div class="selectContainer" style="margin:0; flex: 1;">' +
|
||||||
</div>
|
' <label class="selectLabel">Start Day</label>' +
|
||||||
</div>
|
mkSelect(startDay, days, 'rule-start-day') +
|
||||||
`;
|
' </div>' +
|
||||||
|
' <div class="selectContainer" style="margin:0; flex: 1;">' +
|
||||||
|
' <label class="selectLabel">Month</label>' +
|
||||||
|
mkSelect(startMonth, months, 'rule-start-month') +
|
||||||
|
' </div>' +
|
||||||
|
' </div>' +
|
||||||
|
' <div class="date-range-group">' +
|
||||||
|
' <div class="selectContainer" style="margin:0; flex: 1;">' +
|
||||||
|
' <label class="selectLabel">End Day</label>' +
|
||||||
|
mkSelect(endDay, days, 'rule-end-day') +
|
||||||
|
' </div>' +
|
||||||
|
' <div class="selectContainer" style="margin:0; flex: 1;">' +
|
||||||
|
' <label class="selectLabel">Month</label>' +
|
||||||
|
mkSelect(endMonth, months, 'rule-end-month') +
|
||||||
|
' </div>' +
|
||||||
|
' </div>' +
|
||||||
|
' <div class="selectContainer" style="margin:0;">' +
|
||||||
|
' <label class="selectLabel">Theme</label>' +
|
||||||
|
' <select class="emby-select emby-select-withcolor rule-theme" style="width: 100%; -webkit-appearance: menulist; appearance: menulist;">' +
|
||||||
|
' <option value="none">None</option>' +
|
||||||
|
' <option value="snowflakes">Snowflakes</option>' +
|
||||||
|
' <option value="snowfall">Snowfall</option>' +
|
||||||
|
' <option value="snowstorm">Snowstorm</option>' +
|
||||||
|
' <option value="fireworks">Fireworks</option>' +
|
||||||
|
' <option value="halloween">Halloween</option>' +
|
||||||
|
' <option value="hearts">Hearts</option>' +
|
||||||
|
' <option value="christmas">Christmas</option>' +
|
||||||
|
' <option value="santa">Santa</option>' +
|
||||||
|
' <option value="autumn">Autumn</option>' +
|
||||||
|
' <option value="easter">Easter</option>' +
|
||||||
|
' <option value="resurrection">Resurrection</option>' +
|
||||||
|
' </select>' +
|
||||||
|
' </div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
container.appendChild(div);
|
container.appendChild(div);
|
||||||
|
|
||||||
// Set values programmatically
|
// Set values programmatically
|
||||||
div.querySelector('.rule-name').value = name;
|
div.querySelector('.rule-name').value = name;
|
||||||
div.querySelector('.rule-start-day').value = startDay;
|
|
||||||
div.querySelector('.rule-start-month').value = startMonth;
|
|
||||||
div.querySelector('.rule-end-day').value = endDay;
|
|
||||||
div.querySelector('.rule-end-month').value = endMonth;
|
|
||||||
div.querySelector('.rule-theme').value = theme;
|
div.querySelector('.rule-theme').value = theme;
|
||||||
|
|
||||||
// Bind events
|
// Bind events
|
||||||
|
|||||||
Reference in New Issue
Block a user