| 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726 |
1
1
1
1
1
4
4
4
4
13
13
4
4
4
4
4
4
9
9
9
9
9
20
20
9
22
22
2
9
9
13
13
13
13
46
13
13
10
10
10
10
10
12
10
13
13
7
6
34
34
34
34
15
15
15
15
15
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
23
23
23
13
10
40
40
35
5
10
35
10
3
3
| 'use strict';
;require.register("views/common/configs/service_configs_by_category_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');
var validator = require('utils/validator');
require('utils/configs/modification_handlers/modification_handler');
App.ServiceConfigsByCategoryView = Em.View.extend(App.Persist, App.ConfigOverridable, App.WizardMiscPropertyChecker, {
templateName: require('templates/common/configs/service_config_category'),
classNames: ['panel-group', 'common-config-category', 'clear'],
classNameBindings: ['isShowBlock::hidden'],
'data-qa': function () {
return this.get('category.name') + ' ' + 'panel-group';
}.property('category.name'),
content: null,
category: null,
service: null,
/**
* View is editable or read-only?
* @type {boolean}
*/
canEdit: true,
/**
* All configs for current <code>service</code>
* @type {App.ServiceConfigProperty[]}
*/
serviceConfigs: null,
isUIDGIDVisible: true,
/**
* This is array of all the properties which apply
* to this category, irrespective of visibility. This
* is helpful in Oozie/Hive database configuration, where
* MySQL etc. database options don't show up, because
* they were not visible initially.
* @type {App.ServiceConfigProperty[]}
*/
categoryConfigsAll: [],
/**
* Configs for current category filtered by <code>isVisible</code>
* and sorted by <code>displayType</code> and <code>index</code>
* @type {App.ServiceConfigProperty[]}
*/
categoryConfigs: [],
/**
* Link to main configs view
* @type {Ember.View}
*/
mainView: function () {
//todo: Get rid of this logic. Get data from controller instead.
return ['mainHostServiceConfigsController', 'mainServiceInfoConfigsController'].contains(this.get('controller.name')) ? this.get('parentView.parentView') : this.get('parentView');
}.property('controller.name'),
didInsertElement: function didInsertElement() {
var self = this;
// If `this.categoryConfigsAll` is a computed property then don't set it.
// some extended class like `App.NotificationsConfigsView` overrides `categoryConfigsAll` as computed property
Em.run.next(function () {
Eif (self.get('state') !== 'inDOM') {
return;
}
if ($.isArray(self.categoryConfigsAll)) {
self.setCategoryConfigsAll();
}
self.setVisibleCategoryConfigs();
var isCollapsed = self.calcIsCollapsed();
self.set('category.isCollapsed', isCollapsed);
if (isCollapsed) {
self.$('.accordion-body').hide();
} else {
self.$('.accordion-body').show();
}
$('#serviceConfig').tooltip({
selector: '[data-toggle=tooltip]',
placement: 'top'
});
self.filteredCategoryConfigs();
self.updateReadOnlyFlags();
});
},
willDestroyElement: function willDestroyElement() {
$('[data-toggle=tooltip]').tooltip('destroy');
},
setVisibleCategoryConfigsOnce: function () {
Iif (this.get('controller.isChangingConfigAttributes')) {
this.setVisibleCategoryConfigs();
} else {
Em.run.once(this, 'addConfigToCategoryConfigs');
}
}.observes('categoryConfigsAll.@each.isVisible'),
setCategoryConfigsAll: function setCategoryConfigsAll() {
// reset `categoryConfigsAll` to empty array
this.set('categoryConfigsAll', []);
var categoryConfigsAll = this.get('serviceConfigs').filterProperty('category', this.get('category.name'));
Eif (categoryConfigsAll && categoryConfigsAll.length) {
this.set('categoryConfigsAll', categoryConfigsAll);
}
},
setVisibleCategoryConfigs: function setVisibleCategoryConfigs() {
var orderedCategoryConfigs = this.getOrderedCategoryConfigs();
this.set('categoryConfigs', orderedCategoryConfigs);
},
/**
* This method is invoked when any change in visibility of items of `categoryConfigsAll` array happens and accordingly sets `categoryConfigs` array
* Instead of completely resetting `categoryConfigs` array whenever this function is invoked , items are added/removed in `categoryConfigs` (which is binded in template)
* Doing so is observed to avoid memory leak
*/
addConfigToCategoryConfigs: function addConfigToCategoryConfigs() {
var orderedCategoryConfigs = this.getOrderedCategoryConfigs();
var categoryConfigs = this.get('categoryConfigs');
var configsToAdd = [];
var configsToRemove = [];
// If property is added or made visible then add it to visible categoryconfigs
orderedCategoryConfigs.forEach(function (item) {
var isPresent = categoryConfigs.filterProperty('name', item.get('name')).findProperty('filename', item.get('filename'));
Iif (!isPresent) {
configsToAdd.pushObject(item);
}
}, this);
// If property is removed or made invisible, then remove it from visible categoryconfigs
categoryConfigs.forEach(function (item) {
var orderedCategoryConfig = orderedCategoryConfigs.filterProperty('name', item.get('name')).findProperty('filename', item.get('filename'));
if (!orderedCategoryConfig) {
configsToRemove.pushObject(item);
}
}, this);
categoryConfigs.pushObjects(configsToAdd);
categoryConfigs.removeObjects(configsToRemove);
},
getOrderedCategoryConfigs: function getOrderedCategoryConfigs() {
var categoryConfigsAll = this.get('categoryConfigsAll');
var orderedCategoryConfigs = [];
Eif (categoryConfigsAll) {
var contentOrderedArray = this.orderContentAtLast(categoryConfigsAll.filterProperty('displayType', 'content')),
contentFreeConfigs = categoryConfigsAll.filter(function (config) {
return config.get('displayType') !== 'content';
}),
indexOrdered = this.sortByIndex(contentFreeConfigs);
orderedCategoryConfigs = indexOrdered.concat(contentOrderedArray).filterProperty('isVisible', true);
}
return orderedCategoryConfigs;
},
/**
* If added/removed a serverConfigObject, this property got updated.
* Without this property, all serviceConfigs Objects will show up even if some was collapsed before.
* @type {boolean}
*/
isCategoryBodyVisible: Em.computed.ifThenElse('category.isCollapsed', 'display: none;', 'display: block;'),
/**
* Should we show config group or not
* @type {boolean}
*/
isShowBlock: function () {
var isFilterEmpty = this.get('controller.filter') === '';
var isFilterActive = this.get('mainView.columns') && this.get('mainView.columns').someProperty('selected');
var isCustomPropertiesCategory = this.get('category.customCanAddProperty');
var isCompareMode = this.get('controller.isCompareMode');
var hasFilteredAdvancedConfigs = this.get('categoryConfigs').filter(function (config) {
return config.get('isHiddenByFilter') === false && Em.isNone(config.get('isInDefaultTheme'));
}, this).length > 0;
return isCustomPropertiesCategory && !isCompareMode && isFilterEmpty && !isFilterActive || hasFilteredAdvancedConfigs;
}.property('category.customCanAddProperty', 'categoryConfigs.@each.isHiddenByFilter', 'categoryConfigs.@each.isInDefaultTheme', 'controller.filter', 'controller.isCompareMode', 'mainView.columns.@each.selected'),
/**
* Re-order the configs to list content displayType properties at last in the category
* @param {App.ServiceConfigProperty[]} categoryConfigs
* @method orderContentAtLast
*/
orderContentAtLast: function orderContentAtLast(categoryConfigs) {
var contentProperties = categoryConfigs.filterProperty('displayType', 'content');
if (!contentProperties.length) {
return categoryConfigs;
} else {
return categoryConfigs.sort(function (a, b) {
var aContent = contentProperties.someProperty('name', a.get('name'));
var bContent = contentProperties.someProperty('name', b.get('name'));
Eif (aContent && bContent) {
return 0;
}
return aContent ? 1 : -1;
});
}
},
/**
* Warn/prompt user to adjust Service props when changing user/groups in Misc
* Is triggered when user ended editing text field
*/
configChangeObserver: function (manuallyChangedProperty) {
var changedProperty;
Iif (manuallyChangedProperty.get("id")) {
changedProperty = [manuallyChangedProperty];
} else {
changedProperty = this.get("serviceConfigs").filterProperty("editDone", true);
}
Iif (changedProperty.length > 0) {
changedProperty = changedProperty.objectAt(0);
} else {
return;
}
var stepConfigs = this.get("controller.stepConfigs");
var serviceId = this.get('controller.selectedService.serviceName');
return this.showConfirmationDialogIfShouldChangeProps(changedProperty, stepConfigs, serviceId);
}.observes('categoryConfigs.@each.editDone'),
/**
* When the view is in read-only mode, it marks
* the properties as read-only.
*/
updateReadOnlyFlags: function updateReadOnlyFlags() {
var configs = this.get('serviceConfigs');
var canEdit = this.get('canEdit');
if (!canEdit && configs) {
configs.forEach(function (c) {
c.set('isEditable', false);
var overrides = c.get('overrides');
if (overrides != null) {
overrides.setEach('isEditable', false);
}
});
}
},
/**
* Filtered <code>categoryConfigs</code> array. Used to show filtered result
* @method filteredCategoryConfigs
*/
filteredCategoryConfigs: function () {
Em.run.once(this, 'collapseCategory');
}.observes('serviceConfigs.@each.isHiddenByFilter'),
collapseCategory: function collapseCategory() {
Iif (this.get('state') === 'destroyed') return;
$('.popover').remove();
var filter = this.get('mainView.filter');
filter = filter ? filter.toLowerCase() : filter; // filter can be undefined in some wizard
var filteredResult = this.get('categoryConfigs');
var isInitialRendering = !arguments.length || arguments[1] != 'categoryConfigs';
filteredResult = filteredResult.filterProperty('isHiddenByFilter', false);
filteredResult = this.sortByIndex(filteredResult);
Iif (filter) {
if (filteredResult.length && typeof this.get('category.collapsedByDefault') === 'undefined') {
// Save state
this.set('category.collapsedByDefault', this.get('category.isCollapsed'));
}
this.set('category.isCollapsed', !filteredResult.length);
} else Iif (typeof this.get('category.collapsedByDefault') !== 'undefined') {
// If user clear filter -- restore defaults
this.set('category.isCollapsed', this.get('category.collapsedByDefault'));
this.set('category.collapsedByDefault', undefined);
} else Eif (isInitialRendering && !filteredResult.length) {
this.set('category.isCollapsed', true);
}
var classNames = this.get('category.name').split(' ');
// Escape the dots in category names
classNames = classNames.map(function (className) {
Eif (className.indexOf(".")) {
className = className.split(".").join("\\.");
}
return className;
});
var categoryBlock = $('.' + classNames.join('.') + '>.panel-body');
this.get('category.isCollapsed') ? categoryBlock.hide() : categoryBlock.show();
},
/**
* sort configs in current category by index
* @param configs
* @return {Array}
* @method sortByIndex
*/
sortByIndex: function sortByIndex(configs) {
var sortedConfigs = [];
var unSorted = [];
if (!configs.someProperty('index')) {
return configs;
}
configs.forEach(function (config) {
var index = config.get('index');
if (index !== null && isFinite(index)) {
sortedConfigs[index] ? sortedConfigs.splice(index, 0, config) : sortedConfigs[index] = config;
} else {
unSorted.push(config);
}
});
// remove undefined elements from array
sortedConfigs = sortedConfigs.filter(function (config) {
return config !== undefined;
});
return sortedConfigs.concat(unSorted);
},
/**
* Onclick handler for Config Group Header. Used to show/hide block
* @method onToggleBlock
*/
onToggleBlock: function onToggleBlock() {
this.$('.panel-body').toggle('blind', 500);
this.toggleProperty('category.isCollapsed');
},
/**
* Determines should panel be collapsed by default
* @returns {boolean}
* @method calcIsCollapsed
*/
calcIsCollapsed: function calcIsCollapsed() {
return Em.isNone(this.get('category.isCollapsed')) ? this.get('category.name').indexOf('Advanced') != -1 || this.get('category.name').indexOf('CapacityScheduler') != -1 || this.get('category.name').indexOf('Custom') != -1 : this.get('category.isCollapsed');
},
/**
* @returns {string}
*/
persistKey: function persistKey() {
return 'admin-bulk-add-properties-' + App.router.get('loginName');
},
isSecureConfig: function isSecureConfig(configName, filename) {
var secureConfigs = App.config.get('secureConfigs').filterProperty('filename', filename);
return !!secureConfigs.findProperty('name', configName);
},
createProperty: function createProperty(propertyObj) {
var config;
var selectedConfigGroup = this.get('controller.selectedConfigGroup');
var categoryConfigsAll = this.get('categoryConfigsAll');
if (selectedConfigGroup.get('isDefault')) {
config = App.config.createDefaultConfig(propertyObj.name, propertyObj.filename, false, {
value: propertyObj.value,
propertyType: propertyObj.propertyType,
category: propertyObj.categoryName,
isNotSaved: true
});
} else {
config = App.config.createCustomGroupConfig({
propertyName: propertyObj.name,
filename: propertyObj.filename,
value: propertyObj.value,
propertyType: propertyObj.propertyType,
category: propertyObj.categoryName,
isNotSaved: true
}, selectedConfigGroup);
}
var serviceConfigProperty = App.ServiceConfigProperty.create(config);
var duplicatedProperty = categoryConfigsAll.findProperty('name', config.name);
if (duplicatedProperty && duplicatedProperty.get('isUndefinedLabel')) {
serviceConfigProperty.set('overrides', duplicatedProperty.get('overrides'));
categoryConfigsAll.removeAt(categoryConfigsAll.indexOf(duplicatedProperty));
}
this._appendConfigToCollection(serviceConfigProperty);
},
/**
* @param {App.ServiceConfigProperty} serviceConfigProperty
* @private
*/
_appendConfigToCollection: function _appendConfigToCollection(serviceConfigProperty) {
this.get('serviceConfigs').pushObject(serviceConfigProperty);
this.get('categoryConfigsAll').pushObject(serviceConfigProperty);
this.setVisibleCategoryConfigs();
},
/**
* Find duplications within the same confType
* Result in error, as no duplicated property keys are allowed in the same configType
* */
isDuplicatedConfigKey: function isDuplicatedConfigKey(name) {
var category = this.get('category');
var siteFileName = category.get('siteFileName');
var service = this.get('service');
var serviceName = service.get('serviceName');
var configsOfFile = service.get('configs').filterProperty('filename', siteFileName);
var duplicatedProperty = configsOfFile.findProperty('name', name);
return duplicatedProperty && !duplicatedProperty.get('isUndefinedLabel');
},
/**
* find duplications in all confTypes of the service
* Result in warning, to remind user the existence of a same-named property
* */
isDuplicatedConfigKeyinConfigs: function isDuplicatedConfigKeyinConfigs(name) {
var files = [];
var service = this.get('service');
var configFiles = service.get('configs').mapProperty('filename').uniq();
configFiles.forEach(function (configFile) {
var configsOfFile = service.get('configs').filterProperty('filename', configFile);
var duplicatedProperty = configsOfFile.findProperty('name', name);
if (duplicatedProperty && !duplicatedProperty.get('isUndefinedLabel')) {
files.push(configFile);
}
}, this);
return files;
},
processAddPropertyWindow: function processAddPropertyWindow(isBulkMode, modePersistKey) {
var self = this;
var category = this.get('category');
var siteFileName = category.get('siteFileName');
var service = this.get('service');
var serviceName = service.get('serviceName');
var serviceConfigObj = Em.Object.create({
isBulkMode: isBulkMode,
bulkConfigValue: '',
bulkConfigError: false,
bulkConfigErrorMessage: '',
name: '',
value: '',
propertyType: [],
content: ['PASSWORD', 'USER', 'GROUP', 'TEXT', 'ADDITIONAL_USER_PROPERTY', 'NOT_MANAGED_HDFS_PATH', 'VALUE_FROM_PROPERTY_FILE'],
isKeyError: false,
showFilterLink: false,
errorMessage: '',
observeAddPropertyValue: function observeAddPropertyValue() {
var name = this.get('name').trim();
if (name !== '') {
if (validator.isValidConfigKey(name)) {
if (!self.isDuplicatedConfigKey(name)) {
//no duplication within the same confType
var files = self.isDuplicatedConfigKeyinConfigs(name);
if (files.length > 0) {
//still check for a warning, if there are duplications across confTypes
this.set('showFilterLink', true);
this.set('isKeyWarning', true);
this.set('isKeyError', false);
this.set('warningMessage', Em.I18n.t('services.service.config.addPropertyWindow.error.derivedKey.location').format(files.join(" ")));
} else {
this.set('showFilterLink', false);
this.set('isKeyError', false);
this.set('isKeyWarning', false);
this.set('errorMessage', '');
}
} else {
this.set('showFilterLink', true);
this.set('isKeyError', true);
this.set('isKeyWarning', false);
this.set('errorMessage', Em.I18n.t('services.service.config.addPropertyWindow.error.derivedKey.infile'));
}
} else {
this.set('showFilterLink', false);
this.set('isKeyError', true);
this.set('isKeyWarning', false);
this.set('errorMessage', Em.I18n.t('form.validator.configKey'));
}
} else {
this.set('showFilterLink', false);
this.set('isKeyError', true);
this.set('isKeyWarning', false);
this.set('errorMessage', Em.I18n.t('services.service.config.addPropertyWindow.error.required'));
}
}
});
App.ModalPopup.show({
classNames: ['common-modal-wrapper'],
modalDialogClasses: ['modal-lg'],
header: Em.I18n.t('installer.step7.config.addProperty'),
primary: Em.I18n.t('add'),
secondary: Em.I18n.t('common.cancel'),
onPrimary: function onPrimary() {
var propertyObj = {
filename: siteFileName,
serviceName: serviceName,
categoryName: category.get('name')
};
if (serviceConfigObj.isBulkMode) {
var popup = this;
this.processConfig(serviceConfigObj.bulkConfigValue, function (error, parsedConfig) {
if (error) {
serviceConfigObj.set('bulkConfigError', true);
serviceConfigObj.set('bulkConfigErrorMessage', error);
} else {
for (var key in parsedConfig) {
if (parsedConfig.hasOwnProperty(key)) {
propertyObj.name = key;
propertyObj.value = parsedConfig[key];
self.createProperty(propertyObj);
}
}
popup.hide();
}
});
} else {
serviceConfigObj.observeAddPropertyValue();
/**
* For the first entrance use this if (serviceConfigObj.name.trim() != '')
*/
if (!serviceConfigObj.isKeyError) {
propertyObj.name = serviceConfigObj.get('name').trim();
propertyObj.value = serviceConfigObj.get('value');
propertyObj.propertyType = serviceConfigObj.get('propertyType');
self.createProperty(propertyObj);
this.hide();
}
}
},
lineNumber: function lineNumber(index) {
return Em.I18n.t('services.service.config.addPropertyWindow.error.lineNumber').format(index + 1);
},
processConfig: function processConfig(config, callback) {
var lines = config.split('\n');
var errorMessages = [];
var parsedConfig = {};
var propertyCount = 0;
lines.forEach(function (line, index) {
if (line.trim() === '') {
return;
}
var delimiter = '=';
var delimiterPosition = line.indexOf(delimiter);
if (delimiterPosition === -1) {
errorMessages.push(this.lineNumber(index) + Em.I18n.t('services.service.config.addPropertyWindow.error.format'));
return;
}
var key = Em.Handlebars.Utils.escapeExpression(line.slice(0, delimiterPosition).trim());
var value = line.slice(delimiterPosition + 1);
if (validator.isValidConfigKey(key)) {
if (!self.isDuplicatedConfigKey(key) && !(key in parsedConfig)) {
parsedConfig[key] = value;
propertyCount++;
} else {
errorMessages.push(this.lineNumber(index) + Em.I18n.t('services.service.config.addPropertyWindow.error.derivedKey.specific').format(key));
}
} else {
errorMessages.push(this.lineNumber(index) + Em.I18n.t('form.validator.configKey.specific').format(key));
}
}, this);
if (errorMessages.length > 0) {
callback(errorMessages.join('<br>'), parsedConfig);
} else if (propertyCount === 0) {
callback(Em.I18n.t('services.service.config.addPropertyWindow.propertiesPlaceholder', parsedConfig));
} else {
callback(null, parsedConfig);
}
},
willDestroyElement: function willDestroyElement() {
serviceConfigObj.destroy();
this._super();
},
bodyClass: Em.View.extend({
fileName: siteFileName,
notMisc: serviceName !== 'MISC',
templateName: require('templates/common/configs/addPropertyWindow'),
serviceConfigObj: serviceConfigObj,
didInsertElement: function didInsertElement() {
this._super();
serviceConfigObj.addObserver('name', serviceConfigObj, 'observeAddPropertyValue');
App.tooltip(this.$("[data-toggle=tooltip]"), {
placement: "top"
});
},
willDestroyElement: function willDestroyElement() {
this.$().popover('destroy');
serviceConfigObj.removeObserver('name', serviceConfigObj, 'observeAddPropertyValue');
this.set('serviceConfigObj', null);
this._super();
},
toggleBulkMode: function toggleBulkMode() {
this.toggleProperty('serviceConfigObj.isBulkMode');
self.postUserPref(modePersistKey, this.get('serviceConfigObj.isBulkMode'));
},
filterByKey: function filterByKey(event) {
var controller = App.router.get('currentState.name') == 'configs' ? App.router.get('mainServiceInfoConfigsController') : App.router.get('wizardStep7Controller');
controller.set('filter', this.get('serviceConfigObj.name'));
this.get('parentView').onClose();
}
})
});
},
/**
* Show popup for adding new config-properties
* @method showAddPropertyWindow
*/
showAddPropertyWindow: function showAddPropertyWindow() {
var persistController = this;
var modePersistKey = this.persistKey();
var selectedConfigGroup = this.get('controller.selectedConfigGroup');
persistController.getUserPref(modePersistKey).then(function (data) {
return !!data;
}, function () {
return false;
}).always(function (isBulkMode) {
persistController.processAddPropertyWindow(isBulkMode, modePersistKey);
});
},
/**
* Toggle <code>isFinal</code> for selected config-property if <code>isNotEditable</code> is false
* @param {object} event
* @method toggleFinalFlag
*/
toggleFinalFlag: function toggleFinalFlag(event) {
var serviceConfigProperty = event.contexts[0];
if (serviceConfigProperty.get('isNotEditable')) {
return;
}
serviceConfigProperty.toggleProperty('isFinal');
serviceConfigProperty = null;
},
/**
* Removes the top-level property from list of properties.
* Should be only called on user properties.
* @method removeProperty
*/
removeProperty: function removeProperty(event) {
var serviceConfigProperty = event.contexts[0];
// push config's file name if this config was stored on server
if (!serviceConfigProperty.get('isNotSaved')) {
var modifiedFileNames = this.get('controller.modifiedFileNames'),
wizardController = this.get('controller.wizardController'),
filename = serviceConfigProperty.get('filename');
if (modifiedFileNames && !modifiedFileNames.contains(filename)) {
modifiedFileNames.push(serviceConfigProperty.get('filename'));
} else if (wizardController) {
var fileNamesToUpdate = wizardController.getDBProperty('fileNamesToUpdate') || [];
if (!fileNamesToUpdate.contains(filename)) {
fileNamesToUpdate.push(filename);
wizardController.setDBProperty('fileNamesToUpdate', fileNamesToUpdate);
}
}
}
this.get('serviceConfigs').removeObject(serviceConfigProperty);
this.get('categoryConfigsAll').removeObject(serviceConfigProperty);
serviceConfigProperty = null;
Em.$('body>.tooltip').remove(); //some tooltips get frozen when their owner's DOM element is removed
},
/**
* Set config's value to recommended
* @param event
* @method setRecommendedValue
*/
setRecommendedValue: function setRecommendedValue(event) {
var serviceConfigProperty = event.contexts[0];
serviceConfigProperty.set('value', serviceConfigProperty.get('recommendedValue'));
//in case of USER/GROUP fields, if they have uid/gid set, then these need to be reset to the recommended value as well
if (serviceConfigProperty.get('ugid')) {
serviceConfigProperty.set('ugid.value', serviceConfigProperty.get('ugid.recommendedValue'));
}
serviceConfigProperty = null;
},
/**
* Restores given property's value to be its default value.
* Does not update if there is no default value.
* @method doRestoreDefaultValue
*/
doRestoreDefaultValue: function doRestoreDefaultValue(event) {
var serviceConfigProperty = event.contexts[0];
var savedValue = serviceConfigProperty.get('savedValue');
var supportsFinal = serviceConfigProperty.get('supportsFinal');
var savedIsFinal = serviceConfigProperty.get('savedIsFinal');
if (savedValue != null) {
if (serviceConfigProperty.get('displayType') === 'password') {
serviceConfigProperty.set('retypedPassword', savedValue);
}
serviceConfigProperty.set('changedViaUndoValue', true);
serviceConfigProperty.set('value', savedValue);
serviceConfigProperty.set('changedViaUndoValue', false);
}
if (supportsFinal) {
serviceConfigProperty.set('isFinal', savedIsFinal);
}
this.configChangeObserver(serviceConfigProperty);
serviceConfigProperty = null;
Em.$('body>.tooltip').remove(); //some tooltips get frozen when their owner's DOM element is removed
}
});
}); |