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

1317 lines
40 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;
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);
2013-02-20 18:33:05 -07:00
DashboardPage.startInterval();
2014-04-07 21:17:18 -07:00
2014-03-25 14:13:55 -07:00
$(ApiClient).on("websocketmessage", DashboardPage.onWebSocketMessage)
2014-05-31 07:30:59 -07:00
.on("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
Dashboard.getPluginSecurityInfo().done(function (pluginSecurityInfo) {
if (pluginSecurityInfo.IsMBSupporter) {
$('#contribute', page).hide();
2013-07-07 08:53:26 -07:00
} else {
2013-12-24 11:37:29 -07:00
$('#contribute', page).show();
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();
},
onPageHide: function () {
var page = this;
$('.activityItems', page).activityLogList('destroy');
$(ApiClient).off("websocketmessage", DashboardPage.onWebSocketMessage).off("websocketopen", DashboardPage.onWebSocketConnectionChange).off("websocketerror", DashboardPage.onWebSocketConnectionChange).off("websocketclose", DashboardPage.onWebSocketConnectionChange);
DashboardPage.stopInterval();
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);
$('#imagesByNamePath', page).html(systemInfo.ItemsByNamePath);
$('#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) {
console.log('refreshSessionsLocally');
DashboardPage.renderActiveConnections($.mobile.activePage, list);
}
2014-01-18 14:52:01 -07:00
},
2014-03-25 14:13:55 -07:00
reloadSystemInfo: function (page) {
ApiClient.getSystemInfo().done(function (systemInfo) {
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
var port = systemInfo.HttpServerPortNumber;
2014-07-29 20:31:35 -07:00
$('#ports', page).html(Globalize.translate('LabelRunningOnPort').replace('{0}', '<b>' + port + '</b>'));
2014-03-25 14:13:55 -07:00
if (systemInfo.CanSelfRestart) {
$('.btnRestartContainer', page).removeClass('hide');
} else {
$('.btnRestartContainer', page).addClass('hide');
}
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,
Limit: 5
};
2014-01-18 14:52:01 -07:00
2014-01-22 13:46:01 -07:00
ApiClient.getProductNews(query).done(function (result) {
2014-01-18 14:52:01 -07:00
var html = result.Items.map(function (item) {
var itemHtml = '';
itemHtml += '<div class="newsItem">';
itemHtml += '<a class="newsItemHeader" href="' + item.Link + '" target="_blank">' + item.Title + '</a>';
2014-01-18 15:47:44 -07:00
var date = parseISO8601Date(item.Date, { toLocal: true });
itemHtml += '<div class="newsItemDate">' + date.toLocaleDateString() + '</div>';
2014-07-07 18:41:03 -07:00
itemHtml += '<div class="newsItemDescription">' + item.Description + '</div>';
2014-01-18 14:52:01 -07:00
itemHtml += '</div>';
return itemHtml;
});
2014-01-22 13:46:01 -07:00
var pagingHtml = '';
pagingHtml += '<div>';
pagingHtml += LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false);
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
},
startInterval: function () {
if (ApiClient.isWebSocketOpen()) {
2014-03-25 14:13:55 -07:00
ApiClient.sendWebSocketMessage("SessionsStart", "0,1500");
2014-05-10 10:28:03 -07:00
ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "0,1000");
2013-02-20 18:33:05 -07:00
}
},
stopInterval: function () {
if (ApiClient.isWebSocketOpen()) {
2014-03-25 14:13:55 -07:00
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
DashboardPage.startInterval();
},
2014-06-07 14:06:01 -07:00
pollForInfo: function (page, forceUpdate) {
2013-12-24 11:37:29 -07:00
2014-03-25 14:13:55 -07:00
ApiClient.getSessions().done(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
});
2014-05-31 07:30:59 -07:00
ApiClient.getScheduledTasks().done(function (tasks) {
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>';
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();
2013-05-18 11:58:03 -07:00
2013-03-21 13:20:00 -07:00
if (clientLowered == "dashboard") {
2013-02-20 18:33:05 -07:00
2013-06-02 05:13:41 -07:00
var device = connection.DeviceName.toLowerCase();
var imgUrl;
if (device.indexOf('chrome') != -1) {
imgUrl = 'css/images/clients/chrome.png';
}
else if (device.indexOf('firefox') != -1) {
imgUrl = 'css/images/clients/firefox.png';
}
2013-07-28 06:58:26 -07:00
else if (device.indexOf('internet explorer') != -1) {
2013-06-02 05:13:41 -07:00
imgUrl = 'css/images/clients/ie.png';
}
else if (device.indexOf('safari') != -1) {
imgUrl = 'css/images/clients/safari.png';
}
else {
imgUrl = 'css/images/clients/html5.png';
}
2014-03-14 21:14:07 -07:00
return "<img src='" + imgUrl + "' alt='Dashboard' />";
2013-02-20 18:33:05 -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
}
if (clientLowered == "media browser theater") {
2013-02-20 18:33:05 -07:00
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/mb.png' />";
2013-02-20 18:33:05 -07:00
}
2014-12-10 15:53:07 -07:00
if (clientLowered == "android" || clientLowered == "androidtv") {
2013-02-20 18:33:05 -07:00
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/android.png' />";
2013-02-20 18:33:05 -07:00
}
2014-08-15 09:35:41 -07:00
if (clientLowered == "nuvue") {
return "<img src='css/images/clients/nuvue.png' />";
}
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 == "ios") {
2013-02-20 18:33:05 -07:00
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/ios.png' />";
2013-02-20 18:33:05 -07:00
}
2013-03-21 13:20:00 -07:00
if (clientLowered == "windows rt") {
2013-02-20 18:33:05 -07:00
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/windowsrt.png' />";
2013-02-20 18:33:05 -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-03-04 19:32:14 -07:00
}
2013-08-09 07:25:54 -07:00
if (clientLowered == "mbkinect") {
2014-04-14 20:54:52 -07:00
return "<img src='css/images/clients/mbkinect.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") {
2014-04-14 20:54:52 -07:00
return "<img src='css/images/chromecast/ic_media_route_on_holo_light.png' />";
2014-04-07 21:17:18 -07:00
}
if (clientLowered == "chrome companion") {
return "<img src='css/images/clients/chrome_companion.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) {
return t.State != 'Idle';
});
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
2014-06-17 09:03:14 -07:00
html += '<button type="button" data-icon="stop" data-iconpos="notext" data-inline="true" data-mini="true" onclick="DashboardPage.stopTask(\'' + task.Id + '\');">' + Globalize.translate('ButtonStop') + '</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) {
2014-02-26 14:31:47 -07:00
if (systemInfo.WanAddress) {
2014-07-12 21:55:56 -07:00
var externalUrl = systemInfo.WanAddress + ApiClient.apiPrefix();
2014-02-26 14:31:47 -07:00
2014-06-17 09:03:14 -07:00
var remoteAccessHtml = Globalize.translate('LabelRemoteAccessUrl').replace('{0}', '<a href="' + externalUrl + '" target="_blank">' + externalUrl + '</a>');
$('.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;
if (pluginSecurityInfo.IsMBSupporter) {
imgUrl = "css/images/supporter/supporterbadge.png";
text = "Thank you for supporting Media Browser.";
$('.supporterIconContainer', page).html('<a class="imageLink supporterIcon" href="supporter.html" 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>');
} else {
imgUrl = "css/images/supporter/nonsupporterbadge.png";
text = "Please support Media Browser.";
2014-07-10 21:27:46 -07:00
2014-06-21 22:52:31 -07:00
$('.supporterIconContainer', page).html('<a class="imageLink supporterIcon" href="supporter.html" 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-03-25 14:13:55 -07:00
renderHasPendingRestart: function (page, hasPendingRestart) {
2013-02-20 18:33:05 -07:00
$('#updateFail', page).hide();
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();
ApiClient.getAvailableApplicationUpdate().done(function (packageInfo) {
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
}
}).fail(function () {
$('#updateFail', page).show();
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();
ApiClient.getAvailablePluginUpdates().done(function (updates) {
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
}).fail(function () {
2013-07-10 13:06:11 -07:00
$('#updateFail', page).show();
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();
ApiClient.installPlugin(name, guid, classification, version).done(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();
2014-03-25 14:13:55 -07:00
ApiClient.getScheduledTasks().done(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
ApiClient.startScheduledTask(task.Id).done(function () {
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;
2013-02-20 18:33:05 -07:00
ApiClient.stopScheduledTask(id).done(function () {
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
}
};
2014-05-29 07:19:12 -07:00
$(document).on('pagebeforeshow', "#dashboardPage", DashboardPage.onPageShow)
.on('pagehide', "#dashboardPage", DashboardPage.onPageHide);
2014-04-17 22:03:01 -07:00
(function ($, document, window) {
var showOverlayTimeout;
function onHoverOut() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
2014-08-01 19:34:45 -07:00
$('.cardOverlayTarget:visible', this).each(function () {
2014-04-17 22:03:01 -07:00
var elem = this;
$(this).animate({ "height": "0" }, "fast", function () {
$(elem).hide();
});
});
2014-08-01 19:34:45 -07:00
$('.cardOverlayTarget:visible', this).stop().animate({ "height": "0" }, function () {
2014-04-17 22:03:01 -07:00
$(this).hide();
});
}
$.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);
}
// https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
if (('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)) {
/* browser with either Touch Events of Pointer Events
running on touch-capable device */
return this;
}
2014-04-18 10:16:25 -07:00
return this.off('.sessionItemMenu').on('mouseenter.sessionItemMenu', '.playingSession', onHoverIn)
.on('mouseleave.sessionItemMenu', '.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 = '';
html += '<div class="newsItem" style="padding: .5em 0;">';
html += '<div class="notificationContent" style="display:block;">';
var date = parseISO8601Date(entry.Date, { toLocal: true });
var color = entry.Severity == 'Error' || entry.Severity == 'Fatal' || entry.Severity == 'Warn' ? '#cc0000' : 'green';
2014-10-04 11:05:24 -07:00
html += '<div style="margin: 0;color:' + color + ';">';
2014-10-01 17:28:16 -07:00
if (entry.UserId && entry.UserPrimaryImageTag) {
var userImgUrl = ApiClient.getUserImageUrl(entry.UserId, {
type: 'Primary',
tag: entry.UserPrimaryImageTag,
height: 20
});
html += '<img src="' + userImgUrl + '" style="height:20px;vertical-align:middle;margin-right:5px;" />';
}
2014-10-04 11:05:24 -07:00
html += date.toLocaleDateString() + ' ' + date.toLocaleTimeString().toLowerCase();
html += '</div>';
html += '<div class="notificationName" style="margin:.5em 0 0;white-space:nowrap;">';
2014-08-10 15:13:17 -07:00
html += entry.Name;
html += '</div>';
entry.ShortOverview = entry.ShortOverview || '&nbsp;';
if (entry.ShortOverview) {
html += '<div class="newsItemDescription" style="margin: .5em 0 0;">';
if (entry.Overview) {
html += '<a href="#" class="btnShowOverview" style="text-decoration:none;font-weight:500;">';
}
html += entry.ShortOverview;
if (entry.Overview) {
html += '</a>';
}
html += '</div>';
if (entry.Overview) {
html += '<div class="newsItemLongDescription" style="display:none;">' + entry.Overview + '</div>';
}
}
//if (notification.Url) {
// html += '<p style="margin: .25em 0;"><a href="' + notification.Url + '" target="_blank">' + Globalize.translate('ButtonMoreInformation') + '</a></p>';
//}
html += '</div>';
html += '</div>';
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 };
html += LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, limit, false);
}
$(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
})).done(function (result) {
elem.setAttribute('data-activitystartindex', startIndex);
elem.setAttribute('data-activitylimit', limit);
renderList(elem, result, startIndex, limit);
});
}
function createList(elem) {
elem.each(function () {
reloadData(this);
});
$(ApiClient).on('websocketmessage.activityloglistener', function (e, data) {
var msg = data;
2014-08-11 07:15:53 -07:00
if (msg.MessageType === "ActivityLogEntry") {
2014-08-10 15:13:17 -07:00
elem.each(function () {
reloadData(this);
});
}
2014-08-11 07:15:53 -07:00
}).on('websocketopen.activityloglistener', function (e, data) {
startListening();
2014-08-10 15:13:17 -07:00
});
}
2014-08-11 07:15:53 -07:00
function startListening() {
2014-10-04 11:05:24 -07:00
2014-08-11 07:15:53 -07:00
if (ApiClient.isWebSocketOpen()) {
ApiClient.sendWebSocketMessage("ActivityLogEntryStart", "0,1500");
}
}
function stopListening() {
if (ApiClient.isWebSocketOpen()) {
ApiClient.sendWebSocketMessage("ActivityLogEntryStop", "0,1500");
}
}
2014-08-10 15:13:17 -07:00
function destroyList(elem) {
2014-08-11 07:15:53 -07:00
$(ApiClient).off('websocketopen.activityloglistener').off('websocketmessage.activityloglistener');
stopListening();
return this;
2014-08-10 15:13:17 -07:00
}
$.fn.activityLogList = function (action) {
if (action == 'destroy') {
destroyList(this);
} else {
createList(this);
}
2014-08-11 07:15:53 -07:00
startListening();
2014-08-10 15:13:17 -07:00
return this;
};
2014-10-04 11:05:24 -07:00
})(jQuery, document, window);
(function ($, document, window) {
2014-10-04 11:12:31 -07:00
var welcomeDismissValue = '7';
2014-10-04 11:05:24 -07:00
var welcomeTourKey = 'welcomeTour';
function dismissWelcome(page, userId) {
ApiClient.getDisplayPreferences('dashboard', userId, 'dashboard').done(function (result) {
result.CustomPrefs[welcomeTourKey] = welcomeDismissValue;
ApiClient.updateDisplayPreferences('dashboard', result, userId, 'dashboard');
$(page).off('pagebeforeshow.checktour');
});
}
function showWelcomeIfNeeded(page) {
var userId = Dashboard.getCurrentUserId();
ApiClient.getDisplayPreferences('dashboard', userId, 'dashboard').done(function (result) {
if (result.CustomPrefs[welcomeTourKey] == welcomeDismissValue) {
$('.welcomeMessage', page).hide();
} else {
$('.welcomeMessage', page).show();
}
});
}
function takeTour(page, userId) {
$.swipebox([
{ href: 'css/images/tour/dashboard/dashboard.png', title: Globalize.translate('DashboardTourDashboard') },
{ href: 'css/images/tour/dashboard/users.png', title: Globalize.translate('DashboardTourUsers') },
{ href: 'css/images/tour/dashboard/cinemamode.png', title: Globalize.translate('DashboardTourCinemaMode') },
{ href: 'css/images/tour/dashboard/chapters.png', title: Globalize.translate('DashboardTourChapters') },
{ href: 'css/images/tour/dashboard/subtitles.png', title: Globalize.translate('DashboardTourSubtitles') },
{ href: 'css/images/tour/dashboard/plugins.png', title: Globalize.translate('DashboardTourPlugins') },
{ href: 'css/images/tour/dashboard/notifications.png', title: Globalize.translate('DashboardTourNotifications') },
{ href: 'css/images/tour/dashboard/scheduledtasks.png', title: Globalize.translate('DashboardTourScheduledTasks') },
2014-10-04 11:12:31 -07:00
{ href: 'css/images/tour/dashboard/mobile.png', title: Globalize.translate('DashboardTourMobile') },
2014-10-04 11:05:24 -07:00
{ href: 'css/images/tour/enjoy.jpg', title: Globalize.translate('MessageEnjoyYourStay') }
], {
afterClose: function () {
dismissWelcome(page, userId);
$('.welcomeMessage', page).hide();
},
hideBarsDelay: 30000
});
}
$(document).on('pageinit', "#dashboardPage", function () {
var page = this;
var userId = Dashboard.getCurrentUserId();
$('.btnTakeTour', page).on('click', function () {
takeTour(page, userId);
});
}).on('pagebeforeshow.checktour', "#dashboardPage", function () {
var page = this;
showWelcomeIfNeeded(page);
});
2014-08-10 15:13:17 -07:00
})(jQuery, document, window);