CRM-13783 - ProfileBuilder - Auto-add new custom field to canvas
authorColeman Watts <coleman@civicrm.org>
Mon, 18 Nov 2013 02:34:25 +0000 (18:34 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 18 Nov 2013 02:34:25 +0000 (18:34 -0800)
CRM/Core/BAO/CustomField.php
CRM/Custom/Form/Field.php
js/model/crm.designer.js
js/view/crm.designer.js

index 5177c1c53e9781ced8815f264da34b1ca584a20a..4c70cba3f6c11463d144230230a2af8397978ee7 100644 (file)
@@ -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
    */
index 36b272d494b05caec990112151a69eee318f96d2..2e34075d6088bd13207a743035a1408b40a83289 100644 (file)
@@ -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 = '<p>' . ts("Custom field '%1' has been saved.", array(1 => $customField->label)) . '</p>';
 
     $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 += '<p>' . ts("Ready to add another.") . '</p>';
       $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();
   }
 }
 
index 03f8fc6ccb563d71aa1e4db03a738d73c2f61257..729778ae6a4775a68208972aaca89551eed7cb01 100644 (file)
@@ -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);
       });
     },
 
index 2bea05605fede92320cdac3ecef70bedaa933b62..6c33665f9749600469852d683b30be086e8b648e 100644 (file)
       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');
           }
       });
       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');