ugm-bottom.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * JS file for UpgradeMODX extra
  3. *
  4. * Copyright 2018 by Bob Ray <https://bobsguides.com>
  5. * Created on 07-19-2018
  6. *
  7. * UpgradeMODX is free software; you can redistribute it and/or modify it under the
  8. * terms of the GNU General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option) any later
  10. * version.
  11. *
  12. * UpgradeMODX is distributed in the hope that it will be useful, but WITHOUT ANY
  13. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  14. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * UpgradeMODX; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. * Place, Suite 330, Boston, MA 02111-1307 USA
  19. * @package upgradeMODX
  20. */
  21. /* Set background color of selected version */
  22. var checkedBackground = '#f0f0f0';
  23. // var originalBackground = $('label').css("background-color");
  24. var originalBackground = 'transparent';
  25. $('input[type="radio"]:checked').parent().css("background", checkedBackground);
  26. $("label > input").change(function () {
  27. if ($(this).is(":checked")) {
  28. $(this).parent().css("background", checkedBackground);
  29. $('input[type="radio"]:not(:checked)').parent().css("background", originalBackground);
  30. // console.log("Value: " + $('input[type="radio"]:checked').val());
  31. }
  32. });
  33. $(document).ajaxError(function (event, request, settings) {
  34. $(alert("Error requesting page " + settings.url));
  35. });
  36. var bttn = document.getElementById('ugm_submit_button');
  37. var old = '';
  38. new ProgressButton(bttn, {
  39. callback: function (instance) {
  40. //alert("Clicked");
  41. var button_text = document.getElementById('button_content');
  42. var progress = 0;
  43. var selectedVersion = 'modx-' + $("input:radio[name='modx']:checked").val() + '.zip';
  44. var updateText = function (button_text, msg) {
  45. if ('textContent' in button_text) {
  46. button_text.textContent = msg;
  47. } else {
  48. button_text.innerText = msg;
  49. }
  50. };
  51. var process = function () {
  52. if (progress === 0) {
  53. // console.log("progress is zero");
  54. updateText(button_text, 'Downloading Files');
  55. progress = 0.1;
  56. instance._setProgress(progress);
  57. var maxProgress = 0.3;
  58. var progressInterval = setInterval(function () {
  59. if (progress < 1.0 && progress < maxProgress) {
  60. progress += 0.01;
  61. instance._setProgress(progress);
  62. if (progress >= 1) {
  63. clearInterval(progressInterval);
  64. }
  65. }
  66. }, 1000);
  67. $.ajax({
  68. cache: false,
  69. type: 'GET',
  70. // url: 'http://localhost/addons/assets/mycomponents/upgrademodx/assets/components/upgrademodx/connector.php',
  71. url: ugmConnectorUrl,
  72. data: {
  73. 'action': 'downloadfiles',
  74. 'props': ugm_config,
  75. 'version': selectedVersion
  76. },
  77. success: function (data) {
  78. if (data.success === true) {
  79. updateText(button_text, data.message);
  80. // alert("Got success return from downloadfiles");
  81. progress = 0.3;
  82. maxProgress = 0.6;
  83. instance._setProgress(progress);
  84. /* Run next processor */
  85. // console.log(ugm_config);
  86. $.ajax({
  87. type: 'GET',
  88. url: ugmConnectorUrl,
  89. data: {
  90. 'action': 'unzipfiles',
  91. 'props': ugm_config,
  92. 'version': selectedVersion
  93. },
  94. success: function (data) {
  95. if (data.success === true) {
  96. updateText(button_text, data.message);
  97. // alert("Got success return from unzipfiles");
  98. progress = 0.6;
  99. maxProgress = 0.8;
  100. instance._setProgress(progress);
  101. /* Run next processor */
  102. $.ajax({
  103. type: 'GET',
  104. url: ugmConnectorUrl,
  105. data: {
  106. 'action': 'copyfiles',
  107. 'props': ugm_config,
  108. 'version': selectedVersion
  109. },
  110. success: function (data) {
  111. if (data.success === true) {
  112. updateText(button_text, data.message);
  113. // alert("Got success return from copyfiles");
  114. progress = 0.8;
  115. maxProgress = 0.85;
  116. instance._setProgress(progress);
  117. /* Run next processor */
  118. $.ajax({
  119. type: 'GET',
  120. url: ugmConnectorUrl,
  121. data: {
  122. 'action': 'preparesetup',
  123. 'props': ugm_config,
  124. 'version': selectedVersion
  125. },
  126. success: function (data) {
  127. if (data.success === true) {
  128. updateText(button_text, data.message);
  129. // alert("Got success return from copyfiles");
  130. progress = 0.85;
  131. maxProgress = 0.98;
  132. instance._setProgress(progress);
  133. /* Run next processor */
  134. $.ajax({
  135. type: 'GET',
  136. url: ugmConnectorUrl,
  137. data: {
  138. 'action': 'cleanup',
  139. 'props': ugm_config,
  140. 'version': selectedVersion
  141. },
  142. success: function (data) {
  143. if (data.success === true) {
  144. updateText(button_text, data.message);
  145. // alert("Got success return from preparesetup");
  146. progress = 1;
  147. instance._setProgress(progress);
  148. instance._stop(1);
  149. } else {
  150. displayError(data.message, progressInterval, instance);
  151. }
  152. clearInterval(progressInterval);
  153. //console.log(ugm_setup_url);
  154. setTimeout(function () {
  155. window.location.replace(ugm_setup_url);
  156. }, 1500);
  157. },
  158. dataType: 'json'
  159. });
  160. } else {
  161. displayError(data.message, progressInterval, instance);
  162. }
  163. // clearInterval(progressInterval);
  164. // window.location.replace(ugm_setup_url);
  165. },
  166. dataType: 'json'
  167. });
  168. } else {
  169. displayError(data.message, progressInterval, instance);
  170. }
  171. // console.log(data.message);
  172. },
  173. dataType: 'json'
  174. });
  175. } else {
  176. displayError(data.message, progressInterval, instance);
  177. }
  178. //console.log(data.message);
  179. },
  180. dataType: 'json'
  181. });
  182. } else {
  183. displayError(data.message, progressInterval, instance);
  184. console.log(data.message);
  185. }
  186. },
  187. dataType: 'json'
  188. });
  189. }
  190. progress = Math.min(progress, 1);
  191. if (progress === 1) {
  192. setTimeout(function () {
  193. instance._stop(1);
  194. clearInterval(interval);
  195. }, 1000);
  196. }
  197. instance._setProgress(progress);
  198. if (progress === 1) {
  199. setTimeout(function () {
  200. instance._stop(1);
  201. // clearInterval(interval);
  202. }, 500);
  203. }
  204. };
  205. process();
  206. }
  207. });
  208. function displayError($msg, progressInterval, instance) {
  209. clearInterval(progressInterval);
  210. instance._stop(1);
  211. $("#ugm_submit_button").fadeOut(400, function () {
  212. $(this).html($msg).fadeIn();
  213. });
  214. // bttn.innerHTML = $msg;
  215. }