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.");
$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'),
'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);
},