step5_controller.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 stringUtils = require('utils/string_utils');
  19. App.KerberosWizardStep5Controller = App.KerberosProgressPageController.extend({
  20. name: 'kerberosWizardStep5Controller',
  21. csvData: [],
  22. submit: function() {
  23. App.router.send('next');
  24. },
  25. /**
  26. * get CSV data from the server
  27. */
  28. getCSVData: function () {
  29. App.ajax.send({
  30. name: 'admin.kerberos.cluster.csv',
  31. sender: this,
  32. data: {},
  33. success: 'getCSVDataSuccessCallback',
  34. error: 'getCSVDataSuccessCallback'
  35. })
  36. },
  37. /**
  38. * get CSV data from server success callback
  39. */
  40. getCSVDataSuccessCallback: function (data, opt, params) {
  41. this.set('csvData', this.prepareCSVData(data.split('\n')));
  42. this.downloadCSV();
  43. },
  44. prepareCSVData: function (array) {
  45. for (var i = 0; i < array.length; i += 1) {
  46. array[i] = array[i].split(',');
  47. }
  48. return array;
  49. },
  50. /**
  51. * download CSV file
  52. */
  53. downloadCSV: function () {
  54. if ($.browser.msie && $.browser.version < 10) {
  55. this.openInfoInNewTab();
  56. } else {
  57. try {
  58. var blob = new Blob([stringUtils.arrayToCSV(this.get('csvData'))], {type: "text/csv;charset=utf-8;"});
  59. saveAs(blob, "kerberos.csv");
  60. } catch (e) {
  61. this.openInfoInNewTab();
  62. }
  63. }
  64. },
  65. /**
  66. * open content of CSV file in new window
  67. */
  68. openInfoInNewTab: function () {
  69. var newWindow = window.open('');
  70. var newDocument = newWindow.document;
  71. newDocument.write(stringUtils.arrayToCSV(this.get('hostComponents')));
  72. newWindow.focus();
  73. },
  74. /**
  75. * Send request to post kerberos descriptor
  76. * @param kerberosDescriptor
  77. * @returns {$.ajax|*}
  78. */
  79. postKerberosDescriptor: function (kerberosDescriptor) {
  80. return App.ajax.send({
  81. name: 'admin.kerberos.cluster.artifact.create',
  82. sender: this,
  83. data: {
  84. artifactName: 'kerberos_descriptor',
  85. data: {
  86. artifact_data: kerberosDescriptor
  87. }
  88. }
  89. });
  90. },
  91. /**
  92. * Send request to update kerberos descriptor
  93. * @param kerberosDescriptor
  94. * @returns {$.ajax|*}
  95. */
  96. putKerberosDescriptor: function (kerberosDescriptor) {
  97. return App.ajax.send({
  98. name: 'admin.kerberos.cluster.artifact.update',
  99. sender: this,
  100. data: {
  101. artifactName: 'kerberos_descriptor',
  102. data: {
  103. artifact_data: kerberosDescriptor
  104. }
  105. },
  106. success: 'unkerberizeCluster',
  107. error: 'unkerberizeCluster'
  108. });
  109. },
  110. /**
  111. * Send request to unkerberisze cluster
  112. * @returns {$.ajax}
  113. */
  114. unkerberizeCluster: function () {
  115. return App.ajax.send({
  116. name: 'admin.unkerberize.cluster',
  117. sender: this,
  118. success: 'goToNextStep',
  119. error: 'goToNextStep'
  120. });
  121. },
  122. goToNextStep: function() {
  123. this.clearStage();
  124. App.router.transitionTo('step5');
  125. },
  126. isSubmitDisabled: function () {
  127. return !["COMPLETED", "FAILED"].contains(this.get('status'));
  128. }.property('status')
  129. });