step1_controller.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. require('utils/db');
  20. App.InstallerStep1Controller = Em.Controller.extend({
  21. name: 'installerStep1Controller',
  22. content: [],
  23. clusterName: '',
  24. clusterNameError: '',
  25. invalidClusterName: true,
  26. /**
  27. * Returns true if the cluster name is valid and stores it in localStorage.
  28. * Returns false otherwise, and sets appropriate field error message.
  29. */
  30. clearStep: function() {
  31. this.set('clusterName','');
  32. },
  33. loadStep: function () {
  34. var clusterName;
  35. console.log('The value of the cluster name is: ' + App.db.getClusterName());
  36. if (App.db.getClusterName() !== undefined && App.db.getClusterName() !== true ) {
  37. this.set('clusterName', App.db.getClusterName());
  38. } else {
  39. this.set('clusterNameError','');
  40. this.set('invalidClusterName',true);
  41. }
  42. },
  43. validateStep1: function () {
  44. console.log('TRACE: Entering controller:InstallerStep1:validateStep1 function');
  45. if (this.get('clusterName') == '') {
  46. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.required'));
  47. this.set('invalidClusterName', true);
  48. return false;
  49. } else if (/\s/.test(this.get('clusterName'))) {
  50. console.log('White spaces not allowed for cluster name');
  51. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.whitespaces'));
  52. this.set('invalidClusterName', true);
  53. return false;
  54. } else if (/[^\w\s]/gi.test(this.get('clusterName'))) {
  55. console.log('Special characters are not allowed for the cluster name');
  56. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.specialChar'));
  57. this.set('invalidClusterName', true);
  58. return false;
  59. } else {
  60. console.log('value of clusterName is: ' + this.get('clusterName'));
  61. this.set('clusterNameError', '');
  62. this.set('invalidClusterName', false);
  63. return true;
  64. }
  65. }.observes('clusterName'),
  66. submit: function () {
  67. this.validateStep1();
  68. if (this.get('clusterNameError') === '') {
  69. App.db.setClusterName(this.get('clusterName'));
  70. App.router.send('next');
  71. }
  72. }
  73. })