jellyfin-web/dashboard-ui/scripts/editorsidebar.js

1 line
7.5 KiB
JavaScript
Raw Normal View History

2017-01-27 21:23:06 -07:00
define(["datetime","jQuery","material-icons"],function(datetime,$){"use strict";function getNode(item,folderState,selected){var htmlName=getNodeInnerHtml(item),node={id:item.Id,text:htmlName,state:{opened:item.IsFolder&&"open"==folderState,selected:selected},li_attr:{serveritemtype:item.Type,collectiontype:item.CollectionType}};return item.IsFolder?(node.children=[{text:"Loading...",icon:!1}],node.icon=!1):node.icon=!1,node.state.opened&&(node.li_attr.loadedFromServer=!0),selected&&(selectedNodeId=item.Id),node}function getNodeInnerHtml(item){var name=item.Name;item.Number&&(name=item.Number+" - "+name),null!=item.IndexNumber&&"Season"!=item.Type&&(name=item.IndexNumber+" - "+name);var cssClass="editorNode";"Offline"==item.LocationType&&(cssClass+=" offlineEditorNode");var htmlName="<div class='"+cssClass+"'>";if(item.LockData&&(htmlName+='<i class="md-icon">lock</i>'),htmlName+=name,item.ImageTags&&item.ImageTags.Primary||(htmlName+='<img src="css/images/editor/missingprimaryimage.png" title="'+Globalize.translate("MissingPrimaryImage")+'" />'),item.BackdropImageTags&&item.BackdropImageTags.length||"Episode"!==item.Type&&"Season"!==item.Type&&"Audio"!==item.MediaType&&"TvChannel"!==item.Type&&"MusicAlbum"!==item.Type&&(htmlName+='<img src="css/images/editor/missingbackdrop.png" title="'+Globalize.translate("MissingBackdropImage")+'" />'),item.ImageTags&&item.ImageTags.Logo||"Movie"!=item.Type&&"Trailer"!=item.Type&&"Series"!=item.Type&&"MusicArtist"!=item.Type&&"BoxSet"!=item.Type||(htmlName+='<img src="css/images/editor/missinglogo.png" title="'+Globalize.translate("MissingLogoImage")+'" />'),"Episode"==item.Type&&"Virtual"==item.LocationType)try{item.PremiereDate&&(new Date).getTime()>=datetime.parseISO8601Date(item.PremiereDate,!0).getTime()&&(htmlName+='<img src="css/images/editor/missing.png" title="'+Globalize.translate("MissingEpisode")+'" />')}catch(err){}return htmlName+="</div>"}function loadChildrenOfRootNode(page,scope,callback){ApiClient.getLiveTvChannels({limit:0}).then(function(result){var nodes=[];nodes.push({id:"MediaFolders",text:Globalize.translate("HeaderMediaFolders"),state:{opened:!0},li_attr:{itemtype:"mediafolders",loadedFromServer:!0},icon:!1}),result.TotalRecordCount&&nodes.push({id:"livetv",text:Globalize.translate("HeaderLiveTV"),state:{opened:!1},li_attr:{itemtype:"livetv"},children:[{text:"Loading...",icon:!1}],icon:!1}),callback.call(scope,nodes),nodesToLoad.push("MediaFolders")})}function loadLiveTvChannels(service,openItems,callback){ApiClient.getLiveTvChannels({ServiceName:service,AddCurrentProgram:!1}).then(function(result){var nodes=result.Items.map(function(i){var state=openItems.indexOf(i.Id)==-1?"closed":"open";return getNode(i,state,!1)});callback(nodes)})}function loadMediaFolders(page,scope,openItems,callback){ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders")).then(function(result){var nodes=result.Items.map(function(n){var state=openItems.indexOf(n.Id)==-1?"closed":"open";return getNode(n,state,!1)});callback.call(scope,nodes);for(var i=0,length=nodes.length;i<length;i++)nodes[i].state.opened&&nodesToLoad.push(nodes[i].id)})}function loadNode(page,scope,node,openItems,selectedId,currentUser,callback){var id=node.id;if("#"==id)return void loadChildrenOfRootNode(page,scope,callback);if("livetv"==id)return void loadLiveTvChannels(id,openItems,callback);if("MediaFolders"==id)return void loadMediaFolders(page,scope,openItems,callback);var query={ParentId:id,Fields:"Settings"},itemtype=node.li_attr.itemtype;"Season"!=itemtype&&"Series"!=itemtype&&(query.SortBy="SortName"),ApiClient.getItems(Dashboard.getCurrentUserId(),query).then(function(result){var nodes=result.Items.map(function(n){var state=openItems.indexOf(n.Id)==-1?"closed":"open";return getNode(n,state,n.Id==selectedId)});callback.call(scope,nodes);for(var i=0,length=nodes.length;i<length;i++)nodes[i].state.opened&&nodesToLoad.push(nodes[i].id)})}function scrollToNode(id){var elem=$("#"+id)[0];elem&&elem.scrollIntoView()}function initializeTree(page,currentUser,openItems,selectedId){require(["jstree"],function(){in