AddPluginPage.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. var AddPluginPage = {
  2. onPageShow: function () {
  3. var page = this;
  4. Dashboard.showLoadingMsg();
  5. var name = getParameterByName('name');
  6. var promise1 = ApiClient.getPackageInfo(name);
  7. var promise2 = ApiClient.getInstalledPlugins();
  8. var promise3 = ApiClient.getPluginSecurityInfo();
  9. $.when(promise1, promise2, promise3).done(function (response1, response2, response3) {
  10. AddPluginPage.renderPackage(response1[0], response2[0], response3[0], page);
  11. });
  12. },
  13. renderPackage: function (pkg, installedPlugins, pluginSecurityInfo, page) {
  14. var installedPlugin = installedPlugins.filter(function (ip) {
  15. return ip.Name == pkg.name;
  16. })[0];
  17. AddPluginPage.populateVersions(pkg, page, installedPlugin);
  18. AddPluginPage.populateHistory(pkg);
  19. Dashboard.setPageTitle(pkg.name);
  20. if (pkg.shortDescription) {
  21. $('#tagline', page).show().html(pkg.shortDescription);
  22. } else {
  23. $('#tagline', page).hide();
  24. }
  25. $('#overview', page).html(pkg.overview || "");
  26. $('#developer', page).html(pkg.owner);
  27. if (pkg.isPremium) {
  28. $('.premiumPackage', page).show();
  29. // Fill in registration info
  30. var regStatus = "<strong>";
  31. if (pkg.isRegistered) {
  32. regStatus += "You are currently registered for this feature";
  33. } else {
  34. if (new Date(pkg.expDate).getTime() < new Date(1970, 1, 1).getTime()) {
  35. regStatus += "You have never installed this feature";
  36. } else {
  37. if (pkg.expDate <= new Date().getTime()) {
  38. regStatus += "The trial period for this feature has expired on this machine";
  39. } else {
  40. regStatus += "The trial period for this feature will expire in " + Math.round((new Date(pkg.expDate).getTime() - new Date().getTime()) / (86400000)) + " day(s)";
  41. }
  42. }
  43. }
  44. regStatus += "</strong>";
  45. $('#regStatus', page).html(regStatus);
  46. if (pluginSecurityInfo.IsMBSupporter) {
  47. $('#regInfo', page).html(pkg.regInfo || "");
  48. // Fill in PayPal info
  49. $('#featureId', page).val(pkg.featureId);
  50. $('#featureName', page).val(pkg.name);
  51. $('#amount', page).val(pkg.price);
  52. $('#regPrice', page).html("<h2>Price: $" + pkg.price.toFixed(2) + " (USD)</h2>");
  53. var url = "http://mb3admin.com/admin/service/user/getPayPalEmail?id=" + pkg.owner;
  54. $.getJSON(url).done(function (dev) {
  55. if (dev.payPalEmail) {
  56. $('#payPalEmail', page).val(dev.payPalEmail);
  57. } else {
  58. $('#ppButton', page).hide();
  59. $('#noEmail', page).show();
  60. }
  61. });
  62. } else {
  63. $('#regInfo', page).html("<h3>You must be a <a href='supporter.html'>Media Browser Supporter</a> in order to register this feature.</h3>");
  64. $('#ppButton', page).hide();
  65. }
  66. } else {
  67. $('.premiumPackage', page).hide();
  68. }
  69. if (pkg.richDescUrl) {
  70. $('#pViewWebsite', page).show();
  71. $('#pViewWebsite a', page)[0].href = pkg.richDescUrl;
  72. } else {
  73. $('#pViewWebsite', page).hide();
  74. }
  75. if (pkg.previewImage) {
  76. var color = pkg.tileColor || "#2572EB";
  77. var img = pkg.previewImage ? pkg.previewImage : pkg.thumbImage;
  78. $('#pPreviewImage', page).show().html("<img src='" + img + "' style='max-width: 100%;border-radius:10px;-moz-box-shadow: 0 0 20px 3px " + color + ";-webkit-box-shadow: 0 0 20px 3px " + color + ";box-shadow: 0 0 20px 3px " + color + ";' />");
  79. } else {
  80. $('#pPreviewImage', page).hide().html("");
  81. }
  82. if (installedPlugin) {
  83. $('#pCurrentVersion', page).show().html("You currently have version <strong>" + installedPlugin.Version + "</strong> installed.");
  84. } else {
  85. $('#pCurrentVersion', page).hide().html("");
  86. }
  87. Dashboard.hideLoadingMsg();
  88. },
  89. populateVersions: function (packageInfo, page, installedPlugin) {
  90. var html = '';
  91. for (var i = 0, length = packageInfo.versions.length; i < length; i++) {
  92. var version = packageInfo.versions[i];
  93. html += '<option value="' + version.versionStr + '|' + version.classification + '">' + version.versionStr + ' (' + version.classification + ')</option>';
  94. }
  95. var selectmenu = $('#selectVersion', page).html(html);
  96. var packageVersion;
  97. if (installedPlugin) {
  98. // Select the first available package with the same update class as the installed version
  99. packageVersion = packageInfo.versions.filter(function (current) {
  100. return current.classification == installedPlugin.UpdateClass;
  101. })[0];
  102. } else {
  103. $('#pCurrentVersion', page).hide().html("");
  104. }
  105. // If we don't have a package version to select, pick the first release build
  106. if (!packageVersion) {
  107. // Select the first available package with the same update class as the installed version
  108. packageVersion = packageInfo.versions.filter(function (current) {
  109. return current.classification == "Release";
  110. })[0];
  111. }
  112. // If we still don't have a package version to select, pick the first Beta build
  113. if (!packageVersion) {
  114. // Select the first available package with the same update class as the installed version
  115. packageVersion = packageInfo.versions.filter(function (current) {
  116. return current.classification == "Beta";
  117. })[0];
  118. }
  119. if (packageVersion) {
  120. var val = packageVersion.versionStr + '|' + packageVersion.classification;
  121. $('#selectVersion', page).val(val);
  122. }
  123. selectmenu.selectmenu('refresh');
  124. },
  125. populateHistory: function (packageInfo) {
  126. var html = '';
  127. for (var i = 0, length = Math.min(packageInfo.versions.length, 10) ; i < length; i++) {
  128. var version = packageInfo.versions[i];
  129. html += '<h2 style="margin:.5em 0;">' + version.versionStr + ' (' + version.classification + ')</h2>';
  130. html += '<div style="margin-bottom:1.5em;">' + version.description + '</div>';
  131. }
  132. $('#revisionHistory', $.mobile.activePage).html(html);
  133. },
  134. onSubmit: function () {
  135. Dashboard.showLoadingMsg();
  136. $('#btnInstall', $.mobile.activePage).button('disable');
  137. var name = getParameterByName('name');
  138. ApiClient.getInstalledPlugins().done(function (plugins) {
  139. var installedPlugin = plugins.filter(function (ip) {
  140. return ip.Name == name;
  141. })[0];
  142. var vals = $('#selectVersion', $.mobile.activePage).val().split('|');
  143. var version = vals[0];
  144. if (installedPlugin && installedPlugin.Version == version) {
  145. Dashboard.hideLoadingMsg();
  146. 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) {
  147. if (confirmResult) {
  148. Dashboard.showLoadingMsg();
  149. AddPluginPage.performInstallation(name, vals[1], version);
  150. } else {
  151. $('#btnInstall', $.mobile.activePage).button('enable');
  152. }
  153. });
  154. } else {
  155. AddPluginPage.performInstallation(name, vals[1], version);
  156. }
  157. });
  158. return false;
  159. },
  160. performInstallation: function (packageName, updateClass, version) {
  161. ApiClient.installPlugin(packageName, updateClass, version).done(function () {
  162. Dashboard.hideLoadingMsg();
  163. });
  164. }
  165. };
  166. $(document).on('pageshow', "#addPluginPage", AddPluginPage.onPageShow);