jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/sync/emby-downloadbutton.js
2017-06-20 15:36:34 -04:00

1 line
2.7 KiB
JavaScript

define(["connectionManager","serverNotifications","events","globalize","emby-button"],function(connectionManager,serverNotifications,events,globalize,EmbyButtonPrototype){"use strict";function onClick(e){var button=this,id=button.getAttribute("data-id"),serverId=button.getAttribute("data-serverid"),apiClient=connectionManager.getApiClient(serverId);button.classList.contains("downloadbutton-on")?require(["confirm"],function(confirm){confirm({text:globalize.translate("sharedcomponents#ConfirmRemoveDownload"),confirmText:globalize.translate("sharedcomponents#RemoveDownload"),cancelText:globalize.translate("sharedcomponents#KeepDownload"),primary:"cancel"}).then(function(){apiClient.cancelSyncItems([id]),button.dispatchEvent(new CustomEvent("download-cancel",{cancelable:!1}))})}):require(["syncDialog"],function(syncDialog){syncDialog.showMenu({items:[id],isLocalSync:!0,serverId:serverId}).then(function(){button.dispatchEvent(new CustomEvent("download",{cancelable:!1}))})})}function updateSyncStatus(button,syncPercent){null!=syncPercent?button.classList.add("downloadbutton-on"):button.classList.remove("downloadbutton-on"),(syncPercent||0)>=100?button.classList.add("downloadbutton-complete"):button.classList.remove("downloadbutton-complete");var text;text=(syncPercent||0)>=100?globalize.translate("sharedcomponents#Downloaded"):null!=syncPercent?globalize.translate("sharedcomponents#Downloading"):globalize.translate("sharedcomponents#Download");var textElement=button.querySelector(".emby-downloadbutton-downloadtext");textElement&&(textElement.innerHTML=text),button.title=text}function clearEvents(button){button.removeEventListener("click",onClick)}function bindEvents(button){clearEvents(button),button.addEventListener("click",onClick)}var EmbyDownloadButtonPrototype=Object.create(EmbyButtonPrototype);EmbyDownloadButtonPrototype.createdCallback=function(){EmbyButtonPrototype.createdCallback&&EmbyButtonPrototype.createdCallback.call(this)},EmbyDownloadButtonPrototype.attachedCallback=function(){EmbyButtonPrototype.attachedCallback&&EmbyButtonPrototype.attachedCallback.call(this);var itemId=this.getAttribute("data-id"),serverId=this.getAttribute("data-serverid");itemId&&serverId&&bindEvents(this)},EmbyDownloadButtonPrototype.detachedCallback=function(){EmbyButtonPrototype.detachedCallback&&EmbyButtonPrototype.detachedCallback.call(this),clearEvents(this)},EmbyDownloadButtonPrototype.setItem=function(item){item?(this.setAttribute("data-id",item.Id),this.setAttribute("data-serverid",item.ServerId),updateSyncStatus(this,item.SyncPercent),bindEvents(this)):(this.removeAttribute("data-id"),this.removeAttribute("data-serverid"),clearEvents(this))},document.registerElement("emby-downloadbutton",{prototype:EmbyDownloadButtonPrototype,extends:"button"})});