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

287 lines
7.4 KiB
JavaScript
Raw Normal View History

2013-02-20 18:33:05 -07:00
var SupporterKeyPage = {
onPageShow: function () {
2014-01-02 14:21:06 -07:00
SupporterKeyPage.load(this);
2013-02-20 18:33:05 -07:00
},
2014-01-02 14:21:06 -07:00
load: function (page) {
2014-05-18 12:58:42 -07:00
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
ApiClient.getPluginSecurityInfo().done(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) {
$('#txtSupporterKey', page).addClass("invalidEntry");
$('.notSupporter', page).show();
} else {
$('#txtSupporterKey', page).removeClass("invalidEntry");
$('.notSupporter', page).hide();
}
2014-05-18 12:58:42 -07:00
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
});
},
2014-05-18 12:58:42 -07:00
2013-02-20 18:33:05 -07:00
updateSupporterKey: function () {
Dashboard.showLoadingMsg();
2014-01-02 14:21:06 -07:00
var form = this;
2014-05-18 12:58:42 -07:00
2014-01-02 14:21:06 -07:00
var key = $('#txtSupporterKey', form).val();
2013-02-20 18:33:05 -07:00
2014-05-18 12:58:42 -07:00
var info = {
SupporterKey: key
};
2013-02-20 18:33:05 -07:00
2014-05-18 12:58:42 -07:00
ApiClient.updatePluginSecurityInfo(info).done(function () {
2014-01-02 14:21:06 -07:00
2014-05-18 12:58:42 -07:00
Dashboard.resetPluginSecurityInfo();
Dashboard.hideLoadingMsg();
2014-01-02 14:21:06 -07:00
2014-05-18 12:58:42 -07:00
if (key) {
2014-05-18 12:58:42 -07:00
Dashboard.alert({
2014-05-30 12:23:56 -07:00
message: Globalize.translate('MessageKeyUpdated'),
title: Globalize.translate('HeaderConfirmation')
2014-05-18 12:58:42 -07:00
});
2014-01-02 14:21:06 -07:00
2014-05-18 12:58:42 -07:00
} else {
Dashboard.alert({
2014-05-30 12:23:56 -07:00
message: Globalize.translate('MessageKeyRemoved'),
title: Globalize.translate('HeaderConfirmation')
2014-05-18 12:58:42 -07:00
});
}
var page = $(form).parents('.page');
SupporterKeyPage.load(page);
});
2013-02-20 18:33:05 -07:00
return false;
},
2014-05-18 12:58:42 -07:00
linkSupporterKeys: function () {
Dashboard.showLoadingMsg();
2014-01-02 14:21:06 -07:00
var form = this;
var email = $('#txtNewEmail', form).val();
var newkey = $('#txtNewKey', form).val();
var oldkey = $('#txtOldKey', form).val();
var info = {
email: email,
newkey: newkey,
oldkey: oldkey
};
var url = "http://mb3admin.com/admin/service/supporter/linkKeys";
console.log(url);
$.post(url, info).done(function (res) {
var result = JSON.parse(res);
Dashboard.hideLoadingMsg();
if (result.Success) {
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('MessageKeysLinked'));
} else {
Dashboard.showError(result.ErrorMessage);
}
console.log(result);
});
return false;
},
2014-05-18 12:58:42 -07:00
2013-02-20 18:33:05 -07:00
retrieveSupporterKey: function () {
Dashboard.showLoadingMsg();
2014-01-02 14:21:06 -07:00
var form = this;
2013-02-20 18:33:05 -07:00
2014-01-02 14:21:06 -07:00
var email = $('#txtEmail', form).val();
2013-02-20 18:33:05 -07:00
2014-05-18 12:58:42 -07:00
var url = "http://mb3admin.com/admin/service/supporter/retrievekey?email=" + email;
2013-02-20 18:33:05 -07:00
console.log(url);
$.post(url).done(function (res) {
var result = JSON.parse(res);
Dashboard.hideLoadingMsg();
if (result.Success) {
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('MessageKeyEmailedTo').replace("{0}", email));
2013-02-20 18:33:05 -07:00
} else {
Dashboard.showError(result.ErrorMessage);
}
console.log(result);
});
return false;
}
};
2015-05-20 09:28:55 -07:00
$(document).on('pageshowready', "#supporterKeyPage", SupporterKeyPage.onPageShow);
2015-03-16 22:58:29 -07:00
(function () {
2015-03-17 08:57:06 -07:00
var connectSupporterInfo;
function showAddUserForm(page) {
$('.popupAddUser', page).popup('open');
$('#selectUserToAdd', page).html(connectSupporterInfo.EligibleUsers.map(function (u) {
return '<option value="' + u.ConnectUserId + '">' + u.Name + '</option>';
}).join('')).selectmenu('refresh');
}
function addUser(page, id) {
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl('Connect/Supporters', {
Id: id
})
}).done(function () {
$('.popupAddUser', page).popup('close');
loadConnectSupporters(page);
});
}
2015-03-17 08:03:59 -07:00
function removeUser(page, id) {
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
Dashboard.confirm(Globalize.translate('MessageConfirmRemoveConnectSupporter'), Globalize.translate('HeaderConfirmRemoveUser'), function (result) {
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
if (result) {
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "DELETE",
url: ApiClient.getUrl('Connect/Supporters', {
Id: id
})
}).done(function () {
loadConnectSupporters(page);
});
}
});
}
function getUserHtml(user) {
var html = '';
html += '<li>';
html += '<a href="#">';
var imgUrl = user.ImageUrl || 'css/images/userflyoutdefault.png';
html += '<img src="' + imgUrl + '" />';
html += '<h3>';
2015-03-17 09:24:54 -07:00
html += (user.DisplayName || user.Name);
2015-03-17 08:03:59 -07:00
html += '</h3>';
html += '<p>';
html += user.Email;
html += '</p>';
html += '</a>';
html += '<a href="#" data-icon="delete" class="btnRemoveUser" data-id="' + user.Id + '">';
html += '</a>';
html += '</li>';
return html;
}
function renderUsers(page, result) {
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
$('.linkSupporterKeyMessage', page).html(Globalize.translate('MessageLinkYourSupporterKey', result.MaxUsers));
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
var html = '';
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
if (result.Users.length) {
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
html += '<ul data-role="listview" data-inset="true">';
2015-03-17 21:09:31 -07:00
html += '<li data-role="list-divider">' + Globalize.translate('HeaderUsers');
2015-03-17 08:03:59 -07:00
html += result.Users.map(getUserHtml).join('');
html += '</ul>';
}
var elem = $('.supporters', page).html(html).trigger('create');
$('.btnRemoveUser', elem).on('click', function () {
removeUser(page, this.getAttribute('data-id'));
});
}
function loadConnectSupporters(page) {
2015-03-17 08:57:06 -07:00
Dashboard.showLoadingMsg();
2015-03-17 08:03:59 -07:00
Dashboard.suppressAjaxErrors = true;
ApiClient.ajax({
type: "GET",
url: ApiClient.getUrl('Connect/Supporters'),
dataType: "json"
2015-03-16 22:58:29 -07:00
2015-03-17 08:03:59 -07:00
}).done(function (result) {
2015-03-16 22:58:29 -07:00
2015-03-17 08:57:06 -07:00
connectSupporterInfo = result;
2015-03-17 08:03:59 -07:00
renderUsers(page, result);
2015-03-16 22:58:29 -07:00
2015-03-17 08:57:06 -07:00
Dashboard.hideLoadingMsg();
2015-03-16 22:58:29 -07:00
}).fail(function () {
$('.supporters', page).html('<p>' + Globalize.translate('MessageErrorLoadingSupporterInfo') + '</p>');
}).always(function () {
Dashboard.suppressAjaxErrors = false;
});
}
2015-05-20 09:28:55 -07:00
$(document).on('pageinitdepends', "#supporterKeyPage", function () {
2015-03-17 08:57:06 -07:00
var page = this;
$('#btnAddConnectUser', page).on('click', function () {
showAddUserForm(page);
});
2015-05-20 09:28:55 -07:00
$('#supporterKeyForm').on('submit', SupporterKeyPage.updateSupporterKey);
$('#lostKeyForm').on('submit', SupporterKeyPage.retrieveSupporterKey);
$('#linkKeysForm').on('submit', SupporterKeyPage.linkSupporterKeys);
$('.popupAddUserForm').on('submit', SupporterKeyPage.onAddConnectUserSubmit).on('submit', SupporterKeyPage.onAddConnectUserSubmit);
}).on('pageshowready', "#supporterKeyPage", function () {
2015-03-16 22:58:29 -07:00
var page = this;
loadConnectSupporters(page);
});
2015-03-17 08:57:06 -07:00
window.SupporterKeyPage.onAddConnectUserSubmit = function () {
var page = $(this).parents('.page');
var id = $('#selectUserToAdd', page).val();
addUser(page, id);
return false;
};
2015-03-16 22:58:29 -07:00
})();