wizardDeployProgressController.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. /**
  20. * Mixin for wizard controller for showing command progress on wizard pages
  21. * This should
  22. * @type {Ember.Mixin}
  23. */
  24. App.wizardDeployProgressControllerMixin = Em.Mixin.create({
  25. /**
  26. * Ajax-requests count
  27. * @type {number}
  28. */
  29. ajaxQueueLength: 0,
  30. /**
  31. * Ajax-requests queue
  32. * @type {App.ajaxQueue}
  33. */
  34. ajaxRequestsQueue: null,
  35. /**
  36. * This flag when turned to true launches deploy progress bar
  37. */
  38. isDeployStarted: '',
  39. /**
  40. * We need to do a lot of ajax calls async in special order. To do this,
  41. * generate array of ajax objects and then send requests step by step. All
  42. * ajax objects are stored in <code>ajaxRequestsQueue</code>
  43. *
  44. * @param {Object} params object with ajax-request parameters like url, type, data etc
  45. * @method addRequestToAjaxQueue
  46. */
  47. addRequestToAjaxQueue: function (params) {
  48. if (App.get('testMode')) return;
  49. params = jQuery.extend({
  50. sender: this,
  51. error: 'ajaxQueueRequestErrorCallback'
  52. }, params);
  53. params.data['cluster'] = this.get('clusterName');
  54. this.get('ajaxRequestsQueue').addRequest(params);
  55. },
  56. /**
  57. * Navigate to next step after all requests are sent
  58. * @method ajaxQueueFinished
  59. */
  60. ajaxQueueFinished: function () {
  61. console.log('everything is loaded');
  62. App.router.send('next');
  63. },
  64. /**
  65. * Error callback for each queued ajax-request
  66. * @param {object} xhr
  67. * @param {string} status
  68. * @param {string} error
  69. * @method ajaxQueueRequestErrorCallback
  70. */
  71. ajaxQueueRequestErrorCallback: function (xhr, status, error) {
  72. var responseText = JSON.parse(xhr.responseText);
  73. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  74. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  75. this.set('hasErrorOccurred', true);
  76. // an error will break the ajax call chain and allow submission again
  77. this.set('isSubmitDisabled', false);
  78. this.set('isBackBtnDisabled', false);
  79. App.router.get(this.get('content.controllerName')).setStepsEnable();
  80. }
  81. });