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

1393 lines
43 KiB
JavaScript
Raw Normal View History

2013-02-20 18:33:05 -07:00
var DashboardPage = {
2014-01-22 13:46:01 -07:00
newsStartIndex: 0,
2013-02-20 18:33:05 -07:00
onPageShow: function () {
2013-12-24 11:37:29 -07:00
var page = this;
2015-05-19 12:15:40 -07:00
var apiClient = ApiClient;
if (!apiClient) {
return;
}
2015-01-18 12:53:34 -07:00
if (Dashboard.lastSystemInfo) {
Dashboard.setPageTitle(Dashboard.lastSystemInfo.ServerName);
}
2014-01-22 13:46:01 -07:00
DashboardPage.newsStartIndex = 0;
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
2013-12-24 11:37:29 -07:00
DashboardPage.pollForInfo(page);
2015-05-19 12:15:40 -07:00
DashboardPage.startInterval(apiClient);
2014-04-07 21:17:18 -07:00
2015-12-23 10:46:01 -07:00
Events.on(apiClient, 'websocketmessage', DashboardPage.onWebSocketMessage);
Events.on(apiClient, 'websocketopen', DashboardPage.onWebSocketOpen);
2013-02-20 18:33:05 -07:00
DashboardPage.lastAppUpdateCheck = null;
DashboardPage.lastPluginUpdateCheck = null;
2013-07-07 08:53:26 -07:00
2015-12-14 08:43:03 -07:00
Dashboard.getPluginSecurityInfo().then(function (pluginSecurityInfo) {
2013-07-07 08:53:26 -07:00
2014-06-21 22:52:31 -07:00
DashboardPage.renderSupporterIcon(page, pluginSecurityInfo);
2013-07-07 08:53:26 -07:00
});
2014-01-18 14:52:01 -07:00
2014-03-25 14:13:55 -07:00
DashboardPage.reloadSystemInfo(page);
2014-01-18 14:52:01 -07:00
DashboardPage.reloadNews(page);
2014-05-13 17:46:45 -07:00
DashboardPage.sessionUpdateTimer = setInterval(DashboardPage.refreshSessionsLocally, 60000);
2014-08-10 15:13:17 -07:00
$('.activityItems', page).activityLogList();
2015-02-06 20:25:23 -07:00
2015-09-29 21:19:45 -07:00
$('.swaggerLink', page).attr('href', apiClient.getUrl('swagger-ui/index.html', {
api_key: ApiClient.accessToken()
}));
2014-08-10 15:13:17 -07:00
},
onPageHide: function () {
var page = this;
$('.activityItems', page).activityLogList('destroy');
2015-05-19 12:15:40 -07:00
var apiClient = ApiClient;
2015-05-20 09:28:55 -07:00
if (apiClient) {
2015-12-23 10:46:01 -07:00
Events.off(apiClient, 'websocketmessage', DashboardPage.onWebSocketMessage);
Events.off(apiClient, 'websocketopen', DashboardPage.onWebSocketOpen);
2015-05-20 09:28:55 -07:00
DashboardPage.stopInterval(apiClient);
}
2014-08-10 15:13:17 -07:00
if (DashboardPage.sessionUpdateTimer) {
clearInterval(DashboardPage.sessionUpdateTimer);
}
2014-05-13 17:46:45 -07:00
},
2014-07-10 21:27:46 -07:00
renderPaths: function (page, systemInfo) {
$('#cachePath', page).html(systemInfo.CachePath);
$('#logPath', page).html(systemInfo.LogPath);
$('#transcodingTemporaryPath', page).html(systemInfo.TranscodingTempPath);
$('#metadataPath', page).html(systemInfo.InternalMetadataPath);
},
2014-05-13 17:46:45 -07:00
refreshSessionsLocally: function () {
var list = DashboardPage.sessionsList;
if (list) {
DashboardPage.renderActiveConnections($.mobile.activePage, list);
}
2014-01-18 14:52:01 -07:00
},
2014-03-25 14:13:55 -07:00
reloadSystemInfo: function (page) {
2015-12-14 08:43:03 -07:00
ApiClient.getSystemInfo().then(function (systemInfo) {
2014-03-25 14:13:55 -07:00
2015-01-18 12:53:34 -07:00
Dashboard.setPageTitle(systemInfo.ServerName);
2014-03-25 14:13:55 -07:00
Dashboard.updateSystemInfo(systemInfo);
2014-06-17 09:03:14 -07:00
$('#appVersionNumber', page).html(Globalize.translate('LabelVersionNumber').replace('{0}', systemInfo.Version));
2014-03-25 14:13:55 -07:00
if (systemInfo.SupportsHttps) {
2015-01-18 21:29:57 -07:00
$('#ports', page).html(Globalize.translate('LabelRunningOnPorts', '<b>' + systemInfo.HttpServerPortNumber + '</b>', '<b>' + systemInfo.HttpsPortNumber + '</b>'));
} else {
$('#ports', page).html(Globalize.translate('LabelRunningOnPort', '<b>' + systemInfo.HttpServerPortNumber + '</b>'));
2015-01-17 12:59:06 -07:00
}
2015-12-14 08:43:03 -07:00
if (systemInfo.CanSelfRestart) {
$('.btnRestartContainer', page).removeClass('hide');
} else {
$('.btnRestartContainer', page).addClass('hide');
}
2014-03-25 14:13:55 -07:00
DashboardPage.renderUrls(page, systemInfo);
DashboardPage.renderPendingInstallations(page, systemInfo);
if (systemInfo.CanSelfUpdate) {
$('#btnUpdateApplicationContainer', page).show();
$('#btnManualUpdateContainer', page).hide();
} else {
$('#btnUpdateApplicationContainer', page).hide();
$('#btnManualUpdateContainer', page).show();
}
2014-07-10 21:27:46 -07:00
DashboardPage.renderPaths(page, systemInfo);
2014-03-25 14:13:55 -07:00
DashboardPage.renderHasPendingRestart(page, systemInfo.HasPendingRestart);
});
},
2014-01-18 14:52:01 -07:00
reloadNews: function (page) {
2014-01-22 13:46:01 -07:00
var query = {
StartIndex: DashboardPage.newsStartIndex,
2015-09-29 21:19:45 -07:00
Limit: 7
2014-01-22 13:46:01 -07:00
};
2014-01-18 14:52:01 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getProductNews(query).then(function (result) {
2014-01-18 14:52:01 -07:00
var html = result.Items.map(function (item) {
var itemHtml = '';
2015-09-29 21:19:45 -07:00
itemHtml += '<a class="clearLink" href="' + item.Link + '" target="_blank">';
itemHtml += '<paper-icon-item>';
2014-01-18 15:47:44 -07:00
2015-10-26 11:55:46 -07:00
itemHtml += '<paper-fab mini class="blue" icon="dvr" item-icon></paper-fab>';
2015-09-29 21:19:45 -07:00
itemHtml += '<paper-item-body three-line>';
itemHtml += '<div>';
itemHtml += item.Title;
itemHtml += '</div>';
itemHtml += '<div secondary>';
2014-01-18 15:47:44 -07:00
var date = parseISO8601Date(item.Date, { toLocal: true });
2015-09-29 21:19:45 -07:00
itemHtml += date.toLocaleDateString();
itemHtml += '</div>';
2014-01-18 15:47:44 -07:00
2015-09-29 21:19:45 -07:00
itemHtml += '<div secondary>';
itemHtml += item.Description;
2014-01-18 14:52:01 -07:00
itemHtml += '</div>';
2015-09-29 21:19:45 -07:00
itemHtml += '</paper-item-body>';
itemHtml += '</paper-icon-item>';
itemHtml += '</a>';
2014-01-18 14:52:01 -07:00
return itemHtml;
});
2014-01-22 13:46:01 -07:00
var pagingHtml = '';
pagingHtml += '<div>';
2015-06-18 11:29:44 -07:00
pagingHtml += LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false
});
2014-01-22 13:46:01 -07:00
pagingHtml += '</div>';
2014-01-22 13:46:01 -07:00
html = html.join('') + pagingHtml;
var elem = $('.latestNewsItems', page).html(html).trigger('create');
$('.btnNextPage', elem).on('click', function () {
DashboardPage.newsStartIndex += query.Limit;
DashboardPage.reloadNews(page);
});
$('.btnPreviousPage', elem).on('click', function () {
DashboardPage.newsStartIndex -= query.Limit;
DashboardPage.reloadNews(page);
});
2014-01-18 14:52:01 -07:00
});
2013-02-20 18:33:05 -07:00
},
2015-05-19 12:15:40 -07:00
startInterval: function (apiClient) {
2013-02-20 18:33:05 -07:00
2015-05-19 12:15:40 -07:00
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("SessionsStart", "0,1500");
apiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "0,1000");
2013-02-20 18:33:05 -07:00
}
},
2015-05-19 12:15:40 -07:00
stopInterval: function (apiClient) {
2013-02-20 18:33:05 -07:00
2015-05-19 12:15:40 -07:00
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("SessionsStop");
apiClient.sendWebSocketMessage("ScheduledTasksInfoStop");
2013-02-20 18:33:05 -07:00
}
},
onWebSocketMessage: function (e, msg) {
2013-12-24 11:37:29 -07:00
var page = $.mobile.activePage;
2014-03-25 14:13:55 -07:00
if (msg.MessageType == "Sessions") {
2013-12-24 11:37:29 -07:00
DashboardPage.renderInfo(page, msg.Data);
2013-02-20 18:33:05 -07:00
}
2014-03-25 14:13:55 -07:00
else if (msg.MessageType == "RestartRequired") {
DashboardPage.renderHasPendingRestart(page, true);
}
else if (msg.MessageType == "ServerShuttingDown") {
2014-06-04 09:15:44 -07:00
DashboardPage.renderHasPendingRestart(page, true);
2014-03-25 14:13:55 -07:00
}
else if (msg.MessageType == "ServerRestarting") {
2014-06-04 09:15:44 -07:00
DashboardPage.renderHasPendingRestart(page, true);
2014-03-25 14:13:55 -07:00
}
else if (msg.MessageType == "ScheduledTasksInfo") {
var tasks = msg.Data;
DashboardPage.renderRunningTasks(page, tasks);
}
2014-06-07 14:06:01 -07:00
else if (msg.MessageType == "PackageInstalling" || msg.MessageType == "PackageInstallationCompleted") {
DashboardPage.pollForInfo(page, true);
DashboardPage.reloadSystemInfo(page);
}
2013-02-20 18:33:05 -07:00
},
2014-05-31 07:30:59 -07:00
onWebSocketOpen: function () {
2013-02-20 18:33:05 -07:00
2015-05-19 12:15:40 -07:00
var apiClient = this;
DashboardPage.startInterval(apiClient);
2013-02-20 18:33:05 -07:00
},
2014-06-07 14:06:01 -07:00
pollForInfo: function (page, forceUpdate) {
2013-12-24 11:37:29 -07:00
2015-05-19 12:15:40 -07:00
var apiClient = window.ApiClient;
if (!apiClient) {
return;
}
2015-12-14 08:43:03 -07:00
apiClient.getSessions().then(function (sessions) {
2014-04-07 21:17:18 -07:00
2014-06-07 14:06:01 -07:00
DashboardPage.renderInfo(page, sessions, forceUpdate);
2013-12-24 11:37:29 -07:00
});
2015-12-14 08:43:03 -07:00
apiClient.getScheduledTasks().then(function (tasks) {
2014-05-31 07:30:59 -07:00
DashboardPage.renderRunningTasks(page, tasks);
});
2013-02-20 18:33:05 -07:00
},
2014-06-07 14:06:01 -07:00
renderInfo: function (page, sessions, forceUpdate) {
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
DashboardPage.renderActiveConnections(page, sessions);
2014-06-07 14:06:01 -07:00
DashboardPage.renderPluginUpdateInfo(page, forceUpdate);
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
},
2014-03-25 14:13:55 -07:00
renderActiveConnections: function (page, sessions) {
2013-02-20 18:33:05 -07:00
var html = '';
2014-05-13 17:46:45 -07:00
DashboardPage.sessionsList = sessions;
2014-04-14 20:54:52 -07:00
var parentElement = $('.activeDevices', page);
2013-02-20 18:33:05 -07:00
2014-07-26 10:30:15 -07:00
$('.card', parentElement).addClass('deadSession');
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
for (var i = 0, length = sessions.length; i < length; i++) {
2013-02-20 18:33:05 -07:00
var session = sessions[i];
2013-02-20 18:33:05 -07:00
var rowId = 'session' + session.Id;
2013-02-20 18:33:05 -07:00
2014-03-14 21:14:07 -07:00
var elem = $('#' + rowId, page);
if (elem.length) {
DashboardPage.updateSession(elem, session);
continue;
}
var nowPlayingItem = session.NowPlayingItem;
2014-08-01 19:34:45 -07:00
var className = nowPlayingItem ? 'card activeSession' : 'card activeSession';
if (session.TranscodingInfo && session.TranscodingInfo.CompletionPercentage) {
className += ' transcodingSession';
}
2014-04-17 22:03:01 -07:00
html += '<div class="' + className + '" id="' + rowId + '">';
2013-02-20 18:33:05 -07:00
2014-07-26 10:30:15 -07:00
html += '<div class="cardBox">';
html += '<div class="cardScalable">';
html += '<div class="cardPadder"></div>';
html += '<div class="cardContent">';
2014-04-14 20:54:52 -07:00
html += '<div class="sessionNowPlayingContent"';
var imgUrl = DashboardPage.getNowPlayingImageUrl(nowPlayingItem);
if (imgUrl) {
html += ' data-src="' + imgUrl + '" style="display:inline-block;background-image:url(\'' + imgUrl + '\');"';
}
html += '></div>';
html += '<div class="sessionNowPlayingInnerContent">';
html += '<div class="sessionAppInfo">';
var clientImage = DashboardPage.getClientImage(session);
2014-04-14 20:54:52 -07:00
if (clientImage) {
html += clientImage;
}
2014-04-14 20:54:52 -07:00
2014-04-17 22:03:01 -07:00
html += '<div class="sessionAppName" style="display:inline-block;">';
html += '<div class="sessionDeviceName">' + session.DeviceName + '</div>';
html += '<div class="sessionAppSecondaryText">' + DashboardPage.getAppSecondaryText(session) + '</div>';
2014-03-14 21:14:07 -07:00
html += '</div>';
2014-04-14 20:54:52 -07:00
html += '</div>';
html += '<div class="sessionUserInfo">';
var userImage = DashboardPage.getUserImage(session);
2014-04-14 20:54:52 -07:00
if (userImage) {
html += '<div class="sessionUserImage" data-src="' + userImage + '">';
html += '<img src="' + userImage + '" />';
} else {
html += '<div class="sessionUserImage">';
}
html += '</div>';
2014-04-14 20:54:52 -07:00
html += '<div class="sessionUserName">';
html += DashboardPage.getUsersHtml(session);
2014-03-14 21:14:07 -07:00
html += '</div>';
2013-02-20 18:33:05 -07:00
2014-04-14 20:54:52 -07:00
html += '</div>';
2013-02-20 18:33:05 -07:00
var nowPlayingName = DashboardPage.getNowPlayingName(session);
2014-04-17 22:03:01 -07:00
2014-05-10 10:28:03 -07:00
html += '<div class="sessionNowPlayingInfo" data-imgsrc="' + nowPlayingName.image + '">';
html += nowPlayingName.html;
2014-04-14 20:54:52 -07:00
html += '</div>';
2013-02-20 18:33:05 -07:00
2014-04-15 19:17:48 -07:00
if (nowPlayingItem && nowPlayingItem.RunTimeTicks) {
var position = session.PlayState.PositionTicks || 0;
2014-04-15 19:17:48 -07:00
var value = (100 * position) / nowPlayingItem.RunTimeTicks;
2014-04-14 20:54:52 -07:00
html += '<progress class="itemProgressBar playbackProgress" min="0" max="100" value="' + value + '"></progress>';
2014-04-14 20:54:52 -07:00
} else {
html += '<progress class="itemProgressBar playbackProgress" min="0" max="100" style="display:none;"></progress>';
}
if (session.TranscodingInfo && session.TranscodingInfo.CompletionPercentage) {
html += '<progress class="itemProgressBar transcodingProgress" min="0" max="100" value="' + session.TranscodingInfo.CompletionPercentage.toFixed(1) + '"></progress>';
} else {
html += '<progress class="itemProgressBar transcodingProgress" min="0" max="100" style="display:none;"></progress>';
2014-04-14 20:54:52 -07:00
}
2013-02-20 18:33:05 -07:00
2014-03-14 21:14:07 -07:00
html += '</div>';
2014-04-17 22:03:01 -07:00
2014-08-01 19:34:45 -07:00
html += '<div class="cardOverlayTarget">';
2014-04-19 10:43:12 -07:00
html += '<div class="sessionNowPlayingStreamInfo">' + DashboardPage.getSessionNowPlayingStreamInfo(session) + '</div>';
html += '<div class="sessionNowPlayingTime">' + DashboardPage.getSessionNowPlayingTime(session) + '</div>';
if (session.TranscodingInfo && session.TranscodingInfo.Framerate) {
html += '<div class="sessionTranscodingFramerate">' + session.TranscodingInfo.Framerate + ' fps</div>';
} else {
html += '<div class="sessionTranscodingFramerate"></div>';
}
2014-07-26 10:30:15 -07:00
html += '</div>';
html += '</div>';
// cardScalable
html += '</div>';
2014-07-26 10:30:15 -07:00
// cardBox
2014-04-19 10:43:12 -07:00
html += '</div>';
2014-04-17 22:03:01 -07:00
2014-07-26 10:30:15 -07:00
// card
2014-04-17 22:03:01 -07:00
html += '</div>';
2014-04-14 20:54:52 -07:00
}
2014-04-17 22:03:01 -07:00
parentElement.append(html).createSessionItemMenus().trigger('create');
2014-04-14 20:54:52 -07:00
$('.deadSession', parentElement).remove();
},
2014-04-19 10:43:12 -07:00
getSessionNowPlayingStreamInfo: function (session) {
var html = '';
html += '<div>';
2014-12-18 21:20:07 -07:00
if (session.TranscodingInfo && session.TranscodingInfo.IsAudioDirect && session.TranscodingInfo.IsVideoDirect) {
html += Globalize.translate('LabelPlayMethodDirectStream');
}
else if (session.PlayState.PlayMethod == 'Transcode') {
2014-06-17 09:03:14 -07:00
html += Globalize.translate('LabelPlayMethodTranscoding');
2014-04-19 10:43:12 -07:00
}
else if (session.PlayState.PlayMethod == 'DirectStream') {
2014-06-17 09:03:14 -07:00
html += Globalize.translate('LabelPlayMethodDirectStream');
2014-04-19 10:43:12 -07:00
}
else if (session.PlayState.PlayMethod == 'DirectPlay') {
2014-06-17 09:03:14 -07:00
html += Globalize.translate('LabelPlayMethodDirectPlay');
2014-04-19 10:43:12 -07:00
}
html += '</div>';
if (session.TranscodingInfo) {
html += '<br/>';
var line = [];
if (session.TranscodingInfo.Container) {
line.push(session.TranscodingInfo.Container);
}
if (session.TranscodingInfo.Bitrate) {
if (session.TranscodingInfo.Bitrate > 1000000) {
line.push((session.TranscodingInfo.Bitrate / 1000000).toFixed(1) + ' Mbps');
} else {
line.push(Math.floor(session.TranscodingInfo.Bitrate / 1000) + ' kbps');
}
}
if (line.length) {
html += '<div>' + line.join(' ') + '</div>';
}
if (session.TranscodingInfo.VideoCodec) {
2014-06-17 09:03:14 -07:00
html += '<div>' + Globalize.translate('LabelVideoCodec').replace('{0}', session.TranscodingInfo.VideoCodec) + '</div>';
}
if (session.TranscodingInfo.AudioCodec && session.TranscodingInfo.AudioCodec != session.TranscodingInfo.Container) {
2014-06-17 09:03:14 -07:00
html += '<div>' + Globalize.translate('LabelAudioCodec').replace('{0}', session.TranscodingInfo.AudioCodec) + '</div>';
}
}
2014-04-19 10:43:12 -07:00
return html;
},
getSessionNowPlayingTime: function (session) {
var html = '';
if (session.PlayState.PositionTicks) {
html += Dashboard.getDisplayTime(session.PlayState.PositionTicks);
} else {
html += '--:--:--';
}
html += ' / ';
var nowPlayingItem = session.NowPlayingItem;
if (nowPlayingItem && nowPlayingItem.RunTimeTicks) {
html += Dashboard.getDisplayTime(nowPlayingItem.RunTimeTicks);
} else {
html += '--:--:--';
}
return html;
},
2014-04-17 22:03:01 -07:00
getAppSecondaryText: function (session) {
return session.ApplicationVersion;
},
2014-04-14 20:54:52 -07:00
getNowPlayingName: function (session) {
2014-04-17 22:03:01 -07:00
var imgUrl = '';
2014-04-14 20:54:52 -07:00
var nowPlayingItem = session.NowPlayingItem;
2014-04-15 19:17:48 -07:00
2014-04-14 20:54:52 -07:00
if (!nowPlayingItem) {
2014-04-17 22:03:01 -07:00
return {
html: 'Last seen ' + humane_date(session.LastActivityDate),
image: imgUrl
};
2014-04-14 20:54:52 -07:00
}
2014-04-15 19:17:48 -07:00
2014-04-14 20:54:52 -07:00
var topText = nowPlayingItem.Name;
var bottomText = '';
if (nowPlayingItem.Artists && nowPlayingItem.Artists.length) {
bottomText = topText;
topText = nowPlayingItem.Artists[0];
}
else if (nowPlayingItem.SeriesName || nowPlayingItem.Album) {
bottomText = topText;
topText = nowPlayingItem.SeriesName || nowPlayingItem.Album;
}
else if (nowPlayingItem.ProductionYear) {
bottomText = nowPlayingItem.ProductionYear;
}
2014-04-17 22:03:01 -07:00
if (nowPlayingItem.LogoItemId) {
imgUrl = ApiClient.getScaledImageUrl(nowPlayingItem.LogoItemId, {
2014-04-17 22:03:01 -07:00
tag: session.LogoImageTag,
maxHeight: 24,
maxWidth: 130,
2014-04-17 22:03:01 -07:00
type: 'Logo'
});
topText = '<img src="' + imgUrl + '" style="max-height:24px;max-width:130px;" />';
}
var text = bottomText ? topText + '<br/>' + bottomText : topText;
2014-03-14 21:14:07 -07:00
2014-04-17 22:03:01 -07:00
return {
html: text,
image: imgUrl
};
},
2014-01-03 19:59:20 -07:00
getUsersHtml: function (session) {
2014-04-14 20:54:52 -07:00
var html = [];
if (session.UserId) {
2014-04-14 20:54:52 -07:00
html.push(session.UserName);
}
2014-04-14 20:54:52 -07:00
for (var i = 0, length = session.AdditionalUsers.length; i < length; i++) {
2014-01-03 19:59:20 -07:00
2014-04-14 20:54:52 -07:00
html.push(session.AdditionalUsers[i].UserName);
}
return html.join(', ');
},
getUserImage: function (session) {
if (session.UserId && session.UserPrimaryImageTag) {
return ApiClient.getUserImageUrl(session.UserId, {
2014-04-15 19:17:48 -07:00
2014-04-14 20:54:52 -07:00
tag: session.UserPrimaryImageTag,
height: 24,
type: 'Primary'
});
}
2014-01-03 19:59:20 -07:00
2014-04-14 20:54:52 -07:00
return null;
2014-01-03 19:59:20 -07:00
},
2014-03-14 21:14:07 -07:00
updateSession: function (row, session) {
2014-01-03 19:59:20 -07:00
2014-03-14 21:14:07 -07:00
row.removeClass('deadSession');
2014-01-03 19:59:20 -07:00
var nowPlayingItem = session.NowPlayingItem;
2014-04-14 20:54:52 -07:00
if (nowPlayingItem) {
2014-04-18 10:16:25 -07:00
row.addClass('playingSession');
2014-04-14 20:54:52 -07:00
} else {
2014-04-18 10:16:25 -07:00
row.removeClass('playingSession');
2014-04-14 20:54:52 -07:00
}
2014-04-19 10:43:12 -07:00
$('.sessionNowPlayingStreamInfo', row).html(DashboardPage.getSessionNowPlayingStreamInfo(session));
$('.sessionNowPlayingTime', row).html(DashboardPage.getSessionNowPlayingTime(session));
2014-04-14 20:54:52 -07:00
$('.sessionUserName', row).html(DashboardPage.getUsersHtml(session));
2014-04-17 22:03:01 -07:00
$('.sessionAppSecondaryText', row).html(DashboardPage.getAppSecondaryText(session));
$('.sessionTranscodingFramerate', row).html((session.TranscodingInfo && session.TranscodingInfo.Framerate) ? session.TranscodingInfo.Framerate + ' fps' : '');
2014-04-17 22:03:01 -07:00
var nowPlayingName = DashboardPage.getNowPlayingName(session);
var nowPlayingInfoElem = $('.sessionNowPlayingInfo', row);
2014-04-17 22:03:01 -07:00
if (!nowPlayingName.image || nowPlayingName.image != nowPlayingInfoElem.attr('data-imgsrc')) {
nowPlayingInfoElem.html(nowPlayingName.html);
nowPlayingInfoElem.attr('data-imgsrc', nowPlayingName.image || '');
}
2014-04-19 10:43:12 -07:00
2014-04-14 20:54:52 -07:00
if (nowPlayingItem && nowPlayingItem.RunTimeTicks) {
2014-04-15 19:17:48 -07:00
var position = session.PlayState.PositionTicks || 0;
var value = (100 * position) / nowPlayingItem.RunTimeTicks;
$('.playbackProgress', row).show().val(value);
} else {
$('.playbackProgress', row).hide();
}
if (session.TranscodingInfo && session.TranscodingInfo.CompletionPercentage) {
row.addClass('transcodingSession');
$('.transcodingProgress', row).show().val(session.TranscodingInfo.CompletionPercentage);
2014-04-14 20:54:52 -07:00
} else {
$('.transcodingProgress', row).hide();
row.removeClass('transcodingSession');
2014-04-14 20:54:52 -07:00
}
var imgUrl = DashboardPage.getNowPlayingImageUrl(nowPlayingItem) || '';
var imgElem = $('.sessionNowPlayingContent', row)[0];
if (imgUrl != imgElem.getAttribute('data-src')) {
imgElem.style.backgroundImage = imgUrl ? 'url(\'' + imgUrl + '\')' : '';
imgElem.setAttribute('data-src', imgUrl);
}
2013-02-20 18:33:05 -07:00
},
2014-04-14 20:54:52 -07:00
getClientImage: function (connection) {
2013-02-20 18:33:05 -07:00
2013-03-21 13:20:00 -07:00
var clientLowered = connection.Client.toLowerCase();
2015-05-12 06:58:03 -07:00
var device = connection.DeviceName.toLowerCase();
2013-05-18 11:58:03 -07:00
2015-08-16 08:53:30 -07:00
if (connection.AppIconUrl) {
return "<img src='" + connection.AppIconUrl + "' />";
}
2013-02-20 18:33:05 -07:00
2015-05-12 06:58:03 -07:00
if (clientLowered == "dashboard" || clientLowered == "emby web client") {
2013-06-02 05:13:41 -07:00
var imgUrl;
if (device.indexOf('chrome') != -1) {
imgUrl = 'css/images/clients/chrome.png';
}
else {
imgUrl = 'css/images/clients/html5.png';
}
2015-05-01 11:37:01 -07:00
return "<img src='" + imgUrl + "' alt='Emby Web Client' />";
2013-02-20 18:33:05 -07:00
}
2015-08-16 08:53:30 -07:00
if (clientLowered.indexOf('android') != -1) {
return "<img src='css/images/clients/android.png' />";
}
if (clientLowered.indexOf('ios') != -1) {
return "<img src='css/images/clients/ios.png' />";
2015-05-12 06:58:03 -07:00
}
2013-05-10 09:20:20 -07:00
if (clientLowered == "mb-classic") {
2013-03-21 13:20:00 -07:00
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/mbc.png' />";
2013-03-21 13:20:00 -07:00
}
2013-05-22 12:31:27 -07:00
if (clientLowered == "roku") {
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/roku.jpg' />";
2013-05-22 12:31:27 -07:00
}
2013-03-21 13:20:00 -07:00
if (clientLowered == "windows phone") {
2013-02-20 18:33:05 -07:00
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/windowsphone.png' />";
2013-02-20 18:33:05 -07:00
}
2013-03-21 13:20:00 -07:00
if (clientLowered == "dlna") {
2013-03-04 19:32:14 -07:00
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/dlna.png' />";
2013-08-09 07:25:54 -07:00
}
2014-09-22 14:56:54 -07:00
if (clientLowered == "kodi" || clientLowered == "xbmc") {
return "<img src='css/images/clients/kodi.png' />";
2013-12-21 11:37:34 -07:00
}
2014-04-07 21:17:18 -07:00
if (clientLowered == "chromecast") {
2015-06-04 13:27:46 -07:00
return "<img src='css/images/clients/chromecast.png' />";
2014-04-07 21:17:18 -07:00
}
2014-04-14 20:54:52 -07:00
return null;
2013-02-20 18:33:05 -07:00
},
2014-04-14 20:54:52 -07:00
getNowPlayingImageUrl: function (item) {
2013-02-20 18:33:05 -07:00
2014-04-14 20:54:52 -07:00
if (item && item.BackdropImageTag) {
2014-03-14 21:14:07 -07:00
return ApiClient.getScaledImageUrl(item.BackdropItemId, {
2014-04-14 20:54:52 -07:00
type: "Backdrop",
width: 275,
2014-04-14 20:54:52 -07:00
tag: item.BackdropImageTag
});
2013-02-20 18:33:05 -07:00
}
2014-04-14 20:54:52 -07:00
if (item && item.ThumbImageTag) {
2014-03-14 21:14:07 -07:00
return ApiClient.getScaledImageUrl(item.ThumbItemId, {
2014-04-14 20:54:52 -07:00
type: "Thumb",
width: 275,
2014-04-14 20:54:52 -07:00
tag: item.ThumbImageTag
});
}
2014-03-14 21:14:07 -07:00
2014-04-14 20:54:52 -07:00
if (item && item.PrimaryImageTag) {
2014-03-14 21:14:07 -07:00
return ApiClient.getScaledImageUrl(item.PrimaryImageItemId, {
2014-04-14 20:54:52 -07:00
type: "Primary",
width: 275,
2014-04-14 20:54:52 -07:00
tag: item.PrimaryImageTag
});
2014-03-14 21:14:07 -07:00
}
2014-04-14 20:54:52 -07:00
return null;
2014-03-14 21:14:07 -07:00
},
2014-04-03 15:50:04 -07:00
systemUpdateTaskKey: "SystemUpdateTask",
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
renderRunningTasks: function (page, tasks) {
2013-02-20 18:33:05 -07:00
var html = '';
2014-03-25 14:13:55 -07:00
tasks = tasks.filter(function (t) {
2015-07-16 16:55:16 -07:00
return t.State != 'Idle' && !t.IsHidden;
2014-03-25 14:13:55 -07:00
});
if (tasks.filter(function (t) {
2014-04-03 15:50:04 -07:00
return t.Key == DashboardPage.systemUpdateTaskKey;
2014-03-25 14:13:55 -07:00
}).length) {
$('#btnUpdateApplication', page).buttonEnabled(false);
} else {
$('#btnUpdateApplication', page).buttonEnabled(true);
}
if (!tasks.length) {
2013-09-28 11:16:30 -07:00
$('#runningTasksCollapsible', page).hide();
} else {
$('#runningTasksCollapsible', page).show();
2013-02-20 18:33:05 -07:00
}
2014-03-25 14:13:55 -07:00
for (var i = 0, length = tasks.length; i < length; i++) {
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
var task = tasks[i];
2013-02-20 18:33:05 -07:00
html += '<p>';
2014-03-25 14:13:55 -07:00
html += task.Name + "<br/>";
2013-02-20 18:33:05 -07:00
if (task.State == "Running") {
var progress = (task.CurrentProgressPercentage || 0).toFixed(1);
html += '<progress max="100" value="' + progress + '" title="' + progress + '%">';
html += '' + progress + '%';
html += '</progress>';
html += "<span style='color:#009F00;margin-left:5px;margin-right:5px;'>" + progress + "%</span>";
2013-02-20 18:33:05 -07:00
2015-09-29 21:19:45 -07:00
html += '<paper-icon-button title="' + Globalize.translate('ButtonStop') + '" icon="cancel" onclick="DashboardPage.stopTask(\'' + task.Id + '\');"></paper-icon-button>';
2013-02-20 18:33:05 -07:00
}
else if (task.State == "Cancelling") {
2014-06-17 09:03:14 -07:00
html += '<span style="color:#cc0000;">' + Globalize.translate('LabelStopping') + '</span>';
2013-02-20 18:33:05 -07:00
}
html += '</p>';
}
$('#divRunningTasks', page).html(html).trigger('create');
},
2014-02-26 14:31:47 -07:00
renderUrls: function (page, systemInfo) {
2015-01-18 21:29:57 -07:00
if (systemInfo.LocalAddress) {
var localAccessHtml = Globalize.translate('LabelLocalAccessUrl', '<a href="' + systemInfo.LocalAddress + '" target="_blank">' + systemInfo.LocalAddress + '</a>');
2015-12-14 08:43:03 -07:00
//localAccessHtml += '<a class="clearLink" href="https://github.com/MediaBrowser/Wiki/wiki/Connectivity" target="_blank"><paper-icon-button icon="info"></paper-icon-button></a>';
2015-01-18 21:29:57 -07:00
$('.localUrl', page).html(localAccessHtml).show().trigger('create');
} else {
$('.externalUrl', page).hide();
}
2014-02-26 14:31:47 -07:00
if (systemInfo.WanAddress) {
2015-01-18 21:29:57 -07:00
var externalUrl = systemInfo.WanAddress;
2014-02-26 14:31:47 -07:00
2015-01-18 21:29:57 -07:00
var remoteAccessHtml = Globalize.translate('LabelRemoteAccessUrl', '<a href="' + externalUrl + '" target="_blank">' + externalUrl + '</a>');
2014-06-17 09:03:14 -07:00
$('.externalUrl', page).html(remoteAccessHtml).show().trigger('create');
2014-02-26 14:31:47 -07:00
} else {
$('.externalUrl', page).hide();
}
},
2014-06-21 22:52:31 -07:00
renderSupporterIcon: function (page, pluginSecurityInfo) {
var imgUrl, text;
2015-05-21 13:53:14 -07:00
if (!AppInfo.enableSupporterMembership) {
$('.supporterIconContainer', page).remove();
}
else if (pluginSecurityInfo.IsMBSupporter) {
2014-06-21 22:52:31 -07:00
imgUrl = "css/images/supporter/supporterbadge.png";
2015-01-19 22:19:13 -07:00
text = Globalize.translate('MessageThankYouForSupporting');
2014-06-21 22:52:31 -07:00
2015-10-01 09:28:24 -07:00
$('.supporterIconContainer', page).html('<a class="imageLink supporterIcon" href="http://emby.media/premiere" target="_blank" title="' + text + '"><img src="' + imgUrl + '" style="height:32px;vertical-align: middle; margin-right: .5em;" /></a><span style="position:relative;top:2px;text-decoration:none;">' + text + '</span>');
2014-06-21 22:52:31 -07:00
} else {
imgUrl = "css/images/supporter/nonsupporterbadge.png";
2015-03-21 11:12:12 -07:00
text = Globalize.translate('MessagePleaseSupportProject');
2014-07-10 21:27:46 -07:00
2015-10-01 09:28:24 -07:00
$('.supporterIconContainer', page).html('<a class="imageLink supporterIcon" href="http://emby.media/premiere" target="_blank" title="' + text + '"><img src="' + imgUrl + '" style="height:32px;vertical-align: middle; margin-right: .5em;" /><span style="position:relative;top:2px;text-decoration:none;">' + text + '</span></a>');
2014-06-21 22:52:31 -07:00
}
},
2014-03-25 14:13:55 -07:00
renderHasPendingRestart: function (page, hasPendingRestart) {
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
if (!hasPendingRestart) {
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
// Only check once every 30 mins
if (DashboardPage.lastAppUpdateCheck && (new Date().getTime() - DashboardPage.lastAppUpdateCheck) < 1800000) {
2013-02-20 18:33:05 -07:00
return;
}
DashboardPage.lastAppUpdateCheck = new Date().getTime();
2015-12-14 08:43:03 -07:00
ApiClient.getAvailableApplicationUpdate().then(function (packageInfo) {
2013-02-20 18:33:05 -07:00
2013-02-28 13:00:17 -07:00
var version = packageInfo[0];
2013-02-20 18:33:05 -07:00
if (!version) {
$('#pUpToDate', page).show();
$('#pUpdateNow', page).hide();
} else {
$('#pUpToDate', page).hide();
$('#pUpdateNow', page).show();
2013-12-24 11:37:29 -07:00
$('#newVersionNumber', page).html(Globalize.translate('VersionXIsAvailableForDownload').replace('{0}', version.versionStr));
2013-02-20 18:33:05 -07:00
}
});
} else {
2014-03-25 14:13:55 -07:00
$('#pUpToDate', page).hide();
2013-02-20 18:33:05 -07:00
$('#pUpdateNow', page).hide();
}
},
2014-02-26 14:31:47 -07:00
renderPendingInstallations: function (page, systemInfo) {
if (systemInfo.CompletedInstallations.length) {
$('#collapsiblePendingInstallations', page).show();
} else {
$('#collapsiblePendingInstallations', page).hide();
return;
}
var html = '';
for (var i = 0, length = systemInfo.CompletedInstallations.length; i < length; i++) {
var update = systemInfo.CompletedInstallations[i];
html += '<div><strong>' + update.Name + '</strong> (' + update.Version + ')</div>';
}
$('#pendingInstallations', page).html(html);
},
2014-06-07 14:06:01 -07:00
renderPluginUpdateInfo: function (page, forceUpdate) {
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
// Only check once every 30 mins
2014-06-07 14:06:01 -07:00
if (!forceUpdate && DashboardPage.lastPluginUpdateCheck && (new Date().getTime() - DashboardPage.lastPluginUpdateCheck) < 1800000) {
2013-02-20 18:33:05 -07:00
return;
}
DashboardPage.lastPluginUpdateCheck = new Date().getTime();
2015-12-14 08:43:03 -07:00
ApiClient.getAvailablePluginUpdates().then(function (updates) {
2013-02-20 18:33:05 -07:00
var elem = $('#pPluginUpdates', page);
2013-02-20 18:33:05 -07:00
if (updates.length) {
elem.show();
2013-02-20 18:33:05 -07:00
} else {
elem.hide();
2013-02-20 18:33:05 -07:00
return;
}
var html = '';
for (var i = 0, length = updates.length; i < length; i++) {
var update = updates[i];
html += '<p><strong>' + Globalize.translate('NewVersionOfSomethingAvailable').replace('{0}', update.name) + '</strong></p>';
2013-02-20 18:33:05 -07:00
html += '<button type="button" data-icon="arrow-d" data-theme="b" onclick="DashboardPage.installPluginUpdate(this);" data-name="' + update.name + '" data-guid="' + update.guid + '" data-version="' + update.versionStr + '" data-classification="' + update.classification + '">' + Globalize.translate('ButtonUpdateNow') + '</button>';
2013-02-20 18:33:05 -07:00
}
elem.html(html).trigger('create');
2013-02-20 18:33:05 -07:00
});
},
installPluginUpdate: function (button) {
2013-12-24 11:37:29 -07:00
$(button).buttonEnabled(false);
2013-02-20 18:33:05 -07:00
var name = button.getAttribute('data-name');
var guid = button.getAttribute('data-guid');
2013-02-20 18:33:05 -07:00
var version = button.getAttribute('data-version');
var classification = button.getAttribute('data-classification');
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.installPlugin(name, guid, classification, version).then(function () {
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
});
},
updateApplication: function () {
var page = $.mobile.activePage;
2013-12-24 11:37:29 -07:00
$('#btnUpdateApplication', page).buttonEnabled(false);
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.getScheduledTasks().then(function (tasks) {
2013-02-20 18:33:05 -07:00
2014-03-25 14:13:55 -07:00
var task = tasks.filter(function (t) {
2013-02-20 18:33:05 -07:00
2014-04-03 15:50:04 -07:00
return t.Key == DashboardPage.systemUpdateTaskKey;
})[0];
2014-03-25 14:13:55 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.startScheduledTask(task.Id).then(function () {
2014-03-25 14:13:55 -07:00
DashboardPage.pollForInfo(page);
Dashboard.hideLoadingMsg();
});
2013-02-20 18:33:05 -07:00
});
},
stopTask: function (id) {
2013-12-24 11:37:29 -07:00
var page = $.mobile.activePage;
2015-12-14 08:43:03 -07:00
ApiClient.stopScheduledTask(id).then(function () {
2013-02-20 18:33:05 -07:00
2013-12-24 11:37:29 -07:00
DashboardPage.pollForInfo(page);
2013-02-20 18:33:05 -07:00
});
},
restart: function () {
Dashboard.confirm(Globalize.translate('MessageConfirmRestart'), Globalize.translate('HeaderRestart'), function (result) {
if (result) {
2013-12-24 11:37:29 -07:00
$('#btnRestartServer').buttonEnabled(false);
$('#btnShutdown').buttonEnabled(false);
Dashboard.restartServer();
}
2013-10-01 08:16:38 -07:00
});
},
shutdown: function () {
Dashboard.confirm(Globalize.translate('MessageConfirmShutdown'), Globalize.translate('HeaderShutdown'), function (result) {
2013-10-01 08:16:38 -07:00
if (result) {
2013-12-24 11:37:29 -07:00
$('#btnRestartServer').buttonEnabled(false);
$('#btnShutdown').buttonEnabled(false);
2013-10-01 08:16:38 -07:00
ApiClient.shutdownServer();
}
});
2013-02-20 18:33:05 -07:00
}
};
2015-09-29 21:19:45 -07:00
$(document).on('pageshow', "#dashboardPage", DashboardPage.onPageShow).on('pagebeforehide', "#dashboardPage", DashboardPage.onPageHide);
2014-04-17 22:03:01 -07:00
(function ($, document, window) {
var showOverlayTimeout;
function onHoverOut() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
2015-06-29 11:45:42 -07:00
var elem = this.querySelector('.cardOverlayTarget');
2014-04-17 22:03:01 -07:00
2015-06-29 11:45:42 -07:00
if ($(elem).is(':visible')) {
require(["jquery", "velocity"], function ($, Velocity) {
2014-04-17 22:03:01 -07:00
2015-06-29 11:45:42 -07:00
Velocity.animate(elem, { "height": "0" },
{
complete: function () {
$(elem).hide();
}
});
2014-04-17 22:03:01 -07:00
});
2015-06-29 11:45:42 -07:00
}
2014-04-17 22:03:01 -07:00
}
$.fn.createSessionItemMenus = function () {
function onShowTimerExpired(elem) {
if ($('.itemSelectionPanel:visible', elem).length) {
return;
}
2014-08-01 19:34:45 -07:00
var innerElem = $('.cardOverlayTarget', elem);
2014-04-17 22:03:01 -07:00
innerElem.show().each(function () {
this.style.height = 0;
}).animate({ "height": "100%" }, "fast");
}
function onHoverIn() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
var elem = this;
showOverlayTimeout = setTimeout(function () {
onShowTimerExpired(elem);
}, 1000);
}
2015-10-01 09:28:24 -07:00
if (AppInfo.isTouchPreferred) {
2014-04-17 22:03:01 -07:00
/* browser with either Touch Events of Pointer Events
running on touch-capable device */
return this;
}
2015-06-29 11:45:42 -07:00
return this.off('mouseenter', '.playingSession', onHoverIn).off('mouseleave', '.playingSession', onHoverOut).on('mouseenter', '.playingSession', onHoverIn).on('mouseleave', '.playingSession', onHoverOut);
2014-04-17 22:03:01 -07:00
};
})(jQuery, document, window);
2014-08-10 15:13:17 -07:00
(function ($, document, window) {
function getEntryHtml(entry) {
var html = '';
2015-09-29 21:19:45 -07:00
html += '<paper-icon-item>';
2014-08-10 15:13:17 -07:00
2015-09-29 21:19:45 -07:00
var color = entry.Severity == 'Error' || entry.Severity == 'Fatal' || entry.Severity == 'Warn' ? '#cc0000' : '#52B54B';
2014-08-10 15:13:17 -07:00
2014-10-01 17:28:16 -07:00
if (entry.UserId && entry.UserPrimaryImageTag) {
var userImgUrl = ApiClient.getUserImageUrl(entry.UserId, {
type: 'Primary',
tag: entry.UserPrimaryImageTag,
2015-09-29 21:19:45 -07:00
height: 40
2014-10-01 17:28:16 -07:00
});
2015-09-29 21:19:45 -07:00
2015-10-26 11:55:46 -07:00
html += '<paper-fab mini style="background-color:' + color + ';background-image:url(\'' + userImgUrl + '\');background-repeat:no-repeat;background-position:center center;background-size: cover;" item-icon></paper-fab>';
2015-09-29 21:19:45 -07:00
}
else {
2015-10-26 11:55:46 -07:00
html += '<paper-fab mini icon="dvr" style="background-color:' + color + '" item-icon></paper-fab>';
2014-10-01 17:28:16 -07:00
}
2015-09-29 21:19:45 -07:00
html += '<paper-item-body three-line>';
2014-10-04 11:05:24 -07:00
2015-09-29 21:19:45 -07:00
html += '<div>';
2014-08-10 15:13:17 -07:00
html += entry.Name;
html += '</div>';
2015-09-29 21:19:45 -07:00
html += '<div secondary>';
var date = parseISO8601Date(entry.Date, { toLocal: true });
html += date.toLocaleDateString() + ' ' + date.toLocaleTimeString().toLowerCase();
2015-09-29 21:13:48 -07:00
html += '</div>';
2015-09-29 21:19:45 -07:00
html += '<div secondary>';
html += entry.ShortOverview || '';
2015-09-29 21:13:48 -07:00
html += '</div>';
2015-09-21 18:05:33 -07:00
2015-09-29 21:19:45 -07:00
html += '</paper-item-body>';
html += '</paper-icon-item>';
2014-08-10 15:13:17 -07:00
return html;
}
function renderList(elem, result, startIndex, limit) {
var html = result.Items.map(getEntryHtml).join('');
if (result.TotalRecordCount > limit) {
var query = { StartIndex: startIndex, Limit: limit };
2015-06-18 11:29:44 -07:00
html += LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false
});
2014-08-10 15:13:17 -07:00
}
$(elem).html(html).trigger('create');
$('.btnNextPage', elem).on('click', function () {
reloadData(elem, startIndex + limit, limit);
});
$('.btnPreviousPage', elem).on('click', function () {
reloadData(elem, startIndex - limit, limit);
});
$('.btnShowOverview', elem).on('click', function () {
var item = $(this).parents('.newsItem');
var overview = $('.newsItemLongDescription', item).html();
var name = $('.notificationName', item).html();
Dashboard.alert({
2014-08-11 16:41:11 -07:00
message: '<div style="max-height:300px; overflow: auto;">' + overview + '</div>',
2014-08-10 15:13:17 -07:00
title: name
});
});
}
function reloadData(elem, startIndex, limit) {
if (startIndex == null) {
startIndex = parseInt(elem.getAttribute('data-activitystartindex') || '0');
}
limit = limit || parseInt(elem.getAttribute('data-activitylimit') || '7');
2014-08-14 06:24:30 -07:00
// Show last 24 hours
var minDate = new Date();
minDate.setTime(minDate.getTime() - 86400000);
2014-08-10 15:13:17 -07:00
ApiClient.getJSON(ApiClient.getUrl('System/ActivityLog/Entries', {
startIndex: startIndex,
2014-08-14 06:24:30 -07:00
limit: limit,
minDate: minDate.toISOString()
2014-08-10 15:13:17 -07:00
2015-12-14 08:43:03 -07:00
})).then(function (result) {
2014-08-10 15:13:17 -07:00
elem.setAttribute('data-activitystartindex', startIndex);
elem.setAttribute('data-activitylimit', limit);
renderList(elem, result, startIndex, limit);
});
}
function createList(elem) {
elem.each(function () {
reloadData(this);
2015-06-29 11:45:42 -07:00
}).addClass('activityLogListWidget');
2014-08-10 15:13:17 -07:00
2015-05-19 12:15:40 -07:00
var apiClient = ApiClient;
if (!apiClient) {
return;
}
2015-12-23 10:46:01 -07:00
Events.on(apiClient, 'websocketopen', onSocketOpen);
Events.on(apiClient, 'websocketmessage', onSocketMessage);
2014-08-10 15:13:17 -07:00
}
2015-05-19 12:15:40 -07:00
function startListening(apiClient) {
2014-10-04 11:05:24 -07:00
2015-05-19 12:15:40 -07:00
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("ActivityLogEntryStart", "0,1500");
2014-08-11 07:15:53 -07:00
}
}
2015-05-19 12:15:40 -07:00
function stopListening(apiClient) {
2014-08-11 07:15:53 -07:00
2015-05-19 12:15:40 -07:00
if (apiClient.isWebSocketOpen()) {
apiClient.sendWebSocketMessage("ActivityLogEntryStop", "0,1500");
2014-08-11 07:15:53 -07:00
}
}
2015-06-29 11:45:42 -07:00
function onSocketOpen() {
2015-07-16 16:55:16 -07:00
2015-06-29 11:45:42 -07:00
var apiClient = ApiClient;
if (apiClient) {
startListening(apiClient);
}
}
function onSocketMessage(e, data) {
var msg = data;
if (msg.MessageType === "ActivityLogEntry") {
$('.activityLogListWidget').each(function () {
reloadData(this);
});
}
}
2014-08-10 15:13:17 -07:00
function destroyList(elem) {
2015-05-19 12:15:40 -07:00
var apiClient = ApiClient;
if (apiClient) {
2015-12-23 10:46:01 -07:00
Events.off(apiClient, 'websocketopen', onSocketOpen);
Events.off(apiClient, 'websocketmessage', onSocketMessage);
2014-08-11 07:15:53 -07:00
2015-05-19 12:15:40 -07:00
stopListening(apiClient);
}
2014-08-10 15:13:17 -07:00
}
$.fn.activityLogList = function (action) {
if (action == 'destroy') {
2015-06-29 11:45:42 -07:00
this.removeClass('activityLogListWidget');
2014-08-10 15:13:17 -07:00
destroyList(this);
} else {
createList(this);
}
2015-05-20 09:28:55 -07:00
var apiClient = ApiClient;
if (apiClient) {
startListening(apiClient);
}
2014-08-11 07:15:53 -07:00
2014-08-10 15:13:17 -07:00
return this;
};
2014-10-04 11:05:24 -07:00
})(jQuery, document, window);
(function ($, document, window) {
2016-01-30 23:03:40 -07:00
var welcomeDismissValue = '12';
2014-10-04 11:05:24 -07:00
var welcomeTourKey = 'welcomeTour';
function dismissWelcome(page, userId) {
2015-12-14 08:43:03 -07:00
ApiClient.getDisplayPreferences('dashboard', userId, 'dashboard').then(function (result) {
2014-10-04 11:05:24 -07:00
result.CustomPrefs[welcomeTourKey] = welcomeDismissValue;
ApiClient.updateDisplayPreferences('dashboard', result, userId, 'dashboard');
2015-09-29 21:19:45 -07:00
$(page).off('pageshow', onPageShowCheckTour);
2014-10-04 11:05:24 -07:00
});
}
2015-05-19 12:15:40 -07:00
function showWelcomeIfNeeded(page, apiClient) {
2014-10-04 11:05:24 -07:00
var userId = Dashboard.getCurrentUserId();
2015-12-14 08:43:03 -07:00
apiClient.getDisplayPreferences('dashboard', userId, 'dashboard').then(function (result) {
2014-10-04 11:05:24 -07:00
if (result.CustomPrefs[welcomeTourKey] == welcomeDismissValue) {
$('.welcomeMessage', page).hide();
} else {
2015-01-11 11:36:26 -07:00
var elem = $('.welcomeMessage', page).show();
if (result.CustomPrefs[welcomeTourKey]) {
$('.tourHeader', elem).html(Globalize.translate('HeaderWelcomeBack'));
$('.tourButtonText', elem).html(Globalize.translate('ButtonTakeTheTourToSeeWhatsNew'));
} else {
2015-04-03 08:52:49 -07:00
2015-03-21 11:12:12 -07:00
$('.tourHeader', elem).html(Globalize.translate('HeaderWelcomeToProjectServerDashboard'));
2015-01-11 11:36:26 -07:00
$('.tourButtonText', elem).html(Globalize.translate('ButtonTakeTheTour'));
}
2014-10-04 11:05:24 -07:00
}
});
}
function takeTour(page, userId) {
2016-01-30 23:03:40 -07:00
require(['slideshow'], function () {
var slides = [
{ imageUrl: 'css/images/tour/dashboard/dashboard.png', title: Globalize.translate('DashboardTourDashboard') },
{ imageUrl: 'css/images/tour/dashboard/help.png', title: Globalize.translate('DashboardTourHelp') },
{ imageUrl: 'css/images/tour/dashboard/users.png', title: Globalize.translate('DashboardTourUsers') },
{ imageUrl: 'css/images/tour/dashboard/sync.png', title: Globalize.translate('DashboardTourSync') },
{ imageUrl: 'css/images/tour/dashboard/cinemamode.png', title: Globalize.translate('DashboardTourCinemaMode') },
{ imageUrl: 'css/images/tour/dashboard/chapters.png', title: Globalize.translate('DashboardTourChapters') },
{ imageUrl: 'css/images/tour/dashboard/subtitles.png', title: Globalize.translate('DashboardTourSubtitles') },
{ imageUrl: 'css/images/tour/dashboard/plugins.png', title: Globalize.translate('DashboardTourPlugins') },
{ imageUrl: 'css/images/tour/dashboard/notifications.png', title: Globalize.translate('DashboardTourNotifications') },
{ imageUrl: 'css/images/tour/dashboard/scheduledtasks.png', title: Globalize.translate('DashboardTourScheduledTasks') },
{ imageUrl: 'css/images/tour/dashboard/mobile.png', title: Globalize.translate('DashboardTourMobile') },
{ imageUrl: 'css/images/tour/enjoy.jpg', title: Globalize.translate('MessageEnjoyYourStay') }
];
require(['slideshow'], function (slideshow) {
var newSlideShow = new slideshow({
slides: slides,
interactive: true,
loop: false
});
newSlideShow.show();
dismissWelcome(page, userId);
$('.welcomeMessage', page).hide();
2015-05-08 20:48:43 -07:00
});
2014-10-04 11:05:24 -07:00
});
}
2015-09-29 21:19:45 -07:00
function onPageShowCheckTour() {
2014-10-04 11:05:24 -07:00
var page = this;
2015-05-19 12:15:40 -07:00
var apiClient = ApiClient;
2015-06-08 22:56:46 -07:00
if (apiClient && !AppInfo.isNativeApp) {
2015-05-19 12:15:40 -07:00
showWelcomeIfNeeded(page, apiClient);
}
2015-06-29 11:45:42 -07:00
}
2014-10-04 11:05:24 -07:00
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#dashboardPage", function () {
2015-06-29 11:45:42 -07:00
var page = this;
$('.btnTakeTour', page).on('click', function () {
takeTour(page, Dashboard.getCurrentUserId());
});
2015-09-29 21:19:45 -07:00
}).on('pageshow', "#dashboardPage", onPageShowCheckTour);
2014-10-04 11:05:24 -07:00
2015-04-03 08:52:49 -07:00
})(jQuery, document, window);
(function () {
2015-09-29 21:19:45 -07:00
$(document).on('pageshow', ".type-interior", function () {
2015-04-03 08:52:49 -07:00
var page = this;
2015-12-14 08:43:03 -07:00
Dashboard.getPluginSecurityInfo().then(function (pluginSecurityInfo) {
2015-04-03 08:52:49 -07:00
2015-07-29 10:16:00 -07:00
if (!$('.customSupporterPromotion', page).length) {
2015-04-03 08:52:49 -07:00
$('.supporterPromotion', page).remove();
2015-05-21 13:53:14 -07:00
if (!pluginSecurityInfo.IsMBSupporter && AppInfo.enableSupporterMembership) {
2015-12-14 08:43:03 -07:00
var html = '<div class="supporterPromotion"><a class="clearLink" href="http://emby.media/premiere" target="_blank" style="font-size:14px;"><paper-button raised class="block" style="text-transform:none;background-color:#52B54B;color:#fff;"><div>' + Globalize.translate('HeaderSupportTheTeam') + '</div><div style="font-weight:normal;margin-top:5px;">' + Globalize.translate('TextEnjoyBonusFeatures') + '</div></paper-button></a></div>';
$('.content-primary', page).append(html);
2015-04-03 08:52:49 -07:00
}
}
});
});
})();