2017-06-19 11:09:05 -07:00
|
|
|
define(["itemShortcuts","connectionManager","layoutManager","browser","dom","loading","focusManager","serverNotifications","events","registerElement"],function(itemShortcuts,connectionManager,layoutManager,browser,dom,loading,focusManager,serverNotifications,events){"use strict";function onClick(e){var itemsContainer=this,multiSelect=(e.target,itemsContainer.multiSelect);multiSelect&&multiSelect.onContainerClick.call(itemsContainer,e)===!1||itemShortcuts.onClick.call(itemsContainer,e)}function disableEvent(e){return e.preventDefault(),e.stopPropagation(),!1}function onContextMenu(e){var itemsContainer=this,target=e.target,card=dom.parentWithAttribute(target,"data-id");if(card&&card.getAttribute("data-serverid"))return itemShortcuts.showContextMenu(card,{positionTo:target,itemsContainer:itemsContainer}),e.preventDefault(),e.stopPropagation(),!1}function getShortcutOptions(){return{click:!1}}function onDrop(evt,itemsContainer){var el=evt.item,newIndex=evt.newIndex,itemId=el.getAttribute("data-playlistitemid"),playlistId=el.getAttribute("data-playlistid");if(!playlistId){var oldIndex=evt.oldIndex;return void el.dispatchEvent(new CustomEvent("itemdrop",{detail:{oldIndex:oldIndex,newIndex:newIndex,playlistItemId:itemId},bubbles:!0,cancelable:!1}))}var serverId=el.getAttribute("data-serverid"),apiClient=connectionManager.getApiClient(serverId);newIndex=Math.max(0,newIndex-1),loading.show(),apiClient.ajax({url:apiClient.getUrl("Playlists/"+playlistId+"/Items/"+itemId+"/Move/"+newIndex),type:"POST"}).then(function(){loading.hide()},function(){loading.hide(),itemsContainer.dispatchEvent(new CustomEvent("needsrefresh",{detail:{},cancelable:!1,bubbles:!0}))})}function onUserDataChanged(e,apiClient,userData){var itemsContainer=this;require(["cardBuilder"],function(cardBuilder){cardBuilder.onUserDataChanged(userData,itemsContainer)})}function onTimerCreated(e,apiClient,data){var itemsContainer=this,programId=data.ProgramId,newTimerId=data.Id;require(["cardBuilder"],function(cardBuilder){cardBuilder.onTimerCreated(programId,newTimerId,itemsContainer)})}function onSeriesTimerCreated(e,apiClient,data){}function onTimerCancelled(e,apiClient,data){var itemsContainer=this,id=data.Id;require(["cardBuilder"],function(cardBuilder){cardBuilder.onTimerCancelled(id,itemsContainer)})}function onSeriesTimerCancelled(e,apiClient,data){var itemsContainer=this,id=data.Id;require(["cardBuilder"],function(cardBuilder){cardBuilder.onSeriesTimerCancelled(id,itemsContainer)})}function addNotificationEvent(instance,name,handler){var localHandler=handler.bind(instance);events.on(serverNotifications,name,localHandler),instance[name]=localHandler}function removeNotificationEvent(instance,name){var handler=instance[name];handler&&(events.off(serverNotifications,name,handler),instance[name]=null)}function alphanumeric(value){var letterNumber=/^[0-9a-zA-Z]+$/;return value.match(letterNumber)}function onKeyDown(e){var keyCode=e.keyCode,chrCode=keyCode-48*Math.floor(keyCode/48);chrCode=96<=keyCode?chrCode:keyCode;var chr=String.fromCharCode(chrCode);chr=alphanumeric(chr),chr&&(currentDisplayTextContainer=this,onAlphanumericKeyPress(e,chr))}function ensureInputDisplayElement(){inputDisplayElement||(inputDisplayElement=document.createElement("div"),inputDisplayElement.classList.add("alphanumeric-shortcut"),inputDisplayElement.classList.add("hide"),document.body.appendChild(inputDisplayElement))}function clearAlphaNumericShortcutTimeout(){alpanumericShortcutTimeout&&(clearTimeout(alpanumericShortcutTimeout),alpanumericShortcutTimeout=null)}function resetAlphaNumericShortcutTimeout(){clearAlphaNumericShortcutTimeout(),alpanumericShortcutTimeout=setTimeout(onAlphanumericShortcutTimeout,2e3)}function onAlphanumericKeyPress(e,chr){currentDisplayText.length>=3||(ensureInputDisplayElement(),currentDisplayText+=chr,inputDisplayElement.innerHTML=currentDisplayText,inputDisplayElement.classList.remove("hide"),resetAlphaNumericShortcutTimeout())}function onAlphanumericShortcutTimeout(){var value=currentDisplayText,container=currentDisplayTextContainer;currentDisplayText="",cu
|