From a39f2446705d5f0996838df92a82436f763252ef Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 24 Mar 2015 09:56:16 -0400 Subject: [PATCH] Api explorer options improvements --- templates/CRM/Admin/Page/APIExplorer.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/templates/CRM/Admin/Page/APIExplorer.js b/templates/CRM/Admin/Page/APIExplorer.js index 1b50cb1fbd..e5d1970e58 100644 --- a/templates/CRM/Admin/Page/APIExplorer.js +++ b/templates/CRM/Admin/Page/APIExplorer.js @@ -7,7 +7,6 @@ actions = {values: ['get']}, fields = [], getFieldData = {}, - options = {}, params = {}, smartyStub, entityDoc, @@ -18,6 +17,7 @@ docCodeTpl = _.template($('#doc-code-tpl').html()), // These types of entityRef don't require any input to open + // FIXME: ought to be in getfields metadata OPEN_IMMEDIATELY = ['RelationshipType', 'Event', 'Group', 'Tag'], // Actions that don't support fancy operators @@ -127,18 +127,17 @@ function getFields(changedElement) { var required = []; fields = []; - options = {}; getFieldData = {}; // Special case for getfields if (action === 'getfields') { fields.push({ id: 'api_action', - text: 'Action' + text: 'Action', + options: _.reduce(actions.values, function(ret, item) { + ret[item] = item; + return ret; + }, {}) }); - options.api_action = _.reduce(actions.values, function(ret, item) { - ret[item] = item; - return ret; - }, {}); showFields(['api_action']); return; } @@ -156,9 +155,6 @@ if (field['api.required'] && field['api.required'] !== '0') { required.push(field.name); } - if (field.options) { - options[field.name] = field.options; - } } }); if ($(changedElement).is('#api-entity') && data.deprecated) { @@ -281,7 +277,8 @@ * @returns boolean */ function isSelect(fieldName, operator) { - return (isYesNo(fieldName) || options[fieldName] || (getFieldData[fieldName] && getFieldData[fieldName].FKApiName)) && !_.includes(TEXT, operator); + var fieldSpec = getFieldData[fieldName] || {}; + return (isYesNo(fieldName) || fieldSpec.options || fieldSpec.FKApiName) && !_.includes(TEXT, operator); } /** @@ -349,10 +346,10 @@ }); } // Select options - else if (options[name]) { + else if (getFieldData[name].options) { $valField.select2({ multiple: multiSelect, - data: _.map(options[name], function (value, key) { + data: _.map(getFieldData[name].options, function (value, key) { return {id: key, text: value}; }) }); -- 2.25.1