step1_controller.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.WizardStep1Controller = Em.Controller.extend({
  20. name: 'wizardStep1Controller',
  21. clusterName: function(){
  22. return this.get('content.cluster.name');
  23. }.property('content.cluster.name'),
  24. hasSubmitted : false,
  25. clearStep: function() {
  26. this.set('content.cluster.name','');
  27. },
  28. loadStep: function () {
  29. var clusterName;
  30. console.log('The value of the cluster name is: ' + App.db.getClusterName());
  31. if (App.db.getClusterName() !== undefined) {
  32. this.set('clusterName', App.db.getClusterName());
  33. } else {
  34. this.set('clusterNameError','');
  35. this.set('invalidClusterName',true);
  36. }
  37. },
  38. invalidClusterName : function(){
  39. if(!this.get('hasSubmitted')){
  40. return false;
  41. }
  42. var clusterName = this.get('content.cluster.name');
  43. if (clusterName == '') {
  44. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.required'));
  45. return true;
  46. } else if (/\s/.test(clusterName)) {
  47. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.whitespaces'));
  48. return true;
  49. } else if (/[^\w\s]/gi.test(clusterName)) {
  50. this.set('clusterNameError', Em.I18n.t('installer.step1.clusterName.error.specialChar'));
  51. return true;
  52. } else {
  53. this.set('clusterNameError', '');
  54. return false;
  55. }
  56. }.property('hasSubmitted', 'content.cluster.name').cacheable(),
  57. /**
  58. * calculates by <code>invalidClusterName</code> property
  59. */
  60. clusterNameError: '',
  61. /**
  62. * Onclick handler for <code>next</code> button
  63. */
  64. submit: function () {
  65. this.set('hasSubmitted', true);
  66. if (!this.get('invalidClusterName')) {
  67. this.set('content.cluster',{name: this.get('clusterName'), status: 'PENDING', isCompleted: false});
  68. // App.router.get('installerController').saveClusterStatus({status: 'PENDING', isCompleted: false});
  69. App.router.send('next');
  70. }
  71. }
  72. });