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

266 lines
9.0 KiB
JavaScript
Raw Normal View History

(function ($, document, window) {
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) {
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);
var packageVersion;
2013-05-13 08:55:59 -07:00
if (!installedPlugin) {
$('#pCurrentVersion', page).hide().html("");
}
// If we don't have a package version to select, pick the first release build
if (!packageVersion) {
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];
}
2013-05-13 08:55:59 -07:00
selectmenu.selectmenu('refresh');
if (packageVersion) {
var val = packageVersion.versionStr + '|' + packageVersion.classification;
2013-05-13 08:55:59 -07:00
selectmenu.val(val).selectmenu('refresh');
}
}
2013-02-20 18:33:05 -07:00
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-02-20 18:33:05 -07:00
Dashboard.setPageTitle(pkg.name);
if (pkg.targetSystem == 'Server') {
$("#btnInstallDiv", page).show();
$("#nonServerMsg", page).hide();
$("#pSelectVersion", page).show();
} else {
$("#btnInstallDiv", page).hide();
$("#pSelectVersion", page).hide();
var msg = "This plugin must be installed from ";
switch (pkg.targetSystem) {
case "MBClassic":
msg += "the MBClassic Configurator";
break;
default:
msg += pkg.targetSystem;
}
$("#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);
if (pkg.isPremium) {
$('.premiumPackage', page).show();
// Fill in registration info
var regStatus = "<strong>";
if (pkg.isRegistered) {
regStatus += "You are currently registered for this feature";
} else {
if (new Date(pkg.expDate).getTime() < new Date(1970, 1, 1).getTime()) {
} else {
2013-03-14 11:14:12 -07:00
if (new Date(pkg.expDate).getTime() <= new Date().getTime()) {
regStatus += "The trial period for this feature has expired";
2013-02-20 18:33:05 -07:00
} else {
regStatus += "The trial period for this feature will expire in " + Math.round((new Date(pkg.expDate).getTime() - new Date().getTime()) / (86400000)) + " day(s)";
}
}
}
regStatus += "</strong>";
$('#regStatus', page).html(regStatus);
if (pluginSecurityInfo.IsMBSupporter) {
$('#regInfo', page).html(pkg.regInfo || "");
if (pkg.price > 0) {
// Fill in PayPal info
2013-04-23 07:38:36 -07:00
$('.premiumHasPrice', page).show();
$('#featureId', page).val(pkg.featureId);
$('#featureName', page).val(pkg.name);
$('#amount', page).val(pkg.price);
$('#regPrice', page).html("<h2>Price: $" + pkg.price.toFixed(2) + " (USD)</h2>");
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();
$('#noEmail', page).show();
}
});
} else {
// Supporter-only feature
2013-04-23 07:38:36 -07:00
$('.premiumHasPrice', page).hide();
}
2013-02-20 18:33:05 -07:00
} else {
2013-08-31 09:36:31 -07:00
var pluginTypeHtml = pkg.price ? 'This is a <a data-rel="popup" data-position-to="window" href="#premiumPlugins">premium</a> plugin.' : 'This is a <a data-rel="popup" data-position-to="window" href="#supporterPlugins">supporter-only</a> plugin.';
2013-08-31 09:58:34 -07:00
$('#regInfo', page).html(pluginTypeHtml + '<br/><br/>It will require a <a href="supporter.html">supporter key</a> in order to register after the <strong>14-day free trial</strong>.').trigger('create');
2013-02-20 18:33:05 -07:00
$('#ppButton', page).hide();
}
} else {
$('.premiumPackage', page).hide();
}
if (pkg.richDescUrl) {
$('#pViewWebsite', page).show();
$('#pViewWebsite a', page)[0].href = pkg.richDescUrl;
} 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
var color = pkg.tileColor || "#2572EB";
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) {
$('#pCurrentVersion', page).show().html("You currently have version <strong>" + installedPlugin.Version + "</strong> installed.");
} else {
$('#pCurrentVersion', page).hide().html("");
}
Dashboard.hideLoadingMsg();
}
2013-02-20 18:33:05 -07:00
$(document).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');
2013-02-20 18:33:05 -07:00
var promise1 = ApiClient.getPackageInfo(name);
var promise2 = ApiClient.getInstalledPlugins();
var promise3 = ApiClient.getPluginSecurityInfo();
2013-02-20 18:33:05 -07:00
$.when(promise1, promise2, promise3).done(function (response1, response2, response3) {
2013-02-20 18:33:05 -07:00
renderPackage(response1[0], response2[0], response3[0], page);
2013-02-20 18:33:05 -07:00
});
2013-02-20 18:33:05 -07:00
});
2013-02-20 18:33:05 -07:00
function performInstallation(packageName, updateClass, version) {
2013-02-20 18:33:05 -07:00
ApiClient.installPlugin(packageName, updateClass, version).done(function () {
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
});
}
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
var page = $(this).parents('#addPluginPage');
2013-02-20 18:33:05 -07:00
$('#btnInstall', page).button('disable');
2013-02-20 18:33:05 -07:00
var name = getParameterByName('name');
2013-02-20 18:33:05 -07:00
ApiClient.getInstalledPlugins().done(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
Dashboard.confirm("Are you sure you wish to reinstall the same version you already have? In most cases this will not have any effect.", "Plugin Reinstallation", function (confirmResult) {
2013-02-20 18:33:05 -07:00
if (confirmResult) {
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
performInstallation(name, vals[1], version);
} else {
$('#btnInstall', page).button('enable');
}
2013-02-20 18:33:05 -07:00
});
} else {
performInstallation(name, 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();
})(jQuery, document, window);