step1_controller.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. var db = require('utils/db');
  20. App.InstallerStep1Controller = Em.Controller.extend({
  21. name: 'installerStep1Controller',
  22. content: [],
  23. clusterName: '',
  24. invalidClusterName: false,
  25. clusterNameError: '',
  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. validateStep1: function () {
  31. console.log('TRACE: Entering controller:InstallerStep1:validateStep1 function');
  32. if (this.get('clusterName') == '') {
  33. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.required'));
  34. this.set('invalidClusterName', true);
  35. return false;
  36. } else if (/\s/.test(this.get('clusterName'))) {
  37. console.log('White spaces not allowed for cluster name');
  38. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.whitespaces'));
  39. this.set('invalidClusterName', true);
  40. return false;
  41. } else if (/[^\w\s]/gi.test(this.get('clusterName'))) {
  42. console.log('Special characters are not allowed for the cluster name');
  43. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.specialChar'));
  44. this.set('invalidClusterName', true);
  45. return false;
  46. } else {
  47. console.log('value of clusterName is: ' + this.get('clusterName'));
  48. this.set('clusterNameError', '');
  49. this.set('invalidClusterName', false);
  50. db.setClusterName(this.get('clusterName'));
  51. return true;
  52. }
  53. }.observes('clusterName')
  54. })