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

188 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-07-05 11:11:28 -07:00
define(['fetchHelper', 'jQuery', 'registrationservices'], function (fetchHelper, $, registrationServices) {
2014-05-18 12:58:42 -07:00
2016-03-13 13:12:42 -07:00
function load(page) {
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.getPluginSecurityInfo().then(function (info) {
2014-05-18 12:58:42 -07:00
2013-02-20 18:33:05 -07:00
$('#txtSupporterKey', page).val(info.SupporterKey);
2014-01-02 14:21:06 -07:00
2014-05-18 12:58:42 -07:00
if (info.SupporterKey && !info.IsMBSupporter) {
2015-06-28 07:45:21 -07:00
page.querySelector('#txtSupporterKey').classList.add('invalidEntry');
$('.notSupporter', page).show();
} else {
2015-06-28 07:45:21 -07:00
page.querySelector('#txtSupporterKey').classList.remove('invalidEntry');
$('.notSupporter', page).hide();
}
2014-05-18 12:58:42 -07:00
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
});
2016-03-13 13:12:42 -07:00
}
2014-01-02 14:21:06 -07:00
2016-03-13 13:12:42 -07:00
function loadUserInfo(page) {
2016-03-13 13:12:42 -07:00
Dashboard.getPluginSecurityInfo().then(function (info) {
2014-01-02 14:21:06 -07:00
2016-03-13 13:12:42 -07:00
if (info.IsMBSupporter) {
$('.supporterContainer', page).addClass('hide');
2014-05-18 12:58:42 -07:00
} else {
2016-03-13 13:12:42 -07:00
$('.supporterContainer', page).removeClass('hide');
2014-05-18 12:58:42 -07:00
}
});
2016-03-13 13:12:42 -07:00
}
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
function retrieveSupporterKey() {
Dashboard.showLoadingMsg();
2014-01-02 14:21:06 -07:00
var form = this;
2016-03-13 13:12:42 -07:00
var email = $('#txtEmail', form).val();
2016-03-13 13:12:42 -07:00
var url = "https://mb3admin.com/admin/service/supporter/retrievekey?email=" + email;
2015-12-23 10:46:01 -07:00
console.log(url);
2016-03-13 13:12:42 -07:00
fetchHelper.ajax({
2016-06-24 17:29:39 -07:00
2016-03-13 13:12:42 -07:00
url: url,
type: 'POST',
dataType: 'json'
}).then(function (result) {
Dashboard.hideLoadingMsg();
if (result.Success) {
2016-02-24 23:38:12 -07:00
require(['toast'], function (toast) {
2016-03-13 13:12:42 -07:00
toast(Globalize.translate('MessageKeyEmailedTo').replace("{0}", email));
2016-02-24 23:38:12 -07:00
});
} else {
2016-02-24 23:38:12 -07:00
require(['toast'], function (toast) {
toast(result.ErrorMessage);
});
}
2015-12-23 10:46:01 -07:00
console.log(result);
});
return false;
2016-03-13 13:12:42 -07:00
}
2014-05-18 12:58:42 -07:00
2016-03-13 13:12:42 -07:00
var SupporterKeyPage = {
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
updateSupporterKey: function () {
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
Dashboard.showLoadingMsg();
var form = this;
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
var key = $('#txtSupporterKey', form).val();
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
var info = {
SupporterKey: key
};
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
ApiClient.updatePluginSecurityInfo(info).then(function () {
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
Dashboard.resetPluginSecurityInfo();
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
2016-03-13 13:12:42 -07:00
if (key) {
2016-02-21 15:17:38 -07:00
2016-03-13 13:12:42 -07:00
Dashboard.alert({
message: Globalize.translate('MessageKeyUpdated'),
title: Globalize.translate('HeaderConfirmation')
});
2016-02-21 15:17:38 -07:00
2016-03-13 13:12:42 -07:00
} else {
Dashboard.alert({
message: Globalize.translate('MessageKeyRemoved'),
title: Globalize.translate('HeaderConfirmation')
});
}
2016-02-21 15:17:38 -07:00
2016-03-13 13:12:42 -07:00
var page = $(form).parents('.page')[0];
2016-02-21 15:17:38 -07:00
2016-03-13 13:12:42 -07:00
load(page);
});
return false;
},
linkSupporterKeys: function () {
Dashboard.showLoadingMsg();
var form = this;
var email = $('#txtNewEmail', form).val();
var newkey = $('#txtNewKey', form).val();
var oldkey = $('#txtOldKey', form).val();
var url = "https://mb3admin.com/admin/service/supporter/linkKeys";
console.log(url);
fetchHelper.ajax({
url: url,
type: 'POST',
dataType: 'json',
query: {
email: email,
newkey: newkey,
oldkey: oldkey
}
}).then(function (result) {
Dashboard.hideLoadingMsg();
if (result.Success) {
require(['toast'], function (toast) {
toast(Globalize.translate('MessageKeysLinked'));
});
} else {
require(['toast'], function (toast) {
toast(result.ErrorMessage);
});
}
console.log(result);
});
return false;
}
};
2016-02-21 15:17:38 -07:00
2016-04-12 23:02:07 -07:00
function getTabs() {
return [
{
href: 'about.html',
name: Globalize.translate('TabAbout')
},
{
href: 'supporterkey.html',
name: Globalize.translate('TabEmbyPremiere')
}];
}
2016-07-05 11:11:28 -07:00
function onSupporterLinkClick(e) {
registrationServices.showPremiereInfo();
e.preventDefault();
e.stopPropagation();
}
2016-02-21 15:17:38 -07:00
$(document).on('pageinit', "#supporterKeyPage", function () {
var page = this;
2016-03-13 13:12:42 -07:00
$('#supporterKeyForm', this).on('submit', SupporterKeyPage.updateSupporterKey);
$('#lostKeyForm', this).on('submit', retrieveSupporterKey);
$('#linkKeysForm', this).on('submit', SupporterKeyPage.linkSupporterKeys);
2016-02-21 15:17:38 -07:00
2016-07-05 11:11:28 -07:00
page.querySelector('.benefits').innerHTML = Globalize.translate('HeaderSupporterBenefit', '<a class="lnkPremiere" href="http://emby.media/premiere" target="_blank">', '</a>');
page.querySelector('.lnkPremiere').addEventListener('click', onSupporterLinkClick);
2016-02-21 15:17:38 -07:00
}).on('pageshow', "#supporterKeyPage", function () {
2016-04-12 23:02:07 -07:00
2016-06-24 17:29:39 -07:00
LibraryMenu.setTabs('helpadmin', 1, getTabs);
2016-04-12 23:02:07 -07:00
2016-02-21 15:17:38 -07:00
var page = this;
loadUserInfo(page);
2016-03-13 13:12:42 -07:00
load(page);
2016-02-21 15:17:38 -07:00
});
2016-03-13 13:12:42 -07:00
});