From 90082ed4bcd5f39fd057f7df1acf30d7c894b139 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 24 Oct 2014 00:54:35 -0400 Subject: [PATCH] add LocalFileInfo.Id --- dashboard-ui/metadataadvanced.html | 4 +- dashboard-ui/myprofile.html | 2 +- dashboard-ui/scripts/site.js | 68 +- dashboard-ui/scripts/useredit.js | 3 + .../thirdparty/apiclient/connectionmanager.js | 661 +++++++++++++++++- .../thirdparty/apiclient/credentials.js | 81 +++ .../thirdparty/{ => apiclient}/md5.js | 0 .../apiclient/mediabrowser.apiclient.js | 179 +---- dashboard-ui/thirdparty/apiclient/store.js | 50 ++ dashboard-ui/thirdparty/browser.js | 57 ++ dashboard-ui/useredit.html | 9 +- dashboard-ui/userprofiles.html | 9 +- 12 files changed, 935 insertions(+), 188 deletions(-) create mode 100644 dashboard-ui/thirdparty/apiclient/credentials.js rename dashboard-ui/thirdparty/{ => apiclient}/md5.js (100%) create mode 100644 dashboard-ui/thirdparty/apiclient/store.js create mode 100644 dashboard-ui/thirdparty/browser.js diff --git a/dashboard-ui/metadataadvanced.html b/dashboard-ui/metadataadvanced.html index 56ca68eea3..ffbece16a2 100644 --- a/dashboard-ui/metadataadvanced.html +++ b/dashboard-ui/metadataadvanced.html @@ -23,7 +23,7 @@
  • - +
    ${LabelMetadataPathHelp}
    @@ -34,7 +34,7 @@
  • - diff --git a/dashboard-ui/myprofile.html b/dashboard-ui/myprofile.html index a06f00f6f1..c1ca2f7765 100644 --- a/dashboard-ui/myprofile.html +++ b/dashboard-ui/myprofile.html @@ -46,7 +46,7 @@
    diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index 3e6f0b12d4..b6302a217e 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -551,7 +551,10 @@ var Dashboard = { html += '
    '; - html += '

    ' + Globalize.translate('ButtonMyPreferences') + ''; + if (user.Configuration.EnableUserPreferenceAccess) { + html += '

    ' + Globalize.translate('ButtonMyPreferences') + ''; + } + html += '

    '; html += '
    '; @@ -1191,20 +1194,79 @@ var Dashboard = { (function () { + 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) { alert(Globalize.translate('MessageBrowserDoesNotSupportWebSockets')); } - window.ApiClient = new MediaBrowser.ApiClient(Dashboard.serverAddress(), "Dashboard", window.dashboardVersion, MediaBrowser.ApiClient.generateDeviceName(), MediaBrowser.ApiClient.generateDeviceId()); + var appName = "Dashboard"; + var appVersion = window.dashboardVersion; + var deviceName = generateDeviceName(); + var deviceId = MediaBrowser.ApiClient.generateDeviceId(); + + window.ApiClient = new MediaBrowser.ApiClient(Dashboard.serverAddress(), appName, appVersion, deviceName, deviceId); + window.ConnectionManager = new MediaBrowser.ConnectionManager(new MediaBrowser.CredentialProvider(), appName, appVersion, deviceName, deviceId); $(ApiClient).on("websocketopen", Dashboard.onWebSocketOpened) .on("websocketmessage", Dashboard.onWebSocketMessageReceived); + // TODO: Improve with http://webpjs.appspot.com/ + ApiClient.supportsWebP($.browser.chrome); + ApiClient.setCurrentUserId(Dashboard.getCurrentUserId(), Dashboard.getAccessToken()); + //test(); + })(); +function test() { + + ConnectionManager.loginToConnect("luke", "ac501ac7111a1e5").done(function (result) { + + var promise = ConnectionManager.connect(); + + promise.done(function (r) { + alert(JSON.stringify(r)); + + }).fail(function() { + + alert('fail'); + }); + }); + +} $(function () { @@ -1326,7 +1388,7 @@ $(document).on('pagebeforeshow', ".page", function () { var isConnectMode = Dashboard.isConnectMode(); if (isConnectMode && !page.hasClass('connectLoginPage')) { - + if (!ConnectionManager.isLoggedIntoConnect()) { console.log('Not logged into connect. Redirecting to login.'); diff --git a/dashboard-ui/scripts/useredit.js b/dashboard-ui/scripts/useredit.js index da707c53cb..36da6369af 100644 --- a/dashboard-ui/scripts/useredit.js +++ b/dashboard-ui/scripts/useredit.js @@ -59,6 +59,8 @@ $('#chkEnableLiveTvAccess', page).checked(user.Configuration.EnableLiveTvAccess || false).checkboxradio("refresh"); $('#chkEnableContentDeletion', page).checked(user.Configuration.EnableContentDeletion || false).checkboxradio("refresh"); + $('#chkDisableUserPreferences', page).checked((!user.Configuration.EnableUserPreferenceAccess) || false).checkboxradio("refresh"); + Dashboard.hideLoadingMsg(); } @@ -102,6 +104,7 @@ user.Configuration.EnableMediaPlayback = $('#chkEnableMediaPlayback', page).checked(); user.Configuration.EnableLiveTvAccess = $('#chkEnableLiveTvAccess', page).checked(); user.Configuration.EnableContentDeletion = $('#chkEnableContentDeletion', page).checked(); + user.Configuration.EnableUserPreferenceAccess = !$('#chkDisableUserPreferences', page).checked(); var userId = getParameterByName("userId"); diff --git a/dashboard-ui/thirdparty/apiclient/connectionmanager.js b/dashboard-ui/thirdparty/apiclient/connectionmanager.js index 5e363f8b72..175f54bedb 100644 --- a/dashboard-ui/thirdparty/apiclient/connectionmanager.js +++ b/dashboard-ui/thirdparty/apiclient/connectionmanager.js @@ -2,55 +2,664 @@ window.MediaBrowser = {}; } -MediaBrowser.ConnectionManager = function () { +MediaBrowser.ConnectionManager = function (store) { - return function () { + MediaBrowser.ConnectionState = { + Unavilable: 0, + ServerSelection: 1, + ServerSignIn: 2, + SignedIn: 3 + }; + + MediaBrowser.ConnectionMode = { + Local: 0, + Remote: 1 + }; + + return function (credentialProvider, appName, applicationVersion, deviceName, deviceId) { var self = this; + var apiClients = []; - self.onConnectAuthenticated = function (result) { + function mergeServers(list1, list2) { - store.setItem('ConnectAccessToken', result.AccessToken); - store.setItem('ConnectUserId', result.User.Id); + for (var i = 0, length = list2.length; i < length; i++) { + credentialProvider.addOrUpdateServer(list1, list2[i]); + } + + return list1; + } + + function resolveWithFailure(deferred) { + + deferred.resolveWith(null, [ + { + state: MediaBrowser.ConnectionState.Unavilable, + connectUser: self.connectUser() + }]); + } + + function updateServerInfo(server, systemInfo) { + + server.Name = systemInfo.ServerName; + server.Id = systemInfo.Id; + + if (systemInfo.LocalAddress) { + server.LocalAddress = systemInfo.LocalAddress; + } + if (systemInfo.WanAddress) { + server.RemoteAddress = systemInfo.WanAddress; + } + if (systemInfo.MacAddress) { + server.WakeOnLanInfos = [ + { MacAddress: systemInfo.MacAddress } + ]; + } + + } + + function tryConnect(url) { + + return $.ajax({ + + type: "GET", + url: url + "/mediabrowser/system/info/public", + dataType: "json", + + error: function () { + } + + }); + } + + var connectUser; + self.connectUser = function () { + return connectUser; }; - self.isLoggedIntoConnect = function () { + function onConnectAuthenticated(user) { - return self.connectToken() && self.connectUserId(); - }; + connectUser = user; + $(self).trigger('connectusersignedin', [user]); + } - self.logoutFromConnect = function () { - store.removeItem('ConnectAccessToken'); - store.removeItem('ConnectUserId'); - }; + function getOrAddApiClient(server, connectionMode) { - self.changeServer = function (currentApiClient, server) { + var apiClient = self.getApiClient(server.Id); - }; + if (!apiClient) { - self.connectUserId = function () { - return store.getItem('ConnectUserId'); - }; + var url = connectionMode == MediaBrowser.ConnectionMode.Local ? server.LocalAddress : server.RemoteAddress; - self.connectToken = function () { - return store.getItem('ConnectAccessToken'); - }; + apiClient = new MediaBrowser.ApiClient(url, appName, applicationVersion, deviceName, deviceId); - self.getServers = function () { + apiClients.push(apiClient); - var url = "https://connect.mediabrowser.tv/service/servers?userId=" + self.connectUserId(); + $(apiClient).on('authenticated', function (e, result) { + onLocalAuthenticated(this, result); + }); + + } + + if (!server.accessToken) { + + apiClient.clearAuthenticationInfo(); + } + else { + + apiClient.setAuthenticationInfo(server.accessToken, server.userId); + } + + return apiClient; + } + + function onLocalAuthenticated(apiClient, result) { + + apiClient.getSystemInfo().done(function (systemInfo) { + + var server = apiClient.serverInfo; + updateServerInfo(server, systemInfo); + + var credentials = credentialProvider.credentials(); + + server.DateLastAccessed = new Date().getTime(); + server.UserId = result.User.Id; + server.AccessToken = result.AccessToken; + + credentials.addOrUpdateServer(credentials.servers, server); + credentialProvider.credentials(credentials); + + ensureWebSocket(apiClient); + + onLocalUserSignIn(result.User); + + }); + } + + function ensureWebSocket(apiClient) { + + if (!apiClient.isWebSocketOpenOrConnecting) { + apiClient.openWebSocket(); + } + } + + function onLocalUserSignIn(user) { + + $(self).trigger('localusersignedin', [user]); + } + + function ensureConnectUser(credentials) { + + var deferred = $.Deferred(); + + if (self.isLoggedIntoConnect()) { + deferred.resolveWith(null, [[]]); + + } else { + getConnectUser(credentials.ConnectUserId, credentials.ConnectAccessToken).done(function (user) { + + onConnectAuthenticated(user); + deferred.resolveWith(null, [[]]); + + }).fail(function () { + + deferred.resolveWith(null, [[]]); + }); + } + + return deferred.promise(); + } + + function getConnectUser(userId, accessToken) { + + var url = "https://connect.mediabrowser.tv/service/user?userId=" + userId; return $.ajax({ type: "GET", url: url, dataType: "json", headers: { - "X-Connect-UserToken": self.connectToken() + "X-Connect-UserToken": accessToken + }, + + error: function () { + } + }); + } + + function addAuthenticationInfoFromConnect(server, connectionMode, credentials) { + + var url = connectionMode == MediaBrowser.ConnectionMode.Local ? server.LocalAddress : server.RemoteAddress; + + url += "/mediabrowser/Connect/Exchange?format=json&ConnectUserId=" + credentials.ConnectUserId; + + return $.ajax({ + type: "GET", + url: url, + dataType: "json", + headers: { + "X-MediaBrowser-Token": server.ExchangeToken + }, + + error: function () { + + } + + }).done(function (auth) { + + server.UserId = auth.LocalUserId; + server.AccessToken = auth.AccessToken; + + }).fail(function () { + + server.UserId = null; + server.AccessToken = null; + }); + } + + function validateAuthentication(server, connectionMode) { + + var deferred = $.Deferred(); + + var url = connectionMode == MediaBrowser.ConnectionMode.Local ? server.LocalAddress : server.RemoteAddress; + + $.ajax({ + + type: "GET", + url: url + "/mediabrowser/system/info", + dataType: "json", + headers: { + "X-MediaBrowser-Token": server.AccessToken + }, + + error: function () { + + } + + }).done(function (systemInfo) { + + updateServerInfo(server, systemInfo); + + if (server.UserId) { + + $.ajax({ + + type: "GET", + url: url + "/mediabrowser/users/" + server.UserId, + dataType: "json", + headers: { + "X-MediaBrowser-Token": server.AccessToken + }, + + error: function () { + + } + + }).done(function (user) { + + onLocalUserSignIn(user); + deferred.resolveWith(null, [[]]); + + }).fail(function () { + + server.UserId = null; + server.AccessToken = null; + deferred.resolveWith(null, [[]]); + }); + } + + }).fail(function () { + + server.UserId = null; + server.AccessToken = null; + deferred.resolveWith(null, [[]]); + + }); + + return deferred.promise(); + } + + self.isLoggedIntoConnect = function () { + + return self.connectToken() && self.connectUserId(); + }; + + self.logout = function () { + + var i, length; + var promises = []; + + for (i = 0, length = apiClients.length; i < length; i++) { + + var apiClient = apiClients[i]; + + if (apiClient.accessToken()) { + promises.push(apiClient.logout()); + } + } + + return $.when(promises).done(function () { + + var credentials = credentialProvider.credentials(); + + for (i = 0, length = credentials.servers.length; i < length; i++) { + credentials.servers[i].UserId = null; + credentials.servers[i].AccessToken = null; + credentials.servers[i].ExchangeToken = null; + } + + credentials.ConnectAccessToken = null; + credentials.ConnectUserId = null; + + credentialProvider.credentials(credentials); + + connectUser = null; + + $(self).trigger('signedout'); + + }); + }; + + self.connectUserId = function () { + return credentialProvider.credentials().ConnectUserId; + }; + + self.connectToken = function () { + + return credentialProvider.credentials().ConnectAccessToken; + }; + + function getConnectServers() { + + var deferred = $.Deferred(); + + var url = "https://connect.mediabrowser.tv/service/servers?userId=" + self.connectUserId(); + + $.ajax({ + type: "GET", + url: url, + dataType: "json", + headers: { + "X-Connect-UserToken": self.connectToken() + }, + + error: function () { + + } + + }).done(function (servers) { + + servers = servers.map(function (i) { + return { + ExchangeToken: i.AccessKey, + Id: i.SystemId, + Name: i.Name, + RemoteAddress: i.Url, + LocalAddress: null + }; + }); + + deferred.resolveWith(null, [servers]); + + }).fail(function () { + deferred.resolveWith(null, [[]]); + + }); + + return deferred.promise(); + } + + self.getServers = function () { + + // Clone the array + var credentials = credentialProvider.credentials(); + var servers = credentials.servers.slice(0); + + var deferred = $.Deferred(); + + getConnectServers().done(function (result) { + + var newList = mergeServers(servers, result); + + deferred.resolveWith(null, [newList]); + + credentials.servers = newList; + + credentialProvider.credentials(credentials); + }); + + return deferred.promise(); + }; + + self.connect = function () { + + var deferred = $.Deferred(); + + self.getServers().done(function (servers) { + + self.connectToServers(servers).done(function (result) { + + deferred.resolveWith(null, [result]); + + }); + }); + + return deferred.promise(); + }; + + self.connectToServers = function (servers) { + + var deferred = $.Deferred(); + + servers.sort(function (a, b) { + return b.DateLastAccessed - a.DateLastAccessed; + }); + + if (servers.length == 1) { + if (!servers[0].DateLastAccessed && !self.connectUser()) { + deferred.resolveWith(null, [ + { + Servers: servers, + State: MediaBrowser.ConnectionState.ServerSelection, + ConnectUser: self.connectUser() + } + ]); + } + + self.connectToServer(servers[0]).done(function (result) { + + deferred.resolveWith(null, [result]); + + }).fail(function () { + + deferred.resolveWith(null, [ + { + Servers: servers, + State: MediaBrowser.ConnectionState.ServerSelection, + ConnectUser: self.connectUser() + } + ]); + + }); + + } else { + + // Find the first server with a saved access token + var currentServer = servers.filter(function (s) { + return s.AccessToken; + })[0]; + + if (currentServer) { + self.connectToServer(currentServer).done(function (result) { + + deferred.resolveWith(null, [result]); + + }).fail(function () { + + deferred.resolveWith(null, [ + { + Servers: servers, + State: MediaBrowser.ConnectionState.ServerSelection, + ConnectUser: self.connectUser() + } + ]); + + }); + } else { + deferred.resolveWith(null, [ + { + Servers: servers, + State: servers.length ? MediaBrowser.ConnectionState.ServerSelection : MediaBrowser.ConnectionState.Unavailable, + ConnectUser: self.connectUser() + }]); + } + } + + return deferred.promise(); + }; + + self.connectToServer = function (server) { + + var deferred = $.Deferred(); + + var systemInfo = null; + var connectionMode = MediaBrowser.ConnectionMode.Local; + var credentials = credentialProvider.credentials(); + + function onLocalServerTokenValidationDone() { + + credentialProvider.addOrUpdateServer(credentials.servers, server); + server.DateLastAccessed = new Date().getTime(); + + credentialProvider.credentials(credentials); + + var result = { + Servers: [] + }; + + result.ApiClient = getOrAddApiClient(server, connectionMode); + result.State = server.AccessToken ? + MediaBrowser.ConnectionState.SignedIn : + MediaBrowser.ConnectionState.ServerSignIn; + + result.ApiClient.enableAutomaticNetworking(server, connectionMode); + + if (result.State == MediaBrowser.ConnectionState.SignedIn) { + ensureWebSocket(result.ApiClient); + } + + result.Servers.push(server); + + deferred.resolveWith(null, [result]); + + $(this).trigger('connected', [result]); + } + + function onExchangeTokenDone() { + + if (server.AccessToken) { + validateAuthentication(server, connectionMode).always(onLocalServerTokenValidationDone); + } else { + onLocalServerTokenValidationDone(); + } + } + + function onEnsureConnectUserDone() { + + if (credentials.ConnectUserId && credentials.ConnectAccessToken) { + + addAuthenticationInfoFromConnect(server, connectionMode, credentials).always(onExchangeTokenDone); + + } else { + onExchangeTokenDone(); + } + } + + function onRemoteTestDone() { + + if (systemInfo == null) { + + resolveWithFailure(deferred); + return; + } + + updateServerInfo(server, systemInfo); + + if (credentials.ConnectUserId && credentials.ConnectAccessToken) { + ensureConnectUser(credentials).always(onEnsureConnectUserDone); + } else { + onEnsureConnectUserDone(); + } + } + + function onLocalTestDone() { + + if (!systemInfo && server.RemoteAddress) { + + // Try to connect to the local address + tryConnect(server.RemoteAddress).done(function (result) { + + systemInfo = result; + connectionMode = MediaBrowser.ConnectionMode.Remote; + onRemoteTestDone(); + + }).fail(function () { + onRemoteTestDone(); + }); + + } else { + onRemoteTestDone(); + } + } + + if (server.LocalAddress) { + + // Try to connect to the local address + tryConnect(server.LocalAddress).done(function (result) { + + systemInfo = result; + onLocalTestDone(); + + }).fail(function () { + onLocalTestDone(); + }); + + } else { + onLocalTestDone(); + } + + return deferred.promise(); + }; + + self.connectToAddress = function (address) { + + if (address.toLowerCase().indexOf('http') != 0) { + address = "http://" + address; + } + + var deferred = $.Deferred(); + + tryConnect(address).done(function (publicInfo) { + + var server = {}; + updateServerInfo(server, publicInfo); + + self.connectToServer(server).done(function (result) { + + deferred.resolveWith(null, [result]); + + }).fail(function () { + + resolveWithFailure(deferred); + }); + + }).fail(function () { + + resolveWithFailure(deferred); + }); + + return deferred.promise(); + }; + + self.loginToConnect = function (username, password) { + + var md5 = CryptoJS.MD5(password).toString(); + + return $.ajax({ + type: "POST", + url: "https://connect.mediabrowser.tv/service/user/authenticate", + data: { + userName: username, + password: md5 + }, + dataType: "json", + contentType: 'application/x-www-form-urlencoded; charset=UTF-8', + + error: function () { + // Don't show normal dashboard errors + } + + + }).done(function (result) { + + var credentials = credentialProvider.credentials(); + + credentials.ConnectAccessToken = result.AccessToken; + credentials.ConnectUserId = result.User.Id; + + credentialProvider.credentials(credentials); + + onConnectAuthenticated(result.User); + }); + }; + + self.getApiClient = function (item) { + + // TODO: accept string + objet + return apiClients[0]; }; }; -}(); - -window.ConnectionManager = new MediaBrowser.ConnectionManager(); \ No newline at end of file +}(window.store); \ No newline at end of file diff --git a/dashboard-ui/thirdparty/apiclient/credentials.js b/dashboard-ui/thirdparty/apiclient/credentials.js new file mode 100644 index 0000000000..13deeb398a --- /dev/null +++ b/dashboard-ui/thirdparty/apiclient/credentials.js @@ -0,0 +1,81 @@ +if (!window.MediaBrowser) { + window.MediaBrowser = {}; +} + +MediaBrowser.CredentialProvider = function (store) { + + return function () { + + var self = this; + var credentials; + + function ensure() { + + credentials = credentials || JSON.parse(store.getItem('servercredentials') || '{}'); + credentials.servers = credentials.servers || []; + } + + function get() { + + ensure(); + return credentials; + } + + function set(data) { + credentials = data; + store.setItem('servercredentials', JSON.stringify(get())); + } + + self.credentials = function (data) { + + if (data) { + set(data); + } + + return get(); + }; + + self.addOrUpdateServer = function(list, server) { + + var existing = list.filter(function(s) { + return s.Id == server.Id; + })[0]; + + if (existing) + { + // Merge the data + existing.DateLastAccessed = Math.max(existing.DateLastAccessed || 0, server.DateLastAccessed || 0, new Date().getTime()); + + if (server.AccessToken) + { + existing.AccessToken = server.AccessToken; + existing.UserId = server.UserId; + } + if (server.ExchangeToken) + { + existing.ExchangeToken = server.ExchangeToken; + } + if (server.RemoteAddress) + { + existing.RemoteAddress = server.RemoteAddress; + } + if (server.LocalAddress) + { + existing.LocalAddress = server.LocalAddress; + } + if (server.Name) + { + existing.Name = server.Name; + } + if (server.WakeOnLanInfos && server.WakeOnLanInfos.length) + { + existing.WakeOnLanInfos = server.WakeOnLanInfos; + } + } + else { + list.push(server); + } + }; + }; + +}(window.store); \ No newline at end of file diff --git a/dashboard-ui/thirdparty/md5.js b/dashboard-ui/thirdparty/apiclient/md5.js similarity index 100% rename from dashboard-ui/thirdparty/md5.js rename to dashboard-ui/thirdparty/apiclient/md5.js diff --git a/dashboard-ui/thirdparty/apiclient/mediabrowser.apiclient.js b/dashboard-ui/thirdparty/apiclient/mediabrowser.apiclient.js index 08f8720250..81bb5c7e71 100644 --- a/dashboard-ui/thirdparty/apiclient/mediabrowser.apiclient.js +++ b/dashboard-ui/thirdparty/apiclient/mediabrowser.apiclient.js @@ -1,55 +1,4 @@ -(function (window) { - - function myStore(defaultObject) { - - var self = this; - self.localData = {}; - - var isDefaultAvailable; - - if (defaultObject) { - try { - defaultObject.setItem('_test', '0'); - isDefaultAvailable = true; - } catch (e) { - - } - } - - self.setItem = function (name, value) { - - if (isDefaultAvailable) { - defaultObject.setItem(name, value); - } else { - self.localData[name] = value; - } - }; - - self.getItem = function (name) { - - if (isDefaultAvailable) { - return defaultObject.getItem(name); - } - - return self.localData[name]; - }; - - self.removeItem = function (name) { - - if (isDefaultAvailable) { - defaultObject.removeItem(name); - } else { - self.localData[name] = null; - } - }; - } - - window.store = new myStore(window.localStorage); - window.sessionStore = new myStore(window.sessionStorage); - -})(window); - -if (!window.MediaBrowser) { +if (!window.MediaBrowser) { window.MediaBrowser = {}; } @@ -117,6 +66,16 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi return deviceId; }; + self.clearAuthenticationInfo = function () { + accessToken = null; + currentUserId = null; + }; + + self.setAuthenticationInfo = function (accessKey, userId) { + accessToken = accessKey; + currentUserId = userId; + }; + self.encodeName = function (name) { name = name.split('/').join('-'); @@ -187,6 +146,10 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi return url; }; + self.enableAutomaticNetworking = function(server, connectionMode) { + + }; + self.openWebSocket = function () { var url = serverAddress + self.apiPrefix(); @@ -2117,11 +2080,14 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; - function supportsWebP() { + var supportsWebP = false; + self.supportsWebP = function(val) { - // TODO: Improve with http://webpjs.appspot.com/ - return $.browser.chrome; - } + if (val != null) { + supportsWebP = val; + } + return supportsWebP; + }; function normalizeImageOptions(options) { @@ -2149,7 +2115,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi options.quality = options.quality || (options.type.toLowerCase() == 'backdrop' ? 80 : 90); - if (supportsWebP()) { + if (self.supportsWebP()) { options.format = 'webp'; } } @@ -2225,7 +2191,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi delete options.type; delete options.index; - if (supportsWebP()) { + if (self.supportsWebP()) { options.format = 'webp'; } @@ -2297,6 +2263,11 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi data: JSON.stringify(postData), dataType: "json", contentType: "application/json" + + }).done(function(result) { + + + $(self).trigger('authenticated', [result]); }); }; @@ -3222,94 +3193,4 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi return sha1(keys.join('|')); }; - MediaBrowser.ApiClient.generateDeviceName = function () { - - 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; - }; - -})(window.store); - -(function (jQuery, window, undefined) { - "use strict"; - - var matched, browser; - - jQuery.uaMatch = function (ua) { - ua = ua.toLowerCase(); - - var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || - /(webkit)[ \/]([\w.]+)/.exec(ua) || - /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || - /(msie) ([\w.]+)/.exec(ua) || - ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || - []; - - var platform_match = /(ipad)/.exec(ua) || - /(iphone)/.exec(ua) || - /(android)/.exec(ua) || - []; - - var browser = match[1] || ""; - - if (ua.indexOf("like gecko") != -1 && ua.indexOf('webkit') == -1 && ua.indexOf('opera') == -1) { - browser = "msie"; - } - - return { - browser: browser, - version: match[2] || "0", - platform: platform_match[0] || "" - }; - }; - - matched = jQuery.uaMatch(window.navigator.userAgent); - browser = {}; - - if (matched.browser) { - browser[matched.browser] = true; - browser.version = matched.version; - } - - if (matched.platform) { - browser[matched.platform] = true; - } - - // Chrome is Webkit, but Webkit is also Safari. - if (browser.chrome) { - browser.webkit = true; - } else if (browser.webkit) { - browser.safari = true; - } - - browser.mobile = (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)); - - jQuery.browser = browser; - -})(jQuery, window); \ No newline at end of file +})(window.store); \ No newline at end of file diff --git a/dashboard-ui/thirdparty/apiclient/store.js b/dashboard-ui/thirdparty/apiclient/store.js new file mode 100644 index 0000000000..663959d706 --- /dev/null +++ b/dashboard-ui/thirdparty/apiclient/store.js @@ -0,0 +1,50 @@ +(function (window) { + + function myStore(defaultObject) { + + var self = this; + self.localData = {}; + + var isDefaultAvailable; + + if (defaultObject) { + try { + defaultObject.setItem('_test', '0'); + isDefaultAvailable = true; + } catch (e) { + + } + } + + self.setItem = function (name, value) { + + if (isDefaultAvailable) { + defaultObject.setItem(name, value); + } else { + self.localData[name] = value; + } + }; + + self.getItem = function (name) { + + if (isDefaultAvailable) { + return defaultObject.getItem(name); + } + + return self.localData[name]; + }; + + self.removeItem = function (name) { + + if (isDefaultAvailable) { + defaultObject.removeItem(name); + } else { + self.localData[name] = null; + } + }; + } + + window.store = new myStore(window.localStorage); + window.sessionStore = new myStore(window.sessionStorage); + +})(window); \ No newline at end of file diff --git a/dashboard-ui/thirdparty/browser.js b/dashboard-ui/thirdparty/browser.js new file mode 100644 index 0000000000..2080c937d1 --- /dev/null +++ b/dashboard-ui/thirdparty/browser.js @@ -0,0 +1,57 @@ +(function (jQuery, window, undefined) { + "use strict"; + + var matched, browser; + + jQuery.uaMatch = function (ua) { + ua = ua.toLowerCase(); + + var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || + /(webkit)[ \/]([\w.]+)/.exec(ua) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || + /(msie) ([\w.]+)/.exec(ua) || + ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || + []; + + var platform_match = /(ipad)/.exec(ua) || + /(iphone)/.exec(ua) || + /(android)/.exec(ua) || + []; + + var browser = match[1] || ""; + + if (ua.indexOf("like gecko") != -1 && ua.indexOf('webkit') == -1 && ua.indexOf('opera') == -1) { + browser = "msie"; + } + + return { + browser: browser, + version: match[2] || "0", + platform: platform_match[0] || "" + }; + }; + + matched = jQuery.uaMatch(window.navigator.userAgent); + browser = {}; + + if (matched.browser) { + browser[matched.browser] = true; + browser.version = matched.version; + } + + if (matched.platform) { + browser[matched.platform] = true; + } + + // Chrome is Webkit, but Webkit is also Safari. + if (browser.chrome) { + browser.webkit = true; + } else if (browser.webkit) { + browser.safari = true; + } + + browser.mobile = (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)); + + jQuery.browser = browser; + +})(jQuery, window); \ No newline at end of file diff --git a/dashboard-ui/useredit.html b/dashboard-ui/useredit.html index 2ca83afb8c..d68d4a8941 100644 --- a/dashboard-ui/useredit.html +++ b/dashboard-ui/useredit.html @@ -59,10 +59,15 @@
    ${OptionDisableUserHelp}
    -

    +

    + + +
    ${OptionDisableUserPreferencesHelp}
    +
    +
    -

    +