service_config_layout_tab_view.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.ServiceConfigLayoutTabView = Em.View.extend({
  20. templateName: require('templates/common/configs/service_config_layout_tab'),
  21. classNames: ['enhanced-config-tab-content'],
  22. /**
  23. * ConfigType-Widget map
  24. * key - widget type
  25. * value - widget view
  26. * @type {object}
  27. */
  28. widgetTypeMap: {
  29. slider: App.SliderConfigWidgetView
  30. },
  31. /**
  32. * Prepare configs for render
  33. * <code>subsection.configs</code> is an array of App.StackConfigProperty, but not App.ConfigProperty,
  34. * so proper config-properties should be linked to the subsections.
  35. * Also correct widget should be used for each config (it's selected according to <code>widget.type</code> and
  36. * <code>widgetTypeMap</code>). It may throw an error if needed widget can't be found in the <code>widgetTypeMap</code>
  37. * @method prepareConfigProperties
  38. */
  39. prepareConfigProperties: function () {
  40. var widgetTypeMap = this.get('widgetTypeMap');
  41. var self = this;
  42. var serviceName = self.get('controller.content.serviceName');
  43. this.get('content.sectionRows').forEach(function (row) {
  44. row.forEach(function (section) {
  45. section.get('subsectionRows').forEach(function (subRow) {
  46. subRow.forEach(function (subsection) {
  47. subsection.set('configs', []);
  48. subsection.get('configProperties').forEach(function (config) {
  49. var service = self.get('controller.stepConfigs').findProperty('serviceName', serviceName);
  50. if (!service) return;
  51. var configProperty = service.get('configs').findProperty('name', config.get('name'));
  52. if (!configProperty) return;
  53. subsection.get('configs').pushObject(configProperty);
  54. var configWidgetType = config.get('widget.type');
  55. var widget = widgetTypeMap[configWidgetType];
  56. Em.assert('Unknown config widget view for config ' + configProperty.get('id') + ' with type ' + configWidgetType, widget);
  57. configProperty.set('widget', widget);
  58. configProperty.set('stackConfigProperty', config);
  59. });
  60. });
  61. });
  62. });
  63. });
  64. },
  65. willInsertElement: function () {
  66. this._super();
  67. this.prepareConfigProperties();
  68. }
  69. });