CRM-13863 - ProfileBuilder - Add popups for edit custom field and new custom set
authorColeman Watts <coleman@civicrm.org>
Sat, 30 Nov 2013 04:55:01 +0000 (20:55 -0800)
committerColeman Watts <coleman@civicrm.org>
Sat, 30 Nov 2013 04:55:01 +0000 (20:55 -0800)
CRM/Custom/Form/Field.php
css/crm.designer.css
js/view/crm.designer.js

index 64c83e68859d7701cf860a389588151dea436c04..e4e6a8e13477f814d9a25ce638c15b8f1b7f9df1 100644 (file)
@@ -103,8 +103,23 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       self::$_dataToHTML = CRM_Core_BAO_CustomField::dataToHtml();
     }
 
-    //custom group id
-    $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
+    //custom field id
+    $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
+
+    $this->_values = array();
+    //get the values form db if update.
+    if ($this->_id) {
+      $params = array('id' => $this->_id);
+      CRM_Core_BAO_CustomField::retrieve($params, $this->_values);
+      // note_length is an alias for the text_length field
+      $this->_values['note_length'] = CRM_Utils_Array::value('text_length', $this->_values);
+      // custom group id
+      $this->_gid = $this->_values['custom_group_id'];
+    }
+    else {
+      // custom group id
+      $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
+    }
 
     if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
       CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set.");
@@ -119,18 +134,6 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       $session->pushUserContext($url);
     }
 
-    //custom field id
-    $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
-
-    //get the values form db if update.
-    $this->_values = array();
-    if ($this->_id) {
-      $params = array('id' => $this->_id);
-      CRM_Core_BAO_CustomField::retrieve($params, $this->_values);
-      // note_length is an alias for the text_length field
-      $this->_values['note_length'] = CRM_Utils_Array::value('text_length', $this->_values);
-    }
-
     if (self::$_dataToLabels == NULL) {
       self::$_dataToLabels = array(
         array('Text' => ts('Text'), 'Select' => ts('Select'),
index 7d4db89f0f688d3b7a77353e2eb023a0695906ab..3afec0358f93f441b55ad7f96f0696047dc9604e 100644 (file)
   font-size: .8em;
 }
 
-.crm-designer .crm-designer-palette-add span.ui-button-text {
+.crm-designer .crm-designer-palette-tree span.ui-button-text,
+.crm-designer .crm-designer-edit-custom span.ui-button-text {
   padding: 0.4em;
 }
 
+.crm-designer .crm-designer-edit-custom {
+  position: absolute;
+  right: 5px;
+  top: 35px;
+  font-size: .8em;
+}
+
+button#crm-designer-add-custom-set {
+  margin-top: 10px;
+}
+
 .ui-sortable-helper > .crm-designer-row {
   box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
   opacity: 0.75;
index 3c56019bc248723792ec9767134ccd6deaf4ab55..1a1c372f60e8a7a55dc318b714325f0aa0b63453 100644 (file)
       'click .crm-designer-palette-clear-search': 'clearSearch',
       'click .crm-designer-palette-toggle': 'toggleAll',
       'click .crm-designer-palette-add button': 'doNewCustomFieldDialog',
+      'click #crm-designer-add-custom-set': 'doNewCustomSetDialog',
       'dblclick .crm-designer-palette-field': 'doAddToCanvas'
     },
     initialize: function() {
           paletteView.toggleActive(ufFieldModel, paletteView.model.getRel('ufFieldCollection'))
         });
         paletteView.$('.crm-designer-palette-add a').replaceWith('<button>' + $('.crm-designer-palette-add a').first().text() + '</<button>');
-        paletteView.$('.crm-designer-palette-add button').button();
+        paletteView.$('.crm-designer-palette-tree > ul').append('<li><button id="crm-designer-add-custom-set">+ ' + ts('Add Set of Custom Fields') + '</button></li>');
+        paletteView.$('.crm-designer-palette-tree button').button();
       }).bind("select_node.jstree", function (e, data) {
         $(this).jstree("toggle_node", data.rslt.obj);
         $(this).jstree("deselect_node", data.rslt.obj);
       });
       return false;
     },
+    doNewCustomSetDialog: function(event) {
+      var paletteView = this;
+      var url = CRM.url('civicrm/admin/custom/group', 'action=add&reset=1');
+      // Create custom field set and automatically go to next step (create fields) after save button is clicked.
+      CRM.loadForm(url, {refreshAction: ['next']})
+        .on('crmFormSuccess', function(e, data) {
+          // When form switches to create custom field context, modify button behavior to only continue for "save and new"
+          data.customField && ($(this).data('crmSnippet').options.crmForm.refreshAction = ['next_new']);
+          paletteView.doRefresh(data.customField ? 'custom_' + data.id : null);
+        });
+      return false;
+    },
     doRefresh: function(fieldToAdd) {
       var ufGroupModel = this.model;
       this.getOpenTreeNodes();
     },
     events: {
       "click .crm-designer-action-settings": 'doToggleForm',
+      "click button.crm-designer-edit-custom": 'doEditCustomField',
       "click .crm-designer-action-remove": 'doRemove'
     },
     modelEvents: {
       var $detail = this.detail.$el;
       if (!this.expanded) {
         $detail.toggle('blind', 250);
+        this.$('button.crm-designer-edit-custom').remove();
       }
       else {
         var $canvas = $('.crm-designer-canvas');
             }
           }
         });
+        if (this.model.get('field_name').split('_')[0] == 'custom') {
+          this.$('.crm-designer-field-summary > div').append('<button class="crm-designer-edit-custom">' + ts('Edit Custom Field') + '</button>');
+          this.$('button.crm-designer-edit-custom').button();
+        }
       }
     },
+    doEditCustomField: function() {
+      CRM.loadForm(CRM.url('civicrm/admin/custom/group/field/update', {
+        action: 'update',
+        reset: 1,
+        id: this.model.get('field_name').split('_')[1]
+      })).on('crmFormLoad', function() {
+          $(this).prepend('<div class="messages status"><div class="icon inform-icon"></div>' + ts('Note: This will modify the field system-wide, not just in this profile form.') + '</div>');
+        });
+      return false;
+    },
     onChangeIsDuplicate: function(model, value, options) {
       this.$el.toggleClass('crm-designer-duplicate', value);
     },