API Explorer - Disable operator selection when not appropriate
authorColeman Watts <coleman@civicrm.org>
Sat, 7 Mar 2015 18:27:47 +0000 (13:27 -0500)
committerColeman Watts <coleman@civicrm.org>
Sat, 7 Mar 2015 18:27:47 +0000 (13:27 -0500)
templates/CRM/Admin/Page/APIExplorer.js
templates/CRM/Admin/Page/APIExplorer.tpl

index 72d8999d8675ae8d2224e6cf3dad4a6b0308f980..6167b913d471549dbd8e9fc485f71ba56a5d6f3b 100644 (file)
@@ -20,6 +20,9 @@
     // These types of entityRef don't require any input to open
     OPEN_IMMEDIATELY = ['RelationshipType', 'Event', 'Group', 'Tag'],
 
+    // Actions that don't support fancy operators
+    NO_OPERATORS = ['create', 'update', 'delete', 'setvalue', 'getoptions', 'getactions', 'getfields'],
+
     // Operators with special properties
     BOOL = ['IS NULL', 'IS NOT NULL'],
     TEXT = ['LIKE', 'NOT LIKE'],
@@ -46,7 +49,7 @@
    * @param name
    */
   function addField(name) {
-    $('#api-params').append($(fieldTpl({name: name || ''})));
+    $('#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: fields.concat({id: '-', text: ts('Other') + '...', description: ts('Choose a field not in this list')}),
index 5ff402c142530202e1e2a6c74451d8a805c846c2..0d4936a4188498406bb5f69b379575c0b6d8d7b1 100644 (file)
   <tr class="api-param-row">
     <td><input style="width: 100%;" class="crm-form-text api-param-name api-input" value="<%= name %>" placeholder="{ts}Parameter{/ts}" /></td>
     <td>
-      <select class="crm-form-select api-param-op">
-        {foreach from=$operators item='op'}
-          <option value="{$op|htmlspecialchars}">{$op|htmlspecialchars}</option>
-        {/foreach}
-      </select>
+      {literal}
+      <% if (noOps) { %>
+        <input class="crm-form-text api-param-op" value="=" readonly="true" title="{/literal}{ts}Other operators not available for this action.{/ts}{literal}" />
+      <% } else { %>
+      {/literal}
+        <select class="crm-form-select api-param-op">
+          {foreach from=$operators item='op'}
+            <option value="{$op|htmlspecialchars}">{$op|htmlspecialchars}</option>
+          {/foreach}
+        </select>
+      {literal}
+      <% } %>
+      {/literal}
     </td>
     <td>
       <input style="width: 85%;" class="crm-form-text api-param-value api-input" placeholder="{ts}Value{/ts}"/>