-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
202 lines (181 loc) · 6.27 KB
/
index.js
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
Ext.define('CA.technicalservices.userutilities.FieldPicker', {
alias: 'widget.tsfieldpickerbutton',
extend: 'Rally.ui.Button',
requires: [
'Rally.ui.popover.Popover',
'Rally.ui.Button',
'Rally.ui.picker.FieldPicker',
'Ext.state.Manager'
],
toolTipConfig: {
html: 'Show Columns',
anchor: 'top'
},
iconCls: 'icon-add-column',
cls: 'field-picker-btn secondary rly-small',
alwaysSelectedValues: ['FormattedID', 'Name'], // DragAndDropRank gets added in init if Drag and Drop is enabled for the workspace in the component's context
fieldBlackList: [],
fieldPickerConfig: {},
buttonConfig: {},
modelNames: ['User'],
rankingEnabled: false,
//This does not show the Rank column
constructor: function(config) {
this.config = _.merge({}, this.config || {}, config || {});
this.callParent([config]);
},
initComponent: function() {
if (this.models) {
this.on('click', this._createPopover, this);
this.callParent(arguments);
return;
}
if (this.context && this.modelNames && this.modelNames.length > 0) {
Rally.data.ModelFactory.getModels({
types: this.modelNames,
context: this.context,
success: function(models) {
this.models = models;
},
failure: function(failedParam) {
console.log('failedparam');
},
scope: this
});
this.on('click', this._createPopover, this);
}
else {
this.iconCls = 'icon-none';
var msg = "Please update the CA.technicalservices.FieldPicker configuration with modelNames and context";
this.toolTipConfig = {
html: '<div style="color:red;">' + msg + '</div>'
};
this.on('click', function() { Rally.ui.notify.Notifier.showError({ message: msg }); });
}
this.callParent(arguments);
},
getFields: function() {
return _.union(this._fields || [], this.alwaysSelectedValues);
},
_getPickerConfig: function() {
var pickerConfig;
pickerConfig = _.extend({
value: this._fields,
fieldBlackList: this.fieldBlackList,
alwaysSelectedValues: this.alwaysSelectedValues,
context: this.context
}, this.fieldPickerConfig);
return pickerConfig;
},
_createPopover: function(btn) {
var popoverTarget = btn.getEl();
this.popover = Ext.create('Rally.ui.popover.Popover', {
target: popoverTarget,
placement: ['bottom', 'left', 'top', 'right'],
cls: 'field-picker-popover',
toFront: Ext.emptyFn,
buttonAlign: 'center',
title: this.getTitle(),
listeners: {
destroy: function() {
this.popover = null;
},
scope: this
},
buttons: [{
xtype: "rallybutton",
text: 'Apply',
cls: 'field-picker-apply-btn primary rly-small',
listeners: {
click: function() {
this._onApply(this.popover);
},
scope: this
}
},
{
xtype: "rallybutton",
text: 'Cancel',
cls: 'field-picker-cancel-btn secondary dark rly-small',
listeners: {
click: function() {
this.popover.close();
},
scope: this
}
}
],
items: [
_.extend({
xtype: 'rallyfieldpicker',
cls: 'field-picker',
itemId: 'fieldpicker',
modelTypes: this._getModelTypes(),
alwaysExpanded: true,
width: 200,
emptyText: 'Search',
selectedTextLabel: 'Selected',
availableTextLabel: 'Available',
listeners: {
specialkey: function(field, e) {
if (e.getKey() === e.ESC) {
this.popover.close();
}
},
scope: this
}
}, this._getPickerConfig())
]
});
},
_getModelTypes: function() {
return _.pluck(this._getModels(), 'typePath');
},
_getModels: function() {
return _.reduce(this.models, function(accum, model) {
if (model.typePath === 'artifact') {
accum = accum.concat(model.getArtifactComponentModels());
}
else {
accum.push(model);
}
return accum;
}, []);
},
getTitle: function() {
return 'Show Columns';
},
/**
* Update the fields displayed. In grid mode this will be the columns displayed. In board mode it will be
* the fields on the cards
*
* @param {String[]|Object[]} fields A list of field names to display
* @param {Boolean} true to suspend store load if it will be triggered elsewhere
*/
updateFields: function(fields, suspendLoad) {
this._fields = fields;
if (this.popover && this.popover.down('rallyfieldpicker')) {
this.popover.down('rallyfieldpicker').setValue(fields.join(','));
}
this.saveState();
},
getState: function() {
return {
fields: this._fields
};
},
applyState: function(state) {
if (state) {
this._fields = state.fields;
}
},
_onApply: function(popover) {
var fieldPicker = popover.down('rallyfieldpicker'),
fields = _.map(fieldPicker.getValue(), function(field) {
return field.get('name');
});
this.updateFields(fields);
popover.close();
this.fireEvent('fieldsupdated', fields);
}
});