From 3d9f5b7f58e3a96fd9c71cf0af470100c5b6d9f3 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 25 Jan 2015 15:31:21 -0500 Subject: [PATCH] Fix api explorer chaining to use getactions --- templates/CRM/Admin/Page/APIExplorer.js | 24 ++++++++++++++++++++++-- templates/CRM/Admin/Page/APIExplorer.tpl | 10 ++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/templates/CRM/Admin/Page/APIExplorer.js b/templates/CRM/Admin/Page/APIExplorer.js index 4243705e49..f472cec90c 100644 --- a/templates/CRM/Admin/Page/APIExplorer.js +++ b/templates/CRM/Admin/Page/APIExplorer.js @@ -70,13 +70,32 @@ var $row = $('tr:last-child', '#api-params'); $('.api-chain-entity', $row).crmSelect2({ formatSelection: function(item) { - return ' API ' + item.text; + return ' API ' + + ($(item.element).hasClass('strikethrough') ? '' + item.text + '' : item.text); }, placeholder: ' ' + 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 */ @@ -516,7 +535,8 @@ e.preventDefault(); $(this).closest('tr').remove(); buildParams(); - }); + }) + .on('change', 'select.api-chain-entity', getChainedAction); $('#api-params-add').on('click', function(e) { e.preventDefault(); addField(); diff --git a/templates/CRM/Admin/Page/APIExplorer.tpl b/templates/CRM/Admin/Page/APIExplorer.tpl index cf40d38d85..8d157803b0 100644 --- a/templates/CRM/Admin/Page/APIExplorer.tpl +++ b/templates/CRM/Admin/Page/APIExplorer.tpl @@ -197,18 +197,16 @@ + -- 2.25.1