Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/webroot/rsrc/js/application/owners/OwnersPathEditor.js
12242 views
1
/**
2
* @requires multirow-row-manager
3
* javelin-install
4
* path-typeahead
5
* javelin-dom
6
* javelin-util
7
* phabricator-prefab
8
* phuix-form-control-view
9
* @provides owners-path-editor
10
* @javelin
11
*/
12
13
JX.install('OwnersPathEditor', {
14
construct : function(config) {
15
var root = JX.$(config.root);
16
17
this._rowManager = new JX.MultirowRowManager(
18
JX.DOM.find(root, 'table', config.table));
19
20
JX.DOM.listen(
21
JX.DOM.find(root, 'a', config.add_button),
22
'click',
23
null,
24
JX.bind(this, this._onaddpath));
25
26
this._count = 0;
27
this._inputTemplate = config.input_template;
28
this._repositoryTokenizerSpec = config.repositoryTokenizerSpec;
29
30
this._completeURI = config.completeURI;
31
this._validateURI = config.validateURI;
32
this._icons = config.icons;
33
this._modeOptions = config.modeOptions;
34
35
this._initializePaths(config.pathRefs);
36
},
37
members : {
38
/*
39
* MultirowRowManager for controlling add/remove behavior
40
*/
41
_rowManager : null,
42
43
/*
44
* How many rows have been created, for form name generation.
45
*/
46
_count : 0,
47
/*
48
* URL for the typeahead datasource.
49
*/
50
_completeURI : null,
51
/*
52
* URL for path validation requests.
53
*/
54
_validateURI : null,
55
/*
56
* Template typeahead markup to be copied per row.
57
*/
58
_inputTemplate : null,
59
/*
60
* Most packages will be in one repository, so remember whenever
61
* the user chooses a repository, and use that repository as the
62
* default for future rows.
63
*/
64
_lastRepositoryChoice : null,
65
_icons: null,
66
_modeOptions: null,
67
68
/*
69
* Initialize with 0 or more rows.
70
* Adds one initial row if none are given.
71
*/
72
_initializePaths : function(path_refs) {
73
for (var k in path_refs) {
74
this.addPath(path_refs[k]);
75
}
76
if (!JX.keys(path_refs).length) {
77
this.addPath();
78
}
79
},
80
81
/*
82
* Build a row.
83
*/
84
addPath : function(path_ref) {
85
// Smart default repository. See _lastRepositoryChoice.
86
if (path_ref) {
87
this._lastRepositoryChoice = path_ref.repositoryValue;
88
} else {
89
path_ref = {
90
repositoryValue: this._lastRepositoryChoice || {}
91
};
92
}
93
94
var repo = this._newRepoCell(path_ref.repositoryValue);
95
var path = this._newPathCell(path_ref.display);
96
var icon = this._newIconCell();
97
var mode_cell = this._newModeCell(path_ref.excluded);
98
99
var row = this._rowManager.addRow(
100
[
101
mode_cell,
102
repo.cell,
103
path.cell,
104
icon.cell
105
]);
106
107
new JX.PathTypeahead({
108
repositoryTokenizer: repo.tokenizer,
109
path_input : path.input,
110
hardpoint : path.hardpoint,
111
error_display : icon.cell,
112
completeURI : this._completeURI,
113
validateURI : this._validateURI,
114
icons: this._icons
115
}).start();
116
117
this._count++;
118
return row;
119
},
120
121
_onaddpath : function(e) {
122
e.kill();
123
this.addPath();
124
},
125
126
_newModeCell: function(value) {
127
var options = this._modeOptions;
128
129
var name = 'exclude[' + this._count + ']';
130
131
var control = JX.Prefab.renderSelect(options, value, {name: name});
132
133
return JX.$N(
134
'td',
135
{
136
className: 'owners-path-mode-control'
137
},
138
control);
139
},
140
141
_newRepoCell: function(value) {
142
var repo_control = new JX.PHUIXFormControl()
143
.setControl('tokenizer', this._repositoryTokenizerSpec)
144
.setValue(value);
145
146
var repo_tokenizer = repo_control.getTokenizer();
147
var name = 'repo[' + this._count + ']';
148
149
function get_phid() {
150
var phids = repo_control.getValue();
151
if (!phids.length) {
152
return null;
153
}
154
155
return phids[0];
156
}
157
158
var input = JX.$N(
159
'input',
160
{
161
type: 'hidden',
162
name: name,
163
value: get_phid()
164
});
165
166
repo_tokenizer.listen('change', JX.bind(this, function() {
167
this._lastRepositoryChoice = repo_tokenizer.getTokens();
168
169
input.value = get_phid();
170
}));
171
172
var cell = JX.$N(
173
'td',
174
{
175
className: 'owners-path-repo-control'
176
},
177
[
178
repo_control.getRawInputNode(),
179
input
180
]);
181
182
return {
183
cell: cell,
184
tokenizer: repo_tokenizer
185
};
186
},
187
188
_newPathCell: function(value) {
189
var path_cell = JX.$N(
190
'td',
191
{
192
className: 'owners-path-path-control'
193
},
194
JX.$H(this._inputTemplate));
195
196
var path_input = JX.DOM.find(path_cell, 'input');
197
198
JX.copy(
199
path_input,
200
{
201
value: value || '',
202
name: 'path[' + this._count + ']'
203
});
204
205
var hardpoint = JX.DOM.find(
206
path_cell,
207
'div',
208
'typeahead-hardpoint');
209
210
return {
211
cell: path_cell,
212
input: path_input,
213
hardpoint: hardpoint
214
};
215
},
216
217
_newIconCell: function() {
218
var cell = JX.$N(
219
'td',
220
{
221
className: 'owners-path-icon-control'
222
});
223
224
return {
225
cell: cell
226
};
227
}
228
229
}
230
231
});
232
233