jellyfin-web/dashboard-ui/scripts/livetvseriestimers.js

138 lines
3.9 KiB
JavaScript
Raw Normal View History

2016-06-21 21:39:47 -07:00
define(['datetime', 'paper-icon-button-light', 'emby-button', 'listViewStyle'], function (datetime) {
2016-05-15 10:11:26 -07:00
var query = {
SortBy: "SortName",
SortOrder: "Ascending"
};
function deleteSeriesTimer(context, id) {
require(['confirm'], function (confirm) {
confirm(Globalize.translate('MessageConfirmSeriesCancellation'), Globalize.translate('HeaderConfirmSeriesCancellation')).then(function () {
Dashboard.showLoadingMsg();
ApiClient.cancelLiveTvSeriesTimer(id).then(function () {
require(['toast'], function (toast) {
toast(Globalize.translate('MessageSeriesCancelled'));
});
reload(context);
});
});
});
}
function renderTimers(context, timers) {
var html = '';
if (timers.length) {
html += '<div class="paperList">';
}
for (var i = 0, length = timers.length; i < length; i++) {
var timer = timers[i];
2016-06-21 21:39:47 -07:00
html += '<div class="listItem">';
2016-05-15 10:11:26 -07:00
2016-06-21 21:39:47 -07:00
html += '<button type="button" is="emby-button" class="fab mini autoSize blue" item-icon><i class="md-icon">live_tv</i></button>';
2016-05-15 10:11:26 -07:00
2016-06-26 21:19:10 -07:00
html += '<div class="listItemBody three-line">';
2016-05-15 10:11:26 -07:00
html += '<a class="clearLink" href="livetvseriestimer.html?id=' + timer.Id + '">';
2016-06-21 21:39:47 -07:00
html += '<h3>';
2016-05-15 10:11:26 -07:00
html += timer.Name;
2016-06-21 21:39:47 -07:00
html += '</h3>';
2016-05-15 10:11:26 -07:00
2016-06-21 21:39:47 -07:00
html += '<div class="secondary">';
2016-05-15 10:11:26 -07:00
if (timer.DayPattern) {
html += timer.DayPattern;
}
else {
var days = timer.Days || [];
html += days.join(', ');
}
if (timer.RecordAnyTime) {
html += ' - ' + Globalize.translate('LabelAnytime');
} else {
html += ' - ' + datetime.getDisplayTime(timer.StartDate);
}
html += '</div>';
2016-06-21 21:39:47 -07:00
html += '<div class="secondary">';
2016-05-15 10:11:26 -07:00
if (timer.RecordAnyChannel) {
html += Globalize.translate('LabelAllChannels');
}
else if (timer.ChannelId) {
html += timer.ChannelName;
}
html += '</div>';
2016-06-21 21:39:47 -07:00
html += '</a>';
html += '</div>';
2016-05-15 10:11:26 -07:00
2016-06-18 13:31:22 -07:00
html += '<button type="button" is="paper-icon-button-light" data-seriestimerid="' + timer.Id + '" title="' + Globalize.translate('ButtonCancelSeries') + '" class="btnCancelSeries autoSize"><i class="md-icon">cancel</i></button>';
2016-05-15 10:11:26 -07:00
2016-06-21 21:39:47 -07:00
html += '</div>';
2016-05-15 10:11:26 -07:00
}
if (timers.length) {
html += '</div>';
}
2016-06-06 18:55:16 -07:00
var elem = context.querySelector('#items');
elem.innerHTML = html;
2016-05-15 10:11:26 -07:00
if (timers.length) {
elem.querySelector('.paperList').addEventListener('click', function (e) {
2016-05-15 10:11:26 -07:00
var btnCancelSeries = parentWithClass(e.target, 'btnCancelSeries');
if (btnCancelSeries) {
deleteSeriesTimer(context, btnCancelSeries.getAttribute('data-seriestimerid'));
}
});
}
2016-05-15 10:11:26 -07:00
Dashboard.hideLoadingMsg();
}
2016-06-06 18:55:16 -07:00
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
2016-05-15 10:11:26 -07:00
function reload(context) {
Dashboard.showLoadingMsg();
ApiClient.getLiveTvSeriesTimers(query).then(function (result) {
2016-06-21 21:39:47 -07:00
renderTimers(context, result.Items);
2016-05-15 10:11:26 -07:00
});
}
return function (view, params, tabContent) {
var self = this;
self.renderTab = function () {
reload(tabContent);
};
};
});