From 2b83aa0d5defc89412f486374687424ee37b2d57 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 29 Nov 2013 20:55:01 -0800 Subject: [PATCH] CRM-13863 - ProfileBuilder - Add popups for edit custom field and new custom set --- CRM/Custom/Form/Field.php | 31 +++++++++++++++++-------------- css/crm.designer.css | 14 +++++++++++++- js/view/crm.designer.js | 32 +++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index 64c83e6885..e4e6a8e134 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -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'), diff --git a/css/crm.designer.css b/css/crm.designer.css index 7d4db89f0f..3afec0358f 100644 --- a/css/crm.designer.css +++ b/css/crm.designer.css @@ -153,10 +153,22 @@ 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; diff --git a/js/view/crm.designer.js b/js/view/crm.designer.js index 3c56019bc2..1a1c372f60 100644 --- a/js/view/crm.designer.js +++ b/js/view/crm.designer.js @@ -296,6 +296,7 @@ '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() { @@ -372,7 +373,8 @@ paletteView.toggleActive(ufFieldModel, paletteView.model.getRel('ufFieldCollection')) }); paletteView.$('.crm-designer-palette-add a').replaceWith(''); + 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); @@ -416,6 +418,18 @@ }); 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(); @@ -562,6 +576,7 @@ }, events: { "click .crm-designer-action-settings": 'doToggleForm', + "click button.crm-designer-edit-custom": 'doEditCustomField', "click .crm-designer-action-remove": 'doRemove' }, modelEvents: { @@ -598,6 +613,7 @@ 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'); @@ -613,8 +629,22 @@ } } }); + if (this.model.get('field_name').split('_')[0] == 'custom') { + this.$('.crm-designer-field-summary > div').append(''); + 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('
' + ts('Note: This will modify the field system-wide, not just in this profile form.') + '
'); + }); + return false; + }, onChangeIsDuplicate: function(model, value, options) { this.$el.toggleClass('crm-designer-duplicate', value); }, -- 2.25.1