define(["serverNotifications","events","loading","connectionManager","imageLoader","dom","globalize","registrationServices","layoutManager","listViewStyle"],function(serverNotifications,events,loading,connectionManager,imageLoader,dom,globalize,registrationServices,layoutManager){"use strict";function onSyncJobsUpdated(e,apiClient,data){var listInstance=this;renderList(listInstance,data,apiClient)}function refreshList(listInstance,jobs){for(var i=0,length=jobs.length;i';var imgUrl;job.PrimaryImageItemId&&(imgUrl=apiClient.getImageUrl(job.PrimaryImageItemId,{type:"Primary",width:80,tag:job.PrimaryImageTag,minScale:1.5})),imgUrl?(html+='
',html+="
"):html+='file_download';var textLines=[];job.ParentName&&textLines.push(job.ParentName),textLines.push(job.Name),1===job.ItemCount?textLines.push(globalize.translate("sharedcomponents#ValueOneItem")):textLines.push(globalize.translate("sharedcomponents#ItemCount",job.ItemCount)),html+='
';for(var i=0,length=textLines.length;i',html+=textLines[i],html+=""):(html+='
',html+=textLines[i],html+="
");return html+='
',html+=getProgressText(job),html+="
",html+="
",layoutManager.tv||(html+=''),html+=""}function renderList(listInstance,jobs,apiClient){if((new Date).getTime()-listInstance.lastDataLoad<6e4)return void refreshList(listInstance,jobs);listInstance.lastDataLoad=(new Date).getTime();for(var html="",lastTargetName="",isLocalSync=listInstance.options.isLocalSync,showTargetName=!isLocalSync,hasOpenSection=!1,i=0,length=jobs.length;i",html+="
",hasOpenSection=!1),lastTargetName=targetName,html+='
',html+="

"+targetName+"

",html+="
",html+='
',hasOpenSection=!0)}html+=getSyncJobHtml(listInstance,job,apiClient)}hasOpenSection&&(html+="
");var elem=listInstance.options.element.querySelector(".syncJobListContent");html||(html=isLocalSync?'
'+globalize.translate("sharedcomponents#MessageNoDownloadsFound")+"
":'
'+globalize.translate("sharedcomponents#MessageNoSyncJobsFound")+"
"),elem.innerHTML=html,imageLoader.lazyChildren(elem)}function fetchData(listInstance){listInstance.lastDataLoad=0,loading.show();var options={},apiClient=getApiClient(listInstance);return listInstance.options.userId&&(options.UserId=listInstance.options.userId),listInstance.options.isLocalSync?options.TargetId=apiClient.deviceId():options.ExcludeTargetIds=apiClient.deviceId(),apiClient.getJSON(apiClient.getUrl("Sync/Jobs",options)).then(function(response){renderList(listInstance,response.Items,apiClient),loading.hide()})}function startListening(listInstance){var startParams="0,1500",apiClient=getApiClient(listInstance);listInstance.options.userId&&(startParams+=","+listInstance.options.userId),listInstance.options.isLocalSync&&(startParams+=","+apiClient.deviceId()),apiClient.isWebSocketOpen()&&apiClient.sendWebSocketMessage("SyncJobsStart",startParams)}function stopListening(listInstance){var apiClient=getApiClient(listInstance);apiClient.isWebSocketOpen()&&apiClient.sendWebSocketMessage("SyncJobsStop","")}function getApiClient(listInstance){return connectionManager.getApiClient(listInstance.options.serverId)}function showJobMenu(listInstance,elem){var item=dom.parentWithClass(elem,"listItem"),jobId=item.getAttribute("data-id"),status=item.getAttribute("data-status"),menuItems=[];if("Cancelled"===status)menuItems.push({name:globalize.translate("sharedcomponents#Delete"),id:"delete"});else{var txt=listInstance.options.isLocalSync?globalize.translate("sharedcomponents#RemoveDownload"):globalize.translate("sharedcomponents#ButtonCancelSyncJob");menuItems.push({name:txt,id:"cancel"})}require(["actionsheet"],function(actionsheet){actionsheet.show({items:menuItems,positionTo:elem,callback:function(id){switch(id){case"delete":cancelJob(listInstance,jobId);break;case"cancel":cancelJob(listInstance,jobId)}}})})}function onElementClick(e){var listInstance=this,btnJobMenu=dom.parentWithClass(e.target,"btnJobMenu");if(btnJobMenu)return void showJobMenu(this,btnJobMenu);var listItem=dom.parentWithClass(e.target,"listItem");if(listItem){var jobId=listItem.getAttribute("data-id");require(["syncJobEditor"],function(syncJobEditor){syncJobEditor.show({serverId:listInstance.options.serverId,jobId:jobId}).then(function(){fetchData(listInstance)})})}}function syncJobList(options){this.options=options;var onSyncJobsUpdatedHandler=onSyncJobsUpdated.bind(this);this.onSyncJobsUpdatedHandler=onSyncJobsUpdatedHandler,events.on(serverNotifications,"SyncJobs",onSyncJobsUpdatedHandler);var onClickHandler=onElementClick.bind(this);options.element.addEventListener("click",onClickHandler),this.onClickHandler=onClickHandler,options.element.innerHTML='
',fetchData(this),startListening(this),initSupporterInfo(options.element,getApiClient(this))}function showSupporterInfo(context){var html='