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

295 lines
8.4 KiB
JavaScript
Raw Normal View History

2015-05-22 12:16:14 -07:00
(function () {
2015-05-16 12:09:02 -07:00
2015-05-26 08:31:50 -07:00
function isAndroid() {
2015-05-17 18:27:48 -07:00
2015-07-30 18:52:11 -07:00
return $.browser.android;
2015-05-26 08:31:50 -07:00
}
2015-05-31 14:07:44 -07:00
function getPremiumUnlockFeatureId() {
2015-05-26 08:31:50 -07:00
if (isAndroid()) {
2015-05-31 14:07:44 -07:00
return "com.mb.android.unlock";
2015-05-22 12:16:14 -07:00
}
2015-05-16 12:09:02 -07:00
2015-06-03 21:50:10 -07:00
return 'appunlock';
2015-05-22 12:16:14 -07:00
}
2015-05-16 12:09:02 -07:00
2015-05-31 14:07:44 -07:00
function validatePlayback(deferred) {
2015-05-17 18:27:48 -07:00
2015-05-31 14:07:44 -07:00
// Don't require validation on android
if (isAndroid()) {
2015-05-26 08:31:50 -07:00
deferred.resolve();
return;
}
2015-06-03 21:50:10 -07:00
validateFeature(getPremiumUnlockFeatureId(), deferred);
2015-05-26 08:31:50 -07:00
}
2015-05-31 14:07:44 -07:00
function validateLiveTV(deferred) {
2015-05-22 13:15:29 -07:00
2015-06-04 22:32:14 -07:00
if (!isAndroid()) {
deferred.resolve();
return;
}
2015-06-03 21:50:10 -07:00
validateFeature(getPremiumUnlockFeatureId(), deferred);
2015-05-26 08:31:50 -07:00
}
2015-06-07 14:21:30 -07:00
function validateServerManagement(deferred) {
deferred.resolve();
}
2015-05-26 10:48:05 -07:00
function getRegistrationInfo(feature, enableSupporterUnlock) {
if (!enableSupporterUnlock) {
var deferred = $.Deferred();
deferred.resolveWith(null, [{}]);
return deferred.promise();
}
return ConnectionManager.getRegistrationInfo(feature, ApiClient);
}
2015-06-03 21:50:10 -07:00
function validateFeature(id, deferred) {
var info = IapManager.getProductInfo(id) || {};
2015-05-26 08:31:50 -07:00
2015-06-03 21:50:10 -07:00
if (info.owned) {
2015-05-26 08:31:50 -07:00
deferred.resolve();
return;
}
2015-05-26 10:48:05 -07:00
var productInfo = {
enableSupporterUnlock: isAndroid(),
2015-06-03 21:50:10 -07:00
enableAppUnlock: IapManager.isPurchaseAvailable(id),
id: id,
price: info.price
2015-05-26 10:48:05 -07:00
};
2015-05-27 22:51:48 -07:00
var prefix = isAndroid() ? 'android' : 'ios';
2015-05-26 08:31:50 -07:00
// Get supporter status
2015-05-27 22:51:48 -07:00
getRegistrationInfo(prefix + 'appunlock', productInfo.enableSupporterUnlock).done(function (registrationInfo) {
2015-05-26 08:31:50 -07:00
if (registrationInfo.IsRegistered) {
deferred.resolve();
return;
}
2015-05-26 10:48:05 -07:00
showInAppPurchaseInfo(productInfo, registrationInfo, deferred);
2015-05-26 08:31:50 -07:00
}).fail(function () {
deferred.reject();
});
}
2015-05-26 10:48:05 -07:00
function getInAppPurchaseElement(info) {
2015-06-23 15:13:06 -07:00
require(['paperbuttonstyle']);
2015-05-26 10:48:05 -07:00
cancelInAppPurchase();
var html = '';
html += '<div class="inAppPurchaseOverlay" style="background-image:url(css/images/splash.jpg);top:0;left:0;right:0;bottom:0;position:fixed;background-position:center center;background-size:100% 100%;background-repeat:no-repeat;z-index:999999;">';
html += '<div class="inAppPurchaseOverlayInner" style="background:rgba(10,10,10,.8);width:100%;height:100%;color:#eee;">';
2015-06-03 21:50:10 -07:00
html += '<div class="inAppPurchaseForm" style="margin: 0 auto;padding: 30px 1em 0;">';
2015-05-26 10:48:05 -07:00
html += '<h1 style="color:#fff;">' + Globalize.translate('HeaderUnlockApp') + '</h1>';
html += '<p style="margin:2em 0;">';
if (info.enableSupporterUnlock && info.enableAppUnlock) {
html += Globalize.translate('MessageUnlockAppWithPurchaseOrSupporter');
}
else if (info.enableSupporterUnlock) {
html += Globalize.translate('MessageUnlockAppWithSupporter');
} else if (info.enableAppUnlock) {
html += Globalize.translate('MessageUnlockAppWithPurchase');
} else {
html += '<span style="color:red;">';
html += Globalize.translate('MessagePaymentServicesUnavailable');
html += '</span>';
}
html += '</p>';
if (info.enableSupporterUnlock) {
html += '<p style="margin:2em 0;">';
html += Globalize.translate('MessageToValidateSupporter');
html += '</p>';
}
if (info.enableAppUnlock) {
2015-06-03 21:50:10 -07:00
var unlockText = Globalize.translate('ButtonUnlockWithPurchase');
if (info.price) {
unlockText = Globalize.translate('ButtonUnlockPrice', info.price);
}
2015-06-23 15:13:06 -07:00
html += '<p>';
html += '<paper-button raised class="secondary block btnAppUnlock"><iron-icon icon="check"></iron-icon><span>' + unlockText + '</span></paper-button>';
html += '</p>';
2015-05-26 10:48:05 -07:00
}
if (info.enableSupporterUnlock) {
2015-06-23 15:13:06 -07:00
html += '<p>';
html += '<paper-button raised class="submit block btnSignInSupporter"><iron-icon icon="check"></iron-icon><span>' + Globalize.translate('ButtonUnlockWithSupporter') + '</span></paper-button>';
html += '</p>';
2015-05-26 10:48:05 -07:00
}
2015-05-26 08:31:50 -07:00
2015-06-23 15:13:06 -07:00
html += '<p>';
html += '<paper-button raised class="cancelDark block btnCancel"><iron-icon icon="close"></iron-icon><span>' + Globalize.translate('ButtonCancel') + '</span></paper-button>';
html += '</p>';
2015-05-26 08:31:50 -07:00
2015-06-03 21:50:10 -07:00
html += '</div>';
2015-05-26 10:48:05 -07:00
html += '</div>';
html += '</div>';
$(document.body).append(html);
return $('.inAppPurchaseOverlay');
}
function cancelInAppPurchase() {
$('.inAppPurchaseOverlay').remove();
}
2015-06-01 07:49:23 -07:00
var currentDisplayingProductInfo = null;
var currentDisplayingDeferred = null;
function clearCurrentDisplayingInfo() {
currentDisplayingProductInfo = null;
currentDisplayingDeferred = null;
}
2015-05-26 10:48:05 -07:00
function showInAppPurchaseInfo(info, serverRegistrationInfo, deferred) {
var elem = getInAppPurchaseElement(info);
2015-06-01 07:49:23 -07:00
currentDisplayingProductInfo = info;
currentDisplayingDeferred = deferred;
2015-06-03 21:50:10 -07:00
$('.btnAppUnlock', elem).on('click', function () {
2015-05-26 10:48:05 -07:00
2015-05-28 05:49:46 -07:00
IapManager.beginPurchase(info.id);
2015-05-26 10:48:05 -07:00
});
$('.btnCancel', elem).on('click', function () {
2015-06-01 07:49:23 -07:00
clearCurrentDisplayingInfo();
2015-05-26 10:48:05 -07:00
cancelInAppPurchase();
2015-06-03 21:50:10 -07:00
deferred.reject();
2015-05-26 10:48:05 -07:00
});
$('.btnSignInSupporter', elem).on('click', function () {
2015-06-01 07:49:23 -07:00
clearCurrentDisplayingInfo();
2015-05-26 10:48:05 -07:00
Dashboard.alert({
2015-05-26 12:53:12 -07:00
message: Globalize.translate('MessagePleaseSignInLocalNetwork'),
2015-05-26 10:48:05 -07:00
callback: function () {
cancelInAppPurchase();
Dashboard.logout();
}
});
});
2015-05-17 18:27:48 -07:00
}
2015-05-22 12:16:14 -07:00
2015-06-01 07:49:23 -07:00
function onProductUpdated(e, product) {
var currentInfo = currentDisplayingProductInfo;
var deferred = currentDisplayingDeferred;
if (currentInfo && deferred) {
if (product.owned && product.id == currentInfo.id) {
clearCurrentDisplayingInfo();
cancelInAppPurchase();
deferred.resolve();
}
}
}
2015-07-29 19:08:35 -07:00
function validateSync(deferred) {
Dashboard.getPluginSecurityInfo().done(function (pluginSecurityInfo) {
2015-07-29 20:02:37 -07:00
if (pluginSecurityInfo.IsMBSupporter) {
2015-07-29 19:08:35 -07:00
deferred.resolve();
return;
}
Dashboard.showLoadingMsg();
ApiClient.getRegistrationInfo('Sync').done(function (registrationInfo) {
Dashboard.hideLoadingMsg();
2015-07-29 20:02:37 -07:00
if (registrationInfo.IsRegistered) {
2015-07-29 19:08:35 -07:00
deferred.resolve();
return;
}
Dashboard.alert({
message: Globalize.translate('HeaderSyncRequiresSupporterMembershipAppVersion'),
title: Globalize.translate('HeaderSync')
});
}).fail(function () {
Dashboard.hideLoadingMsg();
Dashboard.alert({
message: Globalize.translate('ErrorValidatingSupporterInfo')
});
});
});
}
2015-05-22 12:16:14 -07:00
window.RegistrationServices = {
renderPluginInfo: function (page, pkg, pluginSecurityInfo) {
},
addRecurringFields: function (page, period) {
},
initSupporterForm: function (page) {
$('.recurringSubscriptionCancellationHelp', page).html('');
},
validateFeature: function (name) {
var deferred = DeferredBuilder.Deferred();
if (name == 'playback') {
2015-05-23 13:44:15 -07:00
validatePlayback(deferred);
2015-05-22 12:16:14 -07:00
} else if (name == 'livetv') {
2015-05-23 13:44:15 -07:00
validateLiveTV(deferred);
2015-06-07 14:21:30 -07:00
} else if (name == 'manageserver') {
validateServerManagement(deferred);
2015-07-29 19:08:35 -07:00
} else if (name == 'sync') {
validateSync(deferred);
2015-05-22 12:16:14 -07:00
} else {
deferred.resolve();
}
return deferred.promise();
}
};
2015-06-01 07:49:23 -07:00
function onIapManagerLoaded() {
Events.on(IapManager, 'productupdated', onProductUpdated);
}
2015-05-31 14:07:44 -07:00
if (isAndroid()) {
2015-06-19 21:48:45 -07:00
requirejs(['cordova/android/iap'], onIapManagerLoaded);
2015-05-31 14:07:44 -07:00
} else {
2015-06-19 21:48:45 -07:00
requirejs(['cordova/iap'], onIapManagerLoaded);
2015-05-31 14:07:44 -07:00
}
2015-05-26 08:31:50 -07:00
2015-05-22 12:16:14 -07:00
})();