瀏覽代碼

AMBARI-10284. Implement radio-buttons widget for config (alexantonenko)

Alex Antonenko 10 年之前
父節點
當前提交
2b43a272c2

+ 33 - 0
ambari-web/app/templates/common/configs/widgets/radio_button_config.hbs

@@ -0,0 +1,33 @@
+{{!
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+}}
+
+{{#if view.isOriginalSCP}}
+  <p class="widget-config-label">
+    {{view.configLabel}}
+  </p>
+{{/if}}
+<div class="pull-left">
+  {{#each item in view.content}}
+    <label>
+      {{view Ember.RadioButton nameBinding="view.elementId" valueBinding="item.value" selectionBinding="view.config.value"}}
+      {{item.label}}
+    </label>
+  {{/each}}
+</div>
+{{view App.RestoreConfigView}}
+<div class="clearfix"></div>

+ 1 - 0
ambari-web/app/views.js

@@ -60,6 +60,7 @@ require('views/common/configs/widgets/combo_config_widget_view');
 require('views/common/configs/widgets/number_config_widget_view');
 require('views/common/configs/widgets/password_config_widget_view');
 require('views/common/configs/widgets/list_config_widget_view');
+require('views/common/configs/widgets/radio_button_config_widget_view');
 require('views/common/configs/widgets/slider_config_widget_view');
 require('views/common/configs/widgets/string_config_widget_view');
 require('views/common/configs/widgets/time_interval_spinner_view');

+ 10 - 1
ambari-web/app/views/common/configs/service_config_layout_tab_view.js

@@ -37,7 +37,16 @@ App.ServiceConfigLayoutTabView = Em.View.extend(App.ConfigOverridable, {
    * @type {object}
    */
   widgetTypeMap: {
-    slider: App.SliderConfigWidgetView
+    checkbox: App.CheckboxConfigWidgetView,
+    combo: App.ComboConfigWidgetView,
+    directory: App.DirectoryConfigWidgetView,
+    directories: App.DirectoryConfigWidgetView,
+    list: App.ListConfigWidgetView,
+    password: App.PasswordConfigWidgetView,
+    'radio-buttons': App.RadioButtonConfigWidgetView,
+    slider: App.SliderConfigWidgetView,
+    'time-interval-spinner': App.TimeIntervalSpinnerView,
+    toggle: App.ToggleConfigWidgetView
   },
 
   /**

+ 48 - 0
ambari-web/app/views/common/configs/widgets/radio_button_config_widget_view.js

@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+App.RadioButtonConfigWidgetView = App.ConfigWidgetView.extend({
+  templateName: require('templates/common/configs/widgets/radio_button_config'),
+  classNames: ['widget', 'radio-button-widget'],
+
+  /**
+   * Content for radio buttons has following structure:
+   *    .value {String} - radio value attribute
+   *    .label {String} - label to display along with radio button
+   *    .description {String} - description for specified value
+   * @type {Em.Object[]}
+   * @property content
+   */
+
+  didInsertElement: function() {
+    this.generateContent();
+  },
+
+  generateContent: function() {
+    this.set('content', this.get('config.stackConfigProperty.valueAttributes.entries').map(function(item, index, collection) {
+      return Em.Object.create({
+        value: item,
+        descripton: this.get('config.stackConfigProperty.valueAttributes.entry_descriptions.' + index),
+        label: this.get('config.stackConfigProperty.valueAttributes.entry_labels.' + index)
+      });
+    }, this));
+  }
+
+});