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

414 lines
14 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-02-20 18:33:05 -07:00
function populateHistory(packageInfo, page) {
2013-02-20 18:33:05 -07:00
var html = '';
2013-02-20 18:33:05 -07:00
for (var i = 0, length = Math.min(packageInfo.versions.length, 10) ; i < length; i++) {
2013-02-20 18:33:05 -07:00
var version = packageInfo.versions[i];
2013-02-20 18:33:05 -07:00
html += '<h2 style="margin:.5em 0;">' + version.versionStr + ' (' + version.classification + ')</h2>';
2013-02-20 18:33:05 -07:00
html += '<div style="margin-bottom:1.5em;">' + version.description + '</div>';
}
2013-02-20 18:33:05 -07:00
$('#revisionHistory', page).html(html);
}
2013-02-20 18:33:05 -07:00
function populateVersions(packageInfo, page, installedPlugin) {
2015-06-19 15:01:47 -07:00
var html = '';
for (var i = 0, length = packageInfo.versions.length; i < length; i++) {
var version = packageInfo.versions[i];
html += '<option value="' + version.versionStr + '|' + version.classification + '">' + version.versionStr + ' (' + version.classification + ')</option>';
}
var selectmenu = $('#selectVersion', page).html(html);
2013-05-13 08:55:59 -07:00
if (!installedPlugin) {
$('#pCurrentVersion', page).hide().html("");
}
var packageVersion = packageInfo.versions.filter(function (current) {
return current.classification == "Release";
})[0];
// If we still don't have a package version to select, pick the first Beta build
if (!packageVersion) {
packageVersion = packageInfo.versions.filter(function (current) {
return current.classification == "Beta";
})[0];
}
if (packageVersion) {
var val = packageVersion.versionStr + '|' + packageVersion.classification;
2015-09-03 10:01:51 -07:00
selectmenu.val(val);
}
}
2014-01-02 14:21:06 -07:00
2013-11-08 13:53:09 -07:00
function populateReviews(id, page) {
2015-12-14 08:43:03 -07:00
ApiClient.getPackageReviews(id, null, null, 3).then(function (positive) {
2014-08-31 12:15:33 -07:00
var html = '';
2014-01-02 14:21:06 -07:00
2013-11-08 13:53:09 -07:00
if (positive && positive.length > 0) {
2014-08-31 12:15:33 -07:00
2016-07-15 12:54:22 -07:00
html += '<div style="margin-top: 2em;" >';
2014-08-31 12:15:33 -07:00
html += '<h3>' + Globalize.translate('HeaderLatestReviews') + '</h3>';
html += "<div><br/>";
2013-11-08 13:53:09 -07:00
for (var i = 0; i < positive.length; i++) {
var review = positive[i];
2014-08-31 12:15:33 -07:00
html += "<div>";
2016-08-10 20:55:44 -07:00
html += "<span class='storeItemReviewText' style='display:inline-flex;align-items:center;'>";
2014-08-31 12:15:33 -07:00
html += new Date(review.timestamp).toDateString();
2016-05-12 12:21:43 -07:00
if (review.rating) {
2016-08-10 20:55:44 -07:00
html += '<i class="md-icon" style="color:#cc3333;height:auto;width:auto;margin-left:.5em;">star</i>';
2016-05-12 12:21:43 -07:00
html += review.rating.toFixed(1);
}
2014-08-31 12:15:33 -07:00
html += " " + review.title;
html += "</span>";
if (review.review) {
html += "<p class='storeItemReviewText'>";
html += review.review;
html += "</p>";
2013-11-08 13:53:09 -07:00
}
2014-08-31 12:15:33 -07:00
html += "</div>";
html += "<hr/>";
2013-11-08 13:53:09 -07:00
}
2014-08-31 12:15:33 -07:00
html += "</div>";
html += "</div>";
2013-11-08 13:53:09 -07:00
}
2014-01-02 14:21:06 -07:00
2015-12-23 10:46:01 -07:00
$('#latestReviews', page).html(html).trigger('create');
2013-11-08 13:53:09 -07:00
});
}
2013-02-20 18:33:05 -07:00
2016-08-16 13:54:13 -07:00
function renderPluginInfo(page, pkg, pluginSecurityInfo) {
if (AppInfo.isNativeApp) {
return;
}
require(['jQuery'], function ($) {
if (pkg.isPremium) {
$('.premiumPackage', page).show();
// Fill in registration info
var regStatus = "";
if (pkg.isRegistered) {
regStatus += "<p style='color:green;'>";
regStatus += Globalize.translate('MessageFeatureIncludedWithSupporter');
} else {
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));
}
}
regStatus += "</p>";
$('#regStatus', page).html(regStatus);
if (pluginSecurityInfo.IsMBSupporter) {
$('#regInfo', page).html(pkg.regInfo || "");
$('.premiumDescription', page).hide();
$('.supporterDescription', page).hide();
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>");
$('#ppButton', page).hide();
var url = "https://mb3admin.com/admin/service/user/getPayPalEmail?id=" + pkg.owner;
fetch(url).then(function (response) {
return response.json();
}).then(function (dev) {
if (dev.payPalEmail) {
$('#payPalEmail', page).val(dev.payPalEmail);
$('#ppButton', page).show();
}
});
} else {
// Supporter-only feature
$('.premiumHasPrice', page).hide();
}
} else {
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();
}
} else {
$('.premiumPackage', page).hide();
}
});
}
function renderPackage(pkg, installedPlugins, pluginSecurityInfo, page) {
2013-02-20 18:33:05 -07:00
var installedPlugin = installedPlugins.filter(function (ip) {
return ip.Name == pkg.name;
})[0];
populateVersions(pkg, page, installedPlugin);
populateHistory(pkg, page);
2013-11-08 13:53:09 -07:00
if (pkg.totalRatings > 0) populateReviews(pkg.id, page);
2014-01-02 14:21:06 -07:00
2014-07-10 21:27:46 -07:00
$('.pluginName', page).html(pkg.name);
2013-02-20 18:33:05 -07:00
if (pkg.targetSystem == 'Server') {
2015-12-14 08:43:03 -07:00
$("#btnInstallDiv", page).removeClass('hide');
$("#nonServerMsg", page).hide();
2015-12-14 08:43:03 -07:00
$("#pSelectVersion", page).removeClass('hide');
} else {
2015-12-14 08:43:03 -07:00
$("#btnInstallDiv", page).addClass('hide');
$("#pSelectVersion", page).addClass('hide');
2014-08-31 12:15:33 -07:00
var msg = Globalize.translate('MessageInstallPluginFromApp');
$("#nonServerMsg", page).html(msg).show();
}
2013-02-20 18:33:05 -07:00
if (pkg.shortDescription) {
$('#tagline', page).show().html(pkg.shortDescription);
} else {
$('#tagline', page).hide();
}
$('#overview', page).html(pkg.overview || "");
$('#developer', page).html(pkg.owner);
2016-08-16 13:54:13 -07:00
renderPluginInfo(page, pkg, pluginSecurityInfo);
2014-01-02 14:21:06 -07:00
2013-11-08 13:53:09 -07:00
//Ratings and Reviews
2016-05-12 12:21:43 -07:00
var ratingHtml = '';
if (pkg.avgRating) {
2016-08-10 20:55:44 -07:00
ratingHtml += '<i class="md-icon" style="color:#cc3333;height:auto;width:auto;">star</i>';
2016-05-12 12:21:43 -07:00
ratingHtml += pkg.avgRating.toFixed(1);
}
ratingHtml += "<span>";
2014-08-31 12:15:33 -07:00
ratingHtml += " " + Globalize.translate('ValueReviewCount').replace('{0}', pkg.totalRatings);
2013-11-08 13:53:09 -07:00
ratingHtml += "</span>";
$('#ratingLine', page).html(ratingHtml);
2013-02-20 18:33:05 -07:00
if (pkg.richDescUrl) {
$('#pViewWebsite', page).show();
2015-08-14 18:10:07 -07:00
$('#pViewWebsite a', page).attr('href', pkg.richDescUrl);
2013-02-20 18:33:05 -07:00
} else {
$('#pViewWebsite', page).hide();
}
2013-05-11 23:05:51 -07:00
if (pkg.previewImage || pkg.thumbImage) {
2013-02-20 18:33:05 -07:00
2014-02-12 22:11:54 -07:00
var color = pkg.tileColor || "#38c";
2013-02-20 18:33:05 -07:00
var img = pkg.previewImage ? pkg.previewImage : pkg.thumbImage;
$('#pPreviewImage', page).show().html("<img src='" + img + "' style='max-width: 100%;-moz-box-shadow: 0 0 20px 3px " + color + ";-webkit-box-shadow: 0 0 20px 3px " + color + ";box-shadow: 0 0 20px 3px " + color + ";' />");
2013-02-20 18:33:05 -07:00
} else {
$('#pPreviewImage', page).hide().html("");
}
if (installedPlugin) {
2014-08-31 12:15:33 -07:00
var currentVersionText = Globalize.translate('MessageYouHaveVersionInstalled').replace('{0}', '<strong>' + installedPlugin.Version + '</strong>');
$('#pCurrentVersion', page).show().html(currentVersionText);
2013-02-20 18:33:05 -07:00
} else {
$('#pCurrentVersion', page).hide().html("");
}
Dashboard.hideLoadingMsg();
}
2013-02-20 18:33:05 -07:00
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#addPluginPage", function () {
2015-06-09 21:01:14 -07:00
$('.addPluginForm').off('submit', AddPluginPage.onSubmit).on('submit', AddPluginPage.onSubmit);
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#addPluginPage", function () {
2013-02-20 18:33:05 -07:00
var page = this;
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
var name = getParameterByName('name');
var guid = getParameterByName('guid');
2013-02-20 18:33:05 -07:00
var promise1 = ApiClient.getPackageInfo(name, guid);
var promise2 = ApiClient.getInstalledPlugins();
var promise3 = ApiClient.getPluginSecurityInfo();
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2, promise3]).then(function (responses) {
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
renderPackage(responses[0], responses[1], responses[2], page);
2013-02-20 18:33:05 -07:00
});
2013-02-20 18:33:05 -07:00
2015-03-30 12:57:37 -07:00
}).on('pagebeforeshow pageinit pageshow', "#addPluginPage", function () {
2015-03-08 10:34:02 -07:00
// This needs both events for the helpurl to get done at the right time
2015-03-08 10:34:02 -07:00
var page = this;
var context = getParameterByName('context');
2015-04-05 20:47:01 -07:00
$('.notificationsTabs', page).hide();
2015-03-08 10:34:02 -07:00
if (context == 'sync') {
page.setAttribute('data-helpurl', 'https://github.com/MediaBrowser/Wiki/wiki/Sync');
LibraryMenu.setTitle(Globalize.translate('TitleSync'));
}
else if (context == 'livetv') {
LibraryMenu.setTitle(Globalize.translate('TitleLiveTV'));
page.setAttribute('data-helpurl', 'https://github.com/MediaBrowser/Wiki/wiki/Live%20TV');
}
2015-04-05 20:47:01 -07:00
else if (context == 'notifications') {
$('.notificationsTabs', page).show();
LibraryMenu.setTitle(Globalize.translate('TitleNotifications'));
2015-04-05 20:47:01 -07:00
page.setAttribute('data-helpurl', 'https://github.com/MediaBrowser/Wiki/wiki/Notifications');
}
else {
2015-03-08 10:34:02 -07:00
page.setAttribute('data-helpurl', 'https://github.com/MediaBrowser/Wiki/wiki/Plugins');
LibraryMenu.setTitle(Globalize.translate('TitlePlugins'));
2015-03-08 10:34:02 -07:00
}
});
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
function performInstallation(page, packageName, guid, updateClass, version) {
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
var developer = $('#developer', page).html().toLowerCase();
var alertCallback = function (confirmed) {
if (confirmed) {
Dashboard.showLoadingMsg();
2016-04-03 10:34:52 -07:00
page.querySelector('#btnInstall').disabled = true;
2015-12-14 08:43:03 -07:00
ApiClient.installPlugin(packageName, guid, updateClass, version).then(function () {
Dashboard.hideLoadingMsg();
});
}
};
if (developer != 'luke' && developer != 'ebr') {
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
2015-12-14 08:43:03 -07:00
var msg = Globalize.translate('MessagePluginInstallDisclaimer');
msg += '<br/>';
msg += '<br/>';
msg += Globalize.translate('PleaseConfirmPluginInstallation');
2016-02-22 12:31:28 -07:00
require(['confirm'], function (confirm) {
confirm(msg, Globalize.translate('HeaderConfirmPluginInstallation')).then(function () {
alertCallback(true);
}, function () {
alertCallback(false);
});
});
2015-12-14 08:43:03 -07:00
} else {
alertCallback(true);
}
}
2013-02-20 18:33:05 -07:00
function addPluginpage() {
2013-02-20 18:33:05 -07:00
var self = this;
2013-02-20 18:33:05 -07:00
self.onSubmit = function () {
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2016-02-14 11:32:29 -07:00
var page = $(this).parents('#addPluginPage')[0];
2013-02-20 18:33:05 -07:00
var name = getParameterByName('name');
var guid = getParameterByName('guid');
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getInstalledPlugins().then(function (plugins) {
2013-02-20 18:33:05 -07:00
var installedPlugin = plugins.filter(function (ip) {
return ip.Name == name;
})[0];
2013-02-20 18:33:05 -07:00
var vals = $('#selectVersion', page).val().split('|');
2013-02-20 18:33:05 -07:00
var version = vals[0];
2013-02-20 18:33:05 -07:00
if (installedPlugin && installedPlugin.Version == version) {
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
2014-08-31 12:15:33 -07:00
Dashboard.alert({
message: Globalize.translate('MessageAlreadyInstalled'),
title: Globalize.translate('HeaderPluginInstallation')
});
} else {
2015-12-14 08:43:03 -07:00
performInstallation(page, name, guid, vals[1], version);
}
});
2013-02-20 18:33:05 -07:00
return false;
};
2013-02-20 18:33:05 -07:00
}
window.AddPluginPage = new addPluginpage();
});