X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fmodel%2Fcrm.uf.js;h=d94bc677c7c30c95dd0916418962640d344ff9ac;hb=b0467361b2522bba63bd5a67854ef91226fb638c;hp=d88578f627c3e77904bfd15fd8e88a9129fcfbca;hpb=3e91789d5906f0e72e2af23df1c31dcb7b6d4bce;p=civicrm-core.git diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index d88578f627..d94bc677c7 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -1,5 +1,4 @@ -(function($) { - var CRM = (window.CRM) ? (window.CRM) : (window.CRM = {}); +(function($, _) { if (!CRM.UF) CRM.UF = {}; var YESNO = [ @@ -77,11 +76,9 @@ switch (field_type) { case 'Contact': case 'Individual': - return 'individual_1'; case 'Organization': - return 'organization_1'; case 'Household': - return 'household_1'; + return 'contact_1'; case 'Activity': return 'activity_1'; case 'Contribution': @@ -90,6 +87,8 @@ return 'membership_1'; case 'Participant': return 'participant_1'; + case 'Case': + return 'case_1'; default: throw "Cannot guess entity name for field_type=" + field_type; } @@ -684,17 +683,60 @@ }); return allMatched; }, + calculateContactEntityType: function() { + var ufGroupModel = this; + + // set proper entity model based on selected profile + var contactTypes = ['Individual', 'Household', 'Organization']; + var profileType = ufGroupModel.get('group_type') || ''; + if (profileType[0]) { + profileType = profileType[0]; + } + profileType = profileType.split(','); + + var ufEntityModel; + _.each(profileType, function (ptype) { + if ($.inArray(ptype, contactTypes) > -1) { + 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 = []; ufGroupModel.getRel('ufFieldCollection').each(function(ufFieldModel){ if (!ufFieldModel.getFieldSchema()) { - CRM.alert(ts('The data model no longer includes field "%1"! All references to the field have been removed.', { - 1: ufFieldModel.get('entity_name') + "." + ufFieldModel.get('field_name') + CRM.alert(ts('This profile no longer includes field "%1"! All references to the field have been removed.', { + 1: ufFieldModel.get('label') }), '', 'alert', {expires: false}); - ufFieldModel.destroyLocal(); + deleteFieldList.push(ufFieldModel); } }); + + _.each(deleteFieldList, function(ufFieldModel) { + ufFieldModel.destroyLocal(); + }); + this.getRel('paletteFieldCollection').reset(this.buildPaletteFields()); + + // reset to redraw the cancel after entity type is updated. + ufGroupModel.getRel('ufFieldCollection').reset(ufGroupModel.getRel('ufFieldCollection').toJSON()); }, /** * @@ -739,4 +781,4 @@ CRM.UF.UFGroupCollection = CRM.Backbone.Collection.extend({ model: CRM.UF.UFGroupModel }); -})(cj); +})(CRM.$, CRM._);