2017-01-27 16:07:14 -07:00
|
|
|
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<length;i++){var job=jobs[i];refreshJob(listInstance,job)}}function cancelJob(listInstance,id){require(["confirm"],function(confirm){var msg=listInstance.options.isLocalSync?globalize.translate("sharedcomponents#ConfirmRemoveDownload"):globalize.translate("sharedcomponents#CancelSyncJobConfirmation");confirm({text:msg,primary:"cancel"}).then(function(){loading.show();var apiClient=getApiClient(listInstance);apiClient.ajax({url:apiClient.getUrl("Sync/Jobs/"+id),type:"DELETE"}).then(function(){fetchData(listInstance)})})})}function refreshJob(listInstance,job){var listItem=listInstance.options.element.querySelector(".listItem[data-id='"+job.Id+"']");listItem&&(listItem.querySelector(".jobStatus").innerHTML=getProgressText(job))}function getProgressText(job){var status=job.Status;"Completed"===status&&(status="Synced");var html=globalize.translate("sharedcomponents#SyncJobItemStatus"+status);return"Transferring"!==job.Status&&"Converting"!==job.Status&&"Completed"!==job.Status||(html+=" ",html+=(job.Progress||0)+"%"),html}function getSyncJobHtml(listInstance,job,apiClient){var html="",tagName=layoutManager.tv?"button":"div",typeAttribute="button"===tagName?' type="button"':"",listItemClass="listItem";layoutManager.tv&&(listItemClass+=" listItem-button listItem-focusscale"),html+="<"+tagName+typeAttribute+' class="'+listItemClass+'" data-id="'+job.Id+'" data-status="'+job.Status+'">';var imgUrl;job.PrimaryImageItemId&&(imgUrl=apiClient.getImageUrl(job.PrimaryImageItemId,{type:"Primary",width:80,tag:job.PrimaryImageTag,minScale:1.5})),imgUrl?(html+='<div class="listItemImage lazy" data-src="'+imgUrl+'" item-icon>',html+="</div>"):html+='<i class="md-icon listItemIcon">file_download</i>';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+='<div class="listItemBody three-line">';for(var i=0,length=textLines.length;i<length;i++)0===i?(html+='<h3 class="listItemBodyText">',html+=textLines[i],html+="</h3>"):(html+='<div class="listItemBodyText secondary">',html+=textLines[i],html+="</div>");return html+='<div class="secondary listItemBodyText jobStatus" style="color:green;">',html+=getProgressText(job),html+="</div>",html+="</div>",layoutManager.tv||(html+='<button type="button" is="paper-icon-button-light" class="btnJobMenu listItemButton"><i class="md-icon">more_vert</i></button>'),html+="</"+tagName+">"}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<length;i++){var job=jobs[i];if(showTargetName){var targetName=job.TargetName||"Unknown";targetName!==lastTargetName&&(lastTargetName&&(html+="</div>",html+="<br/>",hasOpenSection=!1),lastTargetName=targetName,html+='<div class="detailSectionHeader">',html+="<h1>"+targetName+"</h1>",html+="</div>",html+='<div class="itemsContainer vertical-list paperList">',hasOpenSection=!0)}html+=getSyncJobHtml(listInstance,job,apiClient)}hasOpenSection&&(html+="</div>");var elem=listInstance.options.element.querySelector(".syncJobListContent");html||(html=isLocalSync?'<div style="padding:1em .25em;">'+globalize.translate("sharedcomponents#MessageNoDownloadsFound")+"</div>":'<div style="padding:1em .25em;">'+globalize.translate("sharedco
|