overriddenProperty_view.js 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. if (this.get('controller.name') != 'mainServiceInfoConfigsController') {
  27. this.addObserver('isDefaultGroupSelected', this, 'setSwitchText');
  28. }
  29. },
  30. didInsertElement: function () {
  31. this.setSwitchText();
  32. },
  33. willDestroyElement: function () {
  34. if (this.get('controller.name') != 'mainServiceInfoConfigsController') {
  35. this.removeObserver('isDefaultGroupSelected', this, 'setSwitchText');
  36. }
  37. },
  38. setSwitchText: function () {
  39. Em.$('body>.tooltip').remove();
  40. if (this.get('isDefaultGroupSelected')) {
  41. var overrides = this.get('serviceConfigProperty.overrides');
  42. if (!overrides) return;
  43. overrides.forEach(function(overriddenSCP) {
  44. overriddenSCP.get('group').set('switchGroupTextShort',
  45. Em.I18n.t('services.service.config_groups.switchGroupTextShort').format(overriddenSCP.get('group.displayName')));
  46. overriddenSCP.get('group').set('switchGroupTextFull',
  47. Em.I18n.t('services.service.config_groups.switchGroupTextFull').format(overriddenSCP.get('group.displayName')));
  48. });
  49. this.set('serviceConfigProperty.overrides', overrides);
  50. }
  51. App.tooltip(this.$('[data-toggle=tooltip]'),{
  52. placement: 'top'
  53. });
  54. },
  55. toggleFinalFlag: function (event) {
  56. var override = event.contexts[0];
  57. if (override.get('isNotEditable')) {
  58. return;
  59. }
  60. override.set('isFinal', !override.get('isFinal'));
  61. },
  62. removeOverride: function (event) {
  63. // arg 1 SCP means ServiceConfigProperty
  64. var scpToBeRemoved = event.contexts[0];
  65. var overrides = this.get('serviceConfigProperty.overrides');
  66. // remove override property from selectedService on installer 7-th step
  67. if (this.get('controller.name') == 'wizardStep7Controller') {
  68. var controller = this.get('controller');
  69. var group = controller.get('selectedService.configGroups').findProperty('name', controller.get('selectedConfigGroup.name'));
  70. group.get('properties').removeObject(scpToBeRemoved);
  71. }
  72. if (App.get('supports.enhancedConfigs')) {
  73. var deletedConfig = App.ConfigProperty.find().find(function(cp) {
  74. return cp.get('name') === scpToBeRemoved.get('name')
  75. && cp.get('fileName') === scpToBeRemoved.get('filename')
  76. && cp.get('configVersion.groupName') === this.get('controller.selectedConfigGroup.name');
  77. }, this);
  78. if (deletedConfig) {
  79. deletedConfig.deleteRecord();
  80. App.store.commit();
  81. }
  82. }
  83. overrides = overrides.without(scpToBeRemoved);
  84. this.set('serviceConfigProperty.overrides', overrides);
  85. Em.$('body>.tooltip').remove(); //some tooltips get frozen when their owner's DOM element is removed
  86. }
  87. });