From 8fd0e719bbb72f96a5af266b62bd6d6d6a0c06a3 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 13 Mar 2013 19:46:16 -0700 Subject: [PATCH] Profile editor: Fetch pre/post help for custom fields --- js/model/crm.designer.js | 10 +++++++++- js/view/crm.designer.js | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/js/model/crm.designer.js b/js/model/crm.designer.js index 81dd4543f3..8d1eb1f093 100644 --- a/js/model/crm.designer.js +++ b/js/model/crm.designer.js @@ -41,7 +41,7 @@ * @return {CRM.UF.UFFieldModel} or null (if the field is not addable) */ addToUFCollection: function(ufFieldCollection, addOptions) { - var paletteFieldModel = this; + var name, paletteFieldModel = this; var ufFieldModel = paletteFieldModel.createUFFieldModel(ufFieldCollection.getRel('ufGroupModel')); ufFieldModel.set('uf_group_id', ufFieldCollection.uf_group_id); if (!ufFieldCollection.isAddable(ufFieldModel)) { @@ -55,6 +55,14 @@ return null; } ufFieldCollection.add(ufFieldModel, addOptions); + // Load metadata and set defaults + // TODO: currently only works for custom fields + name = this.get('fieldName').split('_'); + if (name[0] === 'custom') { + CRM.api('custom_field', 'getsingle', {id: name[1]}, {success: function(field) { + ufFieldModel.set(field); + }}); + } return ufFieldModel; }, createUFFieldModel: function(ufGroupModel) { diff --git a/js/view/crm.designer.js b/js/view/crm.designer.js index 8d1509c3f1..3680433f3c 100644 --- a/js/view/crm.designer.js +++ b/js/view/crm.designer.js @@ -678,11 +678,17 @@ fields: fields }); this.form.on('change', this.onFormChange, this); + this.model.on('change', this.onModelChange, this); }, render: function() { this.$el.html(this.form.render().el); this.onFormChange(); }, + onModelChange: function() { + $.each(this.form.fields, function(i, field) { + this.form.setValue(field.key, this.model.get(field.key)); + }); + }, onFormChange: function() { this.form.commit(); this.$('.field-is_multi_summary').toggle(this.options.fieldSchema.civiIsMultiple ? true : false); -- 2.25.1