My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 47 attachment: droplistFilter-patch-v2.txt (4.6 KB)

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
Index: C:/work/jmesa/src/org/jmesa/view/html/editor/HtmlFilterDroplistEditor.java
===================================================================
--- C:/work/jmesa/src/org/jmesa/view/html/editor/HtmlFilterDroplistEditor.java (revision 0)
+++ C:/work/jmesa/src/org/jmesa/view/html/editor/HtmlFilterDroplistEditor.java (revision 0)
@@ -0,0 +1,63 @@
+package org.jmesa.view.html.editor;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.jmesa.limit.Filter;
+import org.jmesa.limit.Limit;
+import org.jmesa.util.ItemUtils;
+import org.jmesa.view.editor.AbstractFilterEditor;
+import org.jmesa.view.html.HtmlBuilder;
+import org.jmesa.view.html.component.HtmlColumn;
+
+public class HtmlFilterDroplistEditor extends AbstractFilterEditor {
+
+ public Object getValue() {
+ HtmlBuilder html = new HtmlBuilder();
+
+ Limit limit = getCoreContext().getLimit();
+ HtmlColumn column = (HtmlColumn) getColumn();
+ String property = column.getProperty();
+ Filter filter = limit.getFilterSet().getFilter(property);
+
+ String filterValue = "";
+ if (filter != null) {
+ filterValue = filter.getValue();
+ }
+
+ String mapName = column.getProperty() + "DynFilterMap";
+ StringBuilder map = new StringBuilder();
+ map.append("var ").append(mapName).append("={};");
+ for (String val : getOptions()) {
+ val = StringEscapeUtils.escapeJavaScript(val);
+ map.append(mapName).append("['");
+ map.append(val).append("']='").append(val).append("';");
+ }
+
+ html.script().type("text/javascript").close().append(map).scriptEnd();
+ html.div().styleClass("dynFilter");
+ html.onclick("createDynDroplistFilter(this,'" + limit.getId() + "','" + column.getProperty() + "'," + mapName + ")");
+ html.close();
+ html.append(filterValue);
+ html.divEnd();
+
+ return html.toString();
+ }
+
+ private Collection<String> getOptions() {
+ Set<String> options = new HashSet<String>();
+
+ for (Object item : getCoreContext().getAllItems()) {
+ String property = getColumn().getProperty();
+ Object val = ItemUtils.getItemValue(item, property);
+ if (val != null && String.valueOf(val).length() > 0) {
+ options.add(String.valueOf(val));
+ }
+ }
+
+ return options;
+ }
+
+}
Index: C:/work/jmesa/resources/jmesa.js
===================================================================
--- C:/work/jmesa/resources/jmesa.js (revision 1167)
+++ C:/work/jmesa/resources/jmesa.js (working copy)
@@ -326,6 +326,67 @@
});
}

+/* Droplist Filter */
+
+var dynDroplistFilter;
+
+function DynDroplistFilter(filter, id, property, map) {
+ this.filter = filter;
+ this.id = id;
+ this.property = property;
+ this.map = map;
+}
+
+function createDynDroplistFilter(filter, id, property, map) {
+ dynFilter = new DynFilter(filter, id, property, map);
+
+ /* If already have a filter input box. */
+ if ($('#dynFilterDiv').size() > 0) {
+ return; //already created
+ }
+
+ var cell = $(filter);
+
+ /* Get the original value from the filter. */
+ var originalValue = cell.text();
+ cell.text('')
+
+ var width = cell.width();
+
+ /* Create the dynamic select input box. */
+ html = '<div id="dynFilterDiv"><select id="dynFilterInput" name="filter" style="width:' + width + 'px">';
+ html += '<option value=""> </option>';
+ $.each(map, function(key, value) {
+ if (this == originalValue) {
+ html += '<option selected="selected" value="' + key + '">' + value + '</option>';
+ } else {
+ html += '<option value="' + key + '">' + value + '</option>';
+ }
+ });
+ html += '</select></div>';
+
+ cell.append(html);
+
+ var input = $('#dynFilterInput');
+ input.focus();
+
+ /* Something was selected */
+ $('#dynFilterInput').change(function() {
+ var changedValue = $("#dynFilterInput option:selected").text();
+ cell.text(changedValue);
+ addFilterToLimit(dynFilter.id, dynFilter.property, changedValue);
+ $('#dynFilterDiv').remove();
+ onInvokeAction(dynFilter.id);
+ });
+
+ $('#dynFilterInput').blur(function() {
+ var changedValue = $("#dynFilterInput option:selected").text();
+ cell.text(changedValue);
+ addFilterToLimit(dynFilter.id, dynFilter.property, changedValue);
+ $('#dynFilterDiv').remove();
+ });
+}
+
/* Create a dropshadow for the tables */
function addDropShadow(imagesPath, theme) {
if (!theme) {
Powered by Google Project Hosting