* @param array|string $profiles - name of profile(s) to create links for
* @param array $appendProfiles - name of profile(s) to append to each link
*/
- static function getCreateLinks($profiles, $appendProfiles = array()) {
+ static function getCreateLinks($profiles = '', $appendProfiles = array()) {
+ // Default to contact profiles
+ if (!$profiles) {
+ $profiles = array('new_individual', 'new_organization', 'new_household');
+ }
$profiles = (array) $profiles;
$toGet = array_merge($profiles, (array) $appendProfiles);
$retrieved = civicrm_api3('uf_group', 'get', array(
if (in_array($profile['name'], $profiles)) {
$links[] = array(
'label' => $profile['title'],
- 'url' => CRM_Utils_System::url('civicrm/profile/create', 'reset=1&context=dialog&&gid=' . $id),
- 'name' => $profile['name'],
+ 'url' => CRM_Utils_System::url('civicrm/profile/create', "reset=1&context=dialog&gid=$id",
+ NULL, NULL, FALSE, NULL, FALSE) ,
+ 'type' => ucfirst(str_replace('new_', '', $profile['name'])),
);
}
else {
if ($props['entity'] == 'contact' && isset($props['create']) && !(CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts'))) {
unset($props['create']);
}
- // Convenient shortcut to passing in array create links
- if ($props['entity'] == 'contact' && isset($props['create']) && $props['create'] === TRUE) {
- if (empty($props['api']['params']['contact_type'])) {
- $props['create'] = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'));
- }
- else {
- $props['create'] = CRM_Core_BAO_UFGroup::getCreateLinks('new_' . strtolower($props['api']['params']['contact_type']));
- }
- }
$props['placeholder'] = CRM_Utils_Array::value('placeholder', $props, $required ? ts('- select %1 -', array(1 => ts(str_replace('_', ' ', $props['entity'])))) : ts('- none -'));
$.fn.select2.defaults.formatSearching = " . json_encode(ts("Searching...")) . ";
$.fn.select2.defaults.formatInputTooShort = function(){return cj(this).data('api-entity') == 'contact' ? $contactSearch : $otherSearch};
";
+
+ // Contact create profiles with localized names
+ if (CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts')) {
+ $this->addSetting(array('profile' => array('contactCreate' => CRM_Core_BAO_UFGroup::getCreateLinks())));
+ }
}
/**
background-position: -192px -128px;
}
-.crm-container .new_individual-icon,
+.crm-container .Individual-profile-icon,
.crm-container .user-record-icon {
background-position: -144px -96px;
}
-.crm-container .new_household-icon {
+.crm-container .Household-profile-icon {
background-position: 0 -112px;
}
-.crm-container .new_organization-icon {
+.crm-container .Organization-profile-icon {
background-position: -112px -112px;
}
.crm-container .inform-icon {
$el.data('api-entity', entity);
$el.data('select-params', $.extend({}, $el.data('select-params') || {}, options.select));
$el.data('api-params', $.extend({}, $el.data('api-params') || {}, options.api));
+ $el.data('create-links', options.create || $el.data('create-links'));
$el.addClass('crm-ajax-select crm-' + entity + '-ref');
var settings = {
// Use select2 ajax helper instead of CRM.api because it provides more value
}
},
minimumInputLength: 1,
- formatResult: CRM.utils.formatSelect2Result,
+ formatResult: formatSelect2Result,
formatSelection: function(row) {
return row.label;
},
if ($el.data('create-links')) {
selectParams.formatInputTooShort = function() {
var txt = $el.data('select-params').formatInputTooShort || $.fn.select2.defaults.formatInputTooShort.call(this);
- if ($el.data('create-links').length) {
- txt += ' ' + ts('or') + '<br />' + CRM.utils.formatSelect2CreateLinks($el);
+ if ($el.data('create-links')) {
+ txt += ' ' + ts('or') + '<br />' + formatSelect2CreateLinks($el);
}
return txt;
};
selectParams.formatNoMatches = function() {
var txt = $el.data('select-params').formatNoMatches || $.fn.select2.defaults.formatNoMatches;
- return txt + '<br />' + CRM.utils.formatSelect2CreateLinks($el);
+ return txt + '<br />' + formatSelect2CreateLinks($el);
};
$el.off('.createLinks').on('select2-open.createLinks', function() {
var $el = $(this);
});
};
- CRM.utils.formatSelect2Result = function(row) {
+ function formatSelect2Result(row) {
var markup = '<div class="crm-select2-row">';
if (row.image !== undefined) {
markup += '<div class="crm-select2-image"><img src="' + row.image + '"/></div>';
});
markup += '</div></div></div>';
return markup;
- };
-
- CRM.utils.formatSelect2CreateLinks = function($el) {
+ }
+
+ function formatSelect2CreateLinks($el) {
+ var
+ createLinks = $el.data('create-links'),
+ api = $el.data('api-params') || {},
+ type = api.params ? api.params.contact_type : null;
+ if (createLinks === true) {
+ createLinks = type ? _.where(CRM.profile.contactCreate, {type: type}) : CRM.profile.contactCreate;
+ }
var markup = '';
- $.each($el.data('create-links'), function(k, link) {
+ _.each(createLinks, function(link) {
markup += ' <a class="crm-add-entity crm-hover-button" href="' + link.url + '">';
- if (link.name) {
- markup += '<span class="icon ' + link.name + '-icon"></span> ';
+ if (link.type) {
+ markup += '<span class="icon ' + link.type + '-profile-icon"></span> ';
}
markup += link.label + '</a>';
});
return markup;
- };
+ }
// Initialize widgets
$(document).on('crmLoad', function(e) {