From f34dad5578e6aec29008fafbbe95a4844f63c5b2 Mon Sep 17 00:00:00 2001 From: kurund Date: Fri, 24 Jan 2014 14:05:27 -0800 Subject: [PATCH] more fixes to profile builder --- js/model/crm.uf.js | 17 ++++++++++++++--- js/view/crm.profile-selector.js | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index 2fd7209906..907e108d45 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -692,15 +692,26 @@ var ufEntityModel; _.each(profileType, function (ptype) { if ($.inArray(ptype, contactTypes) > -1) { - ufEntityModel = [ - {'entity_name': 'contact_1', 'entity_type': ptype + 'Model'} - ]; + ufEntityModel = ptype + 'Model'; return true; } }); return ufEntityModel; }, + setUFGroupModel: function(entityType, allEntityModels) { + var ufGroupModel = this; + + var newUfEntityModels = []; + _.each(allEntityModels, function (values) { + if (values.entity_name == 'contact_1') { + values.entity_type = entityType; + } + newUfEntityModels.push(new CRM.UF.UFEntityModel(values)); + }); + + ufGroupModel.getRel('ufEntityCollection').reset(newUfEntityModels); + }, resetEntities: function() { var ufGroupModel = this; var deleteFieldList = []; diff --git a/js/view/crm.profile-selector.js b/js/view/crm.profile-selector.js index 3cc048897e..75977cc83d 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(ufGroupModel.getUFGroupModel()); + ufGroupModel.setUFGroupModel(ufGroupModel.getUFGroupModel(), profileSelectorView.options.ufEntities); 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(ufGroupModel.getUFGroupModel()); + ufGroupModel.setUFGroupModel(ufGroupModel.getUFGroupModel(), profileSelectorView.options.ufEntities); ufGroupModel.getRel('ufFieldCollection').reset(_.values(formData["api.UFField.get"].values)); options.onLoad(ufGroupModel.deepCopy()); } -- 2.25.1