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

1470 lines
47 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";
2014-06-28 12:35:30 -07:00
$.mobile.popup.prototype.options.transition = "fade";
2014-02-22 22:52:30 -07:00
$.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";
},
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();
if (!Dashboard.suppressAjaxErrors) {
setTimeout(function () {
var msg = data.errorCode || Dashboard.defaultErrorMessage;
Dashboard.showError(msg);
}, 500);
}
},
2014-10-29 15:01:02 -07:00
onApiClientServerAddressChanged: function () {
Dashboard.serverAddress(ApiClient.serverAddress());
},
getCurrentUser: function () {
if (!Dashboard.getUserPromise) {
2013-07-16 09:03:28 -07:00
var userId = Dashboard.getCurrentUserId();
2014-10-25 11:32:58 -07:00
Dashboard.getUserPromise = ConnectionManager.currentApiClient().getUser(userId).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();
}
},
2014-07-07 18:41:03 -07:00
getAccessToken: function () {
2014-07-15 12:16:16 -07:00
return store.getItem('token');
2014-07-07 18:41:03 -07:00
},
2014-10-15 20:26:39 -07:00
serverAddress: function (val) {
if (val != null) {
2014-10-21 21:42:26 -07:00
console.log('Setting server address to: ' + val);
2014-10-15 20:26:39 -07:00
store.setItem('serverAddress', val);
}
var address = store.getItem('serverAddress');
2014-10-25 11:32:58 -07:00
if (!address && !Dashboard.isConnectMode()) {
2014-10-15 20:26:39 -07:00
var loc = window.location;
address = loc.protocol + '//' + loc.hostname;
if (loc.port) {
address += ':' + loc.port;
}
}
return address;
},
getCurrentUserId: function () {
2014-02-08 13:02:35 -07:00
var autoLoginUserId = getParameterByName('u');
2014-07-15 12:16:16 -07:00
var storedUserId = store.getItem("userId");
2014-02-08 13:02:35 -07:00
2014-02-08 13:22:40 -07:00
if (autoLoginUserId && autoLoginUserId != storedUserId) {
2014-03-15 13:08:06 -07:00
2014-07-07 18:41:03 -07:00
var token = getParameterByName('t');
Dashboard.setCurrentUser(autoLoginUserId, token);
}
2014-02-08 13:22:40 -07:00
return autoLoginUserId || storedUserId;
},
2014-07-07 18:41:03 -07:00
setCurrentUser: function (userId, token) {
2014-07-15 12:16:16 -07:00
store.setItem("userId", userId);
store.setItem("token", token);
2014-02-08 13:02:35 -07:00
2014-10-25 11:32:58 -07:00
var apiClient = ConnectionManager.currentApiClient();
if (apiClient) {
apiClient.setCurrentUserId(userId, token);
}
Dashboard.getUserPromise = null;
},
2014-10-21 05:42:02 -07:00
isConnectMode: function () {
2014-10-26 20:06:01 -07:00
var url = getWindowUrl().toLowerCase();
return url.indexOf('mediabrowser.tv') != -1 ||
url.indexOf('mediabrowser.github') != -1;
2014-10-21 05:42:02 -07:00
},
2014-07-12 21:55:56 -07:00
logout: function (logoutWithServer) {
2014-07-15 12:16:16 -07:00
store.removeItem("userId");
store.removeItem("token");
2014-10-28 16:17:55 -07:00
store.removeItem("serverAddress");
2014-02-08 13:02:35 -07:00
2014-10-21 05:42:02 -07:00
var loginPage = !Dashboard.isConnectMode() ?
'login.html' :
'connectlogin.html';
2014-07-12 21:55:56 -07:00
if (logoutWithServer === false) {
2014-10-21 05:42:02 -07:00
window.location = loginPage;
2014-07-12 21:55:56 -07:00
} else {
2014-10-25 11:32:58 -07:00
ConnectionManager.logout().done(function () {
2014-10-21 05:42:02 -07:00
window.location = loginPage;
2014-07-12 21:55:56 -07:00
});
}
},
showError: function (message) {
$.mobile.loading('show', {
text: message,
textonly: true,
textVisible: true
});
setTimeout(function () {
$.mobile.loading('hide');
}, 3000);
},
2013-12-26 19:23:57 -07:00
alert: function (options) {
2013-12-26 19:23:57 -07:00
if (typeof options == "string") {
2013-12-26 19:23:57 -07:00
var message = options;
$.mobile.loading('show', {
text: message,
textonly: true,
textVisible: true
});
setTimeout(function () {
$.mobile.loading('hide');
}, 3000);
2013-12-26 19:23:57 -07:00
return;
}
2014-07-16 20:17:14 -07:00
Dashboard.confirmInternal(options.message, options.title || Globalize.translate('HeaderAlert'), false, options.callback);
},
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) {
if (currentUser.Configuration.IsAdministrator) {
2013-10-07 07:38:31 -07:00
Dashboard.showServerRestartWarning(info);
}
});
} else {
Dashboard.hideServerRestartWarning();
if (Dashboard.initialServerVersion != info.Version) {
Dashboard.showDashboardVersionWarning();
}
}
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();
},
showDashboardVersionWarning: 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();
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) {
window.location.href = "dashboard.html";
} else {
2014-10-21 05:42:02 -07:00
window.location.href = getWindowUrl();
}
},
hideDashboardVersionWarning: function () {
$('#dashboardVersionWarning').remove();
},
showFooterNotification: function (options) {
var removeOnHide = !options.id;
options.id = options.id || "notification" + new Date().getTime() + parseInt(Math.random());
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);
},
navigate: function (url, preserveQueryString) {
2014-04-08 19:12:17 -07:00
var queryString = getWindowLocationSearch();
if (preserveQueryString && queryString) {
url += queryString;
}
$.mobile.changePage(url);
},
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");
},
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'));
},
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();
});
},
2013-12-26 19:23:57 -07:00
confirm: function (message, title, callback) {
Dashboard.confirmInternal(message, title, true, callback);
},
refreshSystemInfoFromServer: function () {
2014-08-19 15:28:35 -07:00
if (Dashboard.getAccessToken()) {
2014-07-07 18:41:03 -07:00
ApiClient.getSystemInfo().done(function (info) {
Dashboard.updateSystemInfo(info);
});
}
},
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);
},
showUserFlyout: function (context) {
2014-10-25 11:32:58 -07:00
ConnectionManager.user().done(function (user) {
2014-07-17 15:21:35 -07:00
var html = '<div data-role="panel" data-position="right" data-display="overlay" id="userFlyout" data-position-fixed="true" data-theme="a">';
2014-03-16 22:23:13 -07:00
html += '<h3>';
2014-10-25 11:32:58 -07:00
if (user.imageUrl) {
var url = user.imageUrl;
2014-10-25 11:32:58 -07:00
if (user.supportsImageParams) {
url += "width=" + 28;
}
2014-10-25 11:32:58 -07:00
html += '<img style="max-width:28px;vertical-align:middle;margin-right:5px;" src="' + url + '" />';
2014-03-16 22:23:13 -07:00
}
2014-10-25 11:32:58 -07:00
html += user.name;
2014-03-16 22:23:13 -07:00
html += '</h3>';
2014-04-14 20:54:52 -07:00
html += '<form>';
2014-11-04 05:41:12 -07:00
var isConnectMode = Dashboard.isConnectMode();
2014-10-25 11:32:58 -07:00
if (user.localUser && user.localUser.Configuration.EnableUserPreferenceAccess) {
html += '<p><a data-mini="true" data-role="button" href="mypreferencesdisplay.html?userId=' + user.localUser.Id + '" data-icon="gear">' + Globalize.translate('ButtonMyPreferences') + '</button></a>';
2014-10-23 21:54:35 -07:00
}
2014-11-04 05:41:12 -07:00
if (isConnectMode) {
2014-11-25 21:12:29 -07:00
html += '<p><a data-mini="true" data-role="button" href="selectserver.html" data-icon="cloud" data-ajax="false">' + Globalize.translate('ButtonSelectServer') + '</button></a>';
2014-10-26 20:06:01 -07:00
}
2014-07-16 20:17:14 -07:00
html += '<p><button data-mini="true" type="button" onclick="Dashboard.logout();" data-icon="lock">' + Globalize.translate('ButtonSignOut') + '</button></p>';
2014-04-14 20:54:52 -07:00
html += '</form>';
html += '</div>';
$(document.body).append(html);
2014-07-22 09:36:34 -07:00
var elem = $('#userFlyout').panel({}).trigger('create').panel("open").on("panelclose", function () {
2014-07-22 09:36:34 -07:00
$(this).off("panelclose").remove();
});
});
},
getPluginSecurityInfo: function () {
if (!Dashboard.getPluginSecurityInfoPromise) {
var deferred = $.Deferred();
// Don't let this blow up the dashboard when it fails
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
type: "GET",
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;
Dashboard.validateCurrentUser();
},
2014-06-21 22:52:31 -07:00
ensureHeader: function (page) {
2014-06-21 22:52:31 -07:00
if (page.hasClass('standalonePage')) {
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">';
headerHtml += '<a class="logo" href="index.html">';
if (page.hasClass('standalonePage')) {
headerHtml += '<img class="imgLogoIcon" src="css/images/mblogoicon.png" /><img class="imgLogoText" src="css/images/mblogotextblack.png" />';
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
2014-04-24 10:30:59 -07:00
ensureToolsMenu: function (page, user) {
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">';
var links = Dashboard.getToolsMenuLinks(page);
2013-12-26 22:08:37 -07:00
var i, length, link;
for (i = 0, length = links.length; i < length; i++) {
2013-12-26 22:08:37 -07:00
link = links[i];
2013-12-26 19:23:57 -07:00
2014-04-24 10:30:59 -07:00
if (!user.Configuration.IsAdministrator) {
break;
}
2013-12-25 20:44:26 -07:00
if (link.divider) {
html += "<div class='sidebarDivider'></div>";
}
if (link.href) {
if (link.selected) {
html += '<a class="selectedSidebarLink" href="' + link.href + '">' + link.name + '</a>';
} else {
html += '<a href="' + link.href + '">' + link.name + '</a>';
}
}
}
// collapsible
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
2014-07-26 10:30:15 -07:00
html += '<p class="libraryPanelHeader" style="margin: 15px 0 15px 15px;"><a href="index.html" class="imageLink"><img src="css/images/mblogoicon.png" /><span style="color:#333;">MEDIA</span><span class="mediaBrowserAccent">BROWSER</span></a></p>';
2013-12-26 22:08:37 -07:00
for (i = 0, length = links.length; i < length; i++) {
link = links[i];
2014-04-24 10:30:59 -07:00
if (!user.Configuration.IsAdministrator) {
break;
}
2013-12-26 22:08:37 -07:00
if (link.divider) {
html += "<div class='dashboardPanelDivider'></div>";
}
if (link.href) {
if (link.selected) {
html += '<a class="selectedDashboardPanelLink dashboardPanelLink" href="' + link.href + '">' + link.name + '</a>';
} else {
html += '<a class="dashboardPanelLink" href="' + link.href + '">' + link.name + '</a>';
}
}
}
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];
return [{
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabServer'),
href: "dashboard.html",
2014-02-26 14:31:47 -07:00
selected: page.hasClass("dashboardHomePage")
2014-10-11 13:38:13 -07:00
}, {
name: Globalize.translate('TabDevices'),
href: "devices.html",
selected: page.hasClass("devicesPage")
2014-07-26 10:30:15 -07:00
}, {
name: Globalize.translate('TabUsers'),
href: "userprofiles.html",
selected: page.hasClass("userProfilesPage")
}, {
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",
selected: page.hasClass("mediaLibraryPage")
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabMetadata'),
href: "metadata.html",
2014-05-07 11:38:50 -07:00
selected: page.hasClass('metadataConfigurationPage')
2014-01-22 16:52:01 -07:00
}, {
2014-09-22 14:56:54 -07:00
name: Globalize.translate('TabPlayback'),
href: "playbackconfiguration.html",
selected: page.hasClass('playbackConfigurationPage')
2014-12-17 15:39:17 -07:00
//}, {
// name: Globalize.translate('TabSync'),
// href: "syncactivity.html",
// selected: page.hasClass('syncConfigurationPage')
2014-09-22 14:56:54 -07:00
}, {
divider: true,
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabAutoOrganize'),
2014-01-22 16:52:01 -07:00
href: "autoorganizelog.html",
selected: page.hasClass("organizePage")
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",
selected: page.hasClass("dlnaPage")
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",
2014-01-12 09:55:38 -07:00
selected: page.hasClass("liveTvSettingsPage")
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",
selected: page.hasClass("pluginConfigurationPage")
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabAdvanced'),
2013-12-25 20:44:26 -07:00
divider: true,
href: "advanced.html",
selected: page.hasClass("advancedConfigurationPage")
}, {
2014-07-16 20:17:14 -07:00
name: Globalize.translate('TabHelp'),
href: "support.html",
selected: pageElem.id == "supportPage" || pageElem.id == "logPage" || pageElem.id == "supporterPage" || pageElem.id == "supporterKeyPage" || pageElem.id == "aboutPage"
}];
},
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();
},
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;
if (args.TimeoutMs && WebNotifications.supported()) {
var notification = {
title: args.Header,
body: args.Text,
timeout: args.TimeoutMs
};
WebNotifications.show(notification);
}
else {
2014-07-16 20:17:14 -07:00
Dashboard.showFooterNotification({ html: "<div><b>" + args.Header + "</b></div>" + args.Text, timeout: args.TimeoutMs });
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") {
Dashboard.validateCurrentUser();
var user = msg.Data;
if (user.Id == Dashboard.getCurrentUserId()) {
$('.currentUsername').html(user.Name);
}
}
else if (msg.MessageType === "PackageInstallationCompleted") {
Dashboard.getCurrentUser().done(function (currentUser) {
if (currentUser.Configuration.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "completed");
Dashboard.refreshSystemInfoFromServer();
}
});
}
else if (msg.MessageType === "PackageInstallationFailed") {
Dashboard.getCurrentUser().done(function (currentUser) {
if (currentUser.Configuration.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "failed");
Dashboard.refreshSystemInfoFromServer();
}
});
}
else if (msg.MessageType === "PackageInstallationCancelled") {
Dashboard.getCurrentUser().done(function (currentUser) {
if (currentUser.Configuration.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "cancelled");
Dashboard.refreshSystemInfoFromServer();
}
});
}
else if (msg.MessageType === "PackageInstalling") {
Dashboard.getCurrentUser().done(function (currentUser) {
if (currentUser.Configuration.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-06-21 22:52:31 -07:00
$(parent).prepend("<h1 class='pageTitle'>" + (document.title || "&nbsp;") + "</h1>");
},
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();
return url.indexOf('connectlogin.html') != -1 || url.indexOf('selectserver.html') != -1;
}
};
2013-04-01 22:14:37 -07:00
(function () {
2014-10-23 21:54:35 -07:00
function generateDeviceName() {
var name = "Web Browser";
if ($.browser.chrome) {
name = "Chrome";
} else if ($.browser.safari) {
name = "Safari";
} else if ($.browser.webkit) {
name = "WebKit";
} else if ($.browser.msie) {
name = "Internet Explorer";
} else if ($.browser.opera) {
name = "Opera";
} else if ($.browser.firefox || $.browser.mozilla) {
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;
}
if (!window.WebSocket) {
2014-07-16 20:17:14 -07:00
alert(Globalize.translate('MessageBrowserDoesNotSupportWebSockets'));
}
2013-04-19 15:09:21 -07:00
2014-10-25 11:32:58 -07:00
function initializeApiClient(apiClient) {
2014-10-28 16:17:55 -07:00
$(apiClient).off('.dashboard')
.on("websocketmessage.dashboard", Dashboard.onWebSocketMessageReceived)
2014-10-29 15:01:02 -07:00
.on('requestfail.dashboard', Dashboard.onRequestFail)
.on('serveraddresschanged.dashboard', Dashboard.onApiClientServerAddressChanged);
2014-10-25 11:32:58 -07:00
}
2014-10-23 21:54:35 -07:00
var appName = "Dashboard";
var appVersion = window.dashboardVersion;
var deviceName = generateDeviceName();
2014-10-26 20:06:01 -07:00
var deviceId = MediaBrowser.generateDeviceId();
2014-10-25 11:32:58 -07:00
var credentialProvider = new MediaBrowser.CredentialProvider();
2014-10-23 21:54:35 -07:00
2014-10-25 11:32:58 -07:00
var capabilities = {
PlayableMediaTypes: "Audio,Video",
2013-09-05 10:26:03 -07:00
2014-12-10 23:20:28 -07:00
SupportedCommands: Dashboard.getSupportedRemoteCommands().join(','),
2014-12-12 20:56:30 -07:00
SupportsUniqueIdentifier: false
2014-10-25 11:32:58 -07:00
};
2014-10-25 11:32:58 -07:00
window.ConnectionManager = new MediaBrowser.ConnectionManager(credentialProvider, appName, appVersion, deviceName, deviceId, capabilities);
if (Dashboard.isConnectMode()) {
2014-10-23 21:54:35 -07:00
2014-10-25 11:32:58 -07:00
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
2014-05-16 21:24:10 -07:00
2014-10-25 11:32:58 -07:00
initializeApiClient(apiClient);
});
2014-10-23 21:54:35 -07:00
2014-10-25 11:32:58 -07:00
if (Dashboard.serverAddress() && Dashboard.getCurrentUserId() && Dashboard.getAccessToken() && !Dashboard.isServerlessPage()) {
window.ApiClient = new MediaBrowser.ApiClient(Dashboard.serverAddress(), appName, appVersion, deviceName, deviceId, capabilities);
2014-10-25 11:32:58 -07:00
ApiClient.setCurrentUserId(Dashboard.getCurrentUserId(), Dashboard.getAccessToken());
2014-10-23 21:54:35 -07:00
2014-10-25 11:32:58 -07:00
initializeApiClient(ApiClient);
2014-10-23 21:54:35 -07:00
2014-11-18 19:45:12 -07:00
ConnectionManager.addApiClient(ApiClient, true).fail(Dashboard.logout);
2014-10-25 11:32:58 -07:00
}
2014-10-23 21:54:35 -07:00
2014-10-25 11:32:58 -07:00
} else {
2014-10-23 21:54:35 -07:00
2014-10-25 11:32:58 -07:00
window.ApiClient = new MediaBrowser.ApiClient(Dashboard.serverAddress(), appName, appVersion, deviceName, deviceId, capabilities);
2014-10-23 21:54:35 -07:00
2014-10-25 11:32:58 -07:00
ApiClient.setCurrentUserId(Dashboard.getCurrentUserId(), Dashboard.getAccessToken());
initializeApiClient(ApiClient);
ConnectionManager.addApiClient(ApiClient);
}
})();
$(function () {
var videoPlayerHtml = '<div id="mediaPlayer" data-theme="b" class="ui-bar-b" style="display: none;">';
2014-06-28 12:35:30 -07:00
videoPlayerHtml += '<div class="videoBackdrop">';
2014-05-29 12:34:20 -07:00
videoPlayerHtml += '<div id="videoPlayer">';
2014-06-28 12:35:30 -07:00
videoPlayerHtml += '<div id="videoElement">';
videoPlayerHtml += '<div id="play" class="status"></div>';
videoPlayerHtml += '<div id="pause" class="status"></div>';
videoPlayerHtml += '</div>';
2014-06-28 12:35:30 -07:00
videoPlayerHtml += '<div class="videoTopControls hiddenOnIdle">';
videoPlayerHtml += '<div class="videoTopControlsLogo"></div>';
videoPlayerHtml += '<div class="videoAdvancedControls">';
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button class="imageButton mediaButton videoAudioButton" title="Audio tracks" type="button" data-icon="audiocd" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonAudioTracks') + '</button>';
videoPlayerHtml += '<div data-role="popup" class="videoAudioPopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2014-06-28 12:35:30 -07:00
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button class="imageButton mediaButton videoSubtitleButton" title="Subtitles" type="button" data-icon="subtitles" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonFullscreen') + '</button>';
videoPlayerHtml += '<div data-role="popup" class="videoSubtitlePopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2014-06-28 12:35:30 -07:00
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button class="mediaButton videoChaptersButton" title="Scenes" type="button" data-icon="video" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonScenes') + '</button>';
videoPlayerHtml += '<div data-role="popup" class="videoChaptersPopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button class="mediaButton videoQualityButton" title="Quality" type="button" data-icon="gear" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonQuality') + '</button>';
videoPlayerHtml += '<div data-role="popup" class="videoQualityPopup videoPlayerPopup" data-history="false" data-theme="b"></div>';
2014-06-28 12:35:30 -07:00
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button class="mediaButton" title="Stop" type="button" onclick="MediaPlayer.stop();" data-icon="delete" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonStop') + '</button>';
2014-06-28 12:35:30 -07:00
videoPlayerHtml += '</div>'; // videoAdvancedControls
videoPlayerHtml += '</div>'; // videoTopControls
// Create controls
videoPlayerHtml += '<div class="videoControls hiddenOnIdle">';
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button id="video-previousTrackButton" class="mediaButton previousTrackButton" title="Previous Track" type="button" onclick="MediaPlayer.previousTrack();" data-icon="previous-track" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonPreviousTrack') + '</button>';
videoPlayerHtml += '<button id="video-playButton" class="mediaButton" title="Play" type="button" onclick="MediaPlayer.unpause();" data-icon="play" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonPlay') + '</button>';
videoPlayerHtml += '<button id="video-pauseButton" class="mediaButton" title="Pause" type="button" onclick="MediaPlayer.pause();" data-icon="pause" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonPause') + '</button>';
videoPlayerHtml += '<button id="video-nextTrackButton" class="mediaButton nextTrackButton" title="Next Track" type="button" onclick="MediaPlayer.nextTrack();" data-icon="next-track" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonNextTrack') + '</button>';
2014-06-28 12:35:30 -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>';
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<div class="currentTime">--:--</div>';
2014-06-28 12:35:30 -07:00
videoPlayerHtml += '<div class="nowPlayingInfo hiddenOnIdle">';
videoPlayerHtml += '<div class="nowPlayingImage"></div>';
videoPlayerHtml += '<div class="nowPlayingText"></div>';
2014-06-28 12:35:30 -07:00
videoPlayerHtml += '</div>'; // nowPlayingInfo
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button id="video-muteButton" class="mediaButton muteButton" title="Mute" type="button" onclick="MediaPlayer.mute();" data-icon="audio" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonMute') + '</button>';
videoPlayerHtml += '<button id="video-unmuteButton" class="mediaButton unmuteButton" title="Unmute" type="button" onclick="MediaPlayer.unMute();" data-icon="volume-off" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonUnmute') + '</button>';
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>';
2014-07-16 20:17:14 -07:00
videoPlayerHtml += '<button onclick="MediaPlayer.toggleFullscreen();" id="video-fullscreenButton" class="mediaButton fullscreenButton" title="Fullscreen" type="button" data-icon="expand" data-iconpos="notext" data-inline="true">' + Globalize.translate('ButtonFullscreen') + '</button>';
videoPlayerHtml += '</div>'; // videoControls
videoPlayerHtml += '</div>'; // videoPlayer
videoPlayerHtml += '</div>'; // videoBackdrop
videoPlayerHtml += '</div>'; // mediaPlayer
$(document.body).append(videoPlayerHtml);
var mediaPlayerElem = $('#mediaPlayer', document.body);
mediaPlayerElem.trigger('create');
var footerHtml = '<div id="footer" data-theme="b" class="ui-bar-b">';
2014-04-13 10:27:13 -07:00
footerHtml += '<div id="footerNotifications"></div>';
footerHtml += '</div>';
$(document.body).append(footerHtml);
var footerElem = $('#footer', document.body);
footerElem.trigger('create');
2014-04-13 10:27:13 -07:00
2014-03-31 21:16:35 -07:00
$(window).on("beforeunload", function () {
2013-09-09 11:23:55 -07:00
2014-10-25 11:32:58 -07:00
var apiClient = ConnectionManager.currentApiClient();
2013-09-09 11:23:55 -07:00
// Close the connection gracefully when possible
2014-10-25 11:32:58 -07:00
if (apiClient && apiClient.isWebSocketOpen() && !MediaPlayer.isPlaying()) {
console.log('Sending close web socket command');
2014-10-25 11:32:58 -07:00
apiClient.closeWebSocket();
2013-09-09 11:23:55 -07:00
}
});
2014-07-08 17:46:11 -07:00
$(document).on('contextmenu', '.ui-popup-screen', function (e) {
$('.ui-popup').popup('close');
e.preventDefault();
return false;
});
2014-10-06 16:58:46 -07:00
function isTouchDevice() {
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
}
if (isTouchDevice()) {
$(document.body).addClass('touch');
}
});
Dashboard.jQueryMobileInit();
2013-07-16 09:03:28 -07:00
$(document).on('pagebeforeshow', ".page", function () {
var page = $(this);
2014-10-21 05:42:02 -07:00
var isConnectMode = Dashboard.isConnectMode();
if (isConnectMode && !page.hasClass('connectLoginPage')) {
2014-10-23 21:54:35 -07:00
2014-10-21 05:42:02 -07:00
if (!ConnectionManager.isLoggedIntoConnect()) {
console.log('Not logged into connect. Redirecting to login.');
Dashboard.logout();
return;
}
}
2014-10-25 11:32:58 -07:00
var apiClient = ConnectionManager.currentApiClient();
2014-08-21 08:55:35 -07:00
if (Dashboard.getAccessToken() && Dashboard.getCurrentUserId()) {
2014-10-25 11:32:58 -07:00
if (apiClient) {
Dashboard.getCurrentUser().done(function (user) {
2014-10-25 11:32:58 -07:00
var isSettingsPage = page.hasClass('type-interior');
2013-05-10 05:18:07 -07:00
2014-10-25 11:32:58 -07:00
if (!user.Configuration.IsAdministrator && isSettingsPage) {
window.location.replace("index.html");
return;
}
if (isSettingsPage) {
Dashboard.ensureToolsMenu(page, user);
}
});
}
Dashboard.ensureHeader(page);
Dashboard.ensurePageTitle(page);
}
2013-04-25 20:31:10 -07:00
2014-04-24 10:30:59 -07:00
else {
if (this.id !== "loginPage" && !page.hasClass('forgotPasswordPage') && !page.hasClass('wizardPage') && !isConnectMode) {
2014-10-21 05:42:02 -07:00
console.log('Not logged into server. Redirecting to login.');
2014-04-24 10:30:59 -07:00
Dashboard.logout();
return;
}
Dashboard.ensureHeader(page);
Dashboard.ensurePageTitle(page);
}
2014-10-25 11:32:58 -07:00
if (apiClient && !apiClient.isWebSocketOpen()) {
2013-07-16 09:03:28 -07:00
Dashboard.refreshSystemInfoFromServer();
}
});