step0_controller.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * Onclick handler for <code>next</code> button
  61. * Disable 'Next' button while it is already under process. (using Router's property 'nextBtnClickInProgress')
  62. * @method submit
  63. */
  64. submit: function () {
  65. if(App.get('router.nextBtnClickInProgress')){
  66. return;
  67. }
  68. this.set('hasSubmitted', true);
  69. if (!this.get('invalidClusterName')) {
  70. App.clusterStatus.set('clusterName', this.get('content.cluster.name'));
  71. this.set('content.cluster.status', 'PENDING');
  72. this.set('content.cluster.isCompleted', false);
  73. App.set('router.nextBtnClickInProgress', true);
  74. App.router.send('next');
  75. }
  76. }
  77. });