Fix api explorer chaining to use getactions
authorColeman Watts <coleman@civicrm.org>
Sun, 25 Jan 2015 20:31:21 +0000 (15:31 -0500)
committerColeman Watts <coleman@civicrm.org>
Sun, 25 Jan 2015 20:31:21 +0000 (15:31 -0500)
templates/CRM/Admin/Page/APIExplorer.js
templates/CRM/Admin/Page/APIExplorer.tpl

index 4243705e4903c1837d538e4fc3591e4a157b3191..f472cec90c85204a9e28ed7e99eb7761e20bf23e 100644 (file)
     var $row = $('tr:last-child', '#api-params');
     $('.api-chain-entity', $row).crmSelect2({
       formatSelection: function(item) {
-        return '<span class="icon ui-icon-link"></span> API ' + item.text;
+        return '<span class="icon ui-icon-link"></span> API ' +
+          ($(item.element).hasClass('strikethrough') ? '<span class="strikethrough">' + item.text + '</span>' : item.text);
       },
       placeholder: '<span class="icon ui-icon-link"></span> ' + ts('Entity'),
       escapeMarkup: function(m) {return m}
     });
   }
 
+  /**
+   * Fetch available actions for selected chained entity
+   */
+  function getChainedAction() {
+    var
+      $selector = $(this),
+      entity = $selector.val(),
+      $row = $selector.closest('tr');
+    if (entity) {
+      $selector.prop('disabled', true);
+      CRM.api3(entity, 'getactions')
+        .done(function(actions) {
+          $selector.prop('disabled', false);
+          CRM.utils.setOptions($('.api-chain-action', $row), _.transform(actions.values, function(ret, item) {ret.push({value: item, key: item})}));
+        });
+    }
+  }
+
   /**
    * Fetch fields for entity+action
    */
         e.preventDefault();
         $(this).closest('tr').remove();
         buildParams();
-      });
+      })
+      .on('change', 'select.api-chain-entity', getChainedAction);
     $('#api-params-add').on('click', function(e) {
       e.preventDefault();
       addField();
index cf40d38d858de780d88316d01df0f76a128c4c54..8d157803b0aa2a69eb544304819f7969e3499270 100644 (file)
       <select style="width: 100%;" class="crm-form-select api-chain-entity">
         <option value=""></option>
         {foreach from=$entities.values item=entity}
-          <option value="{$entity}">{$entity}</option>
+          <option value="{$entity}" {if !empty($entities.deprecated) && in_array($entity, $entities.deprecated)}class="strikethrough"{/if}>
+            {$entity}
+          </option>
         {/foreach}
       </select>
     </td>
     <td>
       <select class="crm-form-select api-chain-action">
         <option value="get">get</option>
-        <option value="getsingle">getsingle</option>
-        <option value="getcount">getcount</option>
-        <option value="create">create</option>
-        <option value="delete">delete</option>
-    </select>
+      </select>
     </td>
     <td>
       <input style="width: 85%;" class="crm-form-text api-param-value api-input" value="{ldelim}{rdelim}" placeholder="{ts}Api Params{/ts}"/>