Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | (function($) { |
2 | var ufGroupCollection = new CRM.UF.UFGroupCollection(_.sortBy(CRM.initialProfileList.values, 'title')); | |
3 | //var ufGroupCollection = new CRM.UF.UFGroupCollection(CRM.initialProfileList.values, { | |
4 | // comparator: 'title' // no point, this doesn't work with subcollections | |
5 | //}); | |
6 | ufGroupCollection.unshift(new CRM.UF.UFGroupModel({ | |
7 | id: '', | |
8 | title: ts('- select -') | |
9 | })); | |
10 | ||
11 | /** | |
12 | * Example: | |
13 | * <input type="text" value="{$profileId}" class="crm-profile-selector" /> | |
14 | * ... | |
15 | * cj('.crm-profile-selector').crmProfileSelector({ | |
16 | * groupTypeFilter: "Contact,Individual,Activity;;ActivityType:7", | |
17 | * entities: "contact_1:IndividualModel,activity_1:ActivityModel" | |
18 | * }); | |
19 | * | |
20 | * Note: The system does not currently support dynamic entities -- it only supports | |
21 | * a couple of entities named "contact_1" and "activity_1". See also | |
22 | * CRM.UF.guessEntityName(). | |
23 | */ | |
24 | $.fn.crmProfileSelector = function(options) { | |
25 | return this.each(function() { | |
26 | // Hide the existing <SELECT> and instead construct a ProfileSelector view. | |
27 | // Keep them synchronized. | |
28 | var select = this; | |
29 | ||
30 | var matchingUfGroups; | |
31 | if (options.groupTypeFilter) { | |
32 | matchingUfGroups = ufGroupCollection.subcollection({ | |
33 | filter: function(ufGroupModel) { | |
34 | return ufGroupModel.checkGroupType(options.groupTypeFilter); | |
35 | } | |
36 | }); | |
37 | } else { | |
38 | matchingUfGroups = ufGroupCollection; | |
39 | } | |
40 | ||
41 | var view = new CRM.ProfileSelector.View({ | |
42 | ufGroupId: $(select).val(), | |
43 | ufGroupCollection: matchingUfGroups, | |
44 | ufEntities: options.entities | |
45 | }); | |
46 | view.on('change:ufGroupId', function() { | |
47 | $(select).val(view.getUfGroupId()).change(); | |
48 | }) | |
49 | view.render(); | |
50 | $(select).after(view.el); | |
51 | setTimeout(function() { | |
52 | view.doPreview(); | |
53 | }, 100); | |
54 | }); | |
55 | }; | |
56 | ||
8547369d CW |
57 | $('#crm-container').on('crmLoad', function() { |
58 | $('.crm-profile-selector:not(.rendered)', this).addClass('rendered').each(function() { | |
6a488035 TO |
59 | $(this).crmProfileSelector({ |
60 | groupTypeFilter: $(this).attr('data-group-type'), | |
c50f55b5 | 61 | entities: $(this).data('entities') |
6a488035 TO |
62 | }); |
63 | }); | |
8547369d | 64 | }); |
6a488035 TO |
65 | |
66 | })(cj); |