';
var imageUrl = user.PrimaryImageTag ? ApiClient.getUserImageUrl(user.Id, {
height: 400,
tag: user.PrimaryImageTag,
type: "Primary"
}) : "css/images/userflyoutdefault.png";
html += '';
html += '
';
html += '';
html += '';
html += '
';
html += '
';
$(document.body).append(html);
$('#userFlyout').popup().trigger('create').popup("open").on("popupafterclose", function () {
$(this).off("popupafterclose").remove();
});
});
},
selectDirectory: function (options) {
options = options || {};
options.header = options.header || "Select Media Path";
options.instruction = options.instruction || "Browse to or enter the folder containing the media. Network paths (UNC) are recommended for optimal playback performance.";
var html = '
';
html += '
';
html += '
' + options.header + '
';
html += '
';
html += '
';
html += '';
html += '
';
html += '
';
$($.mobile.activePage).append(html);
var popup = $('#popupDirectoryPicker').popup().trigger('create').on("popupafteropen", function () {
$('#popupDirectoryPicker input:first', this).focus();
}).popup("open").on("popupafterclose", function () {
$('form', this).off("submit");
$(this).off("click").off("popupafterclose").remove();
}).on("click", ".lnkDirectory", function () {
var path = this.getAttribute('data-path');
Dashboard.refreshDirectoryBrowser(path);
});
var txtCurrentPath = $('#txtDirectoryPickerPath', popup);
if (options.path) {
txtCurrentPath.val(options.path);
}
$('form', popup).on('submit', function () {
if (options.callback) {
options.callback($('#txtDirectoryPickerPath', this).val());
}
return false;
});
Dashboard.refreshDirectoryBrowser(txtCurrentPath.val());
},
refreshDirectoryBrowser: function (path) {
var page = $.mobile.activePage;
Dashboard.showLoadingMsg();
var promise;
if (path === "Network") {
promise = ApiClient.getNetworkDevices();
}
else if (path) {
promise = ApiClient.getDirectoryContents(path, { includeDirectories: true });
} else {
promise = ApiClient.getDrives();
}
promise.done(function (folders) {
$('#txtDirectoryPickerPath', page).val(path || "");
var html = '';
if (path) {
var parentPath = path;
if (parentPath.endsWith('\\')) {
parentPath = parentPath.substring(0, parentPath.length - 1);
}
var lastIndex = parentPath.lastIndexOf('\\');
parentPath = lastIndex == -1 ? "" : parentPath.substring(0, lastIndex);
if (parentPath.endsWith(':')) {
parentPath += "\\";
}
if (parentPath == '\\') {
parentPath = "Network";
}
html += '
';
header.append(headerHtml);
Search.onSearchRendered(header);
Dashboard.getPluginSecurityInfo().done(function (pluginSecurityInfo) {
if (pluginSecurityInfo.IsMBSupporter) {
$('').insertBefore('.btnTools', header);
}
});
},
ensureToolsMenu: function (page) {
if (!page.hasClass('type-interior')) {
return;
}
var sidebar = $('.toolsSidebar', page);
if (!sidebar.length) {
var html = '
';
html += '
Tools
';
html += '
';
var links = Dashboard.getToolsMenuLinks(page);
for (var i = 0, length = links.length; i < length; i++) {
var link = links[i];
if (link.href) {
if (link.selected) {
html += '' + link.name + '';
} else {
html += '' + link.name + '';
}
}
}
// collapsible
html += '
';
// content-secondary
html += '
';
$(page).append(html);
}
},
getToolsMenuLinks: function (page) {
var pageElem = page[0];
return [{
name: "Dashboard",
href: "dashboard.html",
selected: pageElem.id == "dashboardPage"
}, {
name: "Default Media Library",
href: "library.html",
selected: pageElem.id == "mediaLibraryPage" && !getParameterByName('userId')
}, {
name: "Metadata",
href: "metadata.html",
selected: pageElem.id == "metadataConfigurationPage" || pageElem.id == "advancedMetadataConfigurationPage" || pageElem.id == "metadataImagesConfigurationPage"
}, {
name: "Plugins",
href: "plugins.html",
selected: page.hasClass("pluginConfigurationPage")
}, {
name: "User Profiles",
href: "userprofiles.html",
selected: page.hasClass("userProfilesConfigurationPage") || (pageElem.id == "mediaLibraryPage" && getParameterByName('userId'))
}, {
name: "Client Settings",
href: "clientsettings.html",
selected: pageElem.id == "clientSettingsPage"
}, {
name: "Advanced",
href: "advanced.html",
selected: pageElem.id == "advancedConfigurationPage"
}, {
name: "Scheduled Tasks",
href: "scheduledtasks.html",
selected: pageElem.id == "scheduledTasksPage" || pageElem.id == "scheduledTaskPage"
}, {
name: "Help",
href: "support.html",
selected: pageElem.id == "supportPage" || pageElem.id == "logPage" || pageElem.id == "supporterPage" || pageElem.id == "supporterKeyPage" || pageElem.id == "aboutPage"
}];
},
ensureWebSocket: function (systemInfo) {
if (!("WebSocket" in window)) {
// Not supported by the browser
return;
}
if (ApiClient.isWebSocketOpenOrConnecting()) {
return;
}
systemInfo = systemInfo || Dashboard.lastSystemInfo;
ApiClient.openWebSocket(systemInfo.WebSocketPortNumber);
$(ApiClient).on("websocketmessage", Dashboard.onWebSocketMessageReceived);
},
onWebSocketMessageReceived: function (e, data) {
var msg = data;
if (msg.MessageType === "LibraryChanged") {
Dashboard.processLibraryUpdateNotification(msg.Data);
}
else if (msg.MessageType === "UserDeleted") {
Dashboard.validateCurrentUser();
}
else if (msg.MessageType === "SystemInfo") {
Dashboard.updateSystemInfo(msg.Data);
}
else if (msg.MessageType === "RestartRequired") {
Dashboard.updateSystemInfo(msg.Data);
}
else if (msg.MessageType === "UserUpdated") {
Dashboard.validateCurrentUser();
var user = msg.Data;
if (user.Id == Dashboard.getCurrentUserId()) {
$('.currentUsername').html(user.Name);
}
}
else if (msg.MessageType === "PackageInstallationCompleted") {
Dashboard.showPackageInstallNotification(msg.Data, "completed");
Dashboard.refreshSystemInfoFromServer();
}
else if (msg.MessageType === "PackageInstallationFailed") {
Dashboard.showPackageInstallNotification(msg.Data, "failed");
Dashboard.refreshSystemInfoFromServer();
}
else if (msg.MessageType === "PackageInstallationCancelled") {
Dashboard.showPackageInstallNotification(msg.Data, "cancelled");
Dashboard.refreshSystemInfoFromServer();
}
else if (msg.MessageType === "PackageInstalling") {
Dashboard.showPackageInstallNotification(msg.Data, "progress");
Dashboard.refreshSystemInfoFromServer();
}
else if (msg.MessageType === "ScheduledTaskEnded") {
Dashboard.showTaskCompletionNotification(msg.Data);
}
},
showTaskCompletionNotification: function (result) {
var html = '';
if (result.Status == "Completed") {
html += '';
return;
}
else if (result.Status == "Cancelled") {
html += '';
return;
}
else {
html += '';
}
html += '';
html += result.Name + " " + result.Status;
html += '';
var timeout = 0;
if (result.Status == 'Cancelled') {
timeout = 2000;
}
Dashboard.showFooterNotification({ html: html, id: result.Id, forceShow: true, timeout: timeout });
},
showPackageInstallNotification: function (installation, status) {
var html = '';
if (status == 'completed') {
html += '';
}
else if (status == 'cancelled') {
html += '';
}
else if (status == 'failed') {
html += '';
}
else if (status == 'progress') {
html += '';
}
html += '';
if (status == 'completed') {
html += installation.Name + ' ' + installation.Version + ' installation completed';
}
else if (status == 'cancelled') {
html += installation.Name + ' ' + installation.Version + ' installation was cancelled';
}
else if (status == 'failed') {
html += installation.Name + ' ' + installation.Version + ' installation failed';
}
else if (status == 'progress') {
html += 'Installing ' + installation.Name + ' ' + installation.Version;
}
html += '';
if (status == 'progress') {
var percentComplete = Math.round(installation.PercentComplete || 0);
html += '';
if (percentComplete < 100) {
var btnId = "btnCancel" + installation.Id;
html += '';
}
}
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) {
if (Dashboard.newItemTimeout) {
clearTimeout(Dashboard.newItemTimeout);
}
Dashboard.newItemTimeout = setTimeout(Dashboard.onNewItemTimerStopped, 60000);
},
onNewItemTimerStopped: function () {
ApiClient.getItems(Dashboard.getCurrentUserId(), {
Recursive: true,
Limit: 2,
Filters: "IsNotFolder",
SortBy: "DateCreated",
SortOrder: "Descending",
ImageTypes: "Primary"
}).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 data = {
title: "New " + item.Type,
body: item.Name,
timeout: 5000
};
var imageTags = item.ImageTags || {};
if (imageTags.Primary) {
data.icon = ApiClient.getImageUrl(item.Id, {
width: 100,
tag: imageTags.Primary,
type: "Primary"
});
}
WebNotifications.show(data);
}
});
Dashboard.newItemTimeout = null;
},
ensurePageTitle: function (page) {
if (!page.hasClass('type-interior')) {
return;
}
var pageElem = page[0];
if (pageElem.hasPageTitle) {
return;
}
var parent = $('.content-primary', page);
if (!parent.length) {
parent = $('.ui-content', page)[0];
}
$(parent).prepend("
" + (document.title || " ") + "
");
pageElem.hasPageTitle = true;
},
setPageTitle: function (title) {
$('.pageTitle', $.mobile.activePage).html(title);
if (title) {
document.title = title;
}
}
};
var ApiClient = MediaBrowser.ApiClient.create("Dashboard");
$(function () {
var footerHtml = '';
$(document.body).append(footerHtml);
if ($.browser.msie && parseInt($.browser.version) < 10) {
Dashboard.confirm("This is an unsupported version of Internet Explorer. Please consider upgrading to IE10.", "Unsupported Browser", function (result) {
if (result) {
window.location = "http://windows.microsoft.com/en-us/internet-explorer/downloads/ie-10/worldwide-languages";
}
});
}
});
Dashboard.jQueryMobileInit();
$(document).on('pageinit', ".page", function () {
var page = $(this);
var userId = Dashboard.getCurrentUserId();
ApiClient.currentUserId(userId);
if (!userId) {
if (this.id !== "loginPage" && !page.hasClass('wizardPage')) {
Dashboard.logout();
}
}
else {
Dashboard.getCurrentUser().done(function (user) {
if (user.Configuration.IsAdministrator) {
Dashboard.ensureToolsMenu(page);
}
});
}
}).on('pagebeforeshow', ".page", function () {
Dashboard.refreshSystemInfoFromServer();
var page = $(this);
Dashboard.ensureHeader(page);
Dashboard.ensurePageTitle(page);
});