Api explorer options improvements
authorColeman Watts <coleman@civicrm.org>
Tue, 24 Mar 2015 13:56:16 +0000 (09:56 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 24 Mar 2015 13:56:16 +0000 (09:56 -0400)
templates/CRM/Admin/Page/APIExplorer.js

index 1b50cb1fbdcfe203e38a9d78c4dc1701ba8b9a7c..e5d1970e58a42c9e71f943a5e633e5e7567a9659 100644 (file)
@@ -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
   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;
     }
           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) {
    * @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);
   }
 
   /**
         });
       }
       // 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};
           })
         });