/
list-facet.js
101 lines (88 loc) · 3.53 KB
/
list-facet.js
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
/*global jQuery */
(function($, Freemix) {
Freemix.facet.addFacetType({
thumbnail: "/static/exhibit/img/list-facet.png",
label: "List",
propertyTypes: ["date", "number", "text", "currency"],
config: {
type: "list",
expression: "",
showMissing: true,
sortDirection: "forward",
sortMode: "value",
selection: undefined,
scroll: true,
fixedOrder: undefined
},
generateExhibitHTML: function(config) {
config = config || this.config;
var result = $("<div ex:role='facet'></div>");
result.attr("ex:expression", config.expression);
if (config.name && config.name.length > 0) {
result.attr("ex:facetLabel", config.name);
}
return result;
},
showEditor: function(facetContainer) {
var facet = this;
var config = $.extend(true, {}, facet.config);
var template = Freemix.getTemplate("list-facet-editor");
facetContainer = facetContainer || facet.findContainer();
var dialog = facetContainer.getDialog();
template.data("model", this);
template.find("form").submit(function() {return false;});
function updatePreview() {
var preview = $(facet.generateExhibitHTML(config));
template.find("#facet-preview").empty().append(preview);
var exhibit = Freemix.getBuilderExhibit();
facet.facetClass.createFromDOM(preview.get(0), null, exhibit.getUIContext());
}
var select = template.find("#facet_property");
var properties = Freemix.facet.generatePropertyList(facet.propertyTypes);
$.each(properties, function() {
var option = "<option value='" + this.expression + "'>" + this.label + "</option>";
select.append(option);
});
if (config.expression) {
select.val(config.expression);
} else {
select.get(0).options[0].selected=true;
config.expression = select.val();
}
select.change(function() {
config.expression = $(this).val();
updatePreview();
});
var label = template.find("#facet_name");
label.val(config.name);
label.change(function() {
config.name = label.val();
updatePreview();
});
dialog.empty().append(template).dialog("option", {
title: "Edit List",
position: "center",
buttons: [{
text: "Ok",
id: "ok-button",
click: function() {
var model = template.data("model");
model.config = config;
facetContainer.findWidget().trigger("edit-facet");
model.refresh();
facetContainer.getDialog().dialog("close");
}
},
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}
}
]
}).dialog("option", "position", "center");
updatePreview();
dialog.dialog("open");
}
});
})(window.Freemix.jQuery, window.Freemix);