formatResult: renderAction
});
// If previously selected action is not available, set it to 'get' if possible
- if (_.indexOf(actions.values, val) < 0) {
- $('#api-action').select2('val', _.indexOf(actions.values, 'get') < 0 ? actions.values[0] : 'get', true);
+ if (!_.includes(actions.values, val)) {
+ $('#api-action').select2('val', !_.includes(actions.values, 'get') ? actions.values[0] : 'get', true);
}
}
* @returns boolean
*/
function isSelect(fieldName, operator) {
- return (options[fieldName] || (getFieldData[fieldName] && getFieldData[fieldName].FKApiName)) && ($.inArray(operator, TEXT) < 0);
+ return (options[fieldName] || (getFieldData[fieldName] && getFieldData[fieldName].FKApiName)) && !_.includes(TEXT, operator);
}
/**
* @returns boolean
*/
function isMultiSelect(fieldName, operator) {
- if ($.inArray(operator, MULTI) > -1) {
+ if (_.includes(MULTI, operator)) {
return true;
}
// The = operator is ambiguous but all others can be safely assumed to be single
multiSelect = isMultiSelect(name, operator),
currentVal = $valField.val();
// Boolean fields only have 1 possible value
- if ($.inArray(operator, BOOL) > -1) {
+ if (_.includes(BOOL, operator)) {
if ($valField.data('select2')) {
$valField.select2('destroy');
}
$valField.val('');
}
// When switching from multi-select to single select
- else if (!multiSelect && currentVal.indexOf(',') > -1) {
+ else if (!multiSelect && _.includes(currentVal, ',')) {
$valField.val(currentVal.split(',')[0]);
}
// Select options
entity: getFieldData[name].FKApiName,
select: {
multiple: multiSelect,
- minimumInputLength: $.inArray(getFieldData[name].FKApiName, OPEN_IMMEDIATELY) > -1 ? 0 : 1
+ minimumInputLength: _.includes(OPEN_IMMEDIATELY, getFieldData[name].FKApiName) ? 0 : 1
}
});
}
* @param key string
*/
function smartyFormat(js, key) {
- if (js.indexOf('[') > -1 || js.indexOf('{') > -1) {
+ if (_.includes(js, '[') || _.includes(js, '{')) {
smartyStub = true;
return '$' + key.replace(/[. -]/g, '_');
}
op = $('select.api-param-op', $row).val() || '=',
name = $('input.api-param-name', $row).val(),
// Workaround for ambiguity of the = operator
- makeArray = (op === '=' && isSelect(name, op)) ? input.indexOf(',') > -1 : op !== '=' && isMultiSelect(name, op),
+ makeArray = (op === '=' && isSelect(name, op)) ? _.includes(input, ',') : op !== '=' && isMultiSelect(name, op),
val = evaluate(input, makeArray);
// Ignore blank values for the return field
q.php += ");";
q.json += ").done(function(result) {\n // do something\n});";
q.smarty += "}\n{foreach from=$result.values item=" + entity.toLowerCase() + "}\n {$" + entity.toLowerCase() + ".some_field}\n{/foreach}";
- if (action.indexOf('get') < 0) {
+ if (!_.includes(action, 'get')) {
q.smarty = '{* Smarty API only works with get actions *}';
} else if (smartyStub) {
q.smarty = "{* Smarty does not have a syntax for array literals; assign complex variables from php *}\n" + q.smarty;
alert(ts('Select an entity.'));
return;
}
- if (action.indexOf('get') < 0 && action != 'check') {
+ if (!_.includes(action, 'get') && action != 'check') {
var msg = action === 'delete' ? ts('This will delete data from CiviCRM. Are you sure?') : ts('This will write to the database. Continue?');
CRM.confirm({title: ts('Confirm %1', {1: action}), message: msg}).on('crmConfirm:yes', execute);
} else {
prettyprint: 1,
json: JSON.stringify(params)
},
- type: action.indexOf('get') < 0 ? 'POST' : 'GET',
+ type: _.includes(action, 'get') ? 'GET' : 'POST',
dataType: 'text'
}).done(function(text) {
$('#api-result').addClass('prettyprint').removeClass('prettyprinted').text(text);