Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Explorer: Minor usability improvements #9539

Merged
merged 4 commits into from
Dec 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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