toggle_isrequired.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.ToggleIsRequiredMixin = Em.Mixin.create({
  20. /**
  21. * Override isRequired property of the configurations in given situation
  22. * @param serviceConfigs - make changes only for properties from this service
  23. */
  24. overrideConfigIsRequired: function (serviceConfigs) {
  25. var excludeProperties = [
  26. {
  27. name: 'KERBEROS', // affected service
  28. exclude: ['kdc_hosts', 'admin_server_host', 'admin_principal', 'admin_password'] // affected properties
  29. },
  30. {
  31. name: 'KERBEROS_GENERAL', // affected service
  32. exclude: ['kdc_hosts', 'admin_server_host', 'admin_principal', 'admin_password'] // affected properties
  33. }
  34. ];
  35. var serviceName = serviceConfigs.get('serviceName'),
  36. service = excludeProperties.findProperty('name', serviceName),
  37. configs = serviceConfigs.get('configs');
  38. if (service && !Em.isEmpty(configs)) {
  39. service.exclude.forEach(function (property) {
  40. var serviceProperty = configs.findProperty('name', property);
  41. if (serviceProperty) {
  42. var value = serviceProperty.get('isRequired');
  43. Em.set(serviceProperty, "isRequired", !value);
  44. if (value && serviceProperty.get('value')==='') {
  45. // clear validation errors because validation does not clear isRequired validations
  46. Em.set(serviceProperty, "error", false);
  47. Em.set(serviceProperty, "errorMessage", '');
  48. }
  49. // validate property
  50. serviceProperty.validate();
  51. }
  52. });
  53. }
  54. }
  55. })