| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 |
1
1
1
4
4
3
3
3
3
3
3
3
3
16
16
14
8
8
3
3
3
3
3
6
6
| 'use strict';
;require.register("views/common/configs/custom_category_views/notification_configs_view", function (exports, require, module) {
/**
* 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');
/**
* Custom view for Notification section for MISC tab
* Used only in the Install Wizard
* Show configs for creating Init Notification (@see 'data/site_properties' for list of the configs used here)
*
* @type {App.NotificationsConfigsView}
*/
App.NotificationsConfigsView = App.ServiceConfigsByCategoryView.extend({
templateName: require('templates/common/configs/notifications_configs'),
/**
* @type {string} "yes|no"
*/
createNotification: 'no',
categoryConfigsAll: Em.computed.filterBy('serviceConfigs', 'filename', 'alert_notification'),
/**
* @type {string} "tls|ssl"
*/
tlsOrSsl: 'tls',
/**
* Determines if notification configs should be disabled
* @type {boolean}
*/
configsAreDisabled: Em.computed.equal('createNotification', 'no'),
/**
* Config with flag for user auth in the notification
* @type {App.ServiceConfigProperty}
*/
useAuthConfig: Em.computed.findBy('categoryConfigs', 'name', 'smtp_use_auth'),
/**
* Empty categoryConfigsAll means that user isn't at Installer, so manage notification view shouldn't be processed
* @method didInsertElement
*/
didInsertElement: function didInsertElement() {
this._super();
if (!this.get('categoryConfigsAll.length')) return;
this.set('createNotification', this.get('categoryConfigsAll').findProperty('name', 'create_notification').get('value'));
this.set('tlsOrSsl', this.get('categoryConfigsAll').findProperty('name', 'mail.smtp.starttls.enable').get('value') ? 'tls' : 'ssl');
var smtpUseAuth = this.get('categoryConfigsAll').findProperty('name', 'smtp_use_auth');
smtpUseAuth.set('value', Boolean(smtpUseAuth.get('value') === 'true'));
this.updateCategoryConfigs();
},
/**
* If <code>tlsOrSsl</code> was changed two configs should be updated
* TLS and SSL can't be enabled in the same time
* @method onTlsOrSslChanged
*/
onTlsOrSslChanged: function () {
var tlsOrSsl = this.get('tlsOrSsl');
this.get('categoryConfigsAll').findProperty('name', 'mail.smtp.starttls.enable').set('value', tlsOrSsl === 'tls');
this.get('categoryConfigsAll').findProperty('name', 'mail.smtp.startssl.enable').set('value', tlsOrSsl === 'ssl');
}.observes('tlsOrSsl'),
/**
* Update username and password fields state according to <code>useAuthConfig.value</code>
* @method onUseAuthConfigChange
*/
onUseAuthConfigChange: function () {
var configsToUpdate = ['ambari.dispatch.credential.username', 'ambari.dispatch.credential.password'],
useAuthConfigValue = this.get('useAuthConfig.value'),
useAuthConfigIsEditable = this.get('useAuthConfig.isEditable');
this.getWithDefault('categoryConfigs', []).forEach(function (config) {
if (configsToUpdate.contains(config.get('name'))) {
var flag = useAuthConfigIsEditable ? useAuthConfigValue : false;
this.updateConfig(config, flag);
}
}, this);
}.observes('useAuthConfig.value'),
/**
* Update all notification fields state according to <code>createNotification</code>
* If user select to create notification, all fields become editable and required (also run validation for each)
* If user select don't create notification, all fields become disabled, not required and valid
* @method updateCategoryConfigs
*/
updateCategoryConfigs: function () {
var createNotification = this.get('createNotification');
this.getWithDefault('categoryConfigs', []).forEach(function (config) {
this.updateConfig(config, Boolean(createNotification === 'yes'));
}, this);
this.onUseAuthConfigChange();
this.get('categoryConfigsAll').findProperty('name', 'create_notification').set('value', createNotification);
}.observes('createNotification'),
/**
* According to <code>flag</code>, enable/disable <code>config</code>
* If <code>flag</code> is true - validate <code>config</code> value
* If <code>flag</code> is false - mark <code>config</code> as valid
* @param {App.ServiceConfigProperty} config
* @param {boolean} flag
* @method updateConfig
*/
updateConfig: function updateConfig(config, flag) {
config.set('isRequired', flag);
config.set('isEditable', flag);
},
/**
* No sense to store config to <code>serviceConfigs</code> and <code>categoryConfigsAll</code> because
* <code>categoryConfigsAll</code> is a subset of <code>serviceConfigs</code>
*
* @override
*/
_appendConfigToCollection: function _appendConfigToCollection(serviceConfigProperty) {
this.get('serviceConfigs').pushObject(serviceConfigProperty);
}
});
}); |