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

1 line
2.5 KiB
JavaScript
Raw Normal View History

2017-05-17 20:18:08 -07:00
define(["datetime","jQuery","loading","libraryMenu"],function(datetime,$,loading,libraryMenu){"use strict";function revoke(page,key){require(["confirm"],function(confirm){confirm(Globalize.translate("MessageConfirmRevokeApiKey"),Globalize.translate("HeaderConfirmRevokeApiKey")).then(function(){loading.show(),ApiClient.ajax({type:"DELETE",url:ApiClient.getUrl("Auth/Keys/"+key)}).then(function(){loadData(page)})})})}function renderKeys(page,keys,users){var rows=keys.map(function(item){var html="";html+="<tr>",html+="<td>",html+='<button data-token="'+item.AccessToken+'" class="btnRevoke" data-mini="true" title="'+Globalize.translate("ButtonRevoke")+'" style="margin:0;">'+Globalize.translate("ButtonRevoke")+"</button>",html+="</td>",html+='<td style="vertical-align:middle;">',html+=item.AccessToken,html+="</td>",html+='<td style="vertical-align:middle;">',html+=item.AppName||"",html+="</td>",html+='<td style="vertical-align:middle;">',html+=item.DeviceName||"",html+="</td>",html+='<td style="vertical-align:middle;">';var user=users.filter(function(u){return u.Id==item.UserId})[0];user&&(html+=user.Name),html+="</td>",html+='<td style="vertical-align:middle;">';var date=datetime.parseISO8601Date(item.DateCreated,!0);return html+=datetime.toLocaleDateString(date)+" "+datetime.getDisplayTime(date),html+="</td>",html+="</tr>"}).join(""),elem=$(".resultBody",page).html(rows).parents(".tblApiKeys").table("refresh").trigger("create");$(".btnRevoke",elem).on("click",function(){revoke(page,this.getAttribute("data-token"))}),loading.hide()}function loadData(page){loading.show(),ApiClient.getUsers().then(function(users){ApiClient.getJSON(ApiClient.getUrl("Auth/Keys")).then(function(result){renderKeys(page,result.Items,users)})})}function showNewKeyPrompt(page){require(["prompt"],function(prompt){prompt({title:Globalize.translate("HeaderNewApiKey"),label:Globalize.translate("LabelAppName"),description:Globalize.translate("LabelAppNameExample")}).then(function(value){ApiClient.ajax({type:"POST",url:ApiClient.getUrl("Auth/Keys",{App:value})}).then(function(){loadData(page)})})})}function getTabs(){return[{href:"dashboardhosting.html",name:Globalize.translate("TabHosting")},{href:"serversecurity.html",name:Globalize.translate("TabSecurity")}]}pageIdOn("pageinit","serverSecurityPage",function(){var page=this;$(".btnNewKey",page).on("click",function(){showNewKeyPrompt(page)})}),pageIdOn("pagebeforeshow","serverSecurityPage",function(){libraryMenu.setTabs("adminadvanced",1,getTabs);var page=this;loadData(page)})});