step1_view.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('models/repository');
  19. App.WizardStep1View = Em.View.extend({
  20. templateName: require('templates/wizard/step1'),
  21. didInsertElement: function () {
  22. $("[rel=skip-validation-tooltip]").tooltip({ placement: 'right'});
  23. $("[rel=use-redhat-tooltip]").tooltip({ placement: 'right'});
  24. $('.add-os-button,.redhat-label').tooltip();
  25. if (this.get('controller.selectedStack.showAvailable')) {
  26. // first time load
  27. if (this.get('controller.selectedStack.useRedhatSatellite')) {
  28. // restore `use local repo` on page refresh
  29. this.get('controller').useLocalRepo();
  30. }
  31. } else {
  32. var selected = this.get('controller.content.stacks') && this.get('controller.content.stacks').findProperty('showAvailable');
  33. if (!selected) {
  34. // network disconnection
  35. Em.trySet(this, 'controller.selectedStack.useLocalRepo', true);
  36. Em.trySet(this, 'controller.selectedStack.usePublicRepo', false);
  37. }
  38. }
  39. },
  40. willDestroyElement: function () {
  41. $("[rel=skip-validation-tooltip]").tooltip('destroy');
  42. $("[rel=use-redhat-tooltip]").tooltip('destroy');
  43. $('.add-os-button,.redhat-label').tooltip('destroy');
  44. },
  45. /**
  46. * Show possible reasons why Public Repo is disabled
  47. *
  48. * @returns {App.ModalPopup}
  49. */
  50. openPublicOptionDisabledWindow: function () {
  51. return App.ModalPopup.show({
  52. header: Em.I18n.t('installer.step1.selectUseRepoOptions.public.networkLost.popup.title'),
  53. bodyClass: Ember.View.extend({
  54. templateName: require('templates/wizard/step1/public_option_disabled_window_body')
  55. }),
  56. secondary: false
  57. });
  58. },
  59. /**
  60. * Disable submit button flag
  61. *
  62. * @type {bool}
  63. */
  64. isSubmitDisabled: Em.computed.or('invalidFormatUrlExist', 'isNoOsChecked', 'isNoOsFilled', 'controller.content.isCheckInProgress', 'App.router.btnClickInProgress'),
  65. /**
  66. * Show warning message flag
  67. *
  68. * @type {bool}
  69. */
  70. warningExist: Em.computed.or('invalidFormatUrlExist', 'isNoOsChecked', 'isNoOsFilled'),
  71. skipVerifyBaseUrl: Em.computed.or('controller.selectedStack.skipValidationChecked', 'controller.selectedStack.useRedhatSatellite'),
  72. verifyBaseUrl: Em.computed.not('skipVerifyBaseUrl'),
  73. showWarning: Em.computed.and('warningExist', 'verifyBaseUrl'),
  74. /**
  75. * Onclick handler for recheck repos urls. Used in Advanced Repository Options.
  76. */
  77. retryRepoUrls: function () {
  78. App.router.get('installerController').checkRepoURL(this.get('controller'));
  79. },
  80. /**
  81. * Checkbox for use Public repo
  82. *
  83. * @type {Ember.Checkbox}
  84. */
  85. usePublicRepoRadioButton: Em.Checkbox.extend({
  86. tagName: 'input',
  87. attributeBindings: [ 'type', 'checked' ],
  88. classNames: [''],
  89. checked: Em.computed.alias('controller.selectedStack.usePublicRepo'),
  90. type: 'radio',
  91. click: function () {
  92. this.get('controller').usePublicRepo();
  93. }
  94. }),
  95. /**
  96. * Checkbox for use Public repo
  97. *
  98. * @type {Ember.Checkbox}
  99. */
  100. useLocalRepoRadioButton: Em.Checkbox.extend({
  101. tagName: 'input',
  102. attributeBindings: [ 'type', 'checked' ],
  103. classNames: [''],
  104. checked: Em.computed.alias('controller.selectedStack.useLocalRepo'),
  105. type: 'radio',
  106. click: function () {
  107. this.get('controller').useLocalRepo();
  108. }
  109. }),
  110. /**
  111. * User already selected all OSes
  112. *
  113. * @type {boolean}
  114. */
  115. allOsesSelected: Em.computed.everyBy('controller.selectedStack.operatingSystems', 'isSelected', true),
  116. /**
  117. * Disallow adding OS if all OSes are already added or user select <code>useRedhatSatellite</code>
  118. *
  119. * @type {boolean}
  120. */
  121. isAddOsButtonDisabled: Em.computed.or('allOsesSelected', 'controller.selectedStack.useRedhatSatellite'),
  122. /**
  123. * Tooltip for Add OS Button
  124. * Empty if this button is enabled
  125. *
  126. * @type {string}
  127. */
  128. addOsButtonTooltip: Em.computed.ifThenElse('allOsesSelected', Em.I18n.t('installer.step1.addOs.disabled.tooltip'), ''),
  129. /**
  130. * Tooltip for useRedhatSatellite block
  131. * Empty if usage Redhat is enabled
  132. *
  133. * @type {string}
  134. */
  135. redhatDisabledTooltip: Em.computed.ifThenElse('controller.selectedStack.usePublicRepo', Em.I18n.t('installer.step1.advancedRepo.useRedhatSatellite.disabled.tooltip'), ''),
  136. /**
  137. * List of all repositories under selected stack operatingSystems
  138. *
  139. * @type {App.Repository[]}
  140. */
  141. allRepositories: function () {
  142. return this.getWithDefault('controller.selectedStack.repositories', []);
  143. }.property('controller.selectedStack.repositories.[]'),
  144. /**
  145. * Verify if some repo has invalid base-url
  146. * Ignore if <code>useRedhatSatellite</code> is true for selected stack
  147. *
  148. * @type {bool}
  149. */
  150. invalidFormatUrlExist: function () {
  151. if (this.get('controller.selectedStack.useRedhatSatellite')) {
  152. return false;
  153. }
  154. var allRepositories = this.get('allRepositories');
  155. if (!allRepositories) {
  156. return false;
  157. }
  158. return allRepositories.someProperty('invalidFormatError', true);
  159. }.property('controller.selectedStack.useRedhatSatellite', 'allRepositories.@each.invalidFormatError'),
  160. /**
  161. * Verify if some invalid repo-urls exist
  162. * @type {bool}
  163. */
  164. invalidUrlExist: Em.computed.someBy('allRepositories', 'validation', App.Repository.validation.INVALID),
  165. /**
  166. * If all repo links are unchecked
  167. * @type {bool}
  168. */
  169. isNoOsChecked: Em.computed.everyBy('controller.selectedStack.operatingSystems', 'isSelected', false),
  170. /**
  171. * If all OSes are empty
  172. * @type {bool}
  173. */
  174. isNoOsFilled: function () {
  175. if (this.get('controller.selectedStack.useRedhatSatellite')) {
  176. return false;
  177. }
  178. var operatingSystems = this.get('controller.selectedStack.operatingSystems');
  179. var selectedOS = operatingSystems.filterProperty('isSelected', true);
  180. return selectedOS.everyProperty('isNotFilled', true);
  181. }.property('controller.selectedStack.operatingSystems.@each.isSelected', 'controller.selectedStack.operatingSystems.@each.isNotFilled', 'controller.selectedStack.useRedhatSatellite'),
  182. popoverView: Em.View.extend({
  183. tagName: 'i',
  184. classNameBindings: ['repository.validation'],
  185. attributeBindings: ['repository.errorTitle:title', 'repository.errorContent:data-content'],
  186. didInsertElement: function () {
  187. App.popover($(this.get('element')), {'trigger': 'hover'});
  188. }
  189. }),
  190. /**
  191. * @type {Em.Checkbox}
  192. */
  193. redhatCheckBoxView: Em.Checkbox.extend({
  194. attributeBindings: [ 'type', 'checked' ],
  195. checkedBinding: 'controller.selectedStack.useRedhatSatellite',
  196. classNames: ['checkbox'],
  197. disabledBinding: 'controller.selectedStack.usePublicRepo',
  198. click: function () {
  199. // click triggered before value is toggled, so if-statement is inverted
  200. if (!this.get('controller.selectedStack.useRedhatSatellite')) {
  201. App.ModalPopup.show({
  202. header: Em.I18n.t('common.important'),
  203. secondary: false,
  204. bodyClass: Ember.View.extend({
  205. template: Ember.Handlebars.compile(Em.I18n.t('installer.step1.advancedRepo.useRedhatSatellite.warning'))
  206. })
  207. });
  208. }
  209. }
  210. }),
  211. /**
  212. * Handler when editing any repo BaseUrl
  213. *
  214. * @method editLocalRepository
  215. */
  216. editLocalRepository: function () {
  217. //upload to content
  218. var repositories = this.get('allRepositories');
  219. if (!repositories) {
  220. return;
  221. }
  222. repositories.forEach(function (repository) {
  223. if (repository.get('lastBaseUrl') !== repository.get('baseUrl')) {
  224. repository.setProperties({
  225. lastBaseUrl: repository.get('baseUrl'),
  226. validation: App.Repository.validation.PENDING
  227. });
  228. }
  229. }, this);
  230. }.observes('allRepositories.@each.baseUrl')
  231. });