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

1 line
11 KiB
JavaScript
Raw Normal View History

2017-06-18 00:09:29 -07:00
define(["browser","appStorage","apphost","loading","connectionManager","globalize","embyRouter","dom","css!./multiselect"],function(browser,appStorage,appHost,loading,connectionManager,globalize,embyRouter,dom){"use strict";function hideSelections(){var selectionCommandsPanel=currentSelectionCommandsPanel;if(selectionCommandsPanel){selectionCommandsPanel.parentNode.removeChild(selectionCommandsPanel),currentSelectionCommandsPanel=null,selectedItems=[],selectedElements=[];for(var elems=document.querySelectorAll(".itemSelectionPanel"),i=0,length=elems.length;i<length;i++){var parent=elems[i].parentNode;parent.removeChild(elems[i]),parent.classList.remove("withMultiSelect")}}}function onItemSelectionPanelClick(e,itemSelectionPanel){if(!dom.parentWithClass(e.target,"chkItemSelect")){var chkItemSelect=itemSelectionPanel.querySelector(".chkItemSelect");if(chkItemSelect)if(chkItemSelect.classList.contains("checkedInitial"))chkItemSelect.classList.remove("checkedInitial");else{var newValue=!chkItemSelect.checked;chkItemSelect.checked=newValue,updateItemSelection(chkItemSelect,newValue)}}return e.preventDefault(),e.stopPropagation(),!1}function updateItemSelection(chkItemSelect,selected){var id=dom.parentWithAttribute(chkItemSelect,"data-id").getAttribute("data-id");if(selected){var current=selectedItems.filter(function(i){return i===id});current.length||(selectedItems.push(id),selectedElements.push(chkItemSelect))}else selectedItems=selectedItems.filter(function(i){return i!==id}),selectedElements=selectedElements.filter(function(i){return i!==chkItemSelect});if(selectedItems.length){var itemSelectionCount=document.querySelector(".itemSelectionCount");itemSelectionCount&&(itemSelectionCount.innerHTML=selectedItems.length)}else hideSelections()}function onSelectionChange(e){updateItemSelection(this,this.checked)}function showSelection(item,isChecked){var itemSelectionPanel=item.querySelector(".itemSelectionPanel");if(!itemSelectionPanel){itemSelectionPanel=document.createElement("div"),itemSelectionPanel.classList.add("itemSelectionPanel");var parent=item.querySelector(".cardBox")||item.querySelector(".cardContent");parent.classList.add("withMultiSelect"),parent.appendChild(itemSelectionPanel);var cssClass="chkItemSelect";isChecked&&!browser.firefox&&(cssClass+=" checkedInitial");var checkedAttribute=isChecked?" checked":"";itemSelectionPanel.innerHTML='<label class="checkboxContainer"><input type="checkbox" is="emby-checkbox" data-outlineclass="multiSelectCheckboxOutline" class="'+cssClass+'"'+checkedAttribute+"/><span></span></label>";var chkItemSelect=itemSelectionPanel.querySelector(".chkItemSelect");chkItemSelect.addEventListener("change",onSelectionChange)}}function showSelectionCommands(){var selectionCommandsPanel=currentSelectionCommandsPanel;if(!selectionCommandsPanel){selectionCommandsPanel=document.createElement("div"),selectionCommandsPanel.classList.add("selectionCommandsPanel"),document.body.appendChild(selectionCommandsPanel),currentSelectionCommandsPanel=selectionCommandsPanel;var html="";html+='<button is="paper-icon-button-light" class="btnCloseSelectionPanel autoSize"><i class="md-icon">close</i></button>',html+='<h1 class="itemSelectionCount"></h1>';var moreIcon="dots-horiz"===appHost.moreIcon?"&#xE5D3;":"&#xE5D4;";html+='<button is="paper-icon-button-light" class="btnSelectionPanelOptions autoSize" style="margin-left:auto;"><i class="md-icon">'+moreIcon+"</i></button>",selectionCommandsPanel.innerHTML=html,selectionCommandsPanel.querySelector(".btnCloseSelectionPanel").addEventListener("click",hideSelections);var btnSelectionPanelOptions=selectionCommandsPanel.querySelector(".btnSelectionPanelOptions");btnSelectionPanelOptions.addEventListener("click",showMenuForSelectedItems)}}function deleteItems(apiClient,itemIds){return new Promise(function(resolve,reject){var msg=globalize.translate("sharedcomponents#ConfirmDeleteItem"),title=globalize.translate("sharedcomponents#HeaderDeleteItem");itemIds.length>1&&(msg=globalize.translate("sharedcomponents#ConfirmDeleteItems"),title=globalize.translate("sharedcompone