step2_view.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.SshKeyFileUploader = Em.View.extend({
  20. //TODO: rewrite it using tagName and attribute binding
  21. //TODO: rewrite it as independent component and place it somewhere in utils
  22. // alternative is to move it to App.WizardStep2View
  23. template: Em.Handlebars.compile('<input type="file" {{bindAttr disabled="view.disabled"}} />'),
  24. classNames: ['ssh-key-input-indentation'],
  25. change: function (e) {
  26. var self = this;
  27. if (e.target.files && e.target.files.length == 1) {
  28. var file = e.target.files[0];
  29. var reader = new FileReader();
  30. reader.onload = (function () {
  31. return function (e) {
  32. $('#sshKey').html(e.target.result);
  33. self.get("controller").setSshKey(e.target.result);
  34. };
  35. })(file);
  36. reader.readAsText(file);
  37. }
  38. }
  39. });
  40. App.WizardStep2View = Em.View.extend({
  41. templateName: require('templates/wizard/step2'),
  42. didInsertElement: function () {
  43. App.popover($("[rel=popover]"), {'placement': 'right', 'trigger': 'hover'});
  44. //todo: move them to conroller
  45. this.set('controller.hostsError', null);
  46. this.set('controller.sshKeyError', null);
  47. },
  48. /**
  49. * Is manualInstall selected
  50. * @type {bool}
  51. */
  52. sshKeyState: function () {
  53. return this.get("controller.content.installOptions.manualInstall");
  54. }.property("controller.content.installOptions.manualInstall"),
  55. /**
  56. * Is File API available
  57. * @type {bool}
  58. * TODO: incupsulate it inside of App.SshKeyFileUploader
  59. */
  60. isFileApi: function () {
  61. /* istanbul ignore next */
  62. return window.File && window.FileReader && window.FileList;
  63. }.property(),
  64. /**
  65. * Checkbox for activate SSH fields
  66. * @type {Ember.Checkbox}
  67. * TODO: replace next 2 properties with new one used in both places
  68. */
  69. providingSSHKeyRadioButton: Em.Checkbox.extend({
  70. tagName: 'input',
  71. attributeBindings: ['type', 'checked'],
  72. checked: function () {
  73. return this.get('controller.content.installOptions.useSsh');
  74. }.property('controller.content.installOptions.useSsh'),
  75. type: 'radio',
  76. click: function () {
  77. this.set('controller.content.installOptions.useSsh', true);
  78. this.set('controller.content.installOptions.manualInstall', false);
  79. }
  80. }),
  81. /**
  82. * Checkbox for manual registration
  83. * @type {Ember.Checkbox}
  84. */
  85. manualRegistrationRadioButton: Em.Checkbox.extend({
  86. tagName: 'input',
  87. attributeBindings: ['type', 'checked'],
  88. type: 'radio',
  89. checked: function () {
  90. return this.get('controller.content.installOptions.manualInstall');
  91. }.property('controller.content.installOptions.manualInstall'),
  92. click: function () {
  93. this.set('controller.content.installOptions.manualInstall', true);
  94. this.set('controller.content.installOptions.useSsh', false);
  95. }
  96. }),
  97. /**
  98. * Textarea with ssh-key
  99. * @type {Ember.TextField}
  100. */
  101. textFieldView: Em.TextField.extend({
  102. /**
  103. * Is textfield disabled
  104. * @type {bool}
  105. */
  106. disabled: function () {
  107. return !this.get('isEnabled');
  108. }.property('isEnabled')
  109. })
  110. });