From 0b1bae4a58299378af286badd1a34245ac1f3033 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 17 Nov 2013 18:34:25 -0800 Subject: [PATCH] CRM-13783 - ProfileBuilder - Auto-add new custom field to canvas --- CRM/Core/BAO/CustomField.php | 2 +- CRM/Custom/Form/Field.php | 10 ++++++---- js/model/crm.designer.js | 2 +- js/view/crm.designer.js | 8 ++++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 5177c1c53e..4c70cba3f6 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -125,7 +125,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { * * @param array $params (reference) an assoc array of name/value pairs * - * @return object CRM_Core_DAO_CustomField object + * @return CRM_Core_DAO_CustomField object * @access public * @static */ diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index 36b272d494..2e34075d60 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -987,14 +987,12 @@ SELECT id // reset the cache CRM_Core_BAO_Cache::deleteGroup('contact fields'); - CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.', - array(1 => $customField->label) - ), ts('Saved'), 'success'); + $msg = '

' . ts("Custom field '%1' has been saved.", array(1 => $customField->label)) . '

'; $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { - CRM_Core_Session::setStatus(ts(' You can add another custom field.'), '', 'info'); + $msg += '

' . ts("Ready to add another.") . '

'; $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add', 'reset=1&action=add&gid=' . $this->_gid )); @@ -1004,6 +1002,10 @@ SELECT id 'reset=1&action=browse&gid=' . $this->_gid )); } + $session->setStatus($msg, ts('Saved'), 'success'); + + // Add data when in ajax contect + $this->ajaxResponse['customField'] = $customField->toArray(); } } diff --git a/js/model/crm.designer.js b/js/model/crm.designer.js index 03f8fc6ccb..729778ae6a 100644 --- a/js/model/crm.designer.js +++ b/js/model/crm.designer.js @@ -97,7 +97,7 @@ */ getFieldByName: function(entityName, fieldName) { return this.find(function(paletteFieldModel) { - return (paletteFieldModel.get('entityName') == entityName && paletteFieldModel.get('fieldName') == fieldName); + return ((!entityName || paletteFieldModel.get('entityName') == entityName) && paletteFieldModel.get('fieldName') == fieldName); }); }, diff --git a/js/view/crm.designer.js b/js/view/crm.designer.js index 2bea05605f..6c33665f97 100644 --- a/js/view/crm.designer.js +++ b/js/view/crm.designer.js @@ -408,7 +408,7 @@ CRM.loadForm(url, { resetButton: 'next_new', onSuccess: function(data, settings) { - paletteView.doRefresh(); + paletteView.doRefresh('custom_' + data.customField.id); if (data.buttonName != 'next_new') { $(settings.target).dialog('close'); } @@ -416,11 +416,15 @@ }); return false; }, - doRefresh: function() { + doRefresh: function(fieldToAdd) { var ufGroupModel = this.model; CRM.Schema.reloadModels() .done(function(data){ ufGroupModel.resetEntities(); + if (fieldToAdd) { + var field = ufGroupModel.getRel('paletteFieldCollection').getFieldByName(null, fieldToAdd); + field.addToUFCollection(ufGroupModel.getRel('ufFieldCollection')); + } }) .fail(function() { CRM.alert(ts('Failed to retrieve schema'), ts('Error'), 'error'); -- 2.25.1