var LoginPage = { getApiClient: function () { var serverId = getParameterByName('serverid'); return new Promise(function (resolve, reject) { if (serverId) { resolve(ConnectionManager.getOrCreateApiClient(serverId)); } else { resolve(ApiClient); } }); }, onPageShow: function () { Dashboard.showLoadingMsg(); var page = this; LoginPage.getApiClient().then(function (apiClient) { apiClient.getPublicUsers().then(function (users) { var showManualForm = !users.length; if (showManualForm) { LoginPage.showManualForm(page, false, false); } else { LoginPage.showVisualForm(page); LoginPage.loadUserList(page, apiClient, users); } Dashboard.hideLoadingMsg(); }); apiClient.getJSON(apiClient.getUrl('Branding/Configuration')).then(function (options) { $('.disclaimer', page).html(options.LoginDisclaimer || ''); }); }); if (Dashboard.isConnectMode()) { $('.connectButtons', page).show(); } else { $('.connectButtons', page).hide(); } }, cancelLogin: function () { LoginPage.showVisualForm($.mobile.activePage); }, showManualForm: function (page, showCancel, focusPassword) { $('.visualLoginForm', page).hide(); $('.manualLoginForm', page).show(); if (focusPassword) { $('#txtManualPassword input', page).focus(); } else { $('#txtManualName input', page).focus(); } if (showCancel) { $('.btnCancel', page).show(); } else { $('.btnCancel', page).hide(); } }, showVisualForm: function (page) { $('.visualLoginForm', page).show(); $('.manualLoginForm', page).hide(); }, getLastSeenText: function (lastActivityDate) { if (!lastActivityDate) { return ""; } return "Last seen " + humane_date(lastActivityDate); }, authenticateUserByName: function (page, apiClient, username, password) { Dashboard.showLoadingMsg(); apiClient.authenticateUserByName(username, password).then(function (result) { var user = result.User; var serverId = getParameterByName('serverid'); var newUrl; if (user.Policy.IsAdministrator && !serverId) { newUrl = "dashboard.html"; } else { newUrl = "index.html"; } Dashboard.hideLoadingMsg(); Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient); Dashboard.navigate(newUrl); }, function () { $('#pw', page).val(''); $('#txtManualName', page).val(''); $('#txtManualPassword', page).val(''); Dashboard.hideLoadingMsg(); setTimeout(function () { require(['toast'], function (toast) { toast(Globalize.translate('MessageInvalidUser')); }); }, 300); }); }, loadUserList: function (page, apiClient, users) { var html = ""; for (var i = 0, length = users.length; i < length; i++) { var user = users[i]; html += '