From 3af1403ab9aeadda50397967c71bb909bf14b200 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 12 Dec 2016 18:16:41 -0500 Subject: [PATCH] API Explorer: Make param selection more convenient Auto-open param select widget, and only show params that have not been previously chosen. --- templates/CRM/Admin/Page/APIExplorer.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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(); -- 2.25.1