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

221 lines
7.0 KiB
JavaScript
Raw Normal View History

2014-08-24 08:48:06 -07:00
(function () {
function addRecurringFields(period, page) {
2013-02-20 18:33:05 -07:00
// Add recurring fields to form
$("<input type='hidden' name='a3' class='pprecurring' />")
2014-08-24 08:48:06 -07:00
.attr('value', $('#donateAmt', page).val())
.appendTo("#payPalSupporterForm", page);
2014-08-24 08:48:06 -07:00
2014-08-16 22:38:13 -07:00
$("<input type='hidden' name='p3' value='1' class='pprecurring' />")
.appendTo("#payPalSupporterForm", page);
2014-08-24 08:48:06 -07:00
2014-09-10 18:57:11 -07:00
$("<input type='hidden' name='t3' value='" + period + "' class='pprecurring' />")
.appendTo("#payPalSupporterForm", page);
2014-08-24 08:48:06 -07:00
$("<input type='hidden' name='src' value='1' class='pprecurring' />")
.appendTo("#payPalSupporterForm", page);
2014-08-24 08:48:06 -07:00
$("<input type='hidden' name='sra' value='1' class='pprecurring' />")
.appendTo("#payPalSupporterForm", page);
2013-02-20 18:33:05 -07:00
//change command for subscriptions
2014-08-24 08:48:06 -07:00
$('#ppCmd', page).val('_xclick-subscriptions');
$('#payPalSupporterForm', page).trigger('create');
console.log($('#payPalSupporterForm', page).html());
2014-08-24 08:48:06 -07:00
}
function removeRecurringFields(page) {
2014-08-16 22:38:13 -07:00
$('.pprecurring', page).remove();
2014-08-24 08:48:06 -07:00
//change command back
2014-08-16 22:38:13 -07:00
$('#ppCmd', page).val('_xclick');
2014-08-24 08:48:06 -07:00
}
2014-08-31 12:15:33 -07:00
2014-08-27 11:55:51 -07:00
function setItemNumber(page, itemNumber) {
$('#ppItemNo', page).val(itemNumber);
}
2014-08-24 08:48:06 -07:00
function getDonationType(page) {
return $(".radioDonationType:checked", page).val();
}
2015-03-31 21:23:34 -07:00
var lifeTimeAmount = 59;
2014-09-03 18:44:40 -07:00
var dailyAmount = 1;
2014-09-29 21:47:30 -07:00
var monthlyAmount = 4;
2015-03-31 21:23:34 -07:00
var yearlyAmount = 32;
2014-08-24 08:48:06 -07:00
function getDonationAmount(page) {
var type = getDonationType(page);
if (type == 'once') {
return $("#selectOneTimeDonationAmount", page).val();
}
if (type == 'yearly') {
return yearlyAmount;
}
if (type == 'monthly') {
return monthlyAmount;
}
2014-09-03 18:44:40 -07:00
if (type == 'daily') {
return dailyAmount;
}
2014-08-24 08:48:06 -07:00
// lifetime
return lifeTimeAmount;
}
function updateSavedDonationAmount(page) {
$("#donateAmt", page).val(getDonationAmount(page));
}
2014-08-31 12:15:33 -07:00
function loadUserInfo(page) {
ApiClient.getJSON(ApiClient.getUrl('System/SupporterInfo')).done(function (info) {
$('.hfPlanType', page).val(info.PlanType || '');
$('.hfIsActive', page).val(info.IsActiveSupporter.toString());
$('.radioDonationType', page).checked(false).checkboxradio('refresh');
if (info.PlanType == 'Lifetime' && info.IsActiveSupporter) {
// If they have an active lifetime plan, select the one-time option
$('#radioOneTimeDonation', page).checked(true).checkboxradio('refresh');
} else {
// For all other statuses, select lifetime, to either acquire or upgrade
$('#radioLifetimeSupporter', page).checked(true).checkboxradio('refresh');
}
$('.radioDonationType:checked', page).trigger('change');
if (info.IsActiveSupporter || info.IsExpiredSupporter) {
$('.currentPlanInfo', page).show();
} else {
$('.currentPlanInfo', page).hide();
}
if (info.IsActiveSupporter && info.PlanType == 'Lifetime') {
$('.planSummary', page)
2014-09-10 18:57:11 -07:00
.html(Globalize.translate('MessageYouHaveALifetimeMembership'))
2015-01-11 11:36:26 -07:00
.css('color', 'green');
2014-08-31 12:15:33 -07:00
}
else if (info.IsActiveSupporter) {
$('.planSummary', page)
2014-09-10 18:57:11 -07:00
.html(Globalize.translate('MessageYouHaveAnActiveRecurringMembership').replace('{0}', info.PlanType))
2015-01-11 11:36:26 -07:00
.css('color', 'green');
2014-08-31 12:15:33 -07:00
}
else if (info.IsExpiredSupporter) {
var expirationDate = info.ExpirationDate ? parseISO8601Date(info.ExpirationDate, { toLocal: true }) : new Date();
expirationDate = expirationDate.toLocaleDateString();
$('.planSummary', page)
2014-09-10 18:57:11 -07:00
.html(Globalize.translate('MessageSupporterMembershipExpiredOn').replace('{0}', expirationDate))
2014-08-31 12:15:33 -07:00
.css('color', 'red');
}
});
}
2014-08-24 08:48:06 -07:00
$(document).on('pageinit', "#supporterPage", function () {
2014-08-24 08:48:06 -07:00
var page = this;
$('.radioDonationType', page).on('change', function () {
var donationType = getDonationType(page);
updateSavedDonationAmount(page);
if (donationType == 'once') {
$('.fldOneTimeDonationAmount', page).show();
removeRecurringFields(page);
2014-08-27 11:55:51 -07:00
setItemNumber(page, 'MBDonation');
$('#oneTimeDescription').show();
2014-08-24 08:48:06 -07:00
}
else if (donationType == 'yearly') {
$('.fldOneTimeDonationAmount', page).hide();
addRecurringFields('Y', page);
2014-08-27 11:55:51 -07:00
setItemNumber(page, 'MBSClubYearly');
$('#oneTimeDescription').hide();
2014-08-24 08:48:06 -07:00
}
else if (donationType == 'monthly') {
$('.fldOneTimeDonationAmount', page).hide();
addRecurringFields('M', page);
2014-08-27 11:55:51 -07:00
setItemNumber(page, 'MBSClubMonthly');
$('#oneTimeDescription').hide();
2014-08-24 08:48:06 -07:00
}
2014-09-03 18:44:40 -07:00
else if (donationType == 'daily') {
$('.fldOneTimeDonationAmount', page).hide();
addRecurringFields('D', page);
setItemNumber(page, 'MBSClubDaily');
$('#oneTimeDescription').hide();
}
2014-08-24 08:48:06 -07:00
else {
// Lifetime
$('.fldOneTimeDonationAmount', page).hide();
removeRecurringFields(page);
2014-08-27 11:55:51 -07:00
setItemNumber(page, 'MBSupporter');
2014-08-31 12:26:01 -07:00
$('#oneTimeDescription').hide();
2014-08-24 08:48:06 -07:00
}
});
$('#selectOneTimeDonationAmount', page).on('change', function () {
updateSavedDonationAmount(page);
});
}).on('pageshow', "#supporterPage", function () {
var page = this;
$('.lifetimeAmount', page).html('$' + lifeTimeAmount);
$('.monthlyAmount', page).html('$' + monthlyAmount);
2014-09-03 18:44:40 -07:00
$('.dailyAmount', page).html('$' + dailyAmount);
2014-08-24 08:48:06 -07:00
$('.yearlyAmount', page).html('$' + yearlyAmount);
$('#paypalReturnUrl', page).val(ApiClient.getUrl("supporterkey.html"));
2014-08-24 08:48:06 -07:00
$('.radioDonationType', page).trigger('change');
2013-02-20 18:33:05 -07:00
2015-03-21 11:12:12 -07:00
$('.benefits', page).html(Globalize.translate('HeaderSupporterBenefit', '<a href="http://emby.media/donate" target="_blank">', '</a>')).trigger('create');
2015-01-11 11:36:26 -07:00
2014-08-31 12:15:33 -07:00
loadUserInfo(page);
2014-08-24 08:48:06 -07:00
});
2013-02-20 18:33:05 -07:00
2014-08-31 12:15:33 -07:00
window.SupporterPage = {
onSubmit: function () {
var form = this;
var page = $(form).parents('.page');
if ($('.hfIsActive', page).val() == 'true') {
var currentPlanType = $('.hfPlanType', page).val();
if (currentPlanType != 'Lifetime') {
// Use a regular alert to block the submission process until they hit ok
2014-09-10 18:57:11 -07:00
alert(Globalize.translate('MessageChangeRecurringPlanConfirm'));
2014-08-31 12:15:33 -07:00
}
}
}
};
2014-08-24 08:48:06 -07:00
})();