Path: blob/master/webroot/rsrc/js/application/owners/OwnersPathEditor.js
12242 views
/**1* @requires multirow-row-manager2* javelin-install3* path-typeahead4* javelin-dom5* javelin-util6* phabricator-prefab7* phuix-form-control-view8* @provides owners-path-editor9* @javelin10*/1112JX.install('OwnersPathEditor', {13construct : function(config) {14var root = JX.$(config.root);1516this._rowManager = new JX.MultirowRowManager(17JX.DOM.find(root, 'table', config.table));1819JX.DOM.listen(20JX.DOM.find(root, 'a', config.add_button),21'click',22null,23JX.bind(this, this._onaddpath));2425this._count = 0;26this._inputTemplate = config.input_template;27this._repositoryTokenizerSpec = config.repositoryTokenizerSpec;2829this._completeURI = config.completeURI;30this._validateURI = config.validateURI;31this._icons = config.icons;32this._modeOptions = config.modeOptions;3334this._initializePaths(config.pathRefs);35},36members : {37/*38* MultirowRowManager for controlling add/remove behavior39*/40_rowManager : null,4142/*43* How many rows have been created, for form name generation.44*/45_count : 0,46/*47* URL for the typeahead datasource.48*/49_completeURI : null,50/*51* URL for path validation requests.52*/53_validateURI : null,54/*55* Template typeahead markup to be copied per row.56*/57_inputTemplate : null,58/*59* Most packages will be in one repository, so remember whenever60* the user chooses a repository, and use that repository as the61* default for future rows.62*/63_lastRepositoryChoice : null,64_icons: null,65_modeOptions: null,6667/*68* Initialize with 0 or more rows.69* Adds one initial row if none are given.70*/71_initializePaths : function(path_refs) {72for (var k in path_refs) {73this.addPath(path_refs[k]);74}75if (!JX.keys(path_refs).length) {76this.addPath();77}78},7980/*81* Build a row.82*/83addPath : function(path_ref) {84// Smart default repository. See _lastRepositoryChoice.85if (path_ref) {86this._lastRepositoryChoice = path_ref.repositoryValue;87} else {88path_ref = {89repositoryValue: this._lastRepositoryChoice || {}90};91}9293var repo = this._newRepoCell(path_ref.repositoryValue);94var path = this._newPathCell(path_ref.display);95var icon = this._newIconCell();96var mode_cell = this._newModeCell(path_ref.excluded);9798var row = this._rowManager.addRow(99[100mode_cell,101repo.cell,102path.cell,103icon.cell104]);105106new JX.PathTypeahead({107repositoryTokenizer: repo.tokenizer,108path_input : path.input,109hardpoint : path.hardpoint,110error_display : icon.cell,111completeURI : this._completeURI,112validateURI : this._validateURI,113icons: this._icons114}).start();115116this._count++;117return row;118},119120_onaddpath : function(e) {121e.kill();122this.addPath();123},124125_newModeCell: function(value) {126var options = this._modeOptions;127128var name = 'exclude[' + this._count + ']';129130var control = JX.Prefab.renderSelect(options, value, {name: name});131132return JX.$N(133'td',134{135className: 'owners-path-mode-control'136},137control);138},139140_newRepoCell: function(value) {141var repo_control = new JX.PHUIXFormControl()142.setControl('tokenizer', this._repositoryTokenizerSpec)143.setValue(value);144145var repo_tokenizer = repo_control.getTokenizer();146var name = 'repo[' + this._count + ']';147148function get_phid() {149var phids = repo_control.getValue();150if (!phids.length) {151return null;152}153154return phids[0];155}156157var input = JX.$N(158'input',159{160type: 'hidden',161name: name,162value: get_phid()163});164165repo_tokenizer.listen('change', JX.bind(this, function() {166this._lastRepositoryChoice = repo_tokenizer.getTokens();167168input.value = get_phid();169}));170171var cell = JX.$N(172'td',173{174className: 'owners-path-repo-control'175},176[177repo_control.getRawInputNode(),178input179]);180181return {182cell: cell,183tokenizer: repo_tokenizer184};185},186187_newPathCell: function(value) {188var path_cell = JX.$N(189'td',190{191className: 'owners-path-path-control'192},193JX.$H(this._inputTemplate));194195var path_input = JX.DOM.find(path_cell, 'input');196197JX.copy(198path_input,199{200value: value || '',201name: 'path[' + this._count + ']'202});203204var hardpoint = JX.DOM.find(205path_cell,206'div',207'typeahead-hardpoint');208209return {210cell: path_cell,211input: path_input,212hardpoint: hardpoint213};214},215216_newIconCell: function() {217var cell = JX.$N(218'td',219{220className: 'owners-path-icon-control'221});222223return {224cell: cell225};226}227228}229230});231232233