forked from hyankov/MultiValueRefiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filter_Contains_MultiValue.html
108 lines (101 loc) · 4.65 KB
/
Filter_Contains_MultiValue.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<title>Contains Multi-value Refinement Item</title>
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:CompatibleManagedProperties msdt:dt="string"></mso:CompatibleManagedProperties>
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
<mso:CompatibleSearchDataTypes msdt:dt="string"></mso:CompatibleSearchDataTypes>
<mso:MasterPageDescription msdt:dt="string"></mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106604</mso:ContentTypeId>
<mso:TargetControlType msdt:dt="string">;#Refinement;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
</mso:CustomDocumentProperties></xml><![endif]-->
</head>
<body>
<script>
$includeScript("", "~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_MultiValue_Body.js");
</script>
<div id="Filter_Contains_MultiValue">
<!--#_
var Options = {
ShowCounts: false
};
var listData = ctx.ListData;
var hasControl = !$isNull(ctx.RefinementControl) && !$isNull(ctx.ClientControl);
if(hasControl) {
var hasNoListData = ($isEmptyArray(listData));
var delimiter = ', ';
var propertyName = ctx.RefinementControl.propertyName;
var displayTitle = Srch.Refinement.getRefinementTitle(ctx.RefinementControl);
var isExpanded = Srch.Refinement.getExpanded(ctx.RefinementControl.propertyName);
var useContains = true;
var useKQL = false;
var refiners = [];
var currentRefinementCategory = ctx.ClientControl.getCurrentRefinementCategory(ctx.RefinementControl.propertyName);
var hasAnyFilterTokens = (!$isNull(currentRefinementCategory) && currentRefinementCategory.get_tokenCount() > 0);
var renderEmptyContainer = hasControl && (hasNoListData && !hasAnyFilterTokens);
if(!renderEmptyContainer) {
var listDataTokenToDisplayMap = {};
var listDataTokenToCountMap = {};
if(!hasNoListData) {
for (var i = 0; i < listData.length; i++) {
var filter = listData[i];
if(!$isNull(filter)) {
var originalRefinementName = filter.RefinementName.split(delimiter);
for (var j = 0; j < originalRefinementName.length; j++){
var refinementToken = (originalRefinementName[j].indexOf('\\') > -1) ? originalRefinementName[j] : '"' + originalRefinementName[j] + '"';
if (typeof listDataTokenToDisplayMap[refinementToken] == 'undefined') {
listDataTokenToDisplayMap[refinementToken] = originalRefinementName[j];
listDataTokenToCountMap[refinementToken] = filter.RefinementCount;
if(!hasAnyFilterTokens && !$isEmptyString(originalRefinementName[j]) && !$isEmptyString(refinementToken)) {
refiners.push(
{
RefinementName: originalRefinementName[j],
RefinementToken: refinementToken,
RefinementCount: filter.RefinementCount,
IsSelected: false
});
}
}
}
}
}
}
if(hasAnyFilterTokens) {
for(var j = 0; j < currentRefinementCategory.get_tokenCount(); j++) {
var token = currentRefinementCategory.t[j];
var displayValue = listDataTokenToDisplayMap[token];
if($isEmptyString(displayValue) && !$isNull(currentRefinementCategory.m)) {
displayValue = currentRefinementCategory.m[token];
}
if(!$isEmptyString(displayValue) && !$isEmptyString(token))
{
refiners.push(
{
RefinementName: displayValue,
RefinementToken: token,
RefinementCount: !$isNull(listDataTokenToCountMap[token]) ? listDataTokenToCountMap[token] : 0,
IsSelected: true
});
}
}
}
}
ctx["DisplayTemplateData"]["BodyTemplateId"] = "~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_MultiValue_Body.js";
ctx.RefinementControl["csr_propertyName"] = propertyName;
ctx.RefinementControl["csr_displayTitle"] = displayTitle;
ctx.RefinementControl["csr_filters"] = refiners;
ctx.RefinementControl["csr_isExpanded"] = isExpanded;
ctx.RefinementControl["csr_renderEmptyContainer"] = renderEmptyContainer;
ctx.RefinementControl["csr_useContains"] = useContains;
ctx.RefinementControl["csr_useKQL"] = useKQL;
ctx.RefinementControl["csr_showCounts"] = Options.ShowCounts;
_#-->
_#= ctx.RenderBody(ctx) =#_
<!--#_
}
_#-->
</div>
</body>
</html>