diff --git a/dashboard-ui/bower_components/emby-webcomponents/chromecastplayer.js b/dashboard-ui/bower_components/emby-webcomponents/chromecastplayer.js index bb8d1df698..5d1fe87b9d 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/chromecastplayer.js +++ b/dashboard-ui/bower_components/emby-webcomponents/chromecastplayer.js @@ -1 +1 @@ -define(["appSettings","playbackManager","connectionManager","globalize","events","castSenderApiLoader"],function(appSettings,playbackManager,connectionManager,globalize,events,castSenderApiLoader){"use strict";function sendConnectionResult(isOk){var resolve=currentResolve,reject=currentReject;currentResolve=null,currentReject=null,isOk?resolve&&resolve():reject?reject():playbackManager.removeActivePlayer(PlayerName)}function alertText(text,title){require(["alert"],function(alert){alert({text:text,title:title})})}function chromecastPlayer(){function initializeChromecast(){castPlayer=new CastPlayer,document.dispatchEvent(new CustomEvent("chromecastloaded",{detail:{player:self}})),events.on(castPlayer,"connect",function(e){currentResolve?sendConnectionResult(!0):playbackManager.setActivePlayer(PlayerName,self.getCurrentTargetInfo()),console.log("cc: connect"),self.lastPlayerData=null}),events.on(castPlayer,"playbackstart",function(e,data){console.log("cc: playbackstart"),castPlayer.initializeCastPlayer();var state=self.getPlayerStateInternal(data);events.trigger(self,"playbackstart",[state])}),events.on(castPlayer,"playbackstop",function(e,data){console.log("cc: playbackstop");var state=self.getPlayerStateInternal(data);events.trigger(self,"playbackstop",[state]),self.lastPlayerData={}}),events.on(castPlayer,"playbackprogress",function(e,data){console.log("cc: positionchange");var state=self.getPlayerStateInternal(data);events.trigger(self,"timeupdate",[state])}),events.on(castPlayer,"volumechange",function(e,data){console.log("cc: volumechange");var state=self.getPlayerStateInternal(data);events.trigger(self,"volumechange",[state])}),events.on(castPlayer,"repeatmodechange",function(e,data){console.log("cc: repeatmodechange");var state=self.getPlayerStateInternal(data);events.trigger(self,"repeatmodechange",[state])}),events.on(castPlayer,"playstatechange",function(e,data){console.log("cc: playstatechange");var state=self.getPlayerStateInternal(data);events.trigger(self,"pause",[state])})}function normalizeImages(state){if(state&&state.NowPlayingItem){var item=state.NowPlayingItem;item.ImageTags&&item.ImageTags.Primary||item.PrimaryImageTag&&(item.ImageTags=item.ImageTags||{},item.ImageTags.Primary=item.PrimaryImageTag),item.BackdropImageTag&&item.BackdropItemId===item.Id&&(item.BackdropImageTags=[item.BackdropImageTag]),item.BackdropImageTag&&item.BackdropItemId!==item.Id&&(item.ParentBackdropImageTags=[item.BackdropImageTag],item.ParentBackdropItemId=item.BackdropItemId)}}var castPlayer,self=this;self.name=PlayerName,self.type="mediaplayer",self.id="chromecast",self.isLocalPlayer=!1,self.getItemsForPlayback=function(query){var apiClient=ApiClient,userId=apiClient.getCurrentUserId();return query.Ids&&1===query.Ids.split(",").length?apiClient.getItem(userId,query.Ids.split(",")).then(function(item){return{Items:[item],TotalRecordCount:1}}):(query.Limit=query.Limit||100,query.ExcludeLocationTypes="Virtual",apiClient.getItems(userId,query))},self.play=function(options){return options.items?self.playWithCommand(options,"PlayNow"):self.getItemsForPlayback({Ids:options.ids.join(",")}).then(function(result){return options.items=result.Items,self.playWithCommand(options,"PlayNow")})},self.playWithCommand=function(options,command){if(!options.items){var apiClient=connectionManager.getApiClient(options.serverId);return apiClient.getItem(apiClient.getCurrentUserId(),options.ids[0]).then(function(item){return options.items=[item],self.playWithCommand(options,command)})}return castPlayer.loadMedia(options,command)},self.unpause=function(){castPlayer.sendMessage({options:{},command:"Unpause"})},self.playPause=function(){castPlayer.sendMessage({options:{},command:"PlayPause"})},self.pause=function(){castPlayer.sendMessage({options:{},command:"Pause"})},self.shuffle=function(item){var apiClient=connectionManager.getApiClient(item.ServerId),userId=apiClient.getCurrentUserId();apiClient.getItem(userId,item.Id).then(function(item){self.playWithCommand({items:[item]},"Shuffle")})},self.instantMix=function(item){var apiClient=connectionManager.getApiClient(item.ServerId),userId=apiClient.getCurrentUserId();apiClient.getItem(userId,item.Id).then(function(item){self.playWithCommand({items:[item]},"InstantMix")})},self.canPlayMediaType=function(mediaType){return mediaType=(mediaType||"").toLowerCase(),"audio"===mediaType||"video"===mediaType},self.canQueueMediaType=function(mediaType){return self.canPlayMediaType(mediaType)},self.queue=function(options){self.playWithCommand(options,"PlayLast")},self.queueNext=function(options){self.playWithCommand(options,"PlayNext")},self.stop=function(){return castPlayer.sendMessage({options:{},command:"Stop"})},self.displayContent=function(options){castPlayer.sendMessage({options:options,command:"DisplayContent"})},self.isPlaying=function(){var state=self.lastPlayerData||{};return null!=state.NowPlayingItem},self.isPlayingVideo=function(){var state=self.lastPlayerData||{};return state=state.NowPlayingItem||{},"Video"===state.MediaType},self.isPlayingAudio=function(){var state=self.lastPlayerData||{};return state=state.NowPlayingItem||{},"Audio"===state.MediaType},self.currentTime=function(val){if(null!=val)return self.seek(val);var state=self.lastPlayerData||{};return state=state.PlayState||{},state.PositionTicks},self.duration=function(){var state=self.lastPlayerData||{};return state=state.NowPlayingItem||{},state.RunTimeTicks},self.paused=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.IsPaused},self.isMuted=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.IsMuted},self.setMute=function(isMuted){isMuted?castPlayer.sendMessage({options:{},command:"Mute"}):castPlayer.sendMessage({options:{},command:"Unmute"})},self.getRepeatMode=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.RepeatMode},self.setRepeatMode=function(mode){castPlayer.sendMessage({options:{RepeatMode:mode},command:"SetRepeatMode"})},self.toggleMute=function(){castPlayer.sendMessage({options:{},command:"ToggleMute"})},self.getTargets=function(){var targets=[];return castPlayer.hasReceivers&&targets.push(self.getCurrentTargetInfo()),Promise.resolve(targets)},self.getCurrentTargetInfo=function(){var appName=null;return castPlayer.session&&castPlayer.session.receiver&&castPlayer.session.receiver.friendlyName&&(appName=castPlayer.session.receiver.friendlyName),{name:PlayerName,id:PlayerName,playerName:PlayerName,playableMediaTypes:["Audio","Video"],isLocalPlayer:!1,appName:PlayerName,deviceName:appName,supportedCommands:["VolumeUp","VolumeDown","Mute","Unmute","ToggleMute","SetVolume","SetAudioStreamIndex","SetSubtitleStreamIndex","DisplayContent","SetRepeatMode","EndSession"]}},self.seek=function(position){position=parseInt(position),position/=1e7,castPlayer.sendMessage({options:{position:position},command:"Seek"})},self.audioTracks=function(){var state=self.lastPlayerData||{};state=state.NowPlayingItem||{};var streams=state.MediaStreams||[];return streams.filter(function(s){return"Audio"===s.Type})},self.setAudioStreamIndex=function(index){castPlayer.sendMessage({options:{index:index},command:"SetAudioStreamIndex"})},self.getAudioStreamIndex=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.AudioStreamIndex},self.subtitleTracks=function(){var state=self.lastPlayerData||{};state=state.NowPlayingItem||{};var streams=state.MediaStreams||[];return streams.filter(function(s){return"Subtitle"===s.Type})},self.getSubtitleStreamIndex=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.SubtitleStreamIndex},self.setSubtitleStreamIndex=function(index){castPlayer.sendMessage({options:{index:index},command:"SetSubtitleStreamIndex"})},self.getMaxStreamingBitrate=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.MaxStreamingBitrate},self.setMaxStreamingBitrate=function(options){castPlayer.sendMessage({options:options,command:"SetMaxStreamingBitrate"})},self.isFullscreen=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.IsFullscreen},self.toggleFullscreen=function(){},self.nextTrack=function(){castPlayer.sendMessage({options:{},command:"NextTrack"})},self.previousTrack=function(){castPlayer.sendMessage({options:{},command:"PreviousTrack"})},self.beginPlayerUpdates=function(){},self.endPlayerUpdates=function(){},self.getVolume=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},null==state.VolumeLevel?100:state.VolumeLevel},self.volumeDown=function(){castPlayer.sendMessage({options:{},command:"VolumeDown"})},self.endSession=function(){self.stop().then(function(){setTimeout(function(){castPlayer.stopApp()},1e3)})},self.volumeUp=function(){castPlayer.sendMessage({options:{},command:"VolumeUp"})},self.setVolume=function(vol){vol=Math.min(vol,100),vol=Math.max(vol,0),castPlayer.sendMessage({options:{volume:vol},command:"SetVolume"})},self.getPlaylist=function(){return Promise.resolve([])},self.getCurrentPlaylistItemId=function(){},self.setCurrentPlaylistItem=function(playlistItemId){return Promise.resolve()},self.removeFromPlaylist=function(playlistItemIds){return Promise.resolve()},self.getPlayerState=function(){return Promise.resolve(self.getPlayerStateInternal()||{})},self.lastPlayerData={},self.getPlayerStateInternal=function(data){var triggerStateChange=!1;return data&&!self.lastPlayerData&&(triggerStateChange=!0),data=data||self.lastPlayerData,self.lastPlayerData=data,normalizeImages(data),triggerStateChange&&events.trigger(self,"statechange",[data]),data},self.tryPair=function(target){return castPlayer.deviceState!==DEVICE_STATE.ACTIVE&&castPlayer.isInitialized?new Promise(function(resolve,reject){currentResolve=resolve,currentReject=reject,castPlayer.launchApp()}):(currentResolve=null,currentReject=null,Promise.reject())},castSenderApiLoader.load().then(initializeChromecast)}var currentResolve,currentReject,PlayerName="Chromecast",DEVICE_STATE={IDLE:0,ACTIVE:1,WARNING:2,ERROR:3},PLAYER_STATE={IDLE:"IDLE",LOADING:"LOADING",LOADED:"LOADED",PLAYING:"PLAYING",PAUSED:"PAUSED",STOPPED:"STOPPED",SEEKING:"SEEKING",ERROR:"ERROR"},applicationID="2D4B1DA3",messageNamespace="urn:x-cast:com.connectsdk",CastPlayer=function(){this.deviceState=DEVICE_STATE.IDLE,this.currentMediaSession=null,this.session=null,this.castPlayerState=PLAYER_STATE.IDLE,this.hasReceivers=!1,this.errorHandler=this.onError.bind(this),this.mediaStatusUpdateHandler=this.onMediaStatusUpdate.bind(this),this.initializeCastPlayer()};return CastPlayer.prototype.initializeCastPlayer=function(){var chrome=window.chrome;if(chrome){if(!chrome.cast||!chrome.cast.isAvailable)return void setTimeout(this.initializeCastPlayer.bind(this),1e3);var sessionRequest=new chrome.cast.SessionRequest(applicationID),apiConfig=new chrome.cast.ApiConfig(sessionRequest,this.sessionListener.bind(this),this.receiverListener.bind(this),"origin_scoped");console.log("chromecast.initialize"),chrome.cast.initialize(apiConfig,this.onInitSuccess.bind(this),this.errorHandler)}},CastPlayer.prototype.onInitSuccess=function(){this.isInitialized=!0,console.log("chromecast init success")},CastPlayer.prototype.onError=function(){console.log("chromecast error")},CastPlayer.prototype.sessionListener=function(e){this.session=e,this.session&&(console.log("sessionListener "+JSON.stringify(e)),this.session.media[0]&&this.onMediaDiscovered("activeSession",this.session.media[0]),this.onSessionConnected(e))},CastPlayer.prototype.messageListener=function(namespace,message){if("string"==typeof message&&(message=JSON.parse(message)),"playbackerror"===message.type){var errorCode=message.data;setTimeout(function(){alertText(globalize.translate("MessagePlaybackError"+errorCode),globalize.translate("HeaderPlaybackError"))},300)}else"connectionerror"===message.type?setTimeout(function(){alertText(globalize.translate("MessageChromecastConnectionError"),globalize.translate("HeaderError"))},300):message.type&&events.trigger(this,message.type,[message.data])},CastPlayer.prototype.receiverListener=function(e){"available"===e?(console.log("chromecast receiver found"),this.hasReceivers=!0):(console.log("chromecast receiver list empty"),this.hasReceivers=!1)},CastPlayer.prototype.sessionUpdateListener=function(isAlive){console.log("sessionUpdateListener alive: "+isAlive),isAlive||(this.session=null,this.deviceState=DEVICE_STATE.IDLE,this.castPlayerState=PLAYER_STATE.IDLE,console.log("sessionUpdateListener: setting currentMediaSession to null"),this.currentMediaSession=null,sendConnectionResult(!1))},CastPlayer.prototype.launchApp=function(){console.log("chromecast launching app..."),chrome.cast.requestSession(this.onRequestSessionSuccess.bind(this),this.onLaunchError.bind(this))},CastPlayer.prototype.onRequestSessionSuccess=function(e){console.log("chromecast session success: "+e.sessionId),this.onSessionConnected(e)},CastPlayer.prototype.onSessionConnected=function(session){this.session=session,this.deviceState=DEVICE_STATE.ACTIVE,this.session.addMessageListener(messageNamespace,this.messageListener.bind(this)),this.session.addMediaListener(this.sessionMediaListener.bind(this)),this.session.addUpdateListener(this.sessionUpdateListener.bind(this)),events.trigger(this,"connect"),this.sendMessage({options:{},command:"Identify"})},CastPlayer.prototype.sessionMediaListener=function(e){console.log("sessionMediaListener"),this.currentMediaSession=e,this.currentMediaSession.addUpdateListener(this.mediaStatusUpdateHandler)},CastPlayer.prototype.onLaunchError=function(){console.log("chromecast launch error"),this.deviceState=DEVICE_STATE.ERROR,sendConnectionResult(!1)},CastPlayer.prototype.stopApp=function(){this.session&&this.session.stop(this.onStopAppSuccess.bind(this,"Session stopped"),this.errorHandler)},CastPlayer.prototype.onStopAppSuccess=function(message){console.log(message),this.deviceState=DEVICE_STATE.IDLE,this.castPlayerState=PLAYER_STATE.IDLE,console.log("onStopAppSuccess: setting currentMediaSession to null"),this.currentMediaSession=null},CastPlayer.prototype.loadMedia=function(options,command){return this.session?(options.items=options.items.map(function(i){return{Id:i.Id,ServerId:i.ServerId,Name:i.Name,Type:i.Type,MediaType:i.MediaType,IsFolder:i.IsFolder}}),this.sendMessage({options:options,command:command})):(console.log("no session"),Promise.reject())},CastPlayer.prototype.sendMessage=function(message){var player=this,receiverName=null,session=player.session;session&&session.receiver&&session.receiver.friendlyName&&(receiverName=session.receiver.friendlyName);var apiClient=ApiClient;message=Object.assign(message,{userId:apiClient.getCurrentUserId(),deviceId:apiClient.deviceId(),accessToken:apiClient.accessToken(),serverAddress:apiClient.serverAddress(),serverId:apiClient.serverId(),receiverName:receiverName});var bitrateSetting=appSettings.maxChromecastBitrate();return bitrateSetting&&(message.maxBitrate=bitrateSetting),new Promise(function(resolve,reject){require(["chromecasthelpers"],function(chromecasthelpers){chromecasthelpers.getServerAddress(apiClient).then(function(serverAddress){message.serverAddress=serverAddress,player.sendMessageInternal(message).then(resolve,reject)},reject)})})},CastPlayer.prototype.sendMessageInternal=function(message){return message=JSON.stringify(message),this.session.sendMessage(messageNamespace,message,this.onPlayCommandSuccess.bind(this),this.errorHandler),Promise.resolve()},CastPlayer.prototype.onPlayCommandSuccess=function(){console.log("Message was sent to receiver ok.")},CastPlayer.prototype.onMediaDiscovered=function(how,mediaSession){console.log("chromecast new media session ID:"+mediaSession.mediaSessionId+" ("+how+")"),this.currentMediaSession=mediaSession,"loadMedia"===how&&(this.castPlayerState=PLAYER_STATE.PLAYING),"activeSession"===how&&(this.castPlayerState=mediaSession.playerState),this.currentMediaSession.addUpdateListener(this.mediaStatusUpdateHandler)},CastPlayer.prototype.onMediaStatusUpdate=function(e){e===!1&&(this.castPlayerState=PLAYER_STATE.IDLE),console.log("chromecast updating media: "+e)},CastPlayer.prototype.setReceiverVolume=function(mute,vol){return this.currentMediaSession?void(mute?this.session.setReceiverMuted(!0,this.mediaCommandSuccessCallback.bind(this),this.errorHandler):this.session.setReceiverVolumeLevel(vol||1,this.mediaCommandSuccessCallback.bind(this),this.errorHandler)):void console.log("this.currentMediaSession is null")},CastPlayer.prototype.mute=function(){this.setReceiverVolume(!0)},CastPlayer.prototype.mediaCommandSuccessCallback=function(info,e){console.log(info)},chromecastPlayer}); \ No newline at end of file +define(["appSettings","playbackManager","connectionManager","globalize","events","castSenderApiLoader"],function(appSettings,playbackManager,connectionManager,globalize,events,castSenderApiLoader){"use strict";function sendConnectionResult(isOk){var resolve=currentResolve,reject=currentReject;currentResolve=null,currentReject=null,isOk?resolve&&resolve():reject?reject():playbackManager.removeActivePlayer(PlayerName)}function alertText(text,title){require(["alert"],function(alert){alert({text:text,title:title})})}function chromecastPlayer(){function initializeChromecast(){castPlayer=new CastPlayer,document.dispatchEvent(new CustomEvent("chromecastloaded",{detail:{player:self}})),events.on(castPlayer,"connect",function(e){currentResolve?sendConnectionResult(!0):playbackManager.setActivePlayer(PlayerName,self.getCurrentTargetInfo()),console.log("cc: connect"),self.lastPlayerData=null}),events.on(castPlayer,"playbackstart",function(e,data){console.log("cc: playbackstart"),castPlayer.initializeCastPlayer();var state=self.getPlayerStateInternal(data);events.trigger(self,"playbackstart",[state])}),events.on(castPlayer,"playbackstop",function(e,data){console.log("cc: playbackstop");var state=self.getPlayerStateInternal(data);events.trigger(self,"playbackstop",[state]),self.lastPlayerData={}}),events.on(castPlayer,"playbackprogress",function(e,data){console.log("cc: positionchange");var state=self.getPlayerStateInternal(data);events.trigger(self,"timeupdate",[state])}),events.on(castPlayer,"volumechange",function(e,data){console.log("cc: volumechange");var state=self.getPlayerStateInternal(data);events.trigger(self,"volumechange",[state])}),events.on(castPlayer,"repeatmodechange",function(e,data){console.log("cc: repeatmodechange");var state=self.getPlayerStateInternal(data);events.trigger(self,"repeatmodechange",[state])}),events.on(castPlayer,"playstatechange",function(e,data){console.log("cc: playstatechange");var state=self.getPlayerStateInternal(data);events.trigger(self,"pause",[state])})}function normalizeImages(state){if(state&&state.NowPlayingItem){var item=state.NowPlayingItem;item.ImageTags&&item.ImageTags.Primary||item.PrimaryImageTag&&(item.ImageTags=item.ImageTags||{},item.ImageTags.Primary=item.PrimaryImageTag),item.BackdropImageTag&&item.BackdropItemId===item.Id&&(item.BackdropImageTags=[item.BackdropImageTag]),item.BackdropImageTag&&item.BackdropItemId!==item.Id&&(item.ParentBackdropImageTags=[item.BackdropImageTag],item.ParentBackdropItemId=item.BackdropItemId)}}var castPlayer,self=this;self.name=PlayerName,self.type="mediaplayer",self.id="chromecast",self.isLocalPlayer=!1,self.getItemsForPlayback=function(query){var apiClient=ApiClient,userId=apiClient.getCurrentUserId();return query.Ids&&1===query.Ids.split(",").length?apiClient.getItem(userId,query.Ids.split(",")).then(function(item){return{Items:[item],TotalRecordCount:1}}):(query.Limit=query.Limit||100,query.ExcludeLocationTypes="Virtual",query.EnableTotalRecordCount=!1,apiClient.getItems(userId,query))},self.play=function(options){return options.items?self.playWithCommand(options,"PlayNow"):self.getItemsForPlayback({Ids:options.ids.join(",")}).then(function(result){return options.items=result.Items,self.playWithCommand(options,"PlayNow")})},self.playWithCommand=function(options,command){if(!options.items){var apiClient=connectionManager.getApiClient(options.serverId);return apiClient.getItem(apiClient.getCurrentUserId(),options.ids[0]).then(function(item){return options.items=[item],self.playWithCommand(options,command)})}return castPlayer.loadMedia(options,command)},self.unpause=function(){castPlayer.sendMessage({options:{},command:"Unpause"})},self.playPause=function(){castPlayer.sendMessage({options:{},command:"PlayPause"})},self.pause=function(){castPlayer.sendMessage({options:{},command:"Pause"})},self.shuffle=function(item){var apiClient=connectionManager.getApiClient(item.ServerId),userId=apiClient.getCurrentUserId();apiClient.getItem(userId,item.Id).then(function(item){self.playWithCommand({items:[item]},"Shuffle")})},self.instantMix=function(item){var apiClient=connectionManager.getApiClient(item.ServerId),userId=apiClient.getCurrentUserId();apiClient.getItem(userId,item.Id).then(function(item){self.playWithCommand({items:[item]},"InstantMix")})},self.canPlayMediaType=function(mediaType){return mediaType=(mediaType||"").toLowerCase(),"audio"===mediaType||"video"===mediaType},self.canQueueMediaType=function(mediaType){return self.canPlayMediaType(mediaType)},self.queue=function(options){self.playWithCommand(options,"PlayLast")},self.queueNext=function(options){self.playWithCommand(options,"PlayNext")},self.stop=function(){return castPlayer.sendMessage({options:{},command:"Stop"})},self.displayContent=function(options){castPlayer.sendMessage({options:options,command:"DisplayContent"})},self.isPlaying=function(){var state=self.lastPlayerData||{};return null!=state.NowPlayingItem},self.isPlayingVideo=function(){var state=self.lastPlayerData||{};return state=state.NowPlayingItem||{},"Video"===state.MediaType},self.isPlayingAudio=function(){var state=self.lastPlayerData||{};return state=state.NowPlayingItem||{},"Audio"===state.MediaType},self.currentTime=function(val){if(null!=val)return self.seek(val);var state=self.lastPlayerData||{};return state=state.PlayState||{},state.PositionTicks},self.duration=function(){var state=self.lastPlayerData||{};return state=state.NowPlayingItem||{},state.RunTimeTicks},self.paused=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.IsPaused},self.isMuted=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.IsMuted},self.setMute=function(isMuted){isMuted?castPlayer.sendMessage({options:{},command:"Mute"}):castPlayer.sendMessage({options:{},command:"Unmute"})},self.getRepeatMode=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.RepeatMode},self.setRepeatMode=function(mode){castPlayer.sendMessage({options:{RepeatMode:mode},command:"SetRepeatMode"})},self.toggleMute=function(){castPlayer.sendMessage({options:{},command:"ToggleMute"})},self.getTargets=function(){var targets=[];return castPlayer.hasReceivers&&targets.push(self.getCurrentTargetInfo()),Promise.resolve(targets)},self.getCurrentTargetInfo=function(){var appName=null;return castPlayer.session&&castPlayer.session.receiver&&castPlayer.session.receiver.friendlyName&&(appName=castPlayer.session.receiver.friendlyName),{name:PlayerName,id:PlayerName,playerName:PlayerName,playableMediaTypes:["Audio","Video"],isLocalPlayer:!1,appName:PlayerName,deviceName:appName,supportedCommands:["VolumeUp","VolumeDown","Mute","Unmute","ToggleMute","SetVolume","SetAudioStreamIndex","SetSubtitleStreamIndex","DisplayContent","SetRepeatMode","EndSession"]}},self.seek=function(position){position=parseInt(position),position/=1e7,castPlayer.sendMessage({options:{position:position},command:"Seek"})},self.audioTracks=function(){var state=self.lastPlayerData||{};state=state.NowPlayingItem||{};var streams=state.MediaStreams||[];return streams.filter(function(s){return"Audio"===s.Type})},self.setAudioStreamIndex=function(index){castPlayer.sendMessage({options:{index:index},command:"SetAudioStreamIndex"})},self.getAudioStreamIndex=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.AudioStreamIndex},self.subtitleTracks=function(){var state=self.lastPlayerData||{};state=state.NowPlayingItem||{};var streams=state.MediaStreams||[];return streams.filter(function(s){return"Subtitle"===s.Type})},self.getSubtitleStreamIndex=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.SubtitleStreamIndex},self.setSubtitleStreamIndex=function(index){castPlayer.sendMessage({options:{index:index},command:"SetSubtitleStreamIndex"})},self.getMaxStreamingBitrate=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.MaxStreamingBitrate},self.setMaxStreamingBitrate=function(options){castPlayer.sendMessage({options:options,command:"SetMaxStreamingBitrate"})},self.isFullscreen=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},state.IsFullscreen},self.toggleFullscreen=function(){},self.nextTrack=function(){castPlayer.sendMessage({options:{},command:"NextTrack"})},self.previousTrack=function(){castPlayer.sendMessage({options:{},command:"PreviousTrack"})},self.beginPlayerUpdates=function(){},self.endPlayerUpdates=function(){},self.getVolume=function(){var state=self.lastPlayerData||{};return state=state.PlayState||{},null==state.VolumeLevel?100:state.VolumeLevel},self.volumeDown=function(){castPlayer.sendMessage({options:{},command:"VolumeDown"})},self.endSession=function(){self.stop().then(function(){setTimeout(function(){castPlayer.stopApp()},1e3)})},self.volumeUp=function(){castPlayer.sendMessage({options:{},command:"VolumeUp"})},self.setVolume=function(vol){vol=Math.min(vol,100),vol=Math.max(vol,0),castPlayer.sendMessage({options:{volume:vol},command:"SetVolume"})},self.getPlaylist=function(){return Promise.resolve([])},self.getCurrentPlaylistItemId=function(){},self.setCurrentPlaylistItem=function(playlistItemId){return Promise.resolve()},self.removeFromPlaylist=function(playlistItemIds){return Promise.resolve()},self.getPlayerState=function(){return Promise.resolve(self.getPlayerStateInternal()||{})},self.lastPlayerData={},self.getPlayerStateInternal=function(data){var triggerStateChange=!1;return data&&!self.lastPlayerData&&(triggerStateChange=!0),data=data||self.lastPlayerData,self.lastPlayerData=data,normalizeImages(data),triggerStateChange&&events.trigger(self,"statechange",[data]),data},self.tryPair=function(target){return castPlayer.deviceState!==DEVICE_STATE.ACTIVE&&castPlayer.isInitialized?new Promise(function(resolve,reject){currentResolve=resolve,currentReject=reject,castPlayer.launchApp()}):(currentResolve=null,currentReject=null,Promise.reject())},castSenderApiLoader.load().then(initializeChromecast)}var currentResolve,currentReject,PlayerName="Chromecast",DEVICE_STATE={IDLE:0,ACTIVE:1,WARNING:2,ERROR:3},PLAYER_STATE={IDLE:"IDLE",LOADING:"LOADING",LOADED:"LOADED",PLAYING:"PLAYING",PAUSED:"PAUSED",STOPPED:"STOPPED",SEEKING:"SEEKING",ERROR:"ERROR"},applicationID="2D4B1DA3",messageNamespace="urn:x-cast:com.connectsdk",CastPlayer=function(){this.deviceState=DEVICE_STATE.IDLE,this.currentMediaSession=null,this.session=null,this.castPlayerState=PLAYER_STATE.IDLE,this.hasReceivers=!1,this.errorHandler=this.onError.bind(this),this.mediaStatusUpdateHandler=this.onMediaStatusUpdate.bind(this),this.initializeCastPlayer()};return CastPlayer.prototype.initializeCastPlayer=function(){var chrome=window.chrome;if(chrome){if(!chrome.cast||!chrome.cast.isAvailable)return void setTimeout(this.initializeCastPlayer.bind(this),1e3);var sessionRequest=new chrome.cast.SessionRequest(applicationID),apiConfig=new chrome.cast.ApiConfig(sessionRequest,this.sessionListener.bind(this),this.receiverListener.bind(this),"origin_scoped");console.log("chromecast.initialize"),chrome.cast.initialize(apiConfig,this.onInitSuccess.bind(this),this.errorHandler)}},CastPlayer.prototype.onInitSuccess=function(){this.isInitialized=!0,console.log("chromecast init success")},CastPlayer.prototype.onError=function(){console.log("chromecast error")},CastPlayer.prototype.sessionListener=function(e){this.session=e,this.session&&(console.log("sessionListener "+JSON.stringify(e)),this.session.media[0]&&this.onMediaDiscovered("activeSession",this.session.media[0]),this.onSessionConnected(e))},CastPlayer.prototype.messageListener=function(namespace,message){if("string"==typeof message&&(message=JSON.parse(message)),"playbackerror"===message.type){var errorCode=message.data;setTimeout(function(){alertText(globalize.translate("MessagePlaybackError"+errorCode),globalize.translate("HeaderPlaybackError"))},300)}else"connectionerror"===message.type?setTimeout(function(){alertText(globalize.translate("MessageChromecastConnectionError"),globalize.translate("HeaderError"))},300):message.type&&events.trigger(this,message.type,[message.data])},CastPlayer.prototype.receiverListener=function(e){"available"===e?(console.log("chromecast receiver found"),this.hasReceivers=!0):(console.log("chromecast receiver list empty"),this.hasReceivers=!1)},CastPlayer.prototype.sessionUpdateListener=function(isAlive){console.log("sessionUpdateListener alive: "+isAlive),isAlive||(this.session=null,this.deviceState=DEVICE_STATE.IDLE,this.castPlayerState=PLAYER_STATE.IDLE,console.log("sessionUpdateListener: setting currentMediaSession to null"),this.currentMediaSession=null,sendConnectionResult(!1))},CastPlayer.prototype.launchApp=function(){console.log("chromecast launching app..."),chrome.cast.requestSession(this.onRequestSessionSuccess.bind(this),this.onLaunchError.bind(this))},CastPlayer.prototype.onRequestSessionSuccess=function(e){console.log("chromecast session success: "+e.sessionId),this.onSessionConnected(e)},CastPlayer.prototype.onSessionConnected=function(session){this.session=session,this.deviceState=DEVICE_STATE.ACTIVE,this.session.addMessageListener(messageNamespace,this.messageListener.bind(this)),this.session.addMediaListener(this.sessionMediaListener.bind(this)),this.session.addUpdateListener(this.sessionUpdateListener.bind(this)),events.trigger(this,"connect"),this.sendMessage({options:{},command:"Identify"})},CastPlayer.prototype.sessionMediaListener=function(e){console.log("sessionMediaListener"),this.currentMediaSession=e,this.currentMediaSession.addUpdateListener(this.mediaStatusUpdateHandler)},CastPlayer.prototype.onLaunchError=function(){console.log("chromecast launch error"),this.deviceState=DEVICE_STATE.ERROR,sendConnectionResult(!1)},CastPlayer.prototype.stopApp=function(){this.session&&this.session.stop(this.onStopAppSuccess.bind(this,"Session stopped"),this.errorHandler)},CastPlayer.prototype.onStopAppSuccess=function(message){console.log(message),this.deviceState=DEVICE_STATE.IDLE,this.castPlayerState=PLAYER_STATE.IDLE,console.log("onStopAppSuccess: setting currentMediaSession to null"),this.currentMediaSession=null},CastPlayer.prototype.loadMedia=function(options,command){return this.session?(options.items=options.items.map(function(i){return{Id:i.Id,ServerId:i.ServerId,Name:i.Name,Type:i.Type,MediaType:i.MediaType,IsFolder:i.IsFolder}}),this.sendMessage({options:options,command:command})):(console.log("no session"),Promise.reject())},CastPlayer.prototype.sendMessage=function(message){var player=this,receiverName=null,session=player.session;session&&session.receiver&&session.receiver.friendlyName&&(receiverName=session.receiver.friendlyName);var apiClient=ApiClient;message=Object.assign(message,{userId:apiClient.getCurrentUserId(),deviceId:apiClient.deviceId(),accessToken:apiClient.accessToken(),serverAddress:apiClient.serverAddress(),serverId:apiClient.serverId(),receiverName:receiverName});var bitrateSetting=appSettings.maxChromecastBitrate();return bitrateSetting&&(message.maxBitrate=bitrateSetting),new Promise(function(resolve,reject){require(["chromecasthelpers"],function(chromecasthelpers){chromecasthelpers.getServerAddress(apiClient).then(function(serverAddress){message.serverAddress=serverAddress,player.sendMessageInternal(message).then(resolve,reject)},reject)})})},CastPlayer.prototype.sendMessageInternal=function(message){return message=JSON.stringify(message),this.session.sendMessage(messageNamespace,message,this.onPlayCommandSuccess.bind(this),this.errorHandler),Promise.resolve()},CastPlayer.prototype.onPlayCommandSuccess=function(){console.log("Message was sent to receiver ok.")},CastPlayer.prototype.onMediaDiscovered=function(how,mediaSession){console.log("chromecast new media session ID:"+mediaSession.mediaSessionId+" ("+how+")"),this.currentMediaSession=mediaSession,"loadMedia"===how&&(this.castPlayerState=PLAYER_STATE.PLAYING),"activeSession"===how&&(this.castPlayerState=mediaSession.playerState),this.currentMediaSession.addUpdateListener(this.mediaStatusUpdateHandler)},CastPlayer.prototype.onMediaStatusUpdate=function(e){e===!1&&(this.castPlayerState=PLAYER_STATE.IDLE),console.log("chromecast updating media: "+e)},CastPlayer.prototype.setReceiverVolume=function(mute,vol){return this.currentMediaSession?void(mute?this.session.setReceiverMuted(!0,this.mediaCommandSuccessCallback.bind(this),this.errorHandler):this.session.setReceiverVolumeLevel(vol||1,this.mediaCommandSuccessCallback.bind(this),this.errorHandler)):void console.log("this.currentMediaSession is null")},CastPlayer.prototype.mute=function(){this.setReceiverVolume(!0)},CastPlayer.prototype.mediaCommandSuccessCallback=function(info,e){console.log(info)},chromecastPlayer}); \ No newline at end of file diff --git a/dashboard-ui/bower_components/emby-webcomponents/collectioneditor/collectioneditor.js b/dashboard-ui/bower_components/emby-webcomponents/collectioneditor/collectioneditor.js index c69d963d35..5c9f66618a 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/collectioneditor/collectioneditor.js +++ b/dashboard-ui/bower_components/emby-webcomponents/collectioneditor/collectioneditor.js @@ -1 +1 @@ -define(["dialogHelper","loading","layoutManager","connectionManager","embyRouter","globalize","emby-checkbox","emby-input","paper-icon-button-light","emby-select","material-icons","css!./../formdialog","emby-button","emby-linkbutton"],function(dialogHelper,loading,layoutManager,connectionManager,embyRouter,globalize){"use strict";function parentWithClass(elem,className){for(;!elem.classList||!elem.classList.contains(className);)if(elem=elem.parentNode,!elem)return null;return elem}function onSubmit(e){loading.show();var panel=parentWithClass(this,"dialog"),collectionId=panel.querySelector("#selectCollectionToAddTo").value,apiClient=connectionManager.getApiClient(currentServerId);return collectionId?addToCollection(apiClient,panel,collectionId):createCollection(apiClient,panel),e.preventDefault(),!1}function createCollection(apiClient,dlg){var url=apiClient.getUrl("Collections",{Name:dlg.querySelector("#txtNewCollectionName").value,IsLocked:!dlg.querySelector("#chkEnableInternetMetadata").checked,Ids:dlg.querySelector(".fldSelectedItemIds").value||""});apiClient.ajax({type:"POST",url:url,dataType:"json"}).then(function(result){loading.hide();var id=result.Id;dlg.submitted=!0,dialogHelper.close(dlg),redirectToCollection(apiClient,id)})}function redirectToCollection(apiClient,id){apiClient.getItem(apiClient.getCurrentUserId(),id).then(function(item){embyRouter.showItem(item)})}function addToCollection(apiClient,dlg,id){var url=apiClient.getUrl("Collections/"+id+"/Items",{Ids:dlg.querySelector(".fldSelectedItemIds").value||""});apiClient.ajax({type:"POST",url:url}).then(function(){loading.hide(),dlg.submitted=!0,dialogHelper.close(dlg),require(["toast"],function(toast){toast(globalize.translate("sharedcomponents#MessageItemsAdded"))})})}function triggerChange(select){select.dispatchEvent(new CustomEvent("change",{}))}function populateCollections(panel){loading.show();var select=panel.querySelector("#selectCollectionToAddTo");panel.querySelector(".newCollectionInfo").classList.add("hide");var options={Recursive:!0,IncludeItemTypes:"BoxSet",SortBy:"SortName"},apiClient=connectionManager.getApiClient(currentServerId);apiClient.getItems(apiClient.getCurrentUserId(),options).then(function(result){var html="";html+='",html+=result.Items.map(function(i){return'"}),select.innerHTML=html,select.value="",triggerChange(select),loading.hide()})}function getEditorHtml(){var html="";return html+='
"+globalize.translate("sharedcomponents#HeaderEnabledFieldsHelp")+"
",html+=generateSliders(metadatafields,lockedFields),container.innerHTML=html}function reload(context,itemId,serverId){loading.show(),Promise.all([getItem(itemId,serverId),getEditorConfig(itemId,serverId)]).then(function(responses){var item=responses[0];metadataEditorInfo=responses[1],currentItem=item;var languages=metadataEditorInfo.Cultures,countries=metadataEditorInfo.Countries;renderContentTypeOptions(context,metadataEditorInfo),loadExternalIds(context,item,metadataEditorInfo.ExternalIdInfos),populateLanguages(context.querySelector("#selectLanguage"),languages),populateCountries(context.querySelector("#selectCountry"),countries),setFieldVisibilities(context,item),fillItemInfo(context,item,metadataEditorInfo.ParentalRatingOptions),"Video"===item.MediaType&&"Episode"!==item.Type?showElement("#fldTagline",context):hideElement("#fldTagline",context),loading.hide()})}function centerFocus(elem,horiz,on){require(["scrollHelper"],function(scrollHelper){var fn=on?"on":"off";scrollHelper.centerFocus[fn](elem,horiz)})}function show(itemId,serverId,resolve,reject){loading.show(),require(["text!./metadataeditor.template.html"],function(template){var dialogOptions={removeOnClose:!0,scrollY:!1};layoutManager.tv?dialogOptions.size="fullscreen":dialogOptions.size="medium-tall";var dlg=dialogHelper.createDialog(dialogOptions);dlg.classList.add("formDialog");var html="";html+=globalize.translateDocument(template,"sharedcomponents"),dlg.innerHTML=html,layoutManager.tv&¢erFocus(dlg.querySelector(".formDialogContent"),!1,!0),dialogHelper.open(dlg),dlg.addEventListener("close",function(){layoutManager.tv&¢erFocus(dlg.querySelector(".formDialogContent"),!1,!1),unbindItemChanged(dlg,connectionManager.getApiClient(serverId)),resolve()}),currentContext=dlg,init(dlg,connectionManager.getApiClient(serverId)),reload(dlg,itemId,serverId)})}var currentContext,metadataEditorInfo,currentItem;return{show:function(itemId,serverId){return new Promise(function(resolve,reject){return show(itemId,serverId,resolve,reject)})},embed:function(elem,itemId,serverId){return new Promise(function(resolve,reject){loading.show(),require(["text!./metadataeditor.template.html"],function(template){elem.innerHTML=globalize.translateDocument(template,"sharedcomponents"),elem.querySelector(".formDialogFooter").classList.remove("formDialogFooter"),elem.querySelector(".btnHeaderSave").classList.remove("hide"),elem.querySelector(".btnCancel").classList.add("hide"),currentContext=elem,init(elem,connectionManager.getApiClient(serverId)),reload(elem,itemId,serverId),focusManager.autoFocus(elem)})})}}}); \ No newline at end of file +define(["itemHelper","dom","layoutManager","dialogHelper","datetime","loading","focusManager","connectionManager","globalize","require","shell","emby-checkbox","emby-input","emby-select","listViewStyle","emby-textarea","emby-button","paper-icon-button-light","css!./../formdialog"],function(itemHelper,dom,layoutManager,dialogHelper,datetime,loading,focusManager,connectionManager,globalize,require,shell){"use strict";function isDialog(){return currentContext.classList.contains("dialog")}function closeDialog(isSubmitted){isDialog()&&dialogHelper.close(currentContext)}function submitUpdatedItem(form,item){function afterContentTypeUpdated(){require(["toast"],function(toast){toast(globalize.translate("sharedcomponents#MessageItemSaved"))}),loading.hide(),closeDialog(!0)}var apiClient=getApiClient();apiClient.updateItem(item).then(function(){var newContentType=form.querySelector("#selectContentType").value||"";(metadataEditorInfo.ContentType||"")!==newContentType?apiClient.ajax({url:apiClient.getUrl("Items/"+item.Id+"/ContentType",{ContentType:newContentType}),type:"POST"}).then(function(){afterContentTypeUpdated()}):afterContentTypeUpdated()})}function getSelectedAirDays(form){var checkedItems=form.querySelectorAll(".chkAirDay:checked")||[];return Array.prototype.map.call(checkedItems,function(c){return c.getAttribute("data-day")})}function getAlbumArtists(form){return form.querySelector("#txtAlbumArtist").value.trim().split(";").filter(function(s){return s.length>0}).map(function(a){return{Name:a}})}function getArtists(form){return form.querySelector("#txtArtist").value.trim().split(";").filter(function(s){return s.length>0}).map(function(a){return{Name:a}})}function getDateFromForm(form,element,property){var val=form.querySelector(element).value;if(!val)return null;if(currentItem[property]){var date=datetime.parseISO8601Date(currentItem[property],!0),parts=date.toISOString().split("T");if(0===parts[0].indexOf(val)){var iso=parts[1];val+="T"+iso}}return val}function onSubmit(e){loading.show();var form=this;try{var item={Id:currentItem.Id,Name:form.querySelector("#txtName").value,OriginalTitle:form.querySelector("#txtOriginalName").value,ForcedSortName:form.querySelector("#txtSortName").value,DisplayMediaType:form.querySelector("#txtDisplayMediaType").value,CommunityRating:form.querySelector("#txtCommunityRating").value,VoteCount:form.querySelector("#txtCommunityVoteCount").value,HomePageUrl:form.querySelector("#txtHomePageUrl").value,CriticRating:form.querySelector("#txtCriticRating").value,IndexNumber:form.querySelector("#txtIndexNumber").value||null,AbsoluteEpisodeNumber:form.querySelector("#txtAbsoluteEpisodeNumber").value,DvdEpisodeNumber:form.querySelector("#txtDvdEpisodeNumber").value,DvdSeasonNumber:form.querySelector("#txtDvdSeasonNumber").value,AirsBeforeSeasonNumber:form.querySelector("#txtAirsBeforeSeason").value,AirsAfterSeasonNumber:form.querySelector("#txtAirsAfterSeason").value,AirsBeforeEpisodeNumber:form.querySelector("#txtAirsBeforeEpisode").value,ParentIndexNumber:form.querySelector("#txtParentIndexNumber").value||null,DisplayOrder:form.querySelector("#selectDisplayOrder").value,Players:form.querySelector("#txtPlayers").value,Album:form.querySelector("#txtAlbum").value,AlbumArtists:getAlbumArtists(form),ArtistItems:getArtists(form),Overview:form.querySelector("#txtOverview").value,Status:form.querySelector("#selectStatus").value,AirDays:getSelectedAirDays(form),AirTime:form.querySelector("#txtAirTime").value,Genres:editableListViewValues(form.querySelector("#listGenres")),Tags:editableListViewValues(form.querySelector("#listTags")),Keywords:editableListViewValues(form.querySelector("#listKeywords")),Studios:editableListViewValues(form.querySelector("#listStudios")).map(function(element){return{Name:element}}),PremiereDate:getDateFromForm(form,"#txtPremiereDate","PremiereDate"),DateCreated:getDateFromForm(form,"#txtDateAdded","DateCreated"),EndDate:getDateFromForm(form,"#txtEndDate","EndDate"),ProductionYear:form.querySelector("#txtProductionYear").value,AspectRatio:form.querySelector("#txtOriginalAspectRatio").value,Video3DFormat:form.querySelector("#select3dFormat").value,OfficialRating:form.querySelector("#selectOfficialRating").value,CustomRating:form.querySelector("#selectCustomRating").value,People:currentItem.People,LockData:form.querySelector("#chkLockData").checked,LockedFields:Array.prototype.filter.call(form.querySelectorAll(".selectLockedField"),function(c){return!c.checked}).map(function(c){return c.getAttribute("data-value")})};item.ProviderIds=Object.assign({},currentItem.ProviderIds);var idElements=form.querySelectorAll(".txtExternalId");if(Array.prototype.map.call(idElements,function(idElem){var providerKey=idElem.getAttribute("data-providerkey");item.ProviderIds[providerKey]=idElem.value}),item.PreferredMetadataLanguage=form.querySelector("#selectLanguage").value,item.PreferredMetadataCountryCode=form.querySelector("#selectCountry").value,"Person"===currentItem.Type){var placeOfBirth=form.querySelector("#txtPlaceOfBirth").value;item.ProductionLocations=placeOfBirth?[placeOfBirth]:[]}if("Series"===currentItem.Type){var seriesRuntime=form.querySelector("#txtSeriesRuntime").value;item.RunTimeTicks=seriesRuntime?6e8*seriesRuntime:null}var tagline=form.querySelector("#txtTagline").value;item.Taglines=tagline?[tagline]:[],submitUpdatedItem(form,item)}catch(err){alert(err)}return e.preventDefault(),e.stopPropagation(),!1}function editableListViewValues(list){return Array.prototype.map.call(list.querySelectorAll(".textValue"),function(el){return el.textContent})}function addElementToEditableListview(source,sortCallback){require(["prompt"],function(prompt){prompt({label:"Value:"}).then(function(text){var list=dom.parentWithClass(source,"editableListviewContainer").querySelector(".paperList"),items=editableListViewValues(list);items.push(text),populateListView(list,items,sortCallback)})})}function removeElementFromListview(source){var el=dom.parentWithClass(source,"listItem");el.parentNode.removeChild(el)}function editPerson(context,person,index){require(["personEditor"],function(personEditor){personEditor.show(person).then(function(updatedPerson){var isNew=index===-1;isNew&¤tItem.People.push(updatedPerson),populatePeople(context,currentItem.People)})})}function showMoreMenu(context,button,user){require(["itemContextMenu"],function(itemContextMenu){var item=currentItem;itemContextMenu.show({item:item,positionTo:button,edit:!1,editImages:!0,editSubtitles:!0,sync:!1,share:!1,play:!1,queue:!1,user:user}).then(function(result){result.deleted?afterDeleted(context,item):result.updated&&reload(context,item.Id,item.ServerId)})})}function afterDeleted(context,item){var parentId=item.ParentId||item.SeasonId||item.SeriesId;parentId?reload(context,parentId,item.ServerId):require(["embyRouter"],function(embyRouter){embyRouter.goHome()})}function onWebSocketMessageReceived(e,data){var msg=data;"LibraryChanged"===msg.MessageType&&msg.Data.ItemsUpdated.indexOf(currentItem.Id)!==-1&&(console.log("Item updated - reloading metadata"),reload(currentContext,currentItem.Id,currentItem.ServerId))}function bindItemChanged(context,apiClient){Events.on(apiClient,"websocketmessage",onWebSocketMessageReceived)}function unbindItemChanged(context,apiClient){Events.off(apiClient,"websocketmessage",onWebSocketMessageReceived)}function onEditorClick(e){var btnRemoveFromEditorList=dom.parentWithClass(e.target,"btnRemoveFromEditorList");if(btnRemoveFromEditorList)return void removeElementFromListview(btnRemoveFromEditorList);var btnAddTextItem=dom.parentWithClass(e.target,"btnAddTextItem");btnAddTextItem&&addElementToEditableListview(btnAddTextItem)}function getApiClient(){return connectionManager.getApiClient(currentItem.ServerId)}function init(context,apiClient){context.querySelector(".externalIds").addEventListener("click",function(e){var btnOpenExternalId=dom.parentWithClass(e.target,"btnOpenExternalId");if(btnOpenExternalId){var field=context.querySelector("#"+btnOpenExternalId.getAttribute("data-fieldid")),formatString=field.getAttribute("data-formatstring");field.value&&shell.openUrl(formatString.replace("{0}",field.value))}}),context.querySelector(".btnCancel").addEventListener("click",function(){closeDialog(!1)}),context.querySelector(".btnMore").addEventListener("click",function(e){getApiClient().getCurrentUser().then(function(user){showMoreMenu(context,e.target,user)})}),context.querySelector(".btnHeaderSave").addEventListener("click",function(e){context.querySelector(".btnSave").click()}),context.querySelector("#chkLockData").addEventListener("click",function(e){e.target.checked?hideElement(".providerSettingsContainer"):showElement(".providerSettingsContainer")}),context.removeEventListener("click",onEditorClick),context.addEventListener("click",onEditorClick);var form=context.querySelector("form");form.removeEventListener("submit",onSubmit),form.addEventListener("submit",onSubmit),context.querySelector("#btnAddPerson").addEventListener("click",function(event,data){editPerson(context,{},-1)}),context.querySelector("#peopleList").addEventListener("click",function(e){var index,btnDeletePerson=dom.parentWithClass(e.target,"btnDeletePerson");btnDeletePerson&&(index=parseInt(btnDeletePerson.getAttribute("data-index")),currentItem.People.splice(index,1),populatePeople(context,currentItem.People));var btnEditPerson=dom.parentWithClass(e.target,"btnEditPerson");btnEditPerson&&(index=parseInt(btnEditPerson.getAttribute("data-index")),editPerson(context,currentItem.People[index],index))}),isDialog()&&bindItemChanged(context,apiClient)}function getItem(itemId,serverId){var apiClient=connectionManager.getApiClient(serverId);return itemId?apiClient.getItem(apiClient.getCurrentUserId(),itemId):apiClient.getRootFolder(apiClient.getCurrentUserId())}function getEditorConfig(itemId,serverId){var apiClient=connectionManager.getApiClient(serverId);return itemId?apiClient.getJSON(apiClient.getUrl("Items/"+itemId+"/MetadataEditor")):Promise.resolve({})}function populateCountries(select,allCountries){var html="";html+="";for(var i=0,length=allCountries.length;i"+globalize.translate("sharedcomponents#HeaderEnabledFieldsHelp")+"
",html+=generateSliders(metadatafields,lockedFields),container.innerHTML=html}function reload(context,itemId,serverId){loading.show(),Promise.all([getItem(itemId,serverId),getEditorConfig(itemId,serverId)]).then(function(responses){var item=responses[0];metadataEditorInfo=responses[1],currentItem=item;var languages=metadataEditorInfo.Cultures,countries=metadataEditorInfo.Countries;renderContentTypeOptions(context,metadataEditorInfo),loadExternalIds(context,item,metadataEditorInfo.ExternalIdInfos),populateLanguages(context.querySelector("#selectLanguage"),languages),populateCountries(context.querySelector("#selectCountry"),countries),setFieldVisibilities(context,item),fillItemInfo(context,item,metadataEditorInfo.ParentalRatingOptions),"Video"===item.MediaType&&"Episode"!==item.Type?showElement("#fldTagline",context):hideElement("#fldTagline",context),loading.hide()})}function centerFocus(elem,horiz,on){require(["scrollHelper"],function(scrollHelper){var fn=on?"on":"off";scrollHelper.centerFocus[fn](elem,horiz)})}function show(itemId,serverId,resolve,reject){loading.show(),require(["text!./metadataeditor.template.html"],function(template){var dialogOptions={removeOnClose:!0,scrollY:!1};layoutManager.tv?dialogOptions.size="fullscreen":dialogOptions.size="medium-tall";var dlg=dialogHelper.createDialog(dialogOptions);dlg.classList.add("formDialog");var html="";html+=globalize.translateDocument(template,"sharedcomponents"),dlg.innerHTML=html,layoutManager.tv&¢erFocus(dlg.querySelector(".formDialogContent"),!1,!0),dialogHelper.open(dlg),dlg.addEventListener("close",function(){layoutManager.tv&¢erFocus(dlg.querySelector(".formDialogContent"),!1,!1),unbindItemChanged(dlg,connectionManager.getApiClient(serverId)),resolve()}),currentContext=dlg,init(dlg,connectionManager.getApiClient(serverId)),reload(dlg,itemId,serverId)})}var currentContext,metadataEditorInfo,currentItem;return{show:function(itemId,serverId){return new Promise(function(resolve,reject){return show(itemId,serverId,resolve,reject)})},embed:function(elem,itemId,serverId){return new Promise(function(resolve,reject){loading.show(),require(["text!./metadataeditor.template.html"],function(template){elem.innerHTML=globalize.translateDocument(template,"sharedcomponents"),elem.querySelector(".formDialogFooter").classList.remove("formDialogFooter"),elem.querySelector(".btnHeaderSave").classList.remove("hide"),elem.querySelector(".btnCancel").classList.add("hide"),currentContext=elem,init(elem,connectionManager.getApiClient(serverId)),reload(elem,itemId,serverId),focusManager.autoFocus(elem)})})}}}); \ No newline at end of file diff --git a/dashboard-ui/bower_components/emby-webcomponents/metadataeditor/metadataeditor.template.html b/dashboard-ui/bower_components/emby-webcomponents/metadataeditor/metadataeditor.template.html index fe0982276e..4e480c6d70 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/metadataeditor/metadataeditor.template.html +++ b/dashboard-ui/bower_components/emby-webcomponents/metadataeditor/metadataeditor.template.html @@ -68,9 +68,6 @@