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

204 lines
7.3 KiB
JavaScript
Raw Normal View History

2015-07-26 22:03:34 -07:00
(function () {
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
var supporterPlaybackKey = 'lastSupporterPlaybackMessage2';
2015-05-17 18:27:48 -07:00
2015-07-26 22:03:34 -07:00
function validatePlayback(deferred) {
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
Dashboard.getPluginSecurityInfo().done(function (pluginSecurityInfo) {
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
if (pluginSecurityInfo.IsMBSupporter) {
deferred.resolve();
2015-05-16 12:09:02 -07:00
} else {
2015-07-26 22:03:34 -07:00
var lastMessage = parseInt(appStorage.getItem(supporterPlaybackKey) || '0');
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
if (!lastMessage) {
// Don't show on the very first playback attempt
appStorage.setItem(supporterPlaybackKey, new Date().getTime());
deferred.resolve();
2015-05-16 12:09:02 -07:00
}
2015-09-07 21:22:38 -07:00
else if ((new Date().getTime() - lastMessage) > 345600000) {
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
showPlaybackOverlay(deferred);
} else {
deferred.resolve();
2015-05-16 12:09:02 -07:00
}
}
2015-07-26 22:03:34 -07:00
});
}
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
function showPlaybackOverlay(deferred) {
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
require(['paperbuttonstyle']);
var html = '';
html += '<div class="supporterInfoOverlay" style="top: 0;left: 0;right: 0;bottom: 0;position: fixed;background-color:#1c1c1c;background-image: url(css/images/splash.jpg);background-position: center center;background-size: 100% 100%;background-repeat: no-repeat;z-index:1097;">';
html += '<div style="background:rgba(0,0,0,.82);top: 0;left: 0;right: 0;bottom: 0;position: fixed;z-index:1098;font-size:14px;">';
html += '<div class="readOnlyContent" style="margin:20px auto 0;color:#fff;padding:1em;">';
html += '<h1>' + Globalize.translate('HeaderTryCinemaMode') + '</h1>';
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
html += '<p>' + Globalize.translate('MessageDidYouKnowCinemaMode') + '</p>';
html += '<p>' + Globalize.translate('MessageDidYouKnowCinemaMode2') + '</p>';
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
html += '<br/>';
2015-05-16 12:09:02 -07:00
2015-10-01 09:28:24 -07:00
html += '<a class="clearLink" href="http://emby.media/premiere" target="_blank"><paper-button raised class="submit block"><iron-icon icon="check"></iron-icon><span>' + Globalize.translate('ButtonBecomeSupporter') + '</span></paper-button></a>';
2015-07-26 22:03:34 -07:00
html += '<paper-button raised class="subdued block btnCancelSupporterInfo" style="background:#444;"><iron-icon icon="close"></iron-icon><span>' + Globalize.translate('ButtonClosePlayVideo') + '</span></paper-button>';
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
html += '</div>';
html += '</div>';
html += '</div>';
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
$(document.body).append(html);
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
$('.btnCancelSupporterInfo').on('click', function () {
$('.supporterInfoOverlay').remove();
appStorage.setItem(supporterPlaybackKey, new Date().getTime());
deferred.resolve();
});
}
2015-07-29 19:08:35 -07:00
function validateSync(deferred) {
Dashboard.getPluginSecurityInfo().done(function (pluginSecurityInfo) {
if (pluginSecurityInfo.IsMBSupporter) {
deferred.resolve();
return;
}
Dashboard.showLoadingMsg();
ApiClient.getRegistrationInfo('Sync').done(function (registrationInfo) {
Dashboard.hideLoadingMsg();
if (registrationInfo.IsRegistered) {
deferred.resolve();
return;
}
Dashboard.alert({
2015-10-01 09:28:24 -07:00
message: Globalize.translate('HeaderSyncRequiresSupporterMembership') + '<br/><p><a href="http://emby.media/premiere" target="_blank">' + Globalize.translate('ButtonLearnMore') + '</a></p>',
2015-07-29 19:08:35 -07:00
title: Globalize.translate('HeaderSync')
});
}).fail(function () {
Dashboard.hideLoadingMsg();
Dashboard.alert({
message: Globalize.translate('ErrorValidatingSupporterInfo')
});
});
});
}
2015-07-26 22:03:34 -07:00
window.RegistrationServices = {
renderPluginInfo: function (page, pkg, pluginSecurityInfo) {
if (pkg.isPremium) {
$('.premiumPackage', page).show();
// Fill in registration info
var regStatus = "";
if (pkg.isRegistered) {
regStatus += "<p style='color:green;'>";
regStatus += Globalize.translate('MessageFeatureIncludedWithSupporter');
2015-05-16 12:09:02 -07:00
} else {
2015-07-26 22:03:34 -07:00
var expDateTime = new Date(pkg.expDate).getTime();
var nowTime = new Date().getTime();
if (expDateTime <= nowTime) {
regStatus += "<p style='color:red;'>";
regStatus += Globalize.translate('MessageTrialExpired');
}
else if (expDateTime > new Date(1970, 1, 1).getTime()) {
regStatus += "<p style='color:blue;'>";
regStatus += Globalize.translate('MessageTrialWillExpireIn').replace('{0}', Math.round(expDateTime - nowTime) / (86400000));
}
2015-05-16 12:09:02 -07:00
}
2015-07-26 22:03:34 -07:00
regStatus += "</p>";
$('#regStatus', page).html(regStatus);
if (pluginSecurityInfo.IsMBSupporter) {
$('#regInfo', page).html(pkg.regInfo || "");
$('.premiumDescription', page).hide();
2015-05-16 12:09:02 -07:00
$('.supporterDescription', page).hide();
2015-07-26 22:03:34 -07:00
if (pkg.price > 0) {
$('.premiumHasPrice', page).show();
$('#featureId', page).val(pkg.featureId);
$('#featureName', page).val(pkg.name);
$('#amount', page).val(pkg.price);
$('#regPrice', page).html("<h3>" + Globalize.translate('ValuePriceUSD').replace('{0}', "$" + pkg.price.toFixed(2)) + "</h3>");
var url = "http://mb3admin.com/admin/service/user/getPayPalEmail?id=" + pkg.owner;
$.getJSON(url).done(function (dev) {
if (dev.payPalEmail) {
$('#payPalEmail', page).val(dev.payPalEmail);
} else {
$('#ppButton', page).hide();
}
});
} else {
// Supporter-only feature
$('.premiumHasPrice', page).hide();
}
2015-05-16 12:09:02 -07:00
} else {
2015-07-26 22:03:34 -07:00
if (pkg.price) {
$('.premiumDescription', page).show();
$('.supporterDescription', page).hide();
$('#regInfo', page).html("");
} else {
$('.premiumDescription', page).hide();
$('.supporterDescription', page).show();
$('#regInfo', page).html("");
}
$('#ppButton', page).hide();
2015-05-16 12:09:02 -07:00
}
2015-07-26 22:03:34 -07:00
} else {
$('.premiumPackage', page).hide();
2015-05-16 12:09:02 -07:00
}
2015-07-26 22:03:34 -07:00
},
2015-05-16 12:09:02 -07:00
2015-07-26 22:03:34 -07:00
validateFeature: function (name) {
2015-05-22 12:16:14 -07:00
2015-07-26 22:03:34 -07:00
var deferred = DeferredBuilder.Deferred();
if (name == 'playback') {
validatePlayback(deferred);
} else if (name == 'livetv') {
deferred.resolve();
2015-07-29 19:08:35 -07:00
} else if (name == 'sync') {
validateSync(deferred);
2015-07-26 22:03:34 -07:00
} else {
deferred.resolve();
}
return deferred.promise();
}
};
})();