From: Coleman Watts Date: Mon, 12 Dec 2016 23:16:41 +0000 (-0500) Subject: API Explorer: Make param selection more convenient X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3af1403ab9aeadda50397967c71bb909bf14b200;p=civicrm-core.git API Explorer: Make param selection more convenient Auto-open param select widget, and only show params that have not been previously chosen. --- diff --git a/templates/CRM/Admin/Page/APIExplorer.js b/templates/CRM/Admin/Page/APIExplorer.js index 2d42363d9c..4b0c172b27 100644 --- a/templates/CRM/Admin/Page/APIExplorer.js +++ b/templates/CRM/Admin/Page/APIExplorer.js @@ -56,13 +56,24 @@ } /** - * Data provider for select2 "field" selectors + * Data provider for select2 "fields to return" selector * @returns {{results: Array.}} */ function returnFields() { return {results: fields.concat({id: '-', text: ts('Other') + '...', description: ts('Choose a field not in this list')})}; } + /** + * Data provider for select2 "field" selectors + * @returns {{results: Array.}} + */ + function selectFields() { + var items = _.filter(fields, function(field) { + return params[field.id] === undefined; + }); + return {results: items.concat({id: '-', text: ts('Other') + '...', description: ts('Choose a field not in this list')})}; + } + /** * Recursively populates data for select2 "field" selectors * @param fields @@ -138,7 +149,7 @@ $('#api-params').append($(fieldTpl({name: name || '', noOps: _.includes(NO_OPERATORS, action)}))); var $row = $('tr:last-child', '#api-params'); $('input.api-param-name', $row).crmSelect2({ - data: returnFields, + data: selectFields, formatSelection: function(field) { return field.text + (field.required ? ' *' : ''); @@ -167,7 +178,8 @@ {id: 'sort', text: 'sort'}, {id: 'metadata', text: 'metadata'}, {id: '-', text: ts('Other') + '...'} - ]}); + ]}) + .select2('open'); } /** @@ -183,7 +195,8 @@ }, placeholder: ' ' + ts('Entity'), escapeMarkup: function(m) {return m;} - }); + }) + .select2('open'); } /** @@ -976,6 +989,7 @@ $('#api-params-add').on('click', function(e) { e.preventDefault(); addField(); + $('tr:last-child input.api-param-name', '#api-params').select2('open'); }); $('#api-option-add').on('click', function(e) { e.preventDefault();