From 06575e57d149bf922a51b92d63fdf52cf4c9a3c6 Mon Sep 17 00:00:00 2001 From: kurund Date: Fri, 24 Jan 2014 01:52:47 -0800 Subject: [PATCH] more work on profile builder, set correct filter defaults --- js/model/crm.uf.js | 19 +++++++++++++++++++ js/view/crm.profile-selector.js | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index 79d43a7a6d..2fd7209906 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -682,6 +682,25 @@ }); return allMatched; }, + getUFGroupModel: function() { + var ufGroupModel = this; + + // set proper entity model based on selected profile + var contactTypes = ['Individual', 'Household', 'Organization']; + var profileType = ufGroupModel.get('group_type'); + profileType = profileType.split(','); + var ufEntityModel; + _.each(profileType, function (ptype) { + if ($.inArray(ptype, contactTypes) > -1) { + ufEntityModel = [ + {'entity_name': 'contact_1', 'entity_type': ptype + 'Model'} + ]; + return true; + } + }); + + return ufEntityModel; + }, resetEntities: function() { var ufGroupModel = this; var deleteFieldList = []; diff --git a/js/view/crm.profile-selector.js b/js/view/crm.profile-selector.js index 19660552f8..3cc048897e 100644 --- a/js/view/crm.profile-selector.js +++ b/js/view/crm.profile-selector.js @@ -115,7 +115,7 @@ success: function(formData) { // Note: With chaining, API returns some extraneous keys that aren't part of UFGroupModel var ufGroupModel = new CRM.UF.UFGroupModel(_.pick(formData, _.keys(CRM.UF.UFGroupModel.prototype.schema))); - ufGroupModel.getRel('ufEntityCollection').reset(profileSelectorView.options.ufEntities); + ufGroupModel.getRel('ufEntityCollection').reset(ufGroupModel.getUFGroupModel()); ufGroupModel.getRel('ufFieldCollection').reset(_.values(formData["api.UFField.get"].values)); options.onLoad(ufGroupModel); } @@ -137,7 +137,7 @@ success: function(formData) { // Note: With chaining, API returns some extraneous keys that aren't part of UFGroupModel var ufGroupModel = new CRM.UF.UFGroupModel(_.pick(formData, _.keys(CRM.UF.UFGroupModel.prototype.schema))); - ufGroupModel.getRel('ufEntityCollection').reset(profileSelectorView.options.ufEntities); + ufGroupModel.getRel('ufEntityCollection').reset(ufGroupModel.getUFGroupModel()); ufGroupModel.getRel('ufFieldCollection').reset(_.values(formData["api.UFField.get"].values)); options.onLoad(ufGroupModel.deepCopy()); } -- 2.25.1