jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/router.js

1 line
13 KiB
JavaScript
Raw Normal View History

2017-07-26 22:18:39 -07:00
define(["loading","globalize","events","viewManager","skinManager","pluginManager","backdrop","browser","pageJs","appSettings","apphost","connectionManager"],function(loading,globalize,events,viewManager,skinManager,pluginManager,backdrop,browser,page,appSettings,appHost,connectionManager){"use strict";function beginConnectionWizard(){backdrop.clear(),loading.show(),connectionManager.connect({enableAutoLogin:appSettings.enableAutoLogin()}).then(function(result){handleConnectionResult(result,loading)})}function handleConnectionResult(result,loading){switch(result.State){case MediaBrowser.ConnectionState.SignedIn:loading.hide(),skinManager.loadUserSkin();break;case MediaBrowser.ConnectionState.ServerSignIn:result.ApiClient.getPublicUsers().then(function(users){users.length?appRouter.showLocalLogin(result.Servers[0].Id):appRouter.showLocalLogin(result.Servers[0].Id,!0)});break;case MediaBrowser.ConnectionState.ServerSelection:appRouter.showSelectServer();break;case MediaBrowser.ConnectionState.ConnectSignIn:appRouter.showWelcome();break;case MediaBrowser.ConnectionState.ServerUpdateNeeded:require(["alert"],function(alert){alert({text:globalize.translate("sharedcomponents#ServerUpdateNeeded","https://emby.media"),html:globalize.translate("sharedcomponents#ServerUpdateNeeded",'<a href="https://emby.media">https://emby.media</a>')}).then(function(){appRouter.showSelectServer()})})}}function loadContentUrl(ctx,next,route,request){var url;url=route.contentPath&&"function"==typeof route.contentPath?route.contentPath(ctx.querystring):route.contentPath||route.path,url.indexOf("://")===-1&&(0!==url.indexOf("/")&&(url="/"+url),url=baseUrl()+url),ctx.querystring&&route.enableContentQueryString&&(url+="?"+ctx.querystring),require(["text!"+url],function(html){loadContent(ctx,route,html,request)})}function handleRoute(ctx,next,route){authenticate(ctx,route,function(){initRoute(ctx,next,route)})}function initRoute(ctx,next,route){var onInitComplete=function(controllerFactory){sendRouteToViewManager(ctx,next,route,controllerFactory)};require(route.dependencies||[],function(){route.controller?require([route.controller],onInitComplete):onInitComplete()})}function cancelCurrentLoadRequest(){var currentRequest=currentViewLoadRequest;currentRequest&&(currentRequest.cancel=!0)}function sendRouteToViewManager(ctx,next,route,controllerFactory){if(isDummyBackToHome&&"home"===route.type)return void(isDummyBackToHome=!1);cancelCurrentLoadRequest();var isBackNav=ctx.isBack,currentRequest={url:baseUrl()+ctx.path,transition:route.transition,isBack:isBackNav,state:ctx.state,type:route.type,fullscreen:route.fullscreen,controllerFactory:controllerFactory,options:{supportsThemeMedia:route.supportsThemeMedia||!1,enableMediaControl:route.enableMediaControl!==!1},autoFocus:route.autoFocus};currentViewLoadRequest=currentRequest;var onNewViewNeeded=function(){"string"==typeof route.path?loadContentUrl(ctx,next,route,currentRequest):next()};return isBackNav?void viewManager.tryRestoreView(currentRequest,function(){currentRouteInfo={route:route,path:ctx.path}}).catch(function(result){result&&result.cancelled||onNewViewNeeded()}):void onNewViewNeeded()}function onForcedLogoutMessageTimeout(){var msg=forcedLogoutMsg;forcedLogoutMsg=null,msg&&require(["alert"],function(alert){alert(msg)})}function showForcedLogoutMessage(msg){forcedLogoutMsg=msg,msgTimeout&&clearTimeout(msgTimeout),msgTimeout=setTimeout(onForcedLogoutMessageTimeout,100)}function onRequestFail(e,data){var apiClient=this;if(401===data.status&&"ParentalControl"===data.errorCode){var isCurrentAllowed=!currentRouteInfo||(currentRouteInfo.route.anonymous||currentRouteInfo.route.startup);isCurrentAllowed||(showForcedLogoutMessage(globalize.translate("sharedcomponents#AccessRestrictedTryAgainLater")),connectionManager.isLoggedIntoConnect()?appRouter.showConnectLogin():appRouter.showLocalLogin(apiClient.serverId()))}}function onApiClientCreated(e,newApiClient){events.off(newApiClient,"requestfail",onRequestFail),events.on(newApiClient,"requestfail",onRequestFail)}function initApiClient(apiClient){onApiClient