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

2171 lines
68 KiB
JavaScript
Raw Normal View History

2014-07-16 20:17:14 -07:00
(function () {
2014-07-12 21:55:56 -07:00
$.ajaxSetup({
2014-10-28 16:17:55 -07:00
crossDomain: true
2014-07-12 21:55:56 -07:00
});
2014-10-28 16:17:55 -07:00
if ($.browser.msie) {
2014-07-12 21:55:56 -07:00
2014-10-28 16:17:55 -07:00
// This is unfortunately required due to IE's over-aggressive caching.
// https://github.com/MediaBrowser/MediaBrowser/issues/179
$.ajaxSetup({
cache: false
});
}
2014-07-12 21:55:56 -07:00
})();
2014-10-28 16:17:55 -07:00
// TODO: Deprecated in 1.9
$.support.cors = true;
$(document).one('click', WebNotifications.requestPermission);
var Dashboard = {
2014-11-14 19:31:03 -07:00
jQueryMobileInit: function () {
// Page
//$.mobile.page.prototype.options.theme = "a";
//$.mobile.page.prototype.options.headerTheme = "a";
//$.mobile.page.prototype.options.contentTheme = "a";
//$.mobile.page.prototype.options.footerTheme = "a";
//$.mobile.button.prototype.options.theme = "c";
2013-12-24 11:37:29 -07:00
//$.mobile.listview.prototype.options.dividerTheme = "b";
2013-12-24 11:37:29 -07:00
//$.mobile.popup.prototype.options.theme = "c";
2015-06-05 07:27:01 -07:00
$.mobile.popup.prototype.options.transition = "pop";
2015-05-15 08:46:20 -07:00
2015-06-07 21:47:19 -07:00
//$.mobile.keepNative = "input[type='text'],input[type='password'],input[type='number']";
2015-05-15 08:46:20 -07:00
if ($.browser.mobile) {
2015-06-07 14:21:30 -07:00
$.mobile.defaultPageTransition = "none";
2015-05-15 08:46:20 -07:00
} else {
$.mobile.defaultPageTransition = "none";
}
//$.mobile.collapsible.prototype.options.contentTheme = "a";
// Make panels a little larger than the defaults
$.mobile.panel.prototype.options.classes.modalOpen = "largePanelModalOpen ui-panel-dismiss-open";
$.mobile.panel.prototype.options.classes.panel = "largePanel ui-panel";
2015-06-07 14:21:30 -07:00
$.event.special.swipe.verticalDistanceThreshold = 40;
$.mobile.loader.prototype.options.disabled = true;
2015-06-08 14:32:20 -07:00
//$.mobile.page.prototype.options.domCache = true;
},
2015-05-05 08:24:47 -07:00
isConnectMode: function () {
2015-05-28 16:37:43 -07:00
if (AppInfo.isNativeApp) {
2015-05-05 08:24:47 -07:00
return true;
}
var url = getWindowUrl().toLowerCase();
return url.indexOf('mediabrowser.tv') != -1 ||
url.indexOf('emby.media') != -1;
},
2015-05-01 11:37:01 -07:00
isRunningInCordova: function () {
2015-05-02 09:34:27 -07:00
return window.appMode == 'cordova';
2015-05-01 11:37:01 -07:00
},
2014-10-28 16:17:55 -07:00
onRequestFail: function (e, data) {
if (data.status == 401) {
var url = data.url.toLowerCase();
// Bounce to the login screen, but not if a password entry fails, obviously
if (url.indexOf('/password') == -1 &&
url.indexOf('/authenticate') == -1 &&
!$($.mobile.activePage).is('.standalonePage')) {
if (data.errorCode == "ParentalControl") {
Dashboard.alert({
message: Globalize.translate('MessageLoggedOutParentalControl'),
2014-10-29 15:01:02 -07:00
callback: function () {
2014-10-28 16:17:55 -07:00
Dashboard.logout(false);
}
});
} else {
Dashboard.logout(false);
}
}
return;
}
Dashboard.hideLoadingMsg();
2015-06-07 14:21:30 -07:00
if (!Dashboard.suppressAjaxErrors && data.type != 'GET' && !AppInfo.isNativeApp) {
2014-10-28 16:17:55 -07:00
setTimeout(function () {
var msg = data.errorCode || Dashboard.defaultErrorMessage;
Dashboard.showError(msg);
}, 500);
}
},
getCurrentUser: function () {
if (!Dashboard.getUserPromise) {
2013-07-16 09:03:28 -07:00
2015-05-18 15:23:03 -07:00
Dashboard.getUserPromise = window.ApiClient.getCurrentUser().fail(Dashboard.logout);
}
return Dashboard.getUserPromise;
},
2014-06-21 22:52:31 -07:00
validateCurrentUser: function () {
2013-07-16 09:03:28 -07:00
Dashboard.getUserPromise = null;
if (Dashboard.getCurrentUserId()) {
Dashboard.getCurrentUser();
}
},
2015-05-20 09:28:55 -07:00
serverAddress: function () {
2014-07-07 18:41:03 -07:00
2015-05-20 09:28:55 -07:00
if (Dashboard.isConnectMode()) {
var apiClient = window.ApiClient;
2014-10-21 21:42:26 -07:00
2015-05-20 09:28:55 -07:00
if (apiClient) {
return apiClient.serverAddress();
}
2014-10-21 21:42:26 -07:00
2015-05-20 09:28:55 -07:00
return null;
2014-10-15 20:26:39 -07:00
}
2015-05-20 09:28:55 -07:00
// Try to get the server address from the browser url
// This will preserve protocol, hostname, port and subdirectory
var urlLower = getWindowUrl().toLowerCase();
var index = urlLower.indexOf('/web');
if (index == -1) {
index = urlLower.indexOf('/dashboard');
}
2015-02-10 20:28:34 -07:00
2015-05-20 09:28:55 -07:00
if (index != -1) {
return urlLower.substring(0, index);
}
2015-02-10 20:28:34 -07:00
2015-05-20 09:28:55 -07:00
// If the above failed, just piece it together manually
var loc = window.location;
2014-10-15 20:26:39 -07:00
2015-05-20 09:28:55 -07:00
var address = loc.protocol + '//' + loc.hostname;
2014-10-15 20:26:39 -07:00
2015-05-20 09:28:55 -07:00
if (loc.port) {
address += ':' + loc.port;
2014-10-15 20:26:39 -07:00
}
return address;
},
getCurrentUserId: function () {
2015-05-20 09:28:55 -07:00
var apiClient = window.ApiClient;
2014-03-15 13:08:06 -07:00
2015-05-20 09:28:55 -07:00
if (apiClient) {
return apiClient.getCurrentUserId();
}
2015-05-20 09:28:55 -07:00
return null;
},
2015-05-20 09:28:55 -07:00
onServerChanged: function (userId, accessToken, apiClient) {
2015-05-20 09:28:55 -07:00
apiClient = apiClient || window.ApiClient;
2014-02-08 13:02:35 -07:00
2015-05-20 09:28:55 -07:00
window.ApiClient = apiClient;
2014-10-25 11:32:58 -07:00
Dashboard.getUserPromise = null;
},
2015-05-21 13:53:14 -07:00
logout: function (logoutWithServer) {
2015-05-17 18:27:48 -07:00
function onLogoutDone() {
2015-05-19 12:15:40 -07:00
var loginPage;
2014-10-21 05:42:02 -07:00
2015-05-18 18:46:31 -07:00
if (Dashboard.isConnectMode()) {
loginPage = 'connectlogin.html';
window.ApiClient = null;
} else {
2015-05-19 12:15:40 -07:00
loginPage = 'login.html';
2015-05-18 18:46:31 -07:00
}
2015-05-21 13:53:14 -07:00
Dashboard.navigate(loginPage);
2015-05-17 18:27:48 -07:00
}
2014-07-12 21:55:56 -07:00
2015-05-17 18:27:48 -07:00
if (logoutWithServer === false) {
onLogoutDone();
} else {
ConnectionManager.logout().done(onLogoutDone);
2014-07-12 21:55:56 -07:00
}
},
2015-01-18 22:41:56 -07:00
importCss: function (url) {
if (document.createStyleSheet) {
document.createStyleSheet(url);
}
else {
$('<link rel="stylesheet" type="text/css" href="' + url + '" />').appendTo('head');
}
},
showError: function (message) {
$.mobile.loading('show', {
text: message,
textonly: true,
textVisible: true
});
setTimeout(function () {
$.mobile.loading('hide');
}, 3000);
},
updateSystemInfo: function (info) {
Dashboard.lastSystemInfo = info;
2014-07-07 18:41:03 -07:00
2014-07-19 21:46:29 -07:00
Dashboard.ensureWebSocket();
if (!Dashboard.initialServerVersion) {
Dashboard.initialServerVersion = info.Version;
}
if (info.HasPendingRestart) {
Dashboard.hideDashboardVersionWarning();
Dashboard.getCurrentUser().done(function (currentUser) {
2014-12-19 23:06:27 -07:00
if (currentUser.Policy.IsAdministrator) {
2013-10-07 07:38:31 -07:00
Dashboard.showServerRestartWarning(info);
}
});
} else {
Dashboard.hideServerRestartWarning();
if (Dashboard.initialServerVersion != info.Version) {
2015-01-18 22:41:56 -07:00
Dashboard.showDashboardRefreshNotification();
}
}
Dashboard.showInProgressInstallations(info.InProgressInstallations);
},
showInProgressInstallations: function (installations) {
installations = installations || [];
for (var i = 0, length = installations.length; i < length; i++) {
var installation = installations[i];
var percent = installation.PercentComplete || 0;
if (percent < 100) {
Dashboard.showPackageInstallNotification(installation, "progress");
}
}
if (installations.length) {
Dashboard.ensureInstallRefreshInterval();
} else {
Dashboard.stopInstallRefreshInterval();
}
},
ensureInstallRefreshInterval: function () {
if (!Dashboard.installRefreshInterval) {
if (ApiClient.isWebSocketOpen()) {
2014-05-10 10:28:03 -07:00
ApiClient.sendWebSocketMessage("SystemInfoStart", "0,500");
}
Dashboard.installRefreshInterval = 1;
}
},
stopInstallRefreshInterval: function () {
if (Dashboard.installRefreshInterval) {
if (ApiClient.isWebSocketOpen()) {
ApiClient.sendWebSocketMessage("SystemInfoStop");
}
Dashboard.installRefreshInterval = null;
}
},
cancelInstallation: function (id) {
ApiClient.cancelPackageInstallation(id).always(Dashboard.refreshSystemInfoFromServer);
},
2013-10-07 07:38:31 -07:00
showServerRestartWarning: function (systemInfo) {
2014-07-16 20:17:14 -07:00
var html = '<span style="margin-right: 1em;">' + Globalize.translate('MessagePleaseRestart') + '</span>';
2013-11-28 11:27:29 -07:00
2013-10-07 07:38:31 -07:00
if (systemInfo.CanSelfRestart) {
2014-07-16 20:17:14 -07:00
html += '<button type="button" data-icon="refresh" onclick="$(this).buttonEnabled(false);Dashboard.restartServer();" data-theme="b" data-inline="true" data-mini="true">' + Globalize.translate('ButtonRestart') + '</button>';
2013-10-07 07:38:31 -07:00
}
Dashboard.showFooterNotification({ id: "serverRestartWarning", html: html, forceShow: true, allowHide: false });
},
hideServerRestartWarning: function () {
$('#serverRestartWarning').remove();
},
2015-01-18 22:41:56 -07:00
showDashboardRefreshNotification: function () {
2014-07-16 20:17:14 -07:00
var html = '<span style="margin-right: 1em;">' + Globalize.translate('MessagePleaseRefreshPage') + '</span>';
2014-07-16 20:17:14 -07:00
html += '<button type="button" data-icon="refresh" onclick="$(this).buttonEnabled(false);Dashboard.reloadPage();" data-theme="b" data-inline="true" data-mini="true">' + Globalize.translate('ButtonRefresh') + '</button>';
2014-04-13 10:27:13 -07:00
Dashboard.showFooterNotification({ id: "dashboardVersionWarning", html: html, forceShow: true, allowHide: false });
},
reloadPage: function () {
2014-10-21 05:42:02 -07:00
var currentUrl = getWindowUrl().toLowerCase();
2015-05-17 18:27:48 -07:00
var newUrl;
2013-11-28 11:27:29 -07:00
// If they're on a plugin config page just go back to the dashboard
// The plugin may not have been loaded yet, or could have been uninstalled
if (currentUrl.indexOf('configurationpage') != -1) {
2015-05-17 18:27:48 -07:00
newUrl = "dashboard.html";
} else {
2015-05-17 18:27:48 -07:00
newUrl = getWindowUrl();
}
2015-05-17 18:27:48 -07:00
window.location.href = newUrl;
},
hideDashboardVersionWarning: function () {
$('#dashboardVersionWarning').remove();
},
showFooterNotification: function (options) {
2015-05-07 15:27:01 -07:00
if (!AppInfo.enableFooterNotifications) {
2015-05-06 20:11:51 -07:00
return;
}
var removeOnHide = !options.id;
options.id = options.id || "notification" + new Date().getTime() + parseInt(Math.random());
2015-05-07 15:27:01 -07:00
var footer = $(".footer").css("top", "initial").show();
var parentElem = $('#footerNotifications', footer);
var elem = $('#' + options.id, parentElem);
if (!elem.length) {
elem = $('<p id="' + options.id + '" class="footerNotification"></p>').appendTo(parentElem);
}
var onclick = removeOnHide ? "$(\"#" + options.id + "\").trigger(\"notification.remove\").remove();" : "$(\"#" + options.id + "\").trigger(\"notification.hide\").hide();";
if (options.allowHide !== false) {
2014-07-16 20:17:14 -07:00
options.html += "<span style='margin-left: 1em;'><button type='button' onclick='" + onclick + "' data-icon='delete' data-iconpos='notext' data-mini='true' data-inline='true' data-theme='b'>" + Globalize.translate('ButtonHide') + "</button></span>";
}
if (options.forceShow) {
elem.slideDown(400);
}
elem.html(options.html).trigger("create");
if (options.timeout) {
setTimeout(function () {
if (removeOnHide) {
elem.trigger("notification.remove").remove();
} else {
elem.trigger("notification.hide").hide();
}
}, options.timeout);
}
footer.on("notification.remove notification.hide", function (e) {
setTimeout(function () { // give the DOM time to catch up
if (!parentElem.html()) {
footer.slideUp();
}
}, 50);
});
},
getConfigurationPageUrl: function (name) {
return "ConfigurationPage?name=" + encodeURIComponent(name);
},
2015-05-20 10:29:26 -07:00
navigate: function (url, preserveQueryString, transition) {
2015-05-12 21:55:19 -07:00
if (!url) {
throw new Error('url cannot be null or empty');
}
2014-04-08 19:12:17 -07:00
var queryString = getWindowLocationSearch();
if (preserveQueryString && queryString) {
url += queryString;
}
2015-05-20 10:29:26 -07:00
var options = {};
if (transition) {
options.transition = transition;
}
$.mobile.changePage(url, options);
},
showLoadingMsg: function () {
2013-03-31 18:52:07 -07:00
$.mobile.loading("show");
},
hideLoadingMsg: function () {
2013-03-31 18:52:07 -07:00
$.mobile.loading("hide");
},
2015-05-06 20:11:51 -07:00
getModalLoadingMsg: function () {
var elem = $('.modalLoading');
if (!elem.length) {
elem = $('<div class="modalLoading"></div>').appendTo(document.body);
}
return elem;
},
showModalLoadingMsg: function () {
Dashboard.showLoadingMsg();
Dashboard.getModalLoadingMsg().show();
},
hideModalLoadingMsg: function () {
Dashboard.getModalLoadingMsg().hide();
Dashboard.hideLoadingMsg();
},
processPluginConfigurationUpdateResult: function () {
Dashboard.hideLoadingMsg();
Dashboard.alert("Settings saved.");
},
2014-11-04 05:41:12 -07:00
defaultErrorMessage: Globalize.translate('DefaultErrorMessage'),
processServerConfigurationUpdateResult: function (result) {
Dashboard.hideLoadingMsg();
2014-07-16 20:17:14 -07:00
Dashboard.alert(Globalize.translate('MessageSettingsSaved'));
},
2015-05-01 11:37:01 -07:00
alert: function (options) {
if (typeof options == "string") {
var message = options;
$.mobile.loading('show', {
text: message,
textonly: true,
textVisible: true
});
setTimeout(function () {
$.mobile.loading('hide');
}, 3000);
return;
}
2015-05-02 09:34:27 -07:00
// Cordova
if (navigator.notification && navigator.notification.alert && options.message.indexOf('<') == -1) {
2015-05-01 11:37:01 -07:00
navigator.notification.alert(options.message, options.callback || function () { }, options.title || Globalize.translate('HeaderAlert'));
} else {
Dashboard.confirmInternal(options.message, options.title || Globalize.translate('HeaderAlert'), false, options.callback);
}
},
confirm: function (message, title, callback) {
2015-05-02 09:34:27 -07:00
// Cordova
if (navigator.notification && navigator.notification.alert && message.indexOf('<') == -1) {
2015-05-01 11:37:01 -07:00
var buttonLabels = [Globalize.translate('ButtonOk'), Globalize.translate('ButtonCancel')];
2015-05-02 09:34:27 -07:00
navigator.notification.confirm(message, function (index) {
2015-05-01 11:37:01 -07:00
2015-05-02 09:34:27 -07:00
callback(index == 1);
2015-05-01 11:37:01 -07:00
2015-05-02 09:34:27 -07:00
}, title || Globalize.translate('HeaderAlert'), buttonLabels.join(','));
2015-05-01 11:37:01 -07:00
} else {
Dashboard.confirmInternal(message, title, true, callback);
}
},
2013-12-26 19:23:57 -07:00
confirmInternal: function (message, title, showCancel, callback) {
2014-01-22 10:05:06 -07:00
$('.confirmFlyout').popup("close").remove();
2014-06-28 12:35:30 -07:00
var html = '<div data-role="popup" class="confirmFlyout" style="max-width:500px;" data-theme="a">';
2013-12-24 11:37:29 -07:00
html += '<div class="ui-bar-a" style="text-align:center;">';
2014-08-10 15:13:17 -07:00
html += '<h3 style="padding: 0 1em;">' + title + '</h3>';
html += '</div>';
2013-12-24 11:37:29 -07:00
html += '<div style="padding: 1em;">';
html += '<div style="padding: 1em .25em;margin: 0;">';
html += message;
html += '</div>';
2014-07-16 20:17:14 -07:00
html += '<p><button type="button" data-icon="check" onclick="$(\'.confirmFlyout\')[0].confirm=true;$(\'.confirmFlyout\').popup(\'close\');" data-theme="b">' + Globalize.translate('ButtonOk') + '</button></p>';
2013-12-26 19:23:57 -07:00
if (showCancel) {
2014-07-16 20:17:14 -07:00
html += '<p><button type="button" data-icon="delete" onclick="$(\'.confirmFlyout\').popup(\'close\');" data-theme="a">' + Globalize.translate('ButtonCancel') + '</button></p>';
2013-12-26 19:23:57 -07:00
}
html += '</div>';
html += '</div>';
$(document.body).append(html);
2014-01-22 10:05:06 -07:00
$('.confirmFlyout').popup({ history: false }).trigger('create').popup("open").on("popupafterclose", function () {
if (callback) {
callback(this.confirm == true);
}
$(this).off("popupafterclose").remove();
});
},
refreshSystemInfoFromServer: function () {
2015-05-20 09:28:55 -07:00
var apiClient = ApiClient;
2015-05-21 13:53:14 -07:00
if (apiClient && apiClient.accessToken()) {
2015-05-20 09:28:55 -07:00
if (apiClient.enableFooterNotifications) {
apiClient.getSystemInfo().done(function (info) {
2014-07-07 18:41:03 -07:00
2015-05-07 15:27:01 -07:00
Dashboard.updateSystemInfo(info);
});
} else {
Dashboard.ensureWebSocket();
}
2014-07-07 18:41:03 -07:00
}
},
restartServer: function () {
Dashboard.suppressAjaxErrors = true;
Dashboard.showLoadingMsg();
2013-07-16 10:18:32 -07:00
ApiClient.restartServer().done(function () {
setTimeout(function () {
Dashboard.reloadPageWhenServerAvailable();
}, 250);
}).fail(function () {
Dashboard.suppressAjaxErrors = false;
});
},
reloadPageWhenServerAvailable: function (retryCount) {
// Don't use apiclient method because we don't want it reporting authentication under the old version
2014-07-01 22:16:59 -07:00
ApiClient.getJSON(ApiClient.getUrl("System/Info")).done(function (info) {
// If this is back to false, the restart completed
if (!info.HasPendingRestart) {
Dashboard.reloadPage();
} else {
Dashboard.retryReload(retryCount);
}
}).fail(function () {
Dashboard.retryReload(retryCount);
});
},
retryReload: function (retryCount) {
setTimeout(function () {
retryCount = retryCount || 0;
retryCount++;
if (retryCount < 10) {
Dashboard.reloadPageWhenServerAvailable(retryCount);
} else {
Dashboard.suppressAjaxErrors = false;
}
}, 500);
},
2015-06-10 06:37:07 -07:00
showUserFlyout: function () {
var html = '<div data-role="panel" data-position="right" data-display="overlay" id="userFlyout" data-position-fixed="true" data-theme="a">';
html += '<h3 class="userHeader">';
html += '</h3>';
html += '<form>';
html += '<p class="preferencesContainer"></p>';
html += '<p><button data-mini="true" type="button" onclick="Dashboard.logout();" data-icon="lock">' + Globalize.translate('ButtonSignOut') + '</button></p>';
html += '</form>';
html += '</div>';
$(document.body).append(html);
var elem = $('#userFlyout').panel({}).lazyChildren().trigger('create').panel("open").on("panelclose", function () {
$(this).off("panelclose").remove();
});
ConnectionManager.user(window.ApiClient).done(function (user) {
Dashboard.updateUserFlyout(elem, user);
});
},
updateUserFlyout: function (elem, user) {
var html = '';
var imgWidth = 48;
if (user.imageUrl && AppInfo.enableUserImage) {
var url = user.imageUrl;
if (user.supportsImageParams) {
url += "&width=" + (imgWidth * Math.max(window.devicePixelRatio || 1, 2));
}
html += '<div class="lazy" data-src="' + url + '" style="width:' + imgWidth + 'px;height:' + imgWidth + 'px;background-size:contain;background-repeat:no-repeat;background-position:center center;border-radius:1000px;vertical-align:middle;margin-right:.8em;display:inline-block;"></div>';
}
html += user.name;
$('.userHeader', elem).html(html).lazyChildren();
html = '';
if (user.localUser && user.localUser.Policy.EnableUserPreferenceAccess) {
html += '<p><a data-mini="true" data-role="button" href="mypreferencesdisplay.html?userId=' + user.localUser.Id + '" data-icon="gear">' + Globalize.translate('ButtonSettings') + '</button></a>';
}
$('.preferencesContainer', elem).html(html).trigger('create');
},
getPluginSecurityInfo: function () {
2015-05-19 12:15:40 -07:00
var apiClient = ApiClient;
if (!apiClient) {
var deferred = $.Deferred();
deferred.reject();
return deferred.promise();
}
if (!Dashboard.getPluginSecurityInfoPromise) {
var deferred = $.Deferred();
// Don't let this blow up the dashboard when it fails
2015-05-19 12:15:40 -07:00
apiClient.ajax({
type: "GET",
2015-05-19 12:15:40 -07:00
url: apiClient.getUrl("Plugins/SecurityInfo"),
dataType: 'json',
error: function () {
// Don't show normal dashboard errors
}
}).done(function (result) {
2013-06-04 09:59:03 -07:00
deferred.resolveWith(null, [result]);
});
Dashboard.getPluginSecurityInfoPromise = deferred;
}
return Dashboard.getPluginSecurityInfoPromise;
},
resetPluginSecurityInfo: function () {
Dashboard.getPluginSecurityInfoPromise = null;
},
2014-06-21 22:52:31 -07:00
ensureHeader: function (page) {
2015-03-01 22:16:29 -07:00
if (page.hasClass('standalonePage') && !page.hasClass('noHeaderPage')) {
2014-06-21 22:52:31 -07:00
Dashboard.renderHeader(page);
}
},
2014-06-21 22:52:31 -07:00
renderHeader: function (page) {
2013-04-22 07:44:11 -07:00
var header = $('.header', page);
2013-04-23 12:17:21 -07:00
2013-04-22 07:44:11 -07:00
if (!header.length) {
2014-06-21 22:52:31 -07:00
var headerHtml = '';
2013-04-22 07:44:11 -07:00
headerHtml += '<div class="header">';
2015-01-11 13:31:09 -07:00
headerHtml += '<a class="logo" href="index.html" style="text-decoration:none;font-size: 22px;">';
if (page.hasClass('standalonePage')) {
2015-01-11 13:31:09 -07:00
headerHtml += '<img class="imgLogoIcon" src="css/images/mblogoicon.png" />';
2015-03-21 11:12:12 -07:00
headerHtml += '<span class="logoLibraryMenuButtonText">EMBY</span>';
2013-03-31 22:08:29 -07:00
}
headerHtml += '</a>';
2013-12-26 22:08:37 -07:00
2013-04-22 07:44:11 -07:00
headerHtml += '</div>';
page.prepend(headerHtml);
}
},
2013-05-10 05:18:07 -07:00
2015-05-31 11:22:51 -07:00
ensureToolsMenu: function (page) {
var sidebar = $('.toolsSidebar', page);
if (!sidebar.length) {
2014-07-26 10:30:15 -07:00
var html = '<div class="content-secondary toolsSidebar">';
2014-06-25 08:12:39 -07:00
html += '<div class="sidebarLinks">';
2015-01-18 12:53:34 -07:00
var items = Dashboard.getToolsMenuLinks(page);
2015-01-18 12:53:34 -07:00
var i, length, item;
2015-01-18 21:29:57 -07:00
var menuHtml = '';
2013-12-26 22:08:37 -07:00
2015-01-18 12:53:34 -07:00
for (i = 0, length = items.length; i < length; i++) {
2015-01-18 12:53:34 -07:00
item = items[i];
2013-12-26 19:23:57 -07:00
2015-01-18 12:53:34 -07:00
if (item.divider) {
2015-05-31 14:07:44 -07:00
menuHtml += "<div class='sidebarDivider'></div>";
2013-12-25 20:44:26 -07:00
}
2015-01-18 12:53:34 -07:00
if (item.href) {
2015-01-18 12:53:34 -07:00
var style = item.color ? ' style="color:' + item.color + '"' : '';
if (item.selected) {
2015-01-18 21:29:57 -07:00
menuHtml += '<a class="sidebarLink selectedSidebarLink" href="' + item.href + '">';
} else {
2015-06-07 14:21:30 -07:00
menuHtml += '<a class="sidebarLink" href="' + item.href + '">';
}
2015-05-31 11:22:51 -07:00
var icon = item.icon;
if (icon) {
if (icon.indexOf('fa') == 0) {
menuHtml += '<span class="fa ' + icon + ' sidebarLinkIcon"' + style + '></span>';
} else {
menuHtml += '<i class="material-icons sidebarLinkIcon"' + style + '>' + icon + '</i>';
}
}
2015-01-18 12:53:34 -07:00
2015-01-18 21:29:57 -07:00
menuHtml += '<span class="sidebarLinkText">';
menuHtml += item.name;
menuHtml += '</span>';
menuHtml += '</a>';
2015-01-18 12:53:34 -07:00
} else {
2015-01-18 21:29:57 -07:00
menuHtml += '<div class="sidebarHeader">';
menuHtml += item.name;
menuHtml += '</div>';
}
}
2015-01-18 21:29:57 -07:00
html += menuHtml;
// sidebarLinks
html += '</div>';
// content-secondary
html += '</div>';
2014-07-26 10:30:15 -07:00
html += '<div data-role="panel" id="dashboardPanel" class="dashboardPanel" data-position="left" data-display="overlay" data-position-fixed="true" data-theme="a">';
2013-12-26 22:08:37 -07:00
2015-06-07 14:21:30 -07:00
html += '<p class="libraryPanelHeader" style="margin: 15px 0 15px 20px;"><a href="index.html" class="imageLink"><img src="css/images/mblogoicon.png" /><span style="color:#333;">EMBY</span></a></p>';
2013-12-26 22:08:37 -07:00
2015-01-18 21:29:57 -07:00
html += '<div class="sidebarLinks">';
html += menuHtml;
// sidebarLinks
2015-05-31 14:07:44 -07:00
html += '<div class="sidebarDivider"></div>';
html += '<div class="userMenuOptions">';
if (Dashboard.isConnectMode()) {
html += '<a class="sidebarLink" data-itemid="selectserver" href="selectserver.html"><span class="fa fa-globe sidebarLinkIcon"></span>';
html += '<span class="sidebarLinkText">';
html += Globalize.translate('ButtonSelectServer');
html += '</span>';
html += '</a>';
}
html += '<a class="sidebarLink" data-itemid="logout" href="#" onclick="Dashboard.logout();"><span class="fa fa-sign-out sidebarLinkIcon"></span>';
html += '<span class="sidebarLinkText">';
html += Globalize.translate('ButtonSignOut');
html += '</span>';
html += '</a>';
html += '</div>';
2015-01-18 21:29:57 -07:00
html += '</div>';
2013-12-26 22:08:37 -07:00
html += '</div>';
2014-07-26 10:30:15 -07:00
$('.content-primary', page).before(html);
$(page).trigger('create');
}
},
getToolsMenuLinks: function (page) {
var pageElem = page[0];
var isServicesPage = page.hasClass('appServicesPage');
var context = getParameterByName('context');
return [{
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabServer'),
href: "dashboard.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("dashboardHomePage"),
icon: 'fa-dashboard',
color: '#38c'
2014-10-11 13:38:13 -07:00
}, {
name: Globalize.translate('TabDevices'),
href: "devices.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("devicesPage"),
icon: 'fa-tablet',
color: '#ECA403'
2014-07-26 10:30:15 -07:00
}, {
name: Globalize.translate('TabUsers'),
href: "userprofiles.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("userProfilesPage"),
icon: 'fa-users',
color: '#679C34'
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabLibrary'),
2013-12-25 20:44:26 -07:00
divider: true,
href: "library.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("mediaLibraryPage"),
icon: 'fa-film'
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabMetadata'),
href: "metadata.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass('metadataConfigurationPage'),
icon: 'fa-file-text'
2014-01-22 16:52:01 -07:00
}, {
2014-09-22 14:56:54 -07:00
name: Globalize.translate('TabPlayback'),
href: "playbackconfiguration.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass('playbackConfigurationPage'),
icon: 'fa-play-circle'
}, {
name: Globalize.translate('TabSync'),
href: "syncactivity.html",
selected: page.hasClass('syncConfigurationPage') || (isServicesPage && context == 'sync'),
2015-06-01 22:46:06 -07:00
icon: 'fa-refresh'
2014-09-22 14:56:54 -07:00
}, {
divider: true,
2015-01-18 12:53:34 -07:00
name: Globalize.translate('TabExtras')
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabAutoOrganize'),
2014-01-22 16:52:01 -07:00
href: "autoorganizelog.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("organizePage"),
icon: 'fa-files-o',
color: '#01C0DD'
2014-06-01 12:41:35 -07:00
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabDLNA'),
2014-03-10 10:38:53 -07:00
href: "dlnasettings.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("dlnaPage"),
icon: 'fa-film',
color: '#E5342E'
2014-01-12 09:55:38 -07:00
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabLiveTV'),
2014-01-22 13:46:01 -07:00
href: "livetvstatus.html",
selected: page.hasClass("liveTvSettingsPage") || (isServicesPage && context == 'livetv'),
2015-01-18 12:53:34 -07:00
icon: 'fa-video-camera',
color: '#293AAE'
}, {
name: Globalize.translate('TabNotifications'),
href: "notificationsettings.html",
selected: page.hasClass("notificationConfigurationPage"),
icon: 'fa-wifi',
color: 'brown'
2014-03-25 14:13:55 -07:00
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabPlugins'),
2014-03-25 14:13:55 -07:00
href: "plugins.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("pluginConfigurationPage"),
icon: 'fa-plus-circle',
color: '#9D22B1'
}, {
2013-12-25 20:44:26 -07:00
divider: true,
2015-01-18 12:53:34 -07:00
name: Globalize.translate('TabExpert')
}, {
name: Globalize.translate('TabAdvanced'),
href: "advanced.html",
2015-01-18 12:53:34 -07:00
selected: page.hasClass("advancedConfigurationPage"),
icon: 'fa-gears',
color: '#F16834'
}, {
name: Globalize.translate('TabScheduledTasks'),
href: "scheduledtasks.html",
selected: page.hasClass("scheduledTasksConfigurationPage"),
icon: 'fa-clock-o',
color: '#38c'
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabHelp'),
2015-01-18 12:53:34 -07:00
divider: true,
href: "support.html",
2015-01-18 12:53:34 -07:00
selected: pageElem.id == "supportPage" || pageElem.id == "logPage" || pageElem.id == "supporterPage" || pageElem.id == "supporterKeyPage" || pageElem.id == "aboutPage",
icon: 'fa-info-circle',
color: '#679C34'
}];
},
2014-07-19 21:46:29 -07:00
ensureWebSocket: function () {
2014-10-27 14:45:50 -07:00
if (ApiClient.isWebSocketOpenOrConnecting() || !ApiClient.isWebSocketSupported()) {
return;
}
2014-10-21 21:42:26 -07:00
ApiClient.openWebSocket();
2015-05-07 15:27:01 -07:00
if (!Dashboard.isConnectMode()) {
ApiClient.reportCapabilities(Dashboard.capabilities());
}
},
2014-04-27 18:57:29 -07:00
processGeneralCommand: function (cmd) {
// Full list
// https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs#L23
2014-05-06 19:28:19 -07:00
2014-04-30 20:24:55 -07:00
switch (cmd.Name) {
2014-05-06 19:28:19 -07:00
2014-04-30 20:24:55 -07:00
case 'GoHome':
Dashboard.navigate('index.html');
break;
case 'GoToSettings':
Dashboard.navigate('dashboard.html');
break;
case 'DisplayContent':
Dashboard.onBrowseCommand(cmd.Arguments);
break;
case 'GoToSearch':
Search.showSearchPanel($.mobile.activePage);
break;
2014-05-08 13:09:53 -07:00
case 'DisplayMessage':
{
var args = cmd.Arguments;
2015-05-21 13:53:14 -07:00
if (args.TimeoutMs) {
Dashboard.showFooterNotification({ html: "<div><b>" + args.Header + "</b></div>" + args.Text, timeout: args.TimeoutMs });
2014-05-08 13:09:53 -07:00
}
else {
2015-05-21 13:53:14 -07:00
Dashboard.alert({ title: args.Header, message: args.Text });
2014-05-08 13:09:53 -07:00
}
break;
}
2014-04-30 20:24:55 -07:00
case 'VolumeUp':
case 'VolumeDown':
case 'Mute':
case 'Unmute':
case 'ToggleMute':
case 'SetVolume':
case 'SetAudioStreamIndex':
case 'SetSubtitleStreamIndex':
case 'ToggleFullscreen':
break;
default:
console.log('Unrecognized command: ' + cmd.Name);
break;
2014-04-27 18:57:29 -07:00
}
},
2013-03-27 22:19:58 -07:00
onWebSocketMessageReceived: function (e, data) {
2013-03-27 22:19:58 -07:00
var msg = data;
2013-03-31 18:52:07 -07:00
if (msg.MessageType === "LibraryChanged") {
Dashboard.processLibraryUpdateNotification(msg.Data);
}
2013-09-05 10:26:03 -07:00
else if (msg.MessageType === "ServerShuttingDown") {
Dashboard.hideServerRestartWarning();
}
else if (msg.MessageType === "ServerRestarting") {
Dashboard.hideServerRestartWarning();
}
else if (msg.MessageType === "UserDeleted") {
Dashboard.validateCurrentUser();
}
else if (msg.MessageType === "SystemInfo") {
Dashboard.updateSystemInfo(msg.Data);
}
2013-03-27 22:19:58 -07:00
else if (msg.MessageType === "RestartRequired") {
Dashboard.updateSystemInfo(msg.Data);
}
2014-06-21 22:52:31 -07:00
else if (msg.MessageType === "UserUpdated" || msg.MessageType === "UserConfigurationUpdated") {
var user = msg.Data;
if (user.Id == Dashboard.getCurrentUserId()) {
2015-05-20 09:28:55 -07:00
Dashboard.validateCurrentUser();
$('.currentUsername').html(user.Name);
}
2015-05-20 09:28:55 -07:00
}
else if (msg.MessageType === "PackageInstallationCompleted") {
Dashboard.getCurrentUser().done(function (currentUser) {
2014-12-19 23:06:27 -07:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "completed");
Dashboard.refreshSystemInfoFromServer();
}
});
}
else if (msg.MessageType === "PackageInstallationFailed") {
Dashboard.getCurrentUser().done(function (currentUser) {
2014-12-19 23:06:27 -07:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "failed");
Dashboard.refreshSystemInfoFromServer();
}
});
}
else if (msg.MessageType === "PackageInstallationCancelled") {
Dashboard.getCurrentUser().done(function (currentUser) {
2014-12-19 23:06:27 -07:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "cancelled");
Dashboard.refreshSystemInfoFromServer();
}
});
}
2015-05-20 09:28:55 -07:00
else if (msg.MessaapiclientcgeType === "PackageInstalling") {
Dashboard.getCurrentUser().done(function (currentUser) {
2014-12-19 23:06:27 -07:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "progress");
Dashboard.refreshSystemInfoFromServer();
}
});
}
2014-03-31 14:04:22 -07:00
else if (msg.MessageType === "GeneralCommand") {
2014-03-31 14:04:22 -07:00
var cmd = msg.Data;
2014-12-15 22:01:57 -07:00
// Media Controller should catch this
//Dashboard.processGeneralCommand(cmd);
}
2013-05-10 05:18:07 -07:00
},
onBrowseCommand: function (cmd) {
var url;
2013-05-25 17:53:51 -07:00
var type = (cmd.ItemType || "").toLowerCase();
2013-05-10 05:18:07 -07:00
if (type == "genre") {
2014-08-18 18:42:53 -07:00
url = "itembynamedetails.html?id=" + cmd.ItemId;
2013-05-10 05:18:07 -07:00
}
2013-06-10 20:31:00 -07:00
else if (type == "musicgenre") {
2014-08-18 18:42:53 -07:00
url = "itembynamedetails.html?id=" + cmd.ItemId;
2013-06-10 20:31:00 -07:00
}
2013-07-01 10:17:33 -07:00
else if (type == "gamegenre") {
2014-08-18 18:42:53 -07:00
url = "itembynamedetails.html?id=" + cmd.ItemId;
2013-07-01 10:17:33 -07:00
}
2013-05-10 05:18:07 -07:00
else if (type == "studio") {
2014-08-18 18:42:53 -07:00
url = "itembynamedetails.html?id=" + cmd.ItemId;
2013-05-10 05:18:07 -07:00
}
else if (type == "person") {
2014-08-18 18:42:53 -07:00
url = "itembynamedetails.html?id=" + cmd.ItemId;
2013-05-10 05:18:07 -07:00
}
2013-11-21 13:48:26 -07:00
else if (type == "musicartist") {
2014-08-18 18:42:53 -07:00
url = "itembynamedetails.html?id=" + cmd.ItemId;
2013-05-10 05:18:07 -07:00
}
2013-05-10 05:18:07 -07:00
if (url) {
Dashboard.navigate(url);
return;
}
2013-05-25 17:53:51 -07:00
ApiClient.getItem(Dashboard.getCurrentUserId(), cmd.ItemId).done(function (item) {
2013-05-10 05:18:07 -07:00
2014-07-16 20:17:14 -07:00
Dashboard.navigate(LibraryBrowser.getHref(item, null, ''));
2013-05-10 05:18:07 -07:00
});
},
showPackageInstallNotification: function (installation, status) {
var html = '';
if (status == 'completed') {
html += '<img src="css/images/notifications/done.png" class="notificationIcon" />';
}
else if (status == 'cancelled') {
html += '<img src="css/images/notifications/info.png" class="notificationIcon" />';
}
else if (status == 'failed') {
html += '<img src="css/images/notifications/error.png" class="notificationIcon" />';
}
else if (status == 'progress') {
html += '<img src="css/images/notifications/download.png" class="notificationIcon" />';
}
html += '<span style="margin-right: 1em;">';
if (status == 'completed') {
2014-07-16 20:17:14 -07:00
html += Globalize.translate('LabelPackageInstallCompleted').replace('{0}', installation.Name + ' ' + installation.Version);
}
else if (status == 'cancelled') {
2014-07-16 20:17:14 -07:00
html += Globalize.translate('LabelPackageInstallCancelled').replace('{0}', installation.Name + ' ' + installation.Version);
}
else if (status == 'failed') {
2014-07-16 20:17:14 -07:00
html += Globalize.translate('LabelPackageInstallFailed').replace('{0}', installation.Name + ' ' + installation.Version);
}
else if (status == 'progress') {
2014-07-16 20:17:14 -07:00
html += Globalize.translate('LabelInstallingPackage').replace('{0}', installation.Name + ' ' + installation.Version);
}
html += '</span>';
if (status == 'progress') {
var percentComplete = Math.round(installation.PercentComplete || 0);
html += '<progress style="margin-right: 1em;" max="100" value="' + percentComplete + '" title="' + percentComplete + '%">';
html += '' + percentComplete + '%';
html += '</progress>';
if (percentComplete < 100) {
var btnId = "btnCancel" + installation.Id;
2014-07-16 20:17:14 -07:00
html += '<button id="' + btnId + '" type="button" data-icon="delete" onclick="$(\'' + btnId + '\').buttonEnabled(false);Dashboard.cancelInstallation(\'' + installation.Id + '\');" data-theme="b" data-inline="true" data-mini="true">' + Globalize.translate('ButtonCancel') + '</button>';
}
}
var timeout = 0;
if (status == 'cancelled') {
timeout = 2000;
}
var forceShow = status != "progress";
var allowHide = status != "progress" && status != 'cancelled';
Dashboard.showFooterNotification({ html: html, id: installation.Id, timeout: timeout, forceShow: forceShow, allowHide: allowHide });
},
processLibraryUpdateNotification: function (data) {
var newItems = data.ItemsAdded;
2013-05-10 05:18:07 -07:00
if (!newItems.length) {
return;
}
2013-04-15 11:45:58 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), {
2013-04-19 15:09:21 -07:00
2013-04-15 11:45:58 -07:00
Recursive: true,
2013-05-18 14:47:50 -07:00
Limit: 3,
2013-04-15 16:45:09 -07:00
Filters: "IsNotFolder",
2013-04-15 11:45:58 -07:00
SortBy: "DateCreated",
SortOrder: "Descending",
ImageTypes: "Primary",
Ids: newItems.join(',')
2013-04-19 15:09:21 -07:00
2013-04-15 11:45:58 -07:00
}).done(function (result) {
var items = result.Items;
for (var i = 0, length = Math.min(items.length, 2) ; i < length; i++) {
var item = items[i];
var notification = {
2013-04-15 11:45:58 -07:00
title: "New " + item.Type,
body: item.Name,
timeout: 5000
};
var imageTags = item.ImageTags || {};
2013-04-19 15:09:21 -07:00
2013-04-15 11:45:58 -07:00
if (imageTags.Primary) {
notification.icon = ApiClient.getScaledImageUrl(item.Id, {
width: 60,
2013-04-15 11:45:58 -07:00
tag: imageTags.Primary,
type: "Primary"
});
}
WebNotifications.show(notification);
}
});
},
ensurePageTitle: function (page) {
if (!page.hasClass('type-interior')) {
return;
}
if ($('.pageTitle', page).length) {
return;
}
var parent = $('.content-primary', page);
if (!parent.length) {
parent = $('.ui-content', page)[0];
}
2014-12-22 21:53:52 -07:00
var helpUrl = page.attr('data-helpurl');
var html = '<div>';
html += '<h1 class="pageTitle" style="display:inline-block;">' + (document.title || '&nbsp;') + '</h1>';
if (helpUrl) {
html += '<a href="' + helpUrl + '" target="_blank" class="accentButton accentButton-g" style="margin-top:-10px;"><i class="fa fa-info-circle"></i>' + Globalize.translate('ButtonHelp') + '</a>';
}
html += '</div>';
$(parent).prepend(html);
},
setPageTitle: function (title) {
$('.pageTitle', $.mobile.activePage).html(title);
if (title) {
document.title = title;
}
2013-06-07 10:29:33 -07:00
},
getDisplayTime: function (ticks) {
var ticksPerHour = 36000000000;
2014-05-10 22:11:53 -07:00
var ticksPerMinute = 600000000;
var ticksPerSecond = 10000000;
2013-06-07 10:29:33 -07:00
var parts = [];
var hours = ticks / ticksPerHour;
2013-12-05 20:39:44 -07:00
hours = Math.floor(hours);
2013-06-07 10:29:33 -07:00
if (hours) {
parts.push(hours);
}
ticks -= (hours * ticksPerHour);
var minutes = ticks / ticksPerMinute;
2013-12-05 20:39:44 -07:00
minutes = Math.floor(minutes);
2013-06-07 10:29:33 -07:00
ticks -= (minutes * ticksPerMinute);
if (minutes < 10 && hours) {
minutes = '0' + minutes;
}
parts.push(minutes);
var seconds = ticks / ticksPerSecond;
2014-05-10 22:11:53 -07:00
seconds = Math.floor(seconds);
2013-06-07 10:29:33 -07:00
if (seconds < 10) {
seconds = '0' + seconds;
}
parts.push(seconds);
return parts.join(':');
2013-11-07 10:27:05 -07:00
},
2013-11-28 11:27:29 -07:00
2014-02-08 13:02:35 -07:00
populateLanguages: function (select, languages) {
2013-12-28 09:58:13 -07:00
var html = "";
html += "<option value=''></option>";
for (var i = 0, length = languages.length; i < length; i++) {
var culture = languages[i];
html += "<option value='" + culture.TwoLetterISOLanguageName + "'>" + culture.DisplayName + "</option>";
}
$(select).html(html).selectmenu("refresh");
},
populateCountries: function (select, allCountries) {
var html = "";
html += "<option value=''></option>";
for (var i = 0, length = allCountries.length; i < length; i++) {
var culture = allCountries[i];
html += "<option value='" + culture.TwoLetterISORegionName + "'>" + culture.DisplayName + "</option>";
}
$(select).html(html).selectmenu("refresh");
2014-04-13 10:27:13 -07:00
},
getSupportedRemoteCommands: function () {
// Full list
// https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs
return [
"GoHome",
"GoToSettings",
"VolumeUp",
"VolumeDown",
"Mute",
"Unmute",
"ToggleMute",
"SetVolume",
"SetAudioStreamIndex",
"SetSubtitleStreamIndex",
2014-04-27 18:57:29 -07:00
"DisplayContent",
2014-05-08 13:09:53 -07:00
"GoToSearch",
"DisplayMessage"
2014-04-13 10:27:13 -07:00
];
2014-10-25 11:32:58 -07:00
},
2014-10-26 20:06:01 -07:00
isServerlessPage: function () {
2014-10-25 11:32:58 -07:00
var url = getWindowUrl().toLowerCase();
2015-05-05 16:20:23 -07:00
return url.indexOf('connectlogin.html') != -1 || url.indexOf('selectserver.html') != -1 || url.indexOf('login.html') != -1 || url.indexOf('forgotpassword.html') != -1 || url.indexOf('forgotpasswordpin.html') != -1;
2015-02-19 10:46:18 -07:00
},
capabilities: function () {
2015-05-26 08:31:50 -07:00
var caps = {
2015-05-28 16:37:43 -07:00
PlayableMediaTypes: ['Audio', 'Video'],
2015-02-19 10:46:18 -07:00
2015-05-28 16:37:43 -07:00
SupportedCommands: Dashboard.getSupportedRemoteCommands(),
2015-06-10 06:37:07 -07:00
// Need to use this rather than AppInfo.isNativeApp because the property isn't set yet at the time we call this
SupportsPersistentIdentifier: Dashboard.isRunningInCordova(),
2015-04-08 22:20:23 -07:00
SupportsMediaControl: true,
SupportedLiveMediaTypes: ['Audio', 'Video']
2015-02-19 10:46:18 -07:00
};
2015-05-26 08:31:50 -07:00
2015-05-28 16:37:43 -07:00
if (Dashboard.isRunningInCordova() && $.browser.android) {
caps.SupportsOfflineAccess = true;
caps.SupportsSync = true;
caps.SupportsContentUploading = true;
}
2015-05-26 08:31:50 -07:00
return caps;
2015-05-02 09:34:27 -07:00
},
2013-04-01 22:14:37 -07:00
2015-05-02 09:34:27 -07:00
getDefaultImageQuality: function (imageType) {
var quality = 90;
var isBackdrop = imageType.toLowerCase() == 'backdrop';
if (isBackdrop) {
2015-05-07 07:04:10 -07:00
quality -= 10;
2015-05-02 09:34:27 -07:00
}
2015-05-06 20:11:51 -07:00
if (AppInfo.hasLowImageBandwidth) {
2014-10-23 21:54:35 -07:00
2015-05-15 08:46:20 -07:00
// The native app can handle a little bit more than safari
2015-05-28 16:37:43 -07:00
if (AppInfo.isNativeApp) {
2015-05-15 08:46:20 -07:00
2015-05-26 12:53:12 -07:00
quality -= 20;
2015-05-15 08:46:20 -07:00
if (isBackdrop) {
2015-05-15 11:07:36 -07:00
quality -= 20;
2015-05-15 08:46:20 -07:00
}
} else {
2014-10-23 21:54:35 -07:00
2015-05-19 12:15:40 -07:00
quality -= 40;
2015-05-02 09:34:27 -07:00
}
2014-10-23 21:54:35 -07:00
}
2015-05-02 09:34:27 -07:00
return quality;
},
2015-05-12 06:58:03 -07:00
normalizeImageOptions: function (options) {
2015-05-11 09:32:15 -07:00
if (AppInfo.hasLowImageBandwidth) {
options.enableImageEnhancers = false;
}
2015-05-15 08:46:20 -07:00
if (AppInfo.forcedImageFormat && options.type != 'Logo') {
options.format = AppInfo.forcedImageFormat;
options.backgroundColor = '#1f1f1f';
}
2015-05-11 09:32:15 -07:00
},
2015-05-19 12:15:40 -07:00
getAppInfo: function (appName, deviceId, deviceName) {
2015-05-02 09:34:27 -07:00
function generateDeviceName() {
var name = "Web Browser";
if ($.browser.chrome) {
name = "Chrome";
} else if ($.browser.safari) {
name = "Safari";
} else if ($.browser.msie) {
name = "Internet Explorer";
} else if ($.browser.opera) {
name = "Opera";
2015-05-11 12:59:59 -07:00
} else if ($.browser.mozilla) {
2015-05-02 09:34:27 -07:00
name = "Firefox";
}
if ($.browser.version) {
name += " " + $.browser.version;
}
if ($.browser.ipad) {
name += " Ipad";
} else if ($.browser.iphone) {
name += " Iphone";
} else if ($.browser.android) {
name += " Android";
}
return name;
2014-10-23 21:54:35 -07:00
}
2015-05-02 09:34:27 -07:00
var appVersion = window.dashboardVersion;
2015-05-19 12:15:40 -07:00
appName = appName || "Emby Web Client";
2015-05-06 21:14:35 -07:00
deviceName = deviceName || generateDeviceName();
2015-05-12 06:58:03 -07:00
var seed = [];
var keyName = 'randomId';
2015-05-12 06:58:03 -07:00
deviceId = deviceId || MediaBrowser.generateDeviceId(keyName, seed.join(','));
2015-05-02 09:34:27 -07:00
return {
appName: appName,
appVersion: appVersion,
deviceName: deviceName,
deviceId: deviceId
};
2015-05-08 20:48:43 -07:00
},
2015-05-12 06:58:03 -07:00
loadSwipebox: function () {
2015-05-08 20:48:43 -07:00
var deferred = DeferredBuilder.Deferred();
require([
'thirdparty/swipebox-master/js/jquery.swipebox.min',
'css!thirdparty/swipebox-master/css/swipebox.min'
], function () {
deferred.resolve();
});
return deferred.promise();
2015-06-02 22:30:14 -07:00
},
2015-05-20 09:28:55 -07:00
ready: function (fn) {
2015-05-17 19:52:52 -07:00
2015-05-19 12:15:40 -07:00
if (Dashboard.initPromiseDone) {
fn();
return;
}
Dashboard.initPromise.done(fn);
},
firePageEvent: function (page, name) {
Dashboard.ready(function () {
$(page).trigger(name);
});
2015-05-25 10:32:22 -07:00
},
loadExternalPlayer: function () {
var deferred = DeferredBuilder.Deferred();
require(['scripts/externalplayer.js'], function () {
if (Dashboard.isRunningInCordova()) {
require(['thirdparty/cordova/externalplayer.js'], function () {
deferred.resolve();
});
} else {
deferred.resolve();
}
});
return deferred.promise();
2015-06-08 14:32:20 -07:00
},
exitOnBack: function () {
return $($.mobile.activePage).is('#indexPage');
},
exit: function () {
Dashboard.logout();
2014-10-23 21:54:35 -07:00
}
2015-05-02 09:34:27 -07:00
};
2015-05-06 20:11:51 -07:00
var AppInfo = {};
2015-05-02 09:34:27 -07:00
(function () {
2014-10-23 21:54:35 -07:00
2015-05-06 20:11:51 -07:00
function isTouchDevice() {
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
}
2015-05-06 20:11:51 -07:00
function setAppInfo() {
2015-05-19 12:15:40 -07:00
if (isTouchDevice()) {
2015-05-06 20:11:51 -07:00
AppInfo.isTouchPreferred = true;
}
2015-05-08 09:58:27 -07:00
var isCordova = Dashboard.isRunningInCordova();
2015-05-15 19:36:47 -07:00
AppInfo.enableDetailPageChapters = true;
AppInfo.enableDetailsMenuImages = true;
2015-05-16 12:09:02 -07:00
AppInfo.enableMovieHomeSuggestions = true;
AppInfo.enableAppStorePolicy = isCordova;
2015-05-15 19:36:47 -07:00
2015-05-29 18:07:54 -07:00
var isIOS = $.browser.safari || $.browser.ipad || $.browser.iphone;
2015-05-27 22:51:48 -07:00
var isAndroid = $.browser.android;
var isMobile = $.browser.mobile;
2015-05-29 18:07:54 -07:00
if (isIOS) {
2015-05-06 20:11:51 -07:00
2015-05-27 22:51:48 -07:00
if (isMobile) {
2015-05-06 20:11:51 -07:00
AppInfo.hasLowImageBandwidth = true;
}
2015-05-07 15:27:01 -07:00
2015-05-08 09:58:27 -07:00
if (isCordova) {
2015-05-07 15:27:01 -07:00
AppInfo.enableBottomTabs = true;
2015-05-26 12:53:12 -07:00
AppInfo.cardMargin = 'mediumCardMargin';
2015-06-04 13:27:46 -07:00
2015-05-15 19:36:47 -07:00
} else {
2015-06-04 13:27:46 -07:00
if (isMobile) {
AppInfo.enableDetailPageChapters = false;
AppInfo.enableDetailsMenuImages = false;
AppInfo.enableMovieHomeSuggestions = false;
AppInfo.cardMargin = 'largeCardMargin';
AppInfo.forcedImageFormat = 'jpg';
}
2015-05-07 15:27:01 -07:00
}
2015-05-06 20:11:51 -07:00
}
else {
if (!$.browser.tv) {
AppInfo.enableHeadRoom = true;
}
}
2015-05-07 07:04:10 -07:00
2015-05-10 06:06:12 -07:00
AppInfo.enableMusicSongsTab = true;
2015-05-08 12:44:13 -07:00
if (!AppInfo.hasLowImageBandwidth) {
2015-05-07 07:04:10 -07:00
AppInfo.enableLatestChannelItems = true;
AppInfo.enableStudioTabs = true;
AppInfo.enablePeopleTabs = true;
AppInfo.enableTvEpisodesTab = true;
AppInfo.enableMusicArtistsTab = true;
2015-05-07 15:27:01 -07:00
AppInfo.enableMovieTrailersTab = true;
}
2015-05-24 11:33:28 -07:00
if (isCordova) {
AppInfo.enableAppLayouts = true;
2015-05-26 12:53:12 -07:00
AppInfo.hasKnownExternalPlayerSupport = true;
2015-05-28 16:37:43 -07:00
AppInfo.isNativeApp = true;
2015-05-24 11:33:28 -07:00
}
else {
2015-05-07 15:27:01 -07:00
AppInfo.enableFooterNotifications = true;
2015-05-21 13:53:14 -07:00
AppInfo.enableSupporterMembership = true;
2015-05-25 10:32:22 -07:00
2015-05-29 18:07:54 -07:00
if (!isAndroid && !isIOS) {
2015-05-25 10:32:22 -07:00
AppInfo.enableAppLayouts = true;
}
2015-05-07 07:04:10 -07:00
}
2015-05-08 09:58:27 -07:00
2015-05-09 21:29:04 -07:00
AppInfo.enableUserImage = true;
2015-05-27 22:51:48 -07:00
AppInfo.hasPhysicalVolumeButtons = isCordova || isMobile;
2015-05-23 13:44:15 -07:00
2015-05-29 18:07:54 -07:00
AppInfo.enableBackButton = (isIOS && window.navigator.standalone) || (isCordova && isIOS);
2015-05-27 22:51:48 -07:00
AppInfo.supportsFullScreen = isCordova && isAndroid;
2015-06-09 21:01:14 -07:00
AppInfo.supportsSyncPathSetting = isCordova && isAndroid;
}
2013-04-19 15:09:21 -07:00
2014-10-25 11:32:58 -07:00
function initializeApiClient(apiClient) {
2015-05-16 12:09:02 -07:00
apiClient.enableAppStorePolicy = AppInfo.enableAppStorePolicy;
2015-06-08 14:32:20 -07:00
apiClient.getDefaultImageQuality = Dashboard.getDefaultImageQuality;
apiClient.normalizeImageOptions = Dashboard.normalizeImageOptions;
2015-05-16 12:09:02 -07:00
2014-10-28 16:17:55 -07:00
$(apiClient).off('.dashboard')
.on("websocketmessage.dashboard", Dashboard.onWebSocketMessageReceived)
2015-05-20 09:28:55 -07:00
.on('requestfail.dashboard', Dashboard.onRequestFail);
2014-10-25 11:32:58 -07:00
}
2015-05-25 10:32:22 -07:00
2015-05-24 11:33:28 -07:00
//localStorage.clear();
2015-05-28 16:37:43 -07:00
function createConnectionManager(capabilities) {
2015-05-01 11:37:01 -07:00
2015-05-02 09:34:27 -07:00
var credentialProvider = new MediaBrowser.CredentialProvider();
2014-10-23 21:54:35 -07:00
2015-05-28 16:37:43 -07:00
window.ConnectionManager = new MediaBrowser.ConnectionManager(Logger, credentialProvider, AppInfo.appName, AppInfo.appVersion, AppInfo.deviceName, AppInfo.deviceId, capabilities);
2015-01-24 23:34:50 -07:00
2015-05-22 08:59:17 -07:00
$(ConnectionManager).on('apiclientcreated', function (e, newApiClient) {
2014-05-16 21:24:10 -07:00
2015-05-22 08:59:17 -07:00
initializeApiClient(newApiClient);
2015-05-20 09:28:55 -07:00
});
2014-10-23 21:54:35 -07:00
2015-06-08 14:32:20 -07:00
var deferred = DeferredBuilder.Deferred();
2015-04-01 14:56:32 -07:00
2015-05-20 09:28:55 -07:00
if (Dashboard.isConnectMode()) {
2015-04-01 14:56:32 -07:00
2015-06-08 14:32:20 -07:00
var server = ConnectionManager.getLastUsedServer();
2015-05-22 08:59:17 -07:00
if (!Dashboard.isServerlessPage()) {
2015-06-08 14:32:20 -07:00
if (server && server.UserId && server.AccessToken) {
ConnectionManager.connectToServer(server).done(function (result) {
if (result.State == MediaBrowser.ConnectionState.SignedIn) {
window.ApiClient = result.ApiClient;
}
deferred.resolve();
});
return deferred.promise();
2015-05-02 09:34:27 -07:00
}
2014-12-29 13:18:48 -07:00
}
2015-06-08 14:32:20 -07:00
deferred.resolve();
2015-04-25 20:25:07 -07:00
2015-05-02 09:34:27 -07:00
} else {
2015-04-25 20:25:07 -07:00
2015-06-08 14:32:20 -07:00
var apiClient = new MediaBrowser.ApiClient(Logger, Dashboard.serverAddress(), AppInfo.appName, AppInfo.appVersion, AppInfo.deviceName, AppInfo.deviceId);
2015-06-03 21:50:10 -07:00
apiClient.enableAutomaticNetworking = false;
2015-05-22 08:59:17 -07:00
ConnectionManager.addApiClient(apiClient);
2015-06-08 14:32:20 -07:00
Dashboard.importCss(apiClient.getUrl('Branding/Css'));
window.ApiClient = apiClient;
2015-05-02 09:34:27 -07:00
}
2015-06-08 14:32:20 -07:00
return deferred.promise();
2015-01-24 23:34:50 -07:00
}
2015-01-18 22:41:56 -07:00
2015-05-08 10:30:24 -07:00
function initFastClick() {
2015-05-08 20:48:43 -07:00
requirejs(["thirdparty/fastclick"], function (FastClick) {
2015-05-08 10:30:24 -07:00
2015-05-08 20:48:43 -07:00
FastClick.attach(document.body);
// Have to work around this issue of fast click breaking the panel dismiss
$(document.body).on('touchstart', '.ui-panel-dismiss', function () {
$(this).trigger('click');
});
2015-05-08 10:30:24 -07:00
});
2015-05-08 20:48:43 -07:00
2015-05-08 10:30:24 -07:00
}
2015-05-19 12:15:40 -07:00
function onDocumentReady() {
2015-05-01 11:37:01 -07:00
2015-05-16 12:09:02 -07:00
if (AppInfo.isTouchPreferred) {
$(document.body).addClass('touch');
}
2015-05-08 10:30:24 -07:00
if ($.browser.safari && $.browser.mobile) {
initFastClick();
2015-05-08 09:58:27 -07:00
}
2015-05-06 20:11:51 -07:00
2015-05-26 12:53:12 -07:00
if (AppInfo.cardMargin) {
$(document.body).addClass(AppInfo.cardMargin);
2015-05-06 20:11:51 -07:00
}
2015-05-07 07:04:10 -07:00
if (!AppInfo.enableLatestChannelItems) {
$(document.body).addClass('latestChannelItemsDisabled');
}
if (!AppInfo.enableStudioTabs) {
$(document.body).addClass('studioTabDisabled');
}
if (!AppInfo.enablePeopleTabs) {
$(document.body).addClass('peopleTabDisabled');
}
if (!AppInfo.enableTvEpisodesTab) {
$(document.body).addClass('tvEpisodesTabDisabled');
}
if (!AppInfo.enableMusicSongsTab) {
$(document.body).addClass('musicSongsTabDisabled');
}
if (!AppInfo.enableMusicArtistsTab) {
$(document.body).addClass('musicArtistsTabDisabled');
}
2015-05-07 15:27:01 -07:00
if (!AppInfo.enableMovieTrailersTab) {
$(document.body).addClass('movieTrailersTabDisabled');
}
2015-05-16 20:17:23 -07:00
if (AppInfo.enableBottomTabs) {
$(document.body).addClass('bottomSecondaryNav');
}
2015-05-21 13:53:14 -07:00
if (!AppInfo.enableSupporterMembership) {
$(document.body).addClass('supporterMembershipDisabled');
}
2015-05-28 16:37:43 -07:00
if (AppInfo.isNativeApp) {
2015-05-07 07:04:10 -07:00
$(document).addClass('nativeApp');
}
2015-05-26 08:31:50 -07:00
if (AppInfo.enableBackButton) {
$(document.body).addClass('enableBackButton');
}
2015-04-30 20:00:29 -07:00
var videoPlayerHtml = '<div id="mediaPlayer" data-theme="b" class="ui-bar-b" style="display: none;">';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div class="videoBackdrop">';
videoPlayerHtml += '<div id="videoPlayer">';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div id="videoElement">';
videoPlayerHtml += '<div id="play" class="status"></div>';
videoPlayerHtml += '<div id="pause" class="status"></div>';
videoPlayerHtml += '</div>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div class="videoTopControls hiddenOnIdle">';
videoPlayerHtml += '<div class="videoTopControlsLogo"></div>';
videoPlayerHtml += '<div class="videoAdvancedControls">';
2015-05-04 21:17:38 -07:00
videoPlayerHtml += '<button class="mediaButton videoTrackControl previousTrackButton imageButton" title="Previous video" type="button" onclick="MediaPlayer.previousTrack();" data-role="none"><i class="fa fa-step-backward"></i></button>';
videoPlayerHtml += '<button class="mediaButton videoTrackControl nextTrackButton imageButton" title="Next video" type="button" onclick="MediaPlayer.nextTrack();" data-role="none"><i class="fa fa-step-forward"></i></button>';
2015-05-21 13:53:14 -07:00
// Embedding onclicks due to issues not firing in cordova safari
videoPlayerHtml += '<button class="mediaButton videoAudioButton imageButton" title="Audio tracks" type="button" data-role="none" onclick="MediaPlayer.showAudioTracksFlyout();"><i class="fa fa-music"></i></button>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div data-role="popup" class="videoAudioPopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2015-05-21 13:53:14 -07:00
videoPlayerHtml += '<button class="mediaButton videoSubtitleButton imageButton" title="Subtitles" type="button" data-role="none" onclick="MediaPlayer.showSubtitleMenu();"><i class="fa fa-text-width"></i></button>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div data-role="popup" class="videoSubtitlePopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2014-06-28 12:35:30 -07:00
2015-05-21 13:53:14 -07:00
videoPlayerHtml += '<button class="mediaButton videoChaptersButton imageButton" title="Scenes" type="button" data-role="none" onclick="MediaPlayer.showChaptersFlyout();"><i class="fa fa-video-camera"></i></button>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div data-role="popup" class="videoChaptersPopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2014-06-28 12:35:30 -07:00
2015-05-21 13:53:14 -07:00
videoPlayerHtml += '<button class="mediaButton videoQualityButton imageButton" title="Quality" type="button" data-role="none" onclick="MediaPlayer.showQualityFlyout();"><i class="fa fa-gear"></i></button>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div data-role="popup" class="videoQualityPopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2015-05-04 21:17:38 -07:00
videoPlayerHtml += '<button class="mediaButton imageButton" title="Stop" type="button" onclick="MediaPlayer.stop();" data-role="none"><i class="fa fa-close"></i></button>';
2014-06-28 12:35:30 -07:00
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '</div>'; // videoAdvancedControls
videoPlayerHtml += '</div>'; // videoTopControls
2014-06-28 12:35:30 -07:00
2015-04-30 20:00:29 -07:00
// Create controls
videoPlayerHtml += '<div class="videoControls hiddenOnIdle">';
2014-06-28 12:35:30 -07:00
2015-05-04 21:17:38 -07:00
videoPlayerHtml += '<div class="nowPlayingInfo hiddenOnIdle">';
videoPlayerHtml += '<div class="nowPlayingImage"></div>';
2015-05-13 20:24:25 -07:00
videoPlayerHtml += '<div class="nowPlayingTabs"></div>';
2015-05-04 21:17:38 -07:00
videoPlayerHtml += '</div>'; // nowPlayingInfo
videoPlayerHtml += '<button id="video-previousTrackButton" class="mediaButton previousTrackButton videoTrackControl imageButton" title="Previous Track" type="button" onclick="MediaPlayer.previousTrack();" data-role="none"><i class="fa fa-step-backward"></i></button>';
videoPlayerHtml += '<button id="video-playButton" class="mediaButton imageButton" title="Play" type="button" onclick="MediaPlayer.unpause();" data-role="none"><i class="fa fa-play"></i></button>';
videoPlayerHtml += '<button id="video-pauseButton" class="mediaButton imageButton" title="Pause" type="button" onclick="MediaPlayer.pause();" data-role="none"><i class="fa fa-pause"></i></button>';
videoPlayerHtml += '<button id="video-nextTrackButton" class="mediaButton nextTrackButton videoTrackControl imageButton" title="Next Track" type="button" onclick="MediaPlayer.nextTrack();" data-role="none"><i class="fa fa-step-forward"></i></button>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div class="positionSliderContainer sliderContainer">';
videoPlayerHtml += '<input type="range" class="mediaSlider positionSlider slider" step=".001" min="0" max="100" value="0" style="display:none;" data-mini="true" data-theme="a" data-highlight="true" />';
videoPlayerHtml += '</div>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div class="currentTime">--:--</div>';
2014-06-28 12:35:30 -07:00
2015-05-04 21:17:38 -07:00
videoPlayerHtml += '<button id="video-muteButton" class="mediaButton muteButton imageButton" title="Mute" type="button" onclick="MediaPlayer.mute();" data-role="none"><i class="fa fa-volume-up"></i></button>';
videoPlayerHtml += '<button id="video-unmuteButton" class="mediaButton unmuteButton imageButton" title="Unmute" type="button" onclick="MediaPlayer.unMute();" data-role="none"><i class="fa fa-volume-off"></i></button>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '<div class="volumeSliderContainer sliderContainer">';
videoPlayerHtml += '<input type="range" class="mediaSlider volumeSlider slider" step=".05" min="0" max="1" value="0" style="display:none;" data-mini="true" data-theme="a" data-highlight="true" />';
videoPlayerHtml += '</div>';
2015-05-04 21:17:38 -07:00
videoPlayerHtml += '<button onclick="MediaPlayer.toggleFullscreen();" id="video-fullscreenButton" class="mediaButton fullscreenButton imageButton" title="Fullscreen" type="button" data-role="none"><i class="fa fa-expand"></i></button>';
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '</div>'; // videoControls
2015-04-30 20:00:29 -07:00
videoPlayerHtml += '</div>'; // videoPlayer
videoPlayerHtml += '</div>'; // videoBackdrop
videoPlayerHtml += '</div>'; // mediaPlayer
2015-04-30 20:00:29 -07:00
$(document.body).append(videoPlayerHtml);
2015-04-30 20:00:29 -07:00
var mediaPlayerElem = $('#mediaPlayer', document.body);
mediaPlayerElem.trigger('create');
2015-05-07 15:27:01 -07:00
var footerHtml = '<div id="footer" class="footer" data-theme="b" class="ui-bar-b">';
2015-04-30 20:00:29 -07:00
footerHtml += '<div id="footerNotifications"></div>';
footerHtml += '</div>';
2014-04-13 10:27:13 -07:00
2015-04-30 20:00:29 -07:00
$(document.body).append(footerHtml);
2015-04-30 20:00:29 -07:00
$(window).on("beforeunload", function () {
2014-04-13 10:27:13 -07:00
2015-05-18 15:23:03 -07:00
var apiClient = window.ApiClient;
2013-09-09 11:23:55 -07:00
2015-04-30 20:00:29 -07:00
// Close the connection gracefully when possible
2015-05-08 20:48:43 -07:00
if (apiClient && apiClient.isWebSocketOpen()) {
var localActivePlayers = MediaController.getPlayers().filter(function (p) {
2014-10-25 11:32:58 -07:00
2015-05-08 20:48:43 -07:00
return p.isLocalPlayer && p.isPlaying();
});
if (!localActivePlayers.length) {
console.log('Sending close web socket command');
apiClient.closeWebSocket();
}
2015-04-30 20:00:29 -07:00
}
});
2015-04-30 20:00:29 -07:00
$(document).on('contextmenu', '.ui-popup-screen', function (e) {
2014-07-08 17:46:11 -07:00
2015-04-30 20:00:29 -07:00
$('.ui-popup').popup('close');
2014-07-08 17:46:11 -07:00
2015-04-30 20:00:29 -07:00
e.preventDefault();
return false;
});
2015-05-17 19:52:52 -07:00
2015-06-08 22:56:46 -07:00
require(['filesystem']);
2015-05-17 19:52:52 -07:00
if (Dashboard.isRunningInCordova()) {
2015-06-08 14:32:20 -07:00
requirejs(['thirdparty/cordova/connectsdk', 'scripts/registrationservices', 'thirdparty/cordova/volume', 'thirdparty/cordova/back']);
2015-05-26 08:31:50 -07:00
if ($.browser.android) {
2015-06-08 22:56:46 -07:00
requirejs(['thirdparty/cordova/android/androidcredentials', 'thirdparty/cordova/android/immersive', 'thirdparty/cordova/android/mediasession']);
2015-05-26 08:31:50 -07:00
}
2015-05-27 22:51:48 -07:00
if ($.browser.safari) {
2015-06-04 13:27:46 -07:00
requirejs(['thirdparty/cordova/remotecontrols', 'thirdparty/cordova/ios/orientation']);
2015-05-27 22:51:48 -07:00
}
2015-05-17 19:52:52 -07:00
} else {
if ($.browser.chrome) {
requirejs(['scripts/chromecast']);
}
}
2014-10-06 16:58:46 -07:00
}
2015-06-08 14:32:20 -07:00
function init(deferred, capabilities, appName, deviceId, deviceName) {
2015-05-08 20:48:43 -07:00
2015-05-19 12:15:40 -07:00
requirejs.config({
map: {
'*': {
'css': 'thirdparty/requirecss' // or whatever the path to require-css is
}
},
2015-06-08 14:32:20 -07:00
urlArgs: "v=" + window.dashboardVersion,
paths: {
"velocity": "thirdparty/velocity.min"
}
2015-05-19 12:15:40 -07:00
});
2015-05-08 20:48:43 -07:00
2015-05-19 12:15:40 -07:00
// Required since jQuery is loaded before requireJs
define('jquery', [], function () {
return jQuery;
});
2015-05-01 11:37:01 -07:00
2015-06-08 14:32:20 -07:00
if (Dashboard.isRunningInCordova() && $.browser.android) {
define("appstorage", ["thirdparty/cordova/android/appstorage"]);
} else {
define('appstorage', [], function () {
return appStorage;
});
}
if (Dashboard.isRunningInCordova()) {
define("serverdiscovery", ["thirdparty/cordova/serverdiscovery"]);
define("wakeonlan", ["thirdparty/cordova/wakeonlan"]);
} else {
define("serverdiscovery", ["thirdparty/apiclient/serverdiscovery"]);
define("wakeonlan", ["thirdparty/apiclient/wakeonlan"]);
}
if (Dashboard.isRunningInCordova() && $.browser.android) {
define("localassetmanager", ["thirdparty/cordova/android/localassetmanager"]);
} else {
define("localassetmanager", ["thirdparty/apiclient/localassetmanager"]);
}
2015-06-08 22:56:46 -07:00
if (Dashboard.isRunningInCordova() && $.browser.android) {
define("filesystem", ["thirdparty/cordova/android/filesystem"]);
}
else if (Dashboard.isRunningInCordova()) {
define("filesystem", ["thirdparty/cordova/filesystem"]);
}
else {
define("filesystem", ["thirdparty/filesystem"]);
}
2015-06-09 21:01:14 -07:00
if (Dashboard.isRunningInCordova() && $.browser.android) {
define("nativedirectorychooser", ["thirdparty/cordova/android/nativedirectorychooser"]);
}
2015-06-10 06:37:07 -07:00
if (Dashboard.isRunningInCordova() && $.browser.android) {
//define("audiorenderer", ["thirdparty/cordova/android/vlcplayer"]);
define("audiorenderer", ["scripts/htmlmediarenderer"]);
define("videorenderer", ["scripts/htmlmediarenderer"]);
}
else {
define("audiorenderer", ["scripts/htmlmediarenderer"]);
define("videorenderer", ["scripts/htmlmediarenderer"]);
}
2015-06-08 14:32:20 -07:00
define("connectservice", ["thirdparty/apiclient/connectservice"]);
2015-06-01 22:46:06 -07:00
//requirejs(['http://viblast.com/player/free-version/qy2fdwajo1/viblast.js']);
2015-05-19 12:15:40 -07:00
setAppInfo();
2015-05-28 16:37:43 -07:00
$.extend(AppInfo, Dashboard.getAppInfo(appName, deviceId, deviceName));
2015-05-19 12:15:40 -07:00
2015-06-08 14:32:20 -07:00
if (Dashboard.isConnectMode()) {
require(['appstorage'], function () {
capabilities.DeviceProfile = MediaPlayer.getDeviceProfile(Math.max(screen.height, screen.width));
2015-06-10 06:37:07 -07:00
createConnectionManager(capabilities).done(function () {
2015-06-08 14:32:20 -07:00
$(function () {
onDocumentReady();
Dashboard.initPromiseDone = true;
deferred.resolve();
});
});
});
2015-05-19 12:15:40 -07:00
2015-06-08 14:32:20 -07:00
} else {
createConnectionManager(capabilities);
2015-05-26 08:31:50 -07:00
2015-05-20 09:28:55 -07:00
Dashboard.initPromiseDone = true;
deferred.resolve();
2015-05-26 08:31:50 -07:00
2015-06-08 14:32:20 -07:00
$(onDocumentReady);
}
2015-05-19 12:15:40 -07:00
}
function initCordovaWithDeviceId(deferred, deviceId) {
2015-05-23 13:44:15 -07:00
2015-05-29 16:51:33 -07:00
if ($.browser.android) {
requirejs(['thirdparty/cordova/android/imagestore.js']);
} else {
requirejs(['thirdparty/cordova/imagestore.js']);
}
2015-05-19 12:15:40 -07:00
2015-05-26 08:31:50 -07:00
var capablities = Dashboard.capabilities();
2015-06-08 14:32:20 -07:00
init(deferred, capablities, "Emby Mobile", deviceId, device.model);
2015-05-19 12:15:40 -07:00
}
function initCordova(deferred) {
2015-05-02 09:34:27 -07:00
2015-05-01 11:37:01 -07:00
document.addEventListener("deviceready", function () {
2015-04-30 20:00:29 -07:00
2015-05-19 12:15:40 -07:00
window.plugins.uniqueDeviceID.get(function (uuid) {
initCordovaWithDeviceId(deferred, uuid);
2015-05-15 08:46:20 -07:00
2015-05-19 12:15:40 -07:00
}, function () {
2015-05-01 11:37:01 -07:00
2015-05-19 12:15:40 -07:00
// Failure. Use cordova uuid
initCordovaWithDeviceId(deferred, device.uuid);
});
2015-05-01 11:37:01 -07:00
}, false);
2015-05-19 12:15:40 -07:00
}
2015-05-01 11:37:01 -07:00
2015-05-19 12:15:40 -07:00
var initDeferred = $.Deferred();
Dashboard.initPromise = initDeferred.promise();
2015-05-02 09:34:27 -07:00
2015-05-19 12:15:40 -07:00
if (Dashboard.isRunningInCordova()) {
initCordova(initDeferred);
} else {
2015-05-26 08:31:50 -07:00
init(initDeferred, Dashboard.capabilities());
2015-05-01 11:37:01 -07:00
}
2015-05-12 21:55:19 -07:00
2015-04-30 20:00:29 -07:00
})();
Dashboard.jQueryMobileInit();
2015-01-17 22:45:10 -07:00
$(document).on('pagecreate', ".page", function () {
var page = $(this);
2015-01-18 21:29:57 -07:00
var current = page.data('theme');
2015-05-13 20:24:25 -07:00
if (!current) {
2015-01-18 21:29:57 -07:00
2015-05-13 20:24:25 -07:00
var newTheme;
2015-01-17 22:45:10 -07:00
2015-05-13 20:24:25 -07:00
if (page.hasClass('libraryPage')) {
newTheme = 'b';
} else {
newTheme = 'a';
}
2015-01-17 22:45:10 -07:00
2015-05-13 20:24:25 -07:00
current = page.page("option", "theme");
2015-01-17 22:45:10 -07:00
2015-05-13 20:24:25 -07:00
if (current && current != newTheme) {
page.page("option", "theme", newTheme);
}
2015-05-14 19:16:57 -07:00
current = newTheme;
2015-05-13 20:24:25 -07:00
}
if (current == 'b') {
$(document.body).addClass('darkScrollbars');
} else {
2015-05-14 19:16:57 -07:00
$(document.body).removeClass('darkScrollbars');
2015-01-17 22:45:10 -07:00
}
2015-05-14 10:16:29 -07:00
}).on('pageinit', ".page", function () {
var page = this;
var require = this.getAttribute('data-require');
if (require) {
2015-05-16 12:09:02 -07:00
requirejs(require.split(','), function () {
2015-05-14 10:16:29 -07:00
2015-05-19 12:15:40 -07:00
Dashboard.firePageEvent(page, 'pageinitdepends');
2015-05-14 10:16:29 -07:00
});
} else {
2015-05-19 12:15:40 -07:00
Dashboard.firePageEvent(page, 'pageinitdepends');
2015-05-14 10:16:29 -07:00
}
2015-06-07 14:21:30 -07:00
//$('.localnav a, .libraryViewNav a').attr('data-transition', 'none');
2015-05-15 08:46:20 -07:00
2015-05-25 10:32:22 -07:00
}).on('pagebeforeshow', ".page", function () {
2015-05-14 10:16:29 -07:00
var page = this;
2015-05-19 12:15:40 -07:00
var require = this.getAttribute('data-require');
2015-06-09 21:01:14 -07:00
Dashboard.ensurePageTitle($(page));
2015-05-19 12:15:40 -07:00
if (require) {
requirejs(require.split(','), function () {
2015-05-25 10:32:22 -07:00
Dashboard.firePageEvent(page, 'pagebeforeshowready');
2015-05-19 12:15:40 -07:00
});
} else {
2015-05-25 10:32:22 -07:00
Dashboard.firePageEvent(page, 'pagebeforeshowready');
2015-05-19 12:15:40 -07:00
}
2015-05-25 10:32:22 -07:00
}).on('pageshow', ".page", function () {
2015-05-14 10:16:29 -07:00
2015-05-19 12:15:40 -07:00
var page = this;
2015-05-14 10:16:29 -07:00
var require = this.getAttribute('data-require');
if (require) {
2015-05-16 12:09:02 -07:00
requirejs(require.split(','), function () {
2015-05-14 10:16:29 -07:00
2015-05-25 10:32:22 -07:00
Dashboard.firePageEvent(page, 'pageshowbeginready');
2015-05-14 10:16:29 -07:00
});
} else {
2015-05-25 10:32:22 -07:00
Dashboard.firePageEvent(page, 'pageshowbeginready');
2015-05-14 10:16:29 -07:00
}
2015-05-25 10:32:22 -07:00
}).on('pageshowbeginready', ".page", function () {
var page = $(this);
2015-05-18 15:23:03 -07:00
var apiClient = window.ApiClient;
2014-10-25 11:32:58 -07:00
2015-05-20 09:28:55 -07:00
if (apiClient && apiClient.accessToken() && Dashboard.getCurrentUserId()) {
2015-05-31 11:22:51 -07:00
var isSettingsPage = page.hasClass('type-interior');
2015-05-31 11:22:51 -07:00
if (isSettingsPage) {
Dashboard.ensureToolsMenu(page);
2013-05-10 05:18:07 -07:00
2015-05-31 11:22:51 -07:00
Dashboard.getCurrentUser().done(function (user) {
2014-10-25 11:32:58 -07:00
2015-05-31 11:22:51 -07:00
if (!user.Policy.IsAdministrator) {
Dashboard.logout();
return;
}
});
}
}
2013-04-25 20:31:10 -07:00
2014-04-24 10:30:59 -07:00
else {
2015-05-05 08:24:47 -07:00
var isConnectMode = Dashboard.isConnectMode();
if (isConnectMode) {
2015-05-06 20:11:51 -07:00
2015-05-05 08:24:47 -07:00
if (!Dashboard.isServerlessPage()) {
2015-05-25 10:32:22 -07:00
Dashboard.logout();
2015-05-05 08:24:47 -07:00
return;
}
}
2015-05-06 20:11:51 -07:00
2015-05-20 10:29:26 -07:00
if (!isConnectMode && this.id !== "loginPage" && !page.hasClass('forgotPasswordPage') && !page.hasClass('wizardPage')) {
2014-10-21 05:42:02 -07:00
console.log('Not logged into server. Redirecting to login.');
2015-05-25 10:32:22 -07:00
Dashboard.logout();
2014-04-24 10:30:59 -07:00
return;
}
}
2015-05-25 10:32:22 -07:00
Dashboard.firePageEvent(page, 'pageshowready');
Dashboard.ensureHeader(page);
2014-10-25 11:32:58 -07:00
if (apiClient && !apiClient.isWebSocketOpen()) {
2013-07-16 09:03:28 -07:00
Dashboard.refreshSystemInfoFromServer();
}
});