summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/FilterController.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/FilterController.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/FilterController.js158
1 files changed, 158 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/FilterController.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/FilterController.js
new file mode 100644
index 0000000..13e02bc
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/FilterController.js
@@ -0,0 +1,158 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers');
30
31Clipperz.PM.UI.Web.Controllers.FilterController = function(args) {
32 args = args || {};
33
34 Clipperz.PM.UI.Web.Controllers.FilterController.superclass.constructor.call(this, args);
35
36 this._filterElements = [];
37 this._filter = "";
38
39 this._pendingSearchClicks = 0;
40
41 return this;
42};
43
44
45Clipperz.Base.extend(Clipperz.PM.UI.Web.Controllers.FilterController, Object, {
46
47 //-----------------------------------------------------------------------------
48
49 'getFilter': function () {
50 return this._filter;
51 },
52
53 '_setFilter': function (aFilterElement, aFilter) {
54 if (aFilter != this._filter) {
55 this._filter = aFilter;
56 MochiKit.Signal.signal(this, 'filterUpdated', aFilter);
57 this.updateFilterElements(aFilterElement, aFilter);
58 }
59 },
60
61 'setFilter': function (aFilter) {
62 this._setFilter(null, aFilter);
63 },
64
65 //-----------------------------------------------------------------------------
66
67 'filterElements': function () {
68 return this._filterElements;
69 },
70
71 'registerFilterElement': function (aFilterElement) {
72//Clipperz.log("=== FilterController.registerFilterElement", aFilterElement);
73 this._filterElements.push(aFilterElement);
74 MochiKit.Signal.connect(aFilterElement, 'onkeydown', this, 'searchClickHandler');
75 MochiKit.Signal.connect(aFilterElement, 'onfocus', this, 'searchClickHandler');
76 },
77
78 'removeFilterElement': function (aFilterElement) {
79 var i;
80 var filterElements;
81 for (i=0; i < filterElements; i++) {
82 if (filterElements[i] == aFilterElement);
83 filterElements.splice(i, 1);
84 // TODO unregister/disconnect filterElement ??MochiKit.Signal.disconnect(this.grid().filterElement(), 'updateFilter', this.filterController(), 'handleUpdateFilter');
85 }
86 },
87
88 'updateFilterElements': function (aSourceElement, aFilterString) {
89 MochiKit.Iter.forEach(this.filterElements(),
90 function (aFilterElement) {
91 if (aFilterElement != aSourceElement) {
92 aFilterElement.value = aFilterString;
93 }
94 }
95 );
96
97 if (aSourceElement != null) {
98 aSourceElement.focus();
99 }
100 },
101
102 //-----------------------------------------------------------------------------
103
104 'run': function () {
105//Clipperz.log("=== FilterController.run");
106 },
107
108 //-----------------------------------------------------------------------------
109
110 'pendingSearchClicks': function () {
111 return this._pendingSearchClicks;
112 },
113
114 'incrementPendingSearchClicks': function () {
115 this._pendingSearchClicks++;
116 },
117
118 'decrementPendingSearchClicks': function () {
119 this._pendingSearchClicks--;
120 },
121
122 //-----------------------------------------------------------------------------
123
124 'searchClickHandler': function (anEvent) {
125 if ((typeof(anEvent.key()) != 'undefined') && (anEvent.key().string == 'KEY_ENTER')) {
126 anEvent.preventDefault();
127 } else {
128 var value;
129
130 if ((typeof(anEvent.key()) != 'undefined') && (anEvent.key().string == 'KEY_ESCAPE')) {
131 value = ""
132 } else if ((typeof(anEvent.key()) != 'undefined') && (anEvent.key().string == 'KEY_ARROW_UP')) {
133 } else if ((typeof(anEvent.key()) != 'undefined') && (anEvent.key().string == 'KEY_ARROW_DOWN')) {
134 } else {
135 value = null;
136 }
137
138 this.incrementPendingSearchClicks();
139 MochiKit.Async.callLater(0.1, MochiKit.Base.method(this, "searchClickDeferredHandler", anEvent.src(), value));
140 }
141 },
142
143 //.........................................................................
144
145 'searchClickDeferredHandler': function (aFilterElement, aValue) {
146 if (aValue != null) {
147 aFilterElement.value = aValue;
148 }
149
150 this.decrementPendingSearchClicks();
151 if (this.pendingSearchClicks()==0) {
152 this._setFilter(aFilterElement, aFilterElement.value);
153 }
154 },
155
156 //-----------------------------------------------------------------------------
157 'syntaxFix': 'syntax fix'
158}); \ No newline at end of file