step1_controller.js 2.7 KB

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