Api explorer - render boolean fields as yes-no select
authorColeman Watts <coleman@civicrm.org>
Sun, 15 Mar 2015 02:49:19 +0000 (22:49 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 15 Mar 2015 02:49:19 +0000 (22:49 -0400)
templates/CRM/Admin/Page/APIExplorer.js

index 6167b913d471549dbd8e9fc485f71ba56a5d6f3b..4f311128b3fb734b6820edff8ead5f40c83bb884 100644 (file)
     }
   }
 
+  function isYesNo(fieldName) {
+    return getFieldData[fieldName] && getFieldData[fieldName].type === 16;
+  }
+
   /**
    * Should we render a select or textfield?
    *
    * @returns boolean
    */
   function isSelect(fieldName, operator) {
-    return (options[fieldName] || (getFieldData[fieldName] && getFieldData[fieldName].FKApiName)) && !_.includes(TEXT, operator);
+    return (isYesNo(fieldName) || options[fieldName] || (getFieldData[fieldName] && getFieldData[fieldName].FKApiName)) && !_.includes(TEXT, operator);
   }
 
   /**
    * @returns boolean
    */
   function isMultiSelect(fieldName, operator) {
+    if (isYesNo(fieldName)) {
+      return false;
+    }
     if (_.includes(MULTI, operator)) {
       return true;
     }
       else if (!multiSelect && _.includes(currentVal, ',')) {
         $valField.val(currentVal.split(',')[0]);
       }
+      // Yes-No options
+      if (isYesNo(name)) {
+        $valField.select2({
+          data: [{id: 1, text: ts('Yes')}, {id: 0, text: ts('No')}]
+        });
+      }
       // Select options
-      if (options[name]) {
+      else if (options[name]) {
         $valField.select2({
           multiple: multiSelect,
           data: _.map(options[name], function (value, key) {