Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/webroot/rsrc/js/application/diff/DiffPathView.js
12242 views
1
/**
2
* @provides phabricator-diff-path-view
3
* @requires javelin-dom
4
* @javelin
5
*/
6
7
JX.install('DiffPathView', {
8
9
construct: function() {
10
},
11
12
members: {
13
_node: null,
14
_path: null,
15
_depth: 0,
16
_selected: false,
17
_focused: false,
18
_icon: null,
19
20
_indentNode: null,
21
_pathNode: null,
22
_changeset: null,
23
_inlineNode: null,
24
_isDirectory: false,
25
_displayPath: null,
26
_isLowImportance: false,
27
_isOwned: false,
28
_isHidden: false,
29
_isLoading: false,
30
31
getNode: function() {
32
if (!this._node) {
33
var attrs = {
34
className: 'diff-tree-path'
35
};
36
37
this._node = JX.$N('li', attrs, this._getIndentNode());
38
39
var onclick = JX.bind(this, this._onclick);
40
JX.DOM.listen(this._node, 'click', null, onclick);
41
}
42
return this._node;
43
},
44
45
getIcon: function() {
46
if (!this._icon) {
47
this._icon = new JX.PHUIXIconView();
48
}
49
return this._icon;
50
},
51
52
setPath: function(path) {
53
this._path = path;
54
this._redrawPath();
55
return this;
56
},
57
58
setDisplayPath: function(path) {
59
this._displayPath = path;
60
this._redrawPath();
61
return this;
62
},
63
64
setIsDirectory: function(is_directory) {
65
this._isDirectory = is_directory;
66
this._redrawPath();
67
return this;
68
},
69
70
setChangeset: function(changeset) {
71
this._changeset = changeset;
72
73
var node = this.getNode();
74
JX.DOM.alterClass(node, 'diff-tree-path-changeset', !!changeset);
75
76
return this;
77
},
78
79
getChangeset: function() {
80
return this._changeset;
81
},
82
83
getPath: function() {
84
return this._path;
85
},
86
87
setHidden: function(hidden) {
88
this._hidden = hidden;
89
90
var node = this.getNode();
91
if (this._hidden) {
92
JX.DOM.hide(node);
93
} else {
94
JX.DOM.show(node);
95
}
96
97
return this;
98
},
99
100
setDepth: function(depth) {
101
this._depth = depth;
102
103
this._getIndentNode().style.marginLeft = (8 * this._depth) + 'px';
104
105
return this;
106
},
107
108
setIsSelected: function(selected) {
109
this._selected = selected;
110
111
var node = this.getNode();
112
JX.DOM.alterClass(node, 'diff-tree-path-selected', this._selected);
113
114
return this;
115
},
116
117
setIsFocused: function(focused) {
118
this._focused = focused;
119
120
var node = this.getNode();
121
JX.DOM.alterClass(node, 'diff-tree-path-focused', this._focused);
122
123
return this;
124
},
125
126
setIsLowImportance: function(low_importance) {
127
this._isLowImportance = low_importance;
128
129
var node = this.getNode();
130
JX.DOM.alterClass(
131
node,
132
'diff-tree-path-low-importance',
133
this._isLowImportance);
134
135
return this;
136
},
137
138
setIsOwned: function(owned) {
139
this._isOwned = owned;
140
141
var node = this.getNode();
142
JX.DOM.alterClass(node, 'diff-tree-path-owned', this._isOwned);
143
144
return this;
145
},
146
147
setIsHidden: function(hidden) {
148
this._isHidden = hidden;
149
150
var node = this.getNode();
151
JX.DOM.alterClass(node, 'diff-tree-path-hidden', this._isHidden);
152
153
return this;
154
},
155
156
setIsLoading: function(loading) {
157
this._isLoading = loading;
158
159
var node = this.getNode();
160
JX.DOM.alterClass(node, 'diff-tree-path-loading', this._isLoading);
161
162
return this;
163
},
164
165
_onclick: function(e) {
166
if (!e.isNormalClick()) {
167
return;
168
}
169
170
var changeset = this.getChangeset();
171
if (changeset) {
172
changeset.select(true);
173
}
174
175
e.kill();
176
},
177
178
_getIndentNode: function() {
179
if (!this._indentNode) {
180
var attrs = {
181
className: 'diff-tree-path-indent'
182
};
183
184
var content = [
185
this.getInlineNode(),
186
this._getHiddenIconNode(),
187
this._getIconNode(),
188
this._getPathNode(),
189
];
190
191
this._indentNode = JX.$N('div', attrs, content);
192
}
193
194
return this._indentNode;
195
},
196
197
_getPathNode: function() {
198
if (!this._pathNode) {
199
var attrs = {
200
className: 'diff-tree-path-name'
201
};
202
this._pathNode = JX.$N('div', attrs);
203
}
204
return this._pathNode;
205
},
206
207
_getIconNode: function() {
208
if (!this._iconNode) {
209
var attrs = {
210
className: 'diff-tree-path-icon diff-tree-path-icon-kind',
211
};
212
this._iconNode = JX.$N('div', attrs, this.getIcon().getNode());
213
}
214
return this._iconNode;
215
},
216
217
_getHiddenIconNode: function() {
218
if (!this._hiddenIconNode) {
219
var attrs = {
220
className: 'diff-tree-path-icon diff-tree-path-icon-hidden',
221
};
222
this._hiddenIconNode =
223
JX.$N('div', attrs, this._getHiddenIcon().getNode());
224
}
225
return this._hiddenIconNode;
226
},
227
228
_getHiddenIcon: function() {
229
if (!this._hiddenIcon) {
230
this._hiddenIcon = new JX.PHUIXIconView()
231
.setIcon('fa-times-circle-o');
232
}
233
return this._hiddenIcon;
234
},
235
236
getInlineNode: function() {
237
if (!this._inlineNode) {
238
var attrs = {
239
className: 'diff-tree-path-inlines',
240
};
241
this._inlineNode = JX.$N('div', attrs, '-');
242
}
243
return this._inlineNode;
244
},
245
246
_redrawPath: function() {
247
var display;
248
if (this._displayPath) {
249
display = this._displayPath;
250
} else {
251
display = this._path[this._path.length - 1];
252
}
253
254
var is_directory = this._isDirectory;
255
256
if (is_directory) {
257
display = display + '/';
258
}
259
260
JX.DOM.setContent(this._getPathNode(), display);
261
}
262
263
}
264
265
});
266
267