step0_controller.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. App.WizardStep0Controller = Em.Controller.extend({
  20. name: 'wizardStep0Controller',
  21. /**
  22. * Is step submitted
  23. * @type {bool}
  24. */
  25. hasSubmitted: false,
  26. /**
  27. * validate cluster name
  28. * set <code>clusterNameError</code> if validation fails
  29. */
  30. invalidClusterName: function () {
  31. var MAX_CLUSTER_NAME_LENGTH = 80;
  32. var clusterName = this.get('content.cluster.name');
  33. if (clusterName == '' && this.get('hasSubmitted')) {
  34. this.set('clusterNameError', Em.I18n.t('installer.step0.clusterName.error.required'));
  35. return true;
  36. } else if (clusterName.length > MAX_CLUSTER_NAME_LENGTH) {
  37. this.set('clusterNameError', Em.I18n.t('installer.step0.clusterName.error.tooLong'));
  38. return true;
  39. } else if (/\s/.test(clusterName)) {
  40. this.set('clusterNameError', Em.I18n.t('installer.step0.clusterName.error.whitespace'));
  41. return true;
  42. } else if (/[^\w\s]/gi.test(clusterName)) {
  43. this.set('clusterNameError', Em.I18n.t('installer.step0.clusterName.error.specialChar'));
  44. return true;
  45. } else {
  46. this.set('clusterNameError', '');
  47. return false;
  48. }
  49. }.property('hasSubmitted', 'content.cluster.name'),
  50. /**
  51. * calculates by <code>invalidClusterName</code> property
  52. * todo: mix this and previous variables in one
  53. */
  54. clusterNameError: '',
  55. loadStep: function () {
  56. this.set('hasSubmitted', false);
  57. this.set('clusterNameError', '');
  58. },
  59. /**
  60. * @type {boolean}
  61. */
  62. isSubmitDisabled: Em.computed.or('invalidClusterName', 'App.router.btnClickInProgress'),
  63. /**
  64. * Onclick handler for <code>next</code> button
  65. * Disable 'Next' button while it is already under process. (using Router's property 'nextBtnClickInProgress')
  66. * @method submit
  67. */
  68. submit: function () {
  69. if(App.get('router.nextBtnClickInProgress')){
  70. return;
  71. }
  72. this.set('hasSubmitted', true);
  73. if (!this.get('invalidClusterName')) {
  74. App.clusterStatus.set('clusterName', this.get('content.cluster.name'));
  75. this.set('content.cluster.status', 'PENDING');
  76. this.set('content.cluster.isCompleted', false);
  77. App.set('router.nextBtnClickInProgress', true);
  78. App.router.send('next');
  79. }
  80. }
  81. });