setup-config.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * Do some cleanup when we get a success response from a POST request
  3. * during setup
  4. * @param data the POST request return data
  5. * @param e the jquery event
  6. */
  7. function cleanupStep(data, e) {
  8. showFeedback(data);
  9. // If there are no errors, we can continue with
  10. // the installation process
  11. if (data.errors.length == 0) {
  12. // Call nextSlide from the submit button's context
  13. nextSlide.call($(e.target));
  14. }
  15. removeOverlay();
  16. }
  17. /**
  18. * Display the form feedback when we get POST results
  19. * @param data the POST request return data
  20. */
  21. function showFeedback(data) {
  22. toggleMessage(data.message);
  23. for (var i = 0; i < data.errors.length; i++) {
  24. $("#" + data.errors[i]).parent().addClass("has-error has-feedback");
  25. }
  26. if (data.errors.length > 0) {
  27. $(".help-message").addClass("has-error");
  28. $(".has-error .form-control-feedback").show();
  29. } else {
  30. $(".help-message").addClass("has-success");
  31. }
  32. }
  33. /**
  34. * Reset form feedback when resubmitting
  35. */
  36. function resetFeedback() {
  37. $(".form-control-feedback").hide();
  38. $(".has-success, .has-error, .has-feedback").removeClass("has-success has-error has-feedback");
  39. }
  40. /**
  41. * Show the return message from the POST request, then set a timeout to hide it again
  42. * @param msg the return message from the POST request
  43. */
  44. function toggleMessage(msg) {
  45. /*
  46. * Since setting display:none; on this element causes odd behaviour
  47. * with bootstrap, hide() the element so we can formSlide it in.
  48. * This is only really only necessary the first time this
  49. * function is called after page load.
  50. */
  51. var help = $(".help-message");
  52. help.html(msg).show();
  53. }
  54. /**
  55. * Show the overlay and loading gif
  56. */
  57. function addOverlay() {
  58. $("body").append("<div id='overlay'></div><img src='css/images/file_import_loader.gif' id='loadingImage'/>");
  59. }
  60. /**
  61. * Remove the overlay and loading gif
  62. */
  63. function removeOverlay() {
  64. var overlay = $("#overlay, #loadingImage");
  65. $("#loadingImage").fadeOut(250);
  66. $("#overlay").fadeOut(500, function() {
  67. overlay.remove();
  68. });
  69. }
  70. function formSlide(dir) {
  71. var delta = (dir == "next") ? "-=100%" : "+=100%",
  72. parent = $(this).parents("div.form-wrapper"),
  73. toForm = (dir == "next") ? parent.next() : parent.prev();
  74. parent.find(".btn").attr("disabled", "disabled");
  75. toForm.find(".btn").removeAttr("disabled");
  76. toForm.find(":input :first").focus();
  77. $(".form-slider").animate({left: delta}, 500);
  78. var stepCount = $("#stepCount"),
  79. steps = parseInt(stepCount.html());
  80. stepCount.html((dir == "next") ? (steps + 1) : (steps - 1));
  81. hideRMQForm();
  82. }
  83. /**
  84. * Fade out the previous setup step and fade in the next one
  85. */
  86. function nextSlide() {
  87. formSlide.call($(this), "next");
  88. }
  89. /**
  90. * Fade out the current setup step and fade in the previous one
  91. */
  92. function prevSlide() {
  93. formSlide.call($(this), "prev");
  94. }
  95. /**
  96. * Hide the RMQ form when the slider is called to avoid showing
  97. * scrollbars on slider panels that fit vertically
  98. */
  99. function hideRMQForm() {
  100. $("#rmqFormBody").slideUp(500);
  101. $("#advCaret").removeClass("caret-up");
  102. }
  103. function submitForm(e, obj) {
  104. resetFeedback();
  105. e.preventDefault();
  106. var d = $(e.target).serializeArray();
  107. addOverlay();
  108. // Append .promise().done() rather than using a
  109. // callback to avoid call duplication
  110. $("#overlay, #loadingImage").fadeIn(500).promise().done(function() {
  111. // Proxy function for passing the event to the cleanup function
  112. var cleanupProxy = function(data) {
  113. cleanupStep.call(this, data, e);
  114. };
  115. $.post('setup/setup-functions.php?obj=' + obj, d, cleanupProxy, "json");
  116. });
  117. }
  118. $(function() {
  119. // Stop the user from dragging the slider
  120. $(".form-slider").draggable('disable');
  121. $(".btn").attr("disabled", "disabled");
  122. $("form:first .btn").removeAttr("disabled");
  123. window.onresize = function() {
  124. var headerHeight = $(".header").outerHeight(),
  125. viewport = $(".viewport"),
  126. viewportHeight = viewport.outerHeight();
  127. // If the viewport would go outside the page bounds,
  128. // shrink it to fit the window
  129. if (viewportHeight + headerHeight > window.innerHeight) {
  130. viewport.css("height", window.innerHeight - headerHeight);
  131. }
  132. // Otherwise, go back to what we have in the stylesheet
  133. else {
  134. viewport.css("height", "");
  135. }
  136. };
  137. });