Path: blob/master/webroot/rsrc/js/application/diff/DiffPathView.js
12242 views
/**1* @provides phabricator-diff-path-view2* @requires javelin-dom3* @javelin4*/56JX.install('DiffPathView', {78construct: function() {9},1011members: {12_node: null,13_path: null,14_depth: 0,15_selected: false,16_focused: false,17_icon: null,1819_indentNode: null,20_pathNode: null,21_changeset: null,22_inlineNode: null,23_isDirectory: false,24_displayPath: null,25_isLowImportance: false,26_isOwned: false,27_isHidden: false,28_isLoading: false,2930getNode: function() {31if (!this._node) {32var attrs = {33className: 'diff-tree-path'34};3536this._node = JX.$N('li', attrs, this._getIndentNode());3738var onclick = JX.bind(this, this._onclick);39JX.DOM.listen(this._node, 'click', null, onclick);40}41return this._node;42},4344getIcon: function() {45if (!this._icon) {46this._icon = new JX.PHUIXIconView();47}48return this._icon;49},5051setPath: function(path) {52this._path = path;53this._redrawPath();54return this;55},5657setDisplayPath: function(path) {58this._displayPath = path;59this._redrawPath();60return this;61},6263setIsDirectory: function(is_directory) {64this._isDirectory = is_directory;65this._redrawPath();66return this;67},6869setChangeset: function(changeset) {70this._changeset = changeset;7172var node = this.getNode();73JX.DOM.alterClass(node, 'diff-tree-path-changeset', !!changeset);7475return this;76},7778getChangeset: function() {79return this._changeset;80},8182getPath: function() {83return this._path;84},8586setHidden: function(hidden) {87this._hidden = hidden;8889var node = this.getNode();90if (this._hidden) {91JX.DOM.hide(node);92} else {93JX.DOM.show(node);94}9596return this;97},9899setDepth: function(depth) {100this._depth = depth;101102this._getIndentNode().style.marginLeft = (8 * this._depth) + 'px';103104return this;105},106107setIsSelected: function(selected) {108this._selected = selected;109110var node = this.getNode();111JX.DOM.alterClass(node, 'diff-tree-path-selected', this._selected);112113return this;114},115116setIsFocused: function(focused) {117this._focused = focused;118119var node = this.getNode();120JX.DOM.alterClass(node, 'diff-tree-path-focused', this._focused);121122return this;123},124125setIsLowImportance: function(low_importance) {126this._isLowImportance = low_importance;127128var node = this.getNode();129JX.DOM.alterClass(130node,131'diff-tree-path-low-importance',132this._isLowImportance);133134return this;135},136137setIsOwned: function(owned) {138this._isOwned = owned;139140var node = this.getNode();141JX.DOM.alterClass(node, 'diff-tree-path-owned', this._isOwned);142143return this;144},145146setIsHidden: function(hidden) {147this._isHidden = hidden;148149var node = this.getNode();150JX.DOM.alterClass(node, 'diff-tree-path-hidden', this._isHidden);151152return this;153},154155setIsLoading: function(loading) {156this._isLoading = loading;157158var node = this.getNode();159JX.DOM.alterClass(node, 'diff-tree-path-loading', this._isLoading);160161return this;162},163164_onclick: function(e) {165if (!e.isNormalClick()) {166return;167}168169var changeset = this.getChangeset();170if (changeset) {171changeset.select(true);172}173174e.kill();175},176177_getIndentNode: function() {178if (!this._indentNode) {179var attrs = {180className: 'diff-tree-path-indent'181};182183var content = [184this.getInlineNode(),185this._getHiddenIconNode(),186this._getIconNode(),187this._getPathNode(),188];189190this._indentNode = JX.$N('div', attrs, content);191}192193return this._indentNode;194},195196_getPathNode: function() {197if (!this._pathNode) {198var attrs = {199className: 'diff-tree-path-name'200};201this._pathNode = JX.$N('div', attrs);202}203return this._pathNode;204},205206_getIconNode: function() {207if (!this._iconNode) {208var attrs = {209className: 'diff-tree-path-icon diff-tree-path-icon-kind',210};211this._iconNode = JX.$N('div', attrs, this.getIcon().getNode());212}213return this._iconNode;214},215216_getHiddenIconNode: function() {217if (!this._hiddenIconNode) {218var attrs = {219className: 'diff-tree-path-icon diff-tree-path-icon-hidden',220};221this._hiddenIconNode =222JX.$N('div', attrs, this._getHiddenIcon().getNode());223}224return this._hiddenIconNode;225},226227_getHiddenIcon: function() {228if (!this._hiddenIcon) {229this._hiddenIcon = new JX.PHUIXIconView()230.setIcon('fa-times-circle-o');231}232return this._hiddenIcon;233},234235getInlineNode: function() {236if (!this._inlineNode) {237var attrs = {238className: 'diff-tree-path-inlines',239};240this._inlineNode = JX.$N('div', attrs, '-');241}242return this._inlineNode;243},244245_redrawPath: function() {246var display;247if (this._displayPath) {248display = this._displayPath;249} else {250display = this._path[this._path.length - 1];251}252253var is_directory = this._isDirectory;254255if (is_directory) {256display = display + '/';257}258259JX.DOM.setContent(this._getPathNode(), display);260}261262}263264});265266267