jellyfin-web/dashboard-ui/scripts/devices.js

1 line
2.1 KiB
JavaScript
Raw Normal View History

2017-05-17 20:18:08 -07:00
define(["jQuery","loading","libraryMenu","listViewStyle"],function($,loading,libraryMenu){"use strict";function deleteDevice(page,id){var msg=Globalize.translate("DeleteDeviceConfirmation");require(["confirm"],function(confirm){confirm(msg,Globalize.translate("HeaderDeleteDevice")).then(function(){loading.show(),ApiClient.ajax({type:"DELETE",url:ApiClient.getUrl("Devices",{Id:id})}).then(function(){loadData(page)})})})}function load(page,devices){var html="";devices.length&&(html+='<div class="paperList">'),html+=devices.map(function(d){var deviceHtml="";return deviceHtml+='<div class="listItem">',deviceHtml+='<i class="listItemIcon md-icon" style="background:#999;">tablet_android</i>',deviceHtml+=d.AppName&&d.LastUserName?'<div class="listItemBody three-line">':'<div class="listItemBody two-line">',deviceHtml+='<a class="clearLink" href="device.html?id='+d.Id+'">',deviceHtml+='<div class="listItemBodyText">',deviceHtml+=d.Name,deviceHtml+="</div>",d.AppName&&(deviceHtml+='<div class="listItemBodyText secondary">',deviceHtml+=d.AppName,deviceHtml+="</div>"),d.LastUserName&&(deviceHtml+='<div class="listItemBodyText secondary">',deviceHtml+=Globalize.translate("DeviceLastUsedByUserName",d.LastUserName),deviceHtml+="</div>"),deviceHtml+="</a>",deviceHtml+="</div>",deviceHtml+='<button type="button" is="paper-icon-button-light" class="btnDeleteDevice" data-id="'+d.Id+'" title="'+Globalize.translate("ButtonDelete")+'"><i class="md-icon">delete</i></button>',deviceHtml+="</div>"}).join(""),devices.length&&(html+="</div>");var elem=$(".devicesList",page).html(html).trigger("create");$(".btnDeleteDevice",elem).on("click",function(){deleteDevice(page,this.getAttribute("data-id"))})}function loadData(page){loading.show(),ApiClient.getJSON(ApiClient.getUrl("Devices",{SupportsPersistentIdentifier:!0})).then(function(result){load(page,result.Items),loading.hide()})}function getTabs(){return[{href:"devices.html",name:Globalize.translate("TabDevices")},{href:"devicesupload.html",name:Globalize.translate("TabCameraUpload")}]}$(document).on("pageshow","#devicesPage",function(){libraryMenu.setTabs("devices",0,getTabs);var page=this;loadData(page)})});