123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- /**
- * 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');
- /**
- * Abstract view for config fields.
- * Add popover support to control
- */
- App.ServiceConfigPopoverSupport = Ember.Mixin.create({
- /**
- * Config object. It will instance of App.ServiceConfigProperty
- */
- serviceConfig: null,
- placeholderBinding: 'serviceConfig.defaultValue',
- isPopoverEnabled: true,
- didInsertElement: function () {
- if (this.get('isPopoverEnabled') !== 'false') {
- this.$().popover({
- title: this.get('serviceConfig.displayName') + '<br><small>' + this.get('serviceConfig.name') + '</small>',
- content: this.get('serviceConfig.description'),
- placement: 'right',
- trigger: 'hover'
- });
- }
- }
- });
- /**
- * Default input control
- * @type {*}
- */
- App.ServiceConfigTextField = Ember.TextField.extend(App.ServiceConfigPopoverSupport, {
- valueBinding: 'serviceConfig.value',
- classNameBindings: 'textFieldClassName',
- placeholderBinding: 'serviceConfig.defaultValue',
- textFieldClassName: function () {
- // sets the width of the field depending on display type
- if (['directory', 'url', 'email', 'user', 'host'].contains(this.get('serviceConfig.displayType'))) {
- return ['span6'];
- } else if(this.get('serviceConfig.displayType') === 'advanced'){
- return ['span6'];
- } else{
- return ['input-small'];
- }
- }.property('serviceConfig.displayType'),
- disabled: function () {
- return !this.get('serviceConfig.isEditable');
- }.property('serviceConfig.isEditable')
- });
- /**
- * Customized input control with Utits type specified
- * @type {*}
- */
- App.ServiceConfigTextFieldWithUnit = Ember.View.extend(App.ServiceConfigPopoverSupport, {
- valueBinding: 'serviceConfig.value',
- classNames: [ 'input-append' ],
- placeholderBinding: 'serviceConfig.defaultValue',
- template: Ember.Handlebars.compile('{{view App.ServiceConfigTextField serviceConfigBinding="view.serviceConfig" isPopoverEnabled="false"}}<span class="add-on">{{view.serviceConfig.unit}}</span>'),
- disabled: function () {
- return !this.get('serviceConfig.isEditable');
- }.property('serviceConfig.isEditable')
- });
- /**
- * Password control
- * @type {*}
- */
- App.ServiceConfigPasswordField = Ember.TextField.extend({
- serviceConfig: null,
- type: 'password',
- valueBinding: 'serviceConfig.value',
- classNames: [ 'span3' ],
- placeholder: 'Type password',
- template: Ember.Handlebars.compile('{{view view.retypePasswordView placeholder="Retype password"}}'),
- retypePasswordView: Ember.TextField.extend({
- type: 'password',
- classNames: [ 'span3', 'retyped-password' ],
- valueBinding: 'parentView.serviceConfig.retypedPassword'
- })
- });
- /**
- * Textarea control
- * @type {*}
- */
- App.ServiceConfigTextArea = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, {
- valueBinding: 'serviceConfig.value',
- rows: 4,
- classNames: ['span6'],
- placeholderBinding: 'serviceConfig.defaultValue',
- disabled: function () {
- return !this.get('serviceConfig.isEditable');
- }.property('serviceConfig.isEditable')
- });
- /**
- * Textarea control with bigger height
- * @type {*}
- */
- App.ServiceConfigBigTextArea = App.ServiceConfigTextArea.extend({
- rows: 10
- });
- /**
- * Checkbox control
- * @type {*}
- */
- App.ServiceConfigCheckbox = Ember.Checkbox.extend(App.ServiceConfigPopoverSupport, {
- checkedBinding: 'serviceConfig.value',
- disabled: function () {
- return !this.get('serviceConfig.isEditable');
- }.property('serviceConfig.isEditable')
- });
- <!-- {{bindAttr name="view.name" value="option"}} '<input type="radio" {{bindAttr name = "view.name" value="view.obj"}}>',-->
- App.ServiceConfigRadioButtons = Ember.View.extend({
- template: Ember.Handlebars.compile([
- '{{#each option in view.options}}',
- '<label class="radio">',
- '{{#view App.ServiceConfigRadioButton nameBinding = "view.name" valueBinding = "option.displayName"}}',
- '{{/view}}',
- '{{option.displayName}} ',
- '</label>',
- '{{/each}}'
- ].join('\n')),
- serviceConfig: null,
- categoryConfigs: null,
- nameBinding: 'serviceConfig.radioName',
- optionsBinding: 'serviceConfig.options'
- });
- App.ServiceConfigRadioButton = Ember.Checkbox.extend({
- tagName: 'input',
- attributeBindings: ['type', 'name', 'value', 'checked'],
- checked: false,
- type: 'radio',
- name: null,
- value: null,
- didInsertElement: function () {
- if (this.get('parentView.serviceConfig.value') === this.get('value')) {
- this.set('checked', true);
- }
- },
- click: function () {
- this.set('checked', true);
- this.onChecked();
- },
- onChecked: function () {
- this.set('parentView.serviceConfig.value', this.get('value'));
- var components = this.get('parentView.serviceConfig.options');
- components.forEach(function (_component) {
- _component.foreignKeys.forEach(function (_componentName) {
- var component = this.get('parentView.categoryConfigs').findProperty('name', _componentName);
- if (_component.displayName === this.get('value')) {
- component.set('isVisible', true);
- } else {
- component.set('isVisible', false);
- }
- }, this);
- }, this);
- }.observes('checked')
- });
- App.ServiceConfigComboBox = Ember.Select.extend(App.ServiceConfigPopoverSupport, {
- contentBinding: 'serviceConfig.options',
- selectionBinding: 'serviceConfig.value',
- classNames: [ 'span3' ]
- });
- /**
- * Base component for host config with popover support
- */
- App.ServiceConfigHostPopoverSupport = Ember.Mixin.create({
- /**
- * Config object. It will instance of App.ServiceConfigProperty
- */
- serviceConfig: null,
- didInsertElement: function () {
- this.$().popover({
- title: this.get('serviceConfig.displayName'),
- content: this.get('serviceConfig.description'),
- placement: 'right',
- trigger: 'hover'
- });
- }
- });
- /**
- * Master host component.
- * Show hostname without ability to edit it
- * @type {*}
- */
- App.ServiceConfigMasterHostView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, {
- classNames: ['master-host', 'span6'],
- valueBinding: 'serviceConfig.value',
- template: Ember.Handlebars.compile('{{value}}')
- });
- /**
- * Base component to display Multiple hosts
- * @type {*}
- */
- App.ServiceConfigMultipleHostsDisplay = Ember.Mixin.create(App.ServiceConfigHostPopoverSupport, {
- hasNoHosts: function () {
- console.log('view', this.get('viewName')); //to know which View cause errors
- console.log('controller', this.get('controller').name); //should be slaveComponentGroupsController
- if(!this.get('value')){
- // debugger;
- return true;
- }
- return this.get('value').length === 0;
- }.property('value'),
- hasOneHost: function () {
- return this.get('value').length > 0;
- }.property('value'),
- hasMultipleHosts: function () {
- return (this.get('value').length > 1 && typeof(this.get('value')) == 'object');
- }.property('value'),
- otherLength: function () {
- var len = this.get('value').length;
- if (len > 2) {
- return (len - 1) + ' others';
- } else {
- return '1 other';
- }
- }.property('value')
- })
- /**
- * Multiple master host component.
- * Show hostnames without ability to edit it
- * @type {*}
- */
- App.ServiceConfigMasterHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
- viewName : "serviceConfigMasterHostsView",
- valueBinding: 'serviceConfig.value',
- classNames: ['master-hosts', 'span6'],
- templateName: require('templates/wizard/master_hosts'),
- /**
- * Onclick handler for link
- */
- showHosts: function () {
- var serviceConfig = this.get('serviceConfig');
- App.ModalPopup.show({
- header: serviceConfig. category + ' Hosts',
- bodyClass: Ember.View.extend({
- serviceConfig: serviceConfig,
- templateName: require('templates/wizard/master_hosts_popup')
- }),
- onPrimary:function(){
- this.hide();
- }
- });
- }
- });
- /**
- * Show tabs list for slave hosts
- * @type {*}
- */
- App.SlaveComponentGroupsMenu = Em.CollectionView.extend({
- content: function(){
- return this.get('controller.componentGroups');
- }.property('controller.componentGroups'),
- tagName:'ul',
- classNames: ["nav", "nav-tabs"],
- itemViewClass:Em.View.extend({
- classNameBindings:["active"],
- active:function(){
- return this.get('content.active');
- }.property('content.active'),
- template:Ember.Handlebars.compile('<a {{action showSlaveComponentGroup view.content target="controller"}} href="#"> {{view.content.name}}</a><i {{action removeSlaveComponentGroup view.content target="controller"}} class="icon-remove"></i>')
- })
- });
- /**
- * <code>Add group</code> button
- * @type {*}
- */
- App.AddSlaveComponentGroupButton = Ember.View.extend({
- tagName: 'span',
- slaveComponentName: null,
- didInsertElement: function () {
- this.$().popover({
- title: 'Add a ' + this.get('slaveComponentName') + ' Group',
- content: 'If you need different settings on certain ' + this.get('slaveComponentName') + 's, you can add a ' + this.get('slaveComponentName') + ' group.<br>' +
- 'All ' + this.get('slaveComponentName') + 's within the same group will have the same set of settings. You can create multiple groups.',
- placement: 'right',
- trigger: 'hover'
- });
- }
- });
- /**
- * Multiple Slave Hosts component
- * @type {*}
- */
- App.ServiceConfigSlaveHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
- viewName : 'serviceConfigSlaveHostsView',
- classNames: ['slave-hosts', 'span6'],
- valueBinding: 'hosts',
- group: function(){
- return this.get('controller.activeGroup');
- }.property('controller.activeGroup'),
- hosts: function(){
- if (this.get('group')){
- return this.get('controller').getHostsByGroup(this.get('group'))
- }
- }.property('controller.hosts.@each.group', 'group'),
- templateName: require('templates/wizard/slave_component_hosts'),
- disabled: function () {
- return !this.get('serviceConfig.isEditable');
- }.property('serviceConfig.isEditable')
- });
- /**
- * DropDown component for <code>select hosts for groups</code> popup
- * @type {*}
- */
- App.SlaveComponentDropDownGroupView = Ember.View.extend({
- viewName : "slaveComponentDropDownGroupView",
- /**
- * On change handler for <code>select hosts for groups</code> popup
- * @param event
- */
- changeGroup: function(event) {
- var host = this.get('content');
- var groupName = $('#'+this.get('elementId') + ' select').val();
- this.get('controller').changeHostGroup(host, groupName);
- },
- optionTag: Ember.View.extend({
- /**
- * Whether current value(OptionTag value) equals to host value(assigned to SlaveComponentDropDownGroupView.content)
- */
- selected: function(){
- return this.get('parentView.content.group') === this.get('content');
- }.property('content')
- })
- });
- /**
- * Show info about current group
- * @type {*}
- */
- App.SlaveComponentChangeGroupNameView = Ember.View.extend({
- contentBinding: 'controller.activeGroup',
- classNames: ['control-group'],
- classNameBindings: 'error',
- error: false,
- setError: function(){
- this.set('error', false);
- }.observes('controller.activeGroup'),
- errorMessage: function(){
- return this.get('error') ? 'group with this name already exist' : '';
- }.property('error'),
- /**
- * Onclick handler for saving updated group name
- * @param event
- */
- changeGroupName: function(event) {
- var inputVal = $('#'+this.get('elementId') + ' input[type="text"]').val();
- if (inputVal !== this.get('content.name')){
- var result = this.get('controller').changeSlaveGroupName(this.get('content'), inputVal);
- this.set('error', result);
- }
- }
- });
|