Path: blob/master/webroot/rsrc/js/phuix/PHUIXActionView.js
12241 views
/**1* @provides phuix-action-view2* @requires javelin-install3* javelin-dom4* javelin-util5* @javelin6*/78JX.install('PHUIXActionView', {910members: {11_node: null,12_name: null,13_icon: 'none',14_iconColor: null,15_disabled: false,16_label: false,17_handler: null,18_selected: false,19_divider: false,20_keyCommand: null,21_unresponsive: null,2223_iconNode: null,24_nameNode: null,2526setDisabled: function(disabled) {27this._disabled = disabled;28JX.DOM.alterClass(29this.getNode(),30'phabricator-action-view-disabled',31disabled);3233this._buildIconNode(true);3435return this;36},3738setUnresponsive: function(unresponsive) {39this._unresponsive = unresponsive;40this._buildNameNode(true);41return this;42},4344getDisabled: function() {45return this._disabled;46},4748setLabel: function(label) {49this._label = label;50JX.DOM.alterClass(51this.getNode(),52'phabricator-action-view-label',53label);54return this;55},5657setDivider: function(divider) {58this._divider = divider;59JX.DOM.alterClass(60this.getNode(),61'phabricator-action-view-type-divider',62divider);63return this;64},6566setSelected: function(selected) {67this._selected = selected;68JX.DOM.alterClass(69this.getNode(),70'phabricator-action-view-selected',71selected);7273return this;74},7576setName: function(name) {77this._name = name;78this._buildNameNode(true);79return this;80},8182setHandler: function(handler) {83this._handler = handler;84this._buildNameNode(true);85this._rebuildClasses();86return this;87},8889setIcon: function(icon) {90this._icon = icon;91this._buildIconNode(true);92return this;93},9495setIconColor: function(color) {96this._iconColor = color;97this._buildIconNode(true);98return this;99},100101setHref: function(href) {102this._href = href;103this._buildNameNode(true);104this._rebuildClasses();105return this;106},107108setKeyCommand: function(command) {109this._keyCommand = command;110111var key_node = this._buildKeyCommandNode();112JX.DOM.setContent(key_node, this._keyCommand);113114var node = this.getNode();115JX.DOM.alterClass(node, 'has-key-command', !!this._keyCommand);116117return this;118},119120getNode: function() {121if (!this._node) {122var classes = ['phabricator-action-view'];123124if (this._icon) {125classes.push('action-has-icon');126}127128var content = [129this._buildIconNode(),130this._buildNameNode(),131this._buildKeyCommandNode(),132];133134var attr = {135className: classes.join(' ')136};137this._node = JX.$N('li', attr, content);138139JX.Stratcom.addSigil(this._node, 'phuix-action-view');140141this._rebuildClasses();142}143144return this._node;145},146147_rebuildClasses: function() {148var node = this.getNode();149150var is_href = !!(this._href || this._handler);151JX.DOM.alterClass(node, 'phabricator-action-view-href', is_href);152},153154_buildIconNode: function(dirty) {155if (!this._iconNode || dirty) {156var attr = {157className: [158'phui-icon-view',159'phabricator-action-view-icon',160'phui-font-fa'161].join(' ')162};163var node = JX.$N('span', attr);164165var icon_class = this._icon;166if (this._disabled) {167icon_class = icon_class + ' grey';168}169170if (this._iconColor) {171icon_class = icon_class + ' ' + this._iconColor;172}173174JX.DOM.alterClass(node, icon_class, true);175176if (this._iconNode && this._iconNode.parentNode) {177JX.DOM.replace(this._iconNode, node);178}179this._iconNode = node;180}181182return this._iconNode;183},184185_buildKeyCommandNode: function() {186if (!this._keyCommandNode) {187var attrs = {188className: 'keyboard-shortcut-key'189};190191this._keyCommandNode = JX.$N('div', attrs);192}193return this._keyCommandNode;194},195196_buildNameNode: function(dirty) {197if (!this._nameNode || dirty) {198var attr = {199className: 'phabricator-action-view-item'200};201202var href = this._href;203if (!href && this._handler && !this._unresponsive) {204href = '#';205}206if (href) {207attr.href = href;208}209210var tag = href ? 'a' : 'span';211212var node = JX.$N(tag, attr, this._name);213JX.DOM.listen(node, 'click', null, JX.bind(this, this._onclick));214215if (this._nameNode && this._nameNode.parentNode) {216JX.DOM.replace(this._nameNode, node);217}218this._nameNode = node;219}220221return this._nameNode;222},223224_onclick: function(e) {225if (this._unresponsive) {226e.prevent();227return;228}229230if (this._handler) {231this._handler(e);232}233}234235}236237});238239240