From cc244c60e069251162426183cd38aa54f62ad1a1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 24 Apr 2013 17:01:48 -0400 Subject: [PATCH] re factored add plugin page to new js format --- dashboard-ui/scripts/addpluginpage.js | 347 +++++++++++++------------- 1 file changed, 177 insertions(+), 170 deletions(-) diff --git a/dashboard-ui/scripts/addpluginpage.js b/dashboard-ui/scripts/addpluginpage.js index a844f90685..20c167a293 100644 --- a/dashboard-ui/scripts/addpluginpage.js +++ b/dashboard-ui/scripts/addpluginpage.js @@ -1,138 +1,22 @@ -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); - var promise2 = ApiClient.getInstalledPlugins(); - var promise3 = ApiClient.getPluginSecurityInfo(); + html += '

' + version.versionStr + ' (' + version.classification + ')

'; - $.when(promise1, promise2, promise3).done(function (response1, response2, response3) { - - AddPluginPage.renderPackage(response1[0], response2[0], response3[0], page); - - }); - }, - - renderPackage: function (pkg, installedPlugins, pluginSecurityInfo, page) { - - var installedPlugin = installedPlugins.filter(function (ip) { - return ip.Name == pkg.name; - })[0]; - - AddPluginPage.populateVersions(pkg, page, installedPlugin); - AddPluginPage.populateHistory(pkg); - - Dashboard.setPageTitle(pkg.name); - - if (pkg.targetSystem == 'Server') { - $("#btnInstallDiv", page).show(); - $("#nonServerMsg", page).hide(); - $("#pSelectVersion", page).show(); - }else { - $("#btnInstallDiv", page).hide(); - $("#pSelectVersion", page).hide(); - $("#nonServerMsg", page).html("This plugin must be installed from "+pkg.targetSystem).show(); - } - - if (pkg.shortDescription) { - $('#tagline', page).show().html(pkg.shortDescription); - } else { - $('#tagline', page).hide(); + html += '
' + version.description + '
'; } - $('#overview', page).html(pkg.overview || ""); - - - $('#developer', page).html(pkg.owner); - - if (pkg.isPremium) { - $('.premiumPackage', page).show(); - - // Fill in registration info - var regStatus = ""; - if (pkg.isRegistered) { - regStatus += "You are currently registered for this feature"; - } else { - if (new Date(pkg.expDate).getTime() < new Date(1970, 1, 1).getTime()) { - regStatus += "This feature has no registration information"; - } else { - if (new Date(pkg.expDate).getTime() <= new Date().getTime()) { - regStatus += "The trial period for this feature has expired"; - } 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 += ""; - $('#regStatus', page).html(regStatus); - - if (pluginSecurityInfo.IsMBSupporter) { - $('#regInfo', page).html(pkg.regInfo || ""); - if (pkg.price > 0) { - // Fill in PayPal info - $('.premiumHasPrice', page).show(); - $('#featureId', page).val(pkg.featureId); - $('#featureName', page).val(pkg.name); - $('#amount', page).val(pkg.price); - $('#regPrice', page).html("

Price: $" + pkg.price.toFixed(2) + " (USD)

"); - 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 - $('.premiumHasPrice', page).hide(); - } - } else { - $('#regInfo', page).html("You must be a Media Browser Supporter in order to gain access to this feature.").trigger('create'); - $('#ppButton', page).hide(); - } - - } else { - $('.premiumPackage', page).hide(); - } - - if (pkg.richDescUrl) { - $('#pViewWebsite', page).show(); - $('#pViewWebsite a', page)[0].href = pkg.richDescUrl; - } else { - $('#pViewWebsite', page).hide(); - } - - if (pkg.previewImage) { - - var color = pkg.tileColor || "#2572EB"; - var img = pkg.previewImage ? pkg.previewImage : pkg.thumbImage; - $('#pPreviewImage', page).show().html(""); - } else { - $('#pPreviewImage', page).hide().html(""); - } - - if (installedPlugin) { - $('#pCurrentVersion', page).show().html("You currently have version " + installedPlugin.Version + " installed."); - - } else { - $('#pCurrentVersion', page).hide().html(""); - } - - Dashboard.hideLoadingMsg(); - }, - - populateVersions: function (packageInfo, page, installedPlugin) { + $('#revisionHistory', page).html(html); + } + function populateVersions(packageInfo, page, installedPlugin) { var html = ''; for (var i = 0, length = packageInfo.versions.length; i < length; i++) { @@ -187,73 +71,196 @@ } selectmenu.selectmenu('refresh'); - }, + } - populateHistory: function (packageInfo) { + function renderPackage(pkg, installedPlugins, pluginSecurityInfo, page) { - var html = ''; + var installedPlugin = installedPlugins.filter(function (ip) { + return ip.Name == pkg.name; + })[0]; - for (var i = 0, length = Math.min(packageInfo.versions.length, 10) ; i < length; i++) { + populateVersions(pkg, page, installedPlugin); + populateHistory(pkg, page); - var version = packageInfo.versions[i]; + Dashboard.setPageTitle(pkg.name); - html += '

' + version.versionStr + ' (' + version.classification + ')

'; - - html += '
' + version.description + '
'; + if (pkg.targetSystem == 'Server') { + $("#btnInstallDiv", page).show(); + $("#nonServerMsg", page).hide(); + $("#pSelectVersion", page).show(); + } else { + $("#btnInstallDiv", page).hide(); + $("#pSelectVersion", page).hide(); + $("#nonServerMsg", page).html("This plugin must be installed from " + pkg.targetSystem).show(); } - $('#revisionHistory', $.mobile.activePage).html(html); - }, + if (pkg.shortDescription) { + $('#tagline', page).show().html(pkg.shortDescription); + } else { + $('#tagline', page).hide(); + } - onSubmit: function () { + $('#overview', page).html(pkg.overview || ""); + + + $('#developer', page).html(pkg.owner); + + if (pkg.isPremium) { + $('.premiumPackage', page).show(); + + // Fill in registration info + var regStatus = ""; + if (pkg.isRegistered) { + regStatus += "You are currently registered for this feature"; + } else { + if (new Date(pkg.expDate).getTime() < new Date(1970, 1, 1).getTime()) { + regStatus += "This feature has no registration information"; + } else { + if (new Date(pkg.expDate).getTime() <= new Date().getTime()) { + regStatus += "The trial period for this feature has expired"; + } 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 += ""; + $('#regStatus', page).html(regStatus); + + if (pluginSecurityInfo.IsMBSupporter) { + $('#regInfo', page).html(pkg.regInfo || ""); + if (pkg.price > 0) { + // Fill in PayPal info + $('.premiumHasPrice', page).show(); + $('#featureId', page).val(pkg.featureId); + $('#featureName', page).val(pkg.name); + $('#amount', page).val(pkg.price); + $('#regPrice', page).html("

Price: $" + pkg.price.toFixed(2) + " (USD)

"); + 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 + $('.premiumHasPrice', page).hide(); + } + } else { + $('#regInfo', page).html("You must be a Media Browser Supporter in order to gain access to this feature.").trigger('create'); + $('#ppButton', page).hide(); + } + + } else { + $('.premiumPackage', page).hide(); + } + + if (pkg.richDescUrl) { + $('#pViewWebsite', page).show(); + $('#pViewWebsite a', page)[0].href = pkg.richDescUrl; + } else { + $('#pViewWebsite', page).hide(); + } + + if (pkg.previewImage) { + + var color = pkg.tileColor || "#2572EB"; + var img = pkg.previewImage ? pkg.previewImage : pkg.thumbImage; + $('#pPreviewImage', page).show().html(""); + } else { + $('#pPreviewImage', page).hide().html(""); + } + + if (installedPlugin) { + $('#pCurrentVersion', page).show().html("You currently have version " + installedPlugin.Version + " installed."); + + } else { + $('#pCurrentVersion', page).hide().html(""); + } + + Dashboard.hideLoadingMsg(); + } + + $(document).on('pageshow', "#addPluginPage", function () { + + var page = this; Dashboard.showLoadingMsg(); - $('#btnInstall', $.mobile.activePage).button('disable'); - var name = getParameterByName('name'); - ApiClient.getInstalledPlugins().done(function (plugins) { + var promise1 = ApiClient.getPackageInfo(name); + var promise2 = ApiClient.getInstalledPlugins(); + var promise3 = ApiClient.getPluginSecurityInfo(); - var installedPlugin = plugins.filter(function (ip) { - return ip.Name == name; - })[0]; + $.when(promise1, promise2, promise3).done(function (response1, response2, response3) { - var vals = $('#selectVersion', $.mobile.activePage).val().split('|'); + renderPackage(response1[0], response2[0], response3[0], page); - var version = vals[0]; - - if (installedPlugin && installedPlugin.Version == version) { - - Dashboard.hideLoadingMsg(); - - 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) { - - if (confirmResult) { - - Dashboard.showLoadingMsg(); - AddPluginPage.performInstallation(name, vals[1], version); - } else { - $('#btnInstall', $.mobile.activePage).button('enable'); - } - - }); - } else { - AddPluginPage.performInstallation(name, vals[1], version); - } }); + }); - return false; - }, - - performInstallation: function (packageName, updateClass, version) { + function performInstallation(packageName, updateClass, version) { ApiClient.installPlugin(packageName, updateClass, version).done(function () { Dashboard.hideLoadingMsg(); }); } -}; -$(document).on('pageshow', "#addPluginPage", AddPluginPage.onPageShow); \ No newline at end of file + function addPluginpage() { + + var self = this; + + self.onSubmit = function () { + + Dashboard.showLoadingMsg(); + + var page = $(this).parents('#addPluginPage'); + + $('#btnInstall', page).button('disable'); + + var name = getParameterByName('name'); + + ApiClient.getInstalledPlugins().done(function (plugins) { + + var installedPlugin = plugins.filter(function (ip) { + return ip.Name == name; + })[0]; + + var vals = $('#selectVersion', page).val().split('|'); + + var version = vals[0]; + + if (installedPlugin && installedPlugin.Version == version) { + + Dashboard.hideLoadingMsg(); + + 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) { + + if (confirmResult) { + + Dashboard.showLoadingMsg(); + performInstallation(name, vals[1], version); + } else { + $('#btnInstall', page).button('enable'); + } + + }); + } else { + performInstallation(name, vals[1], version); + } + }); + + return false; + }; + } + + window.AddPluginPage = new addPluginpage(); + +})(jQuery, document, window); \ No newline at end of file