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

222 lines
6.2 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-05-22 12:16:14 -07:00
var platform = (device.platform || '').toLowerCase();
2015-05-16 12:09:02 -07:00
2015-05-26 08:31:50 -07:00
return platform.indexOf('android') != -1;
}
function validatePlayback(deferred) {
2015-05-22 13:15:29 -07:00
// Don't require validation on android
2015-05-26 08:31:50 -07:00
if (isAndroid()) {
2015-05-22 12:16:14 -07:00
deferred.resolve();
return;
}
2015-05-16 12:09:02 -07:00
2015-05-26 08:31:50 -07:00
validateFeature({
2015-05-28 05:49:46 -07:00
id: 'premiumunlock'
2015-05-26 08:31:50 -07:00
}, deferred);
2015-05-22 12:16:14 -07:00
}
2015-05-16 12:09:02 -07:00
2015-05-22 12:16:14 -07:00
function validateLiveTV(deferred) {
2015-05-17 18:27:48 -07:00
2015-05-26 08:31:50 -07:00
// Don't require validation if not android
if (!isAndroid()) {
deferred.resolve();
return;
}
validateFeature({
2015-05-28 05:49:46 -07:00
id: 'premiumunlock'
2015-05-26 08:31:50 -07:00
}, deferred);
}
function validateSmb(deferred) {
2015-05-22 13:15:29 -07:00
// Don't require validation if not android
2015-05-26 08:31:50 -07:00
if (!isAndroid()) {
2015-05-22 13:15:29 -07:00
deferred.resolve();
return;
}
2015-05-26 08:31:50 -07:00
validateFeature({
2015-05-28 05:49:46 -07:00
id: 'premiumunlock'
2015-05-26 08:31:50 -07:00
}, deferred);
}
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-05-26 08:31:50 -07:00
function validateFeature(info, deferred) {
2015-05-28 05:49:46 -07:00
if (IapManager.hasPurchased(info.id)) {
2015-05-26 08:31:50 -07:00
deferred.resolve();
return;
}
2015-05-26 10:48:05 -07:00
var productInfo = {
enableSupporterUnlock: isAndroid(),
2015-05-28 05:49:46 -07:00
enableAppUnlock: IapManager.isPurchaseAvailable(info.id),
id: info.id
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) {
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;">';
html += '<form class="inAppPurchaseForm" style="margin: 0 auto;padding: 30px 1em 0;">';
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-05-28 05:49:46 -07:00
html += '<button class="btn btnActionAccent btnAppUnlock" data-role="none" type="submit"><span>' + Globalize.translate('ButtonUnlockWithPurchase') + '</span><i class="fa fa-check"></i></button>';
2015-05-26 10:48:05 -07:00
}
if (info.enableSupporterUnlock) {
html += '<button class="btn btnSignInSupporter" data-role="none" type="button"><span>' + Globalize.translate('ButtonUnlockWithSupporter') + '</span><i class="fa fa-check"></i></button>';
}
2015-05-26 08:31:50 -07:00
2015-05-26 10:48:05 -07:00
html += '<button class="btn btnCancel" data-role="none" type="button"><span>' + Globalize.translate('ButtonCancel') + '</span><i class="fa fa-close"></i></button>';
2015-05-26 08:31:50 -07:00
2015-05-26 10:48:05 -07:00
html += '</form>';
html += '</div>';
html += '</div>';
$(document.body).append(html);
return $('.inAppPurchaseOverlay');
}
function cancelInAppPurchase() {
$('.inAppPurchaseOverlay').remove();
}
function showInAppPurchaseInfo(info, serverRegistrationInfo, deferred) {
var elem = getInAppPurchaseElement(info);
$('.inAppPurchaseForm', elem).on('submit', function () {
2015-05-28 05:49:46 -07:00
IapManager.beginPurchase(info.id);
2015-05-26 10:48:05 -07:00
return false;
});
$('.btnCancel', elem).on('click', function () {
cancelInAppPurchase();
// For testing purposes
if (!info.enableSupporterUnlock && !info.enableAppUnlock) {
deferred.resolve();
} else {
deferred.reject();
}
});
$('.btnSignInSupporter', elem).on('click', function () {
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
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-05-22 12:16:14 -07:00
} else {
deferred.resolve();
}
return deferred.promise();
}
};
2015-05-28 05:49:46 -07:00
var depends = isAndroid() ? 'thirdparty/cordova/android/iap' : 'thirdparty/cordova/iap';
2015-05-26 08:31:50 -07:00
2015-05-28 05:49:46 -07:00
requirejs([depends]);
2015-05-26 08:31:50 -07:00
2015-05-22 12:16:14 -07:00
})();