From: Coleman Watts Date: Thu, 6 Mar 2014 01:28:04 +0000 (-0500) Subject: CRM-13966 HR-301 - Support contact create on clientside, toward refactoring out jquer... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a4799f04eeb6b965d1b5e85a5ecc0c6050ed8f14;p=civicrm-core.git CRM-13966 HR-301 - Support contact create on clientside, toward refactoring out jquery.crmContactField.js --- diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index d389744fe2..0341d8d088 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -3210,7 +3210,11 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) * @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( @@ -3223,8 +3227,9 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) 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 { diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index fd47c2de40..97e53f67c5 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1270,15 +1270,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 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 -')); diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index edc0a95118..d34d6f9aa9 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -540,6 +540,11 @@ class CRM_Core_Resources { $.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()))); + } } /** diff --git a/css/civicrm.css b/css/civicrm.css index 9b0be57d6e..220f0d4364 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -2518,14 +2518,14 @@ div.grippie { 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 { diff --git a/js/Common.js b/js/Common.js index b34348d89f..93448f3eff 100644 --- a/js/Common.js +++ b/js/Common.js @@ -315,6 +315,7 @@ CRM.validate = CRM.validate || { $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 @@ -335,7 +336,7 @@ CRM.validate = CRM.validate || { } }, minimumInputLength: 1, - formatResult: CRM.utils.formatSelect2Result, + formatResult: formatSelect2Result, formatSelection: function(row) { return row.label; }, @@ -363,14 +364,14 @@ CRM.validate = CRM.validate || { 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') + '
' + CRM.utils.formatSelect2CreateLinks($el); + if ($el.data('create-links')) { + txt += ' ' + ts('or') + '
' + formatSelect2CreateLinks($el); } return txt; }; selectParams.formatNoMatches = function() { var txt = $el.data('select-params').formatNoMatches || $.fn.select2.defaults.formatNoMatches; - return txt + '
' + CRM.utils.formatSelect2CreateLinks($el); + return txt + '
' + formatSelect2CreateLinks($el); }; $el.off('.createLinks').on('select2-open.createLinks', function() { var $el = $(this); @@ -397,7 +398,7 @@ CRM.validate = CRM.validate || { }); }; - CRM.utils.formatSelect2Result = function(row) { + function formatSelect2Result(row) { var markup = '
'; if (row.image !== undefined) { markup += '
'; @@ -412,19 +413,26 @@ CRM.validate = CRM.validate || { }); markup += '
'; 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 += ' '; - if (link.name) { - markup += ' '; + if (link.type) { + markup += ' '; } markup += link.label + ''; }); return markup; - }; + } // Initialize widgets $(document).on('crmLoad', function(e) {