AddPluginPage.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 += "This feature has no registration information";
  36. } else {
  37. if (new Date(pkg.expDate).getTime() <= new Date().getTime()) {
  38. regStatus += "The trial period for this feature has expired";
  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. if (pkg.price > 0) {
  49. // Fill in PayPal info
  50. $('premiumHasPrice', page).show();
  51. $('#featureId', page).val(pkg.featureId);
  52. $('#featureName', page).val(pkg.name);
  53. $('#amount', page).val(pkg.price);
  54. $('#regPrice', page).html("<h2>Price: $" + pkg.price.toFixed(2) + " (USD)</h2>");
  55. var url = "http://mb3admin.com/admin/service/user/getPayPalEmail?id=" + pkg.owner;
  56. $.getJSON(url).done(function(dev) {
  57. if (dev.payPalEmail) {
  58. $('#payPalEmail', page).val(dev.payPalEmail);
  59. } else {
  60. $('#ppButton', page).hide();
  61. $('#noEmail', page).show();
  62. }
  63. });
  64. } else {
  65. // Supporter-only feature
  66. $('premiumHasPrice', page).hide();
  67. }
  68. } else {
  69. $('#regInfo', page).html("<h3>You must be a <a href='supporter.html'>Media Browser Supporter</a> in order to gain access to this feature.</h3>");
  70. $('#ppButton', page).hide();
  71. }
  72. } else {
  73. $('.premiumPackage', page).hide();
  74. }
  75. if (pkg.richDescUrl) {
  76. $('#pViewWebsite', page).show();
  77. $('#pViewWebsite a', page)[0].href = pkg.richDescUrl;
  78. } else {
  79. $('#pViewWebsite', page).hide();
  80. }
  81. if (pkg.previewImage) {
  82. var color = pkg.tileColor || "#2572EB";
  83. var img = pkg.previewImage ? pkg.previewImage : pkg.thumbImage;
  84. $('#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 + ";' />");
  85. } else {
  86. $('#pPreviewImage', page).hide().html("");
  87. }
  88. if (installedPlugin) {
  89. $('#pCurrentVersion', page).show().html("You currently have version <strong>" + installedPlugin.Version + "</strong> installed.");
  90. } else {
  91. $('#pCurrentVersion', page).hide().html("");
  92. }
  93. Dashboard.hideLoadingMsg();
  94. },
  95. populateVersions: function (packageInfo, page, installedPlugin) {
  96. var html = '';
  97. for (var i = 0, length = packageInfo.versions.length; i < length; i++) {
  98. var version = packageInfo.versions[i];
  99. html += '<option value="' + version.versionStr + '|' + version.classification + '">' + version.versionStr + ' (' + version.classification + ')</option>';
  100. }
  101. var selectmenu = $('#selectVersion', page).html(html);
  102. var packageVersion;
  103. if (installedPlugin) {
  104. // Select the first available package with the same update class as the installed version
  105. packageVersion = packageInfo.versions.filter(function (current) {
  106. return current.classification == installedPlugin.UpdateClass;
  107. })[0];
  108. } else {
  109. $('#pCurrentVersion', page).hide().html("");
  110. }
  111. // If we don't have a package version to select, pick the first release build
  112. if (!packageVersion) {
  113. // Select the first available package with the same update class as the installed version
  114. packageVersion = packageInfo.versions.filter(function (current) {
  115. return current.classification == "Release";
  116. })[0];
  117. }
  118. // If we still don't have a package version to select, pick the first Beta build
  119. if (!packageVersion) {
  120. // Select the first available package with the same update class as the installed version
  121. packageVersion = packageInfo.versions.filter(function (current) {
  122. return current.classification == "Beta";
  123. })[0];
  124. }
  125. if (packageVersion) {
  126. var val = packageVersion.versionStr + '|' + packageVersion.classification;
  127. $('#selectVersion', page).val(val);
  128. }
  129. selectmenu.selectmenu('refresh');
  130. },
  131. populateHistory: function (packageInfo) {
  132. var html = '';
  133. for (var i = 0, length = Math.min(packageInfo.versions.length, 10) ; i < length; i++) {
  134. var version = packageInfo.versions[i];
  135. html += '<h2 style="margin:.5em 0;">' + version.versionStr + ' (' + version.classification + ')</h2>';
  136. html += '<div style="margin-bottom:1.5em;">' + version.description + '</div>';
  137. }
  138. $('#revisionHistory', $.mobile.activePage).html(html);
  139. },
  140. onSubmit: function () {
  141. Dashboard.showLoadingMsg();
  142. $('#btnInstall', $.mobile.activePage).button('disable');
  143. var name = getParameterByName('name');
  144. ApiClient.getInstalledPlugins().done(function (plugins) {
  145. var installedPlugin = plugins.filter(function (ip) {
  146. return ip.Name == name;
  147. })[0];
  148. var vals = $('#selectVersion', $.mobile.activePage).val().split('|');
  149. var version = vals[0];
  150. if (installedPlugin && installedPlugin.Version == version) {
  151. Dashboard.hideLoadingMsg();
  152. 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) {
  153. if (confirmResult) {
  154. Dashboard.showLoadingMsg();
  155. AddPluginPage.performInstallation(name, vals[1], version);
  156. } else {
  157. $('#btnInstall', $.mobile.activePage).button('enable');
  158. }
  159. });
  160. } else {
  161. AddPluginPage.performInstallation(name, vals[1], version);
  162. }
  163. });
  164. return false;
  165. },
  166. performInstallation: function (packageName, updateClass, version) {
  167. ApiClient.installPlugin(packageName, updateClass, version).done(function () {
  168. Dashboard.hideLoadingMsg();
  169. });
  170. }
  171. };
  172. $(document).on('pageshow', "#addPluginPage", AddPluginPage.onPageShow);