Skip to content

Commit

Permalink
Merge pull request #9539 from colemanw/api
Browse files Browse the repository at this point in the history
API Explorer: Minor usability improvements
  • Loading branch information
colemanw authored Dec 15, 2016
2 parents 612b614 + 0a5c58d commit 3f22aa0
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions templates/CRM/Admin/Page/APIExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,24 @@
}

/**
* Data provider for select2 "field" selectors
* Data provider for select2 "fields to return" selector
* @returns {{results: Array.<T>}}
*/
function returnFields() {
return {results: fields.concat({id: '-', text: ts('Other') + '...', description: ts('Choose a field not in this list')})};
}

/**
* Data provider for select2 "field" selectors
* @returns {{results: Array.<T>}}
*/
function selectFields() {
var items = _.filter(fields, function(field) {
return params[field.id] === undefined;
});
return {results: items.concat({id: '-', text: ts('Other') + '...', description: ts('Choose a field not in this list')})};
}

/**
* Recursively populates data for select2 "field" selectors
* @param fields
Expand Down Expand Up @@ -138,7 +149,8 @@
$('#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: returnFields,
data: selectFields,
allowClear: false,
formatSelection: function(field) {
return field.text +
(field.required ? ' <span class="crm-marker">*</span>' : '');
Expand All @@ -161,13 +173,20 @@
$('#api-params').append($(optionsTpl({})));
}
var $row = $('.api-options-row:last', '#api-params');
$('.api-option-name', $row).crmSelect2({data: [
{id: 'limit', text: 'limit'},
{id: 'offset', text: 'offset'},
{id: 'sort', text: 'sort'},
{id: 'metadata', text: 'metadata'},
{id: '-', text: ts('Other') + '...'}
]});
$('.api-option-name', $row).crmSelect2({
data: [
{id: 'limit', text: 'limit'},
{id: 'offset', text: 'offset'},
{id: 'match', text: 'match'},
{id: 'match-mandatory', text: 'match-mandatory'},
{id: 'metadata', text: 'metadata'},
{id: 'reload', text: 'reload'},
{id: 'sort', text: 'sort'},
{id: '-', text: ts('Other') + '...'}
],
allowClear: false
})
.select2('open');
}

/**
Expand All @@ -182,8 +201,10 @@
($(item.element).hasClass('strikethrough') ? '<span class="strikethrough">' + item.text + '</span>' : item.text);
},
placeholder: '<i class="crm-i fa-link"></i> ' + ts('Entity'),
allowClear: false,
escapeMarkup: function(m) {return m;}
});
})
.select2('open');
}

/**
Expand Down Expand Up @@ -323,6 +344,11 @@
}
$('#api-params').prepend($(returnTpl({title: title, required: action == 'getvalue'})));
$('#api-return-value').crmSelect2(params);
$("#api-return-value").select2("container").find("ul.select2-choices").sortable({
containment: 'parent',
start: function() { $("#api-return-value").select2("onSortStart"); },
update: function() { $("#api-return-value").select2("onSortEnd"); }
});
}

/**
Expand Down Expand Up @@ -976,6 +1002,7 @@
$('#api-params-add').on('click', function(e) {
e.preventDefault();
addField();
$('tr:last-child input.api-param-name', '#api-params').select2('open');
});
$('#api-option-add').on('click', function(e) {
e.preventDefault();
Expand Down

0 comments on commit 3f22aa0

Please sign in to comment.