overriddenProperty_view.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // SCP means ServiceConfigProperty
  18. var App = require('app');
  19. App.ServiceConfigView.SCPOverriddenRowsView = Ember.View.extend({
  20. templateName: require('templates/common/configs/overriddenProperty'),
  21. serviceConfigProperty: null, // is passed dynamically at runtime where ever
  22. // we are declaring this from configs.hbs ( we are initializing this from UI )
  23. categoryConfigs: null, // just declared as viewClass need it
  24. init: function () {
  25. this._super();
  26. this.addObserver('isDefaultGroupSelected', this, 'setSwitchText');
  27. },
  28. didInsertElement: function () {
  29. this.setSwitchText();
  30. },
  31. willDestroyElement: function () {
  32. this.removeObserver('isDefaultGroupSelected', this, 'setSwitchText');
  33. },
  34. setSwitchText: function () {
  35. Em.$('body>.tooltip').remove();
  36. if (this.get('isDefaultGroupSelected')) {
  37. var overrides = this.get('serviceConfigProperty.overrides');
  38. overrides.forEach(function(overriddenSCP) {
  39. overriddenSCP.get('group').set('switchGroupTextShort',
  40. Em.I18n.t('services.service.config_groups.switchGroupTextShort').format(overriddenSCP.get('group.displayName')));
  41. overriddenSCP.get('group').set('switchGroupTextFull',
  42. Em.I18n.t('services.service.config_groups.switchGroupTextFull').format(overriddenSCP.get('group.displayName')));
  43. })
  44. this.set('serviceConfigProperty.overrides', overrides);
  45. }
  46. App.tooltip(this.$('[data-toggle=tooltip]'),{
  47. placement: 'top'
  48. });
  49. },
  50. toggleFinalFlag: function (event) {
  51. var override = event.contexts[0];
  52. if (override.get('isNotEditable')) {
  53. return;
  54. }
  55. override.set('isFinal', !override.get('isFinal'));
  56. },
  57. removeOverride: function (event) {
  58. // arg 1 SCP means ServiceConfigProperty
  59. var scpToBeRemoved = event.contexts[0];
  60. var overrides = this.get('serviceConfigProperty.overrides');
  61. // remove override property from selectedService on installer 7-th step
  62. if (this.get('controller.name') == 'wizardStep7Controller') {
  63. var controller = this.get('controller');
  64. var group = controller.get('selectedService.configGroups').findProperty('name', controller.get('selectedConfigGroup.name'));
  65. group.get('properties').removeObject(scpToBeRemoved);
  66. }
  67. overrides = overrides.without(scpToBeRemoved);
  68. this.set('serviceConfigProperty.overrides', overrides);
  69. Em.$('body>.tooltip').remove(); //some tooltips get frozen when their owner's DOM element is removed
  70. }
  71. });