2020-04-18 19:20:15 -05:00
|
|
|
define(['require', 'apphost', 'layoutManager', 'focusManager', 'globalize', 'loading', 'connectionManager', 'listViewStyle', 'emby-select', 'emby-checkbox'], function (require, appHost, layoutManager, focusManager, globalize, loading, connectionManager) {
|
2020-04-12 00:44:30 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function authorizeRequest(event) {
|
2020-04-26 16:19:58 -05:00
|
|
|
let lookup = event.data.lookup;
|
|
|
|
let url = ApiClient.getUrl("/QuickConnect/Authorize");
|
2020-04-18 19:20:15 -05:00
|
|
|
ApiClient.ajax({
|
2020-04-12 00:44:30 -05:00
|
|
|
type: "POST",
|
|
|
|
url: url,
|
|
|
|
data: {
|
|
|
|
"Lookup": lookup
|
|
|
|
}
|
|
|
|
}, true);
|
2020-04-25 15:46:22 -05:00
|
|
|
|
|
|
|
require(["toast"], function (toast) {
|
|
|
|
toast("Request authorized");
|
|
|
|
});
|
|
|
|
|
|
|
|
// prevent bubbling
|
|
|
|
return false;
|
2020-04-12 00:44:30 -05:00
|
|
|
}
|
2020-04-18 19:20:15 -05:00
|
|
|
|
|
|
|
QuickConnectSettings.prototype.list = function(argPage) {
|
|
|
|
ApiClient.getJSON("/QuickConnect/List").then(json => {
|
2020-04-25 15:46:22 -05:00
|
|
|
let found = false;
|
2020-04-26 17:47:31 -05:00
|
|
|
let elem = argPage.querySelector('#quickConnectIncoming');
|
2020-04-26 16:19:58 -05:00
|
|
|
elem.innerText = globalize.translate('QuickConnectNoPending');
|
2020-04-25 15:46:22 -05:00
|
|
|
|
2020-04-26 17:47:31 -05:00
|
|
|
for (let i = 0; i < json.length; i++) {
|
2020-04-25 15:46:22 -05:00
|
|
|
if (!found) {
|
2020-04-26 16:19:58 -05:00
|
|
|
elem.innerHTML = "";
|
2020-04-25 15:46:22 -05:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
2020-04-26 17:47:31 -05:00
|
|
|
let current = json[i];
|
2020-04-25 15:46:22 -05:00
|
|
|
|
|
|
|
let html = '<div class="listItem listItem-border" id="div' + current.Lookup + '"><div class="listItemBody three-line">';
|
|
|
|
html += '<div class="listItemBodyText"><code style="font-size:large">' + current.Code + '</code></div>';
|
|
|
|
html += '<div class="listItemBodyText secondary">' + current.FriendlyName + '</div>';
|
|
|
|
html += '<div class="listItemBodyText secondary listItemBodyText-nowrap">';
|
2020-04-18 19:20:15 -05:00
|
|
|
|
|
|
|
if (!current.Authenticated) {
|
2020-04-26 16:19:58 -05:00
|
|
|
html += '<a style="color:rgb(15,150,255)" href="#" id="qc' + current.Lookup + '">' + globalize.translate('Authorize') + '</a>';
|
2020-04-12 00:44:30 -05:00
|
|
|
}
|
2020-04-18 19:20:15 -05:00
|
|
|
|
2020-04-25 15:46:22 -05:00
|
|
|
html += '</div></div></div>';
|
2020-04-26 16:19:58 -05:00
|
|
|
elem.innerHTML += html;
|
2020-04-25 15:46:22 -05:00
|
|
|
|
2020-04-18 19:20:15 -05:00
|
|
|
$("#qc" + current.Lookup).click({ lookup: current.Lookup }, authorizeRequest);
|
2020-04-25 15:46:22 -05:00
|
|
|
$("#div" + current.Lookup).click({ lookup: current.Lookup }, authorizeRequest);
|
2020-04-12 00:44:30 -05:00
|
|
|
}
|
2020-04-18 19:20:15 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}).catch((e) => {
|
|
|
|
console.error("Unable to get quick connect login requests. error:", e);
|
2020-04-12 00:44:30 -05:00
|
|
|
});
|
2020-04-18 19:20:15 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
QuickConnectSettings.prototype.activate = function() {
|
2020-04-26 17:47:31 -05:00
|
|
|
let url = ApiClient.getUrl("/QuickConnect/Activate");
|
2020-04-18 19:20:15 -05:00
|
|
|
ApiClient.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: url,
|
|
|
|
contentType: "application/json",
|
|
|
|
dataType: "json"
|
|
|
|
}).then((json) => {
|
|
|
|
let message = json.Error;
|
|
|
|
|
|
|
|
if (message && message !== "") {
|
|
|
|
console.error("Error activating quick connect. Error: ", json.Error);
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
title: "Unable to activate quick connect",
|
|
|
|
message: message
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-25 15:46:22 -05:00
|
|
|
require(["toast"], function (toast) {
|
2020-04-26 16:19:58 -05:00
|
|
|
toast(globalize.translate("QuickConnectActivationSuccessful"));
|
2020-04-18 19:20:15 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}).catch((e) => {
|
|
|
|
console.error("Error activating quick connect. Error:", e);
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
};
|
2020-04-12 00:44:30 -05:00
|
|
|
|
|
|
|
function QuickConnectSettings(options) {
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
QuickConnectSettings.prototype.loadData = function () {
|
2020-04-18 19:20:15 -05:00
|
|
|
this.options.interval = setInterval(this.list, 5000, this.options.page);
|
|
|
|
this.list(this.options.page);
|
2020-04-12 00:44:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
QuickConnectSettings.prototype.submit = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
QuickConnectSettings.prototype.destroy = function () {
|
2020-04-18 19:20:15 -05:00
|
|
|
console.debug("clearing refresh interval", this.options.interval);
|
|
|
|
clearInterval(this.options.interval);
|
2020-04-12 00:44:30 -05:00
|
|
|
this.options = null;
|
|
|
|
};
|
|
|
|
|
2020-04-18 19:20:15 -05:00
|
|
|
QuickConnectSettings.prototype.interval = function (interval) {
|
|
|
|
this.options.interval = interval;
|
|
|
|
};
|
|
|
|
|
2020-04-12 00:44:30 -05:00
|
|
|
return QuickConnectSettings;
|
|
|
|
});
|