1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

re factored add plugin page to new js format

This commit is contained in:
Luke Pulverenti 2013-04-24 17:01:48 -04:00
parent 097653775a
commit cc244c60e0

View file

@ -1,32 +1,86 @@
var AddPluginPage = { (function ($, document, window) {
onPageShow: function () { function populateHistory(packageInfo, page) {
var page = this; var html = '';
Dashboard.showLoadingMsg(); for (var i = 0, length = Math.min(packageInfo.versions.length, 10) ; i < length; i++) {
var name = getParameterByName('name'); var version = packageInfo.versions[i];
var promise1 = ApiClient.getPackageInfo(name); html += '<h2 style="margin:.5em 0;">' + version.versionStr + ' (' + version.classification + ')</h2>';
var promise2 = ApiClient.getInstalledPlugins();
var promise3 = ApiClient.getPluginSecurityInfo();
$.when(promise1, promise2, promise3).done(function (response1, response2, response3) { html += '<div style="margin-bottom:1.5em;">' + version.description + '</div>';
}
AddPluginPage.renderPackage(response1[0], response2[0], response3[0], page); $('#revisionHistory', page).html(html);
}
}); function populateVersions(packageInfo, page, installedPlugin) {
}, var html = '';
renderPackage: function (pkg, installedPlugins, pluginSecurityInfo, page) { 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;
if (installedPlugin) {
// Select the first available package with the same update class as the installed version
packageVersion = packageInfo.versions.filter(function (current) {
return current.classification == installedPlugin.UpdateClass;
})[0];
} else {
$('#pCurrentVersion', page).hide().html("");
}
// If we don't have a package version to select, pick the first release build
if (!packageVersion) {
// Select the first available package with the same update class as the installed version
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) {
// Select the first available package with the same update class as the installed version
packageVersion = packageInfo.versions.filter(function (current) {
return current.classification == "Beta";
})[0];
}
if (packageVersion) {
var val = packageVersion.versionStr + '|' + packageVersion.classification;
$('#selectVersion', page).val(val);
}
selectmenu.selectmenu('refresh');
}
function renderPackage(pkg, installedPlugins, pluginSecurityInfo, page) {
var installedPlugin = installedPlugins.filter(function (ip) { var installedPlugin = installedPlugins.filter(function (ip) {
return ip.Name == pkg.name; return ip.Name == pkg.name;
})[0]; })[0];
AddPluginPage.populateVersions(pkg, page, installedPlugin); populateVersions(pkg, page, installedPlugin);
AddPluginPage.populateHistory(pkg); populateHistory(pkg, page);
Dashboard.setPageTitle(pkg.name); Dashboard.setPageTitle(pkg.name);
@ -129,87 +183,47 @@
} }
Dashboard.hideLoadingMsg(); Dashboard.hideLoadingMsg();
},
populateVersions: function (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); $(document).on('pageshow', "#addPluginPage", function () {
var packageVersion; var page = this;
if (installedPlugin) {
// Select the first available package with the same update class as the installed version
packageVersion = packageInfo.versions.filter(function (current) {
return current.classification == installedPlugin.UpdateClass;
})[0];
} else {
$('#pCurrentVersion', page).hide().html("");
}
// If we don't have a package version to select, pick the first release build
if (!packageVersion) {
// Select the first available package with the same update class as the installed version
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) {
// Select the first available package with the same update class as the installed version
packageVersion = packageInfo.versions.filter(function (current) {
return current.classification == "Beta";
})[0];
}
if (packageVersion) {
var val = packageVersion.versionStr + '|' + packageVersion.classification;
$('#selectVersion', page).val(val);
}
selectmenu.selectmenu('refresh');
},
populateHistory: function (packageInfo) {
var html = '';
for (var i = 0, length = Math.min(packageInfo.versions.length, 10) ; i < length; i++) {
var version = packageInfo.versions[i];
html += '<h2 style="margin:.5em 0;">' + version.versionStr + ' (' + version.classification + ')</h2>';
html += '<div style="margin-bottom:1.5em;">' + version.description + '</div>';
}
$('#revisionHistory', $.mobile.activePage).html(html);
},
onSubmit: function () {
Dashboard.showLoadingMsg(); Dashboard.showLoadingMsg();
$('#btnInstall', $.mobile.activePage).button('disable'); var name = getParameterByName('name');
var promise1 = ApiClient.getPackageInfo(name);
var promise2 = ApiClient.getInstalledPlugins();
var promise3 = ApiClient.getPluginSecurityInfo();
$.when(promise1, promise2, promise3).done(function (response1, response2, response3) {
renderPackage(response1[0], response2[0], response3[0], page);
});
});
function performInstallation(packageName, updateClass, version) {
ApiClient.installPlugin(packageName, updateClass, version).done(function () {
Dashboard.hideLoadingMsg();
});
}
function addPluginpage() {
var self = this;
self.onSubmit = function () {
Dashboard.showLoadingMsg();
var page = $(this).parents('#addPluginPage');
$('#btnInstall', page).button('disable');
var name = getParameterByName('name'); var name = getParameterByName('name');
@ -219,7 +233,7 @@
return ip.Name == name; return ip.Name == name;
})[0]; })[0];
var vals = $('#selectVersion', $.mobile.activePage).val().split('|'); var vals = $('#selectVersion', page).val().split('|');
var version = vals[0]; var version = vals[0];
@ -232,28 +246,21 @@
if (confirmResult) { if (confirmResult) {
Dashboard.showLoadingMsg(); Dashboard.showLoadingMsg();
AddPluginPage.performInstallation(name, vals[1], version); performInstallation(name, vals[1], version);
} else { } else {
$('#btnInstall', $.mobile.activePage).button('enable'); $('#btnInstall', page).button('enable');
} }
}); });
} else { } else {
AddPluginPage.performInstallation(name, vals[1], version); performInstallation(name, vals[1], version);
} }
}); });
return false; return false;
},
performInstallation: function (packageName, updateClass, version) {
ApiClient.installPlugin(packageName, updateClass, version).done(function () {
Dashboard.hideLoadingMsg();
});
}
}; };
}
$(document).on('pageshow', "#addPluginPage", AddPluginPage.onPageShow); window.AddPluginPage = new addPluginpage();
})(jQuery, document, window);