";
if (item.RunTimeTicks) {
html += Dashboard.getDisplayTime(connection.NowPlayingPositionTicks || 0) + " / ";
html += Dashboard.getDisplayTime(item.RunTimeTicks);
}
html += "
";
}
return html;
},
renderRunningTasks: function (dashboardInfo) {
var page = $.mobile.activePage;
var html = '';
if (!dashboardInfo.RunningTasks.length) {
html += '
No tasks are currently running.
';
$('#runningTasksCollapsible', page).hide();
} else {
$('#runningTasksCollapsible', page).show();
}
for (var i = 0, length = dashboardInfo.RunningTasks.length; i < length; i++) {
var task = dashboardInfo.RunningTasks[i];
html += '
';
html += task.Name;
if (task.State == "Running") {
var progress = (task.CurrentProgressPercentage || 0).toFixed(1);
html += ' - ' + progress + '%';
html += '';
}
else if (task.State == "Cancelling") {
html += ' - Stopping';
}
html += '
';
}
$('#divRunningTasks', page).html(html).trigger('create');
},
renderSystemInfo: function (page, dashboardInfo) {
Dashboard.updateSystemInfo(dashboardInfo.SystemInfo);
$('#appVersionNumber', page).html(dashboardInfo.SystemInfo.Version);
var port = dashboardInfo.SystemInfo.HttpServerPortNumber;
if (port == dashboardInfo.SystemInfo.WebSocketPortNumber) {
$('#ports', page).html('Running on port ' + port + '');
} else {
$('#ports', page).html('Running on ports ' + port + ' and ' + dashboardInfo.SystemInfo.WebSocketPortNumber + '');
}
if (dashboardInfo.RunningTasks.filter(function (task) {
return task.Id == dashboardInfo.ApplicationUpdateTaskId;
}).length) {
$('#btnUpdateApplication', page).buttonEnabled(false);
} else {
$('#btnUpdateApplication', page).buttonEnabled(true);
}
if (dashboardInfo.SystemInfo.CanSelfRestart) {
$('.btnRestartContainer', page).removeClass('hide');
} else {
$('.btnRestartContainer', page).addClass('hide');
}
DashboardPage.renderUrls(page, dashboardInfo.SystemInfo);
DashboardPage.renderApplicationUpdateInfo(page, dashboardInfo);
DashboardPage.renderPluginUpdateInfo(page, dashboardInfo);
DashboardPage.renderPendingInstallations(page, dashboardInfo.SystemInfo);
},
renderUrls: function (page, systemInfo) {
var url = ApiClient.serverAddress() + "/mediabrowser";
$('#bookmarkUrl', page).html(url).attr("href", url);
if (systemInfo.WanAddress) {
var externalUrl = systemInfo.WanAddress + "/mediabrowser";
$('.externalUrl', page).html('Remote access: ' + externalUrl + '').show().trigger('create');
} else {
$('.externalUrl', page).hide();
}
},
renderApplicationUpdateInfo: function (page, dashboardInfo) {
$('#updateFail', page).hide();
if (!dashboardInfo.SystemInfo.HasPendingRestart) {
// Only check once every 10 mins
if (DashboardPage.lastAppUpdateCheck && (new Date().getTime() - DashboardPage.lastAppUpdateCheck) < 600000) {
return;
}
DashboardPage.lastAppUpdateCheck = new Date().getTime();
ApiClient.getAvailableApplicationUpdate().done(function (packageInfo) {
var version = packageInfo[0];
if (!version) {
$('#pUpToDate', page).show();
$('#pUpdateNow', page).hide();
} else {
$('#pUpToDate', page).hide();
$('#pUpdateNow', page).show();
if (dashboardInfo.SystemInfo.CanSelfUpdate) {
$('#btnUpdateApplicationContainer', page).show();
$('#btnManualUpdateContainer', page).hide();
} else {
$('#btnUpdateApplicationContainer', page).hide();
$('#btnManualUpdateContainer', page).show();
}
$('#newVersionNumber', page).html("Version " + version.versionStr + " is now available for download.");
}
}).fail(function () {
$('#updateFail', page).show();
});
} else {
if (dashboardInfo.SystemInfo.HasPendingRestart) {
$('#pUpToDate', page).hide();
} else {
$('#pUpToDate', page).show();
}
$('#pUpdateNow', page).hide();
}
},
renderPendingInstallations: function (page, systemInfo) {
if (systemInfo.CompletedInstallations.length) {
$('#collapsiblePendingInstallations', page).show();
} else {
$('#collapsiblePendingInstallations', page).hide();
return;
}
var html = '';
for (var i = 0, length = systemInfo.CompletedInstallations.length; i < length; i++) {
var update = systemInfo.CompletedInstallations[i];
html += '
' + update.Name + ' (' + update.Version + ')
';
}
$('#pendingInstallations', page).html(html);
},
renderPluginUpdateInfo: function (page, dashboardInfo) {
// Only check once every 10 mins
if (DashboardPage.lastPluginUpdateCheck && (new Date().getTime() - DashboardPage.lastPluginUpdateCheck) < 600000) {
return;
}
DashboardPage.lastPluginUpdateCheck = new Date().getTime();
ApiClient.getAvailablePluginUpdates().done(function (updates) {
var elem = $('#pPluginUpdates', page);
if (updates.length) {
elem.show();
} else {
elem.hide();
return;
}
var html = '';
for (var i = 0, length = updates.length; i < length; i++) {
var update = updates[i];
html += '
A new version of ' + update.name + ' is available!
';
html += '';
}
elem.html(html).trigger('create');
}).fail(function () {
$('#updateFail', page).show();
});
},
installPluginUpdate: function (button) {
$(button).buttonEnabled(false);
var name = button.getAttribute('data-name');
var guid = button.getAttribute('data-guid');
var version = button.getAttribute('data-version');
var classification = button.getAttribute('data-classification');
Dashboard.showLoadingMsg();
ApiClient.installPlugin(name, guid, classification, version).done(function () {
Dashboard.hideLoadingMsg();
});
},
updateApplication: function () {
var page = $.mobile.activePage;
$('#btnUpdateApplication', page).buttonEnabled(false);
Dashboard.showLoadingMsg();
ApiClient.startScheduledTask(DashboardPage.lastDashboardInfo.ApplicationUpdateTaskId).done(function () {
DashboardPage.pollForInfo(page);
Dashboard.hideLoadingMsg();
});
},
stopTask: function (id) {
var page = $.mobile.activePage;
ApiClient.stopScheduledTask(id).done(function () {
DashboardPage.pollForInfo(page);
});
},
restart: function () {
Dashboard.confirm("Are you sure you wish to restart Media Browser Server?", "Restart", function (result) {
if (result) {
$('#btnRestartServer').buttonEnabled(false);
$('#btnShutdown').buttonEnabled(false);
Dashboard.restartServer();
}
});
},
shutdown: function () {
Dashboard.confirm("Are you sure you wish to shutdown Media Browser Server?", "Shutdown", function (result) {
if (result) {
$('#btnRestartServer').buttonEnabled(false);
$('#btnShutdown').buttonEnabled(false);
ApiClient.shutdownServer();
}
});
}
};
$(document).on('pageshow', "#dashboardPage", DashboardPage.onPageShow).on('pagehide', "#dashboardPage", DashboardPage.onPageHide);