will_filter 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. data/.loadpath +12 -0
  2. data/.project +18 -0
  3. data/CHANGELOG.rdoc +1 -0
  4. data/Gemfile +32 -0
  5. data/Gemfile.lock +73 -0
  6. data/LICENSE +18 -0
  7. data/README.rdoc +74 -0
  8. data/Rakefile +54 -0
  9. data/VERSION +1 -0
  10. data/app/controllers/application_controller.rb +27 -0
  11. data/app/controllers/will_filter/calendar_controller.rb +31 -0
  12. data/app/controllers/will_filter/exporter_controller.rb +122 -0
  13. data/app/controllers/will_filter/filter_controller.rb +107 -0
  14. data/app/helpers/application_helper.rb +26 -0
  15. data/app/models/will_filter/filter.rb +694 -0
  16. data/app/views/layouts/application.html.erb +11 -0
  17. data/app/views/will_filter/calendar/_annual.html.erb +14 -0
  18. data/app/views/will_filter/calendar/_month.html.erb +39 -0
  19. data/app/views/will_filter/calendar/_quarter.html.erb +15 -0
  20. data/app/views/will_filter/calendar/index.html.erb +52 -0
  21. data/app/views/will_filter/common/_actions_bar.html.erb +5 -0
  22. data/app/views/will_filter/common/_results_table.html.erb +129 -0
  23. data/app/views/will_filter/common/_scripts.html.erb +10 -0
  24. data/app/views/will_filter/exporter/export.html.erb +11 -0
  25. data/app/views/will_filter/exporter/index.html.erb +47 -0
  26. data/app/views/will_filter/filter/_condition.html.erb +30 -0
  27. data/app/views/will_filter/filter/_conditions.html.erb +56 -0
  28. data/app/views/will_filter/filter/_container.html.erb +31 -0
  29. data/app/views/will_filter/filter/containers/_blank.html.erb +1 -0
  30. data/app/views/will_filter/filter/containers/_boolean.html.erb +5 -0
  31. data/app/views/will_filter/filter/containers/_date.html.erb +12 -0
  32. data/app/views/will_filter/filter/containers/_date_range.html.erb +20 -0
  33. data/app/views/will_filter/filter/containers/_date_time.html.erb +12 -0
  34. data/app/views/will_filter/filter/containers/_date_time_range.html.erb +20 -0
  35. data/app/views/will_filter/filter/containers/_list.html.erb +7 -0
  36. data/app/views/will_filter/filter/containers/_numeric_range.html.erb +13 -0
  37. data/app/views/will_filter/filter/containers/_text.html.erb +7 -0
  38. data/app/views/will_filter/filter/index.html.erb +4 -0
  39. data/config/application.rb +45 -0
  40. data/config/boot.rb +6 -0
  41. data/config/database.yml +22 -0
  42. data/config/environment.rb +13 -0
  43. data/config/environments/development.rb +26 -0
  44. data/config/environments/production.rb +49 -0
  45. data/config/environments/test.rb +38 -0
  46. data/config/routes.rb +64 -0
  47. data/config/will_filter/config.yml +97 -0
  48. data/config.ru +4 -0
  49. data/db/development.sqlite3 +0 -0
  50. data/db/migrate/20090730070119_create_will_filter_tables.rb +19 -0
  51. data/db/seeds.rb +7 -0
  52. data/db/test.sqlite3 +0 -0
  53. data/doc/README_FOR_APP +2 -0
  54. data/examples/README +1 -0
  55. data/lib/application_helper.rb +45 -0
  56. data/lib/core_ext/active_record/base.rb +44 -0
  57. data/lib/core_ext/array.rb +34 -0
  58. data/lib/core_ext/object.rb +34 -0
  59. data/lib/generators/will_filter/templates/config.yml +97 -0
  60. data/lib/generators/will_filter/templates/create_will_filter_tables.rb +19 -0
  61. data/lib/generators/will_filter/will_filter_generator.rb +24 -0
  62. data/lib/tasks/.gitkeep +0 -0
  63. data/lib/tasks/will_filter_tasks.rake +32 -0
  64. data/lib/will_filter/calendar.rb +168 -0
  65. data/lib/will_filter/common_methods.rb +49 -0
  66. data/lib/will_filter/config.rb +104 -0
  67. data/lib/will_filter/containers/boolean.rb +43 -0
  68. data/lib/will_filter/containers/date.rb +51 -0
  69. data/lib/will_filter/containers/date_range.rb +56 -0
  70. data/lib/will_filter/containers/date_time.rb +50 -0
  71. data/lib/will_filter/containers/date_time_range.rb +64 -0
  72. data/lib/will_filter/containers/filter_list.rb +59 -0
  73. data/lib/will_filter/containers/list.rb +56 -0
  74. data/lib/will_filter/containers/nil.rb +45 -0
  75. data/lib/will_filter/containers/numeric.rb +52 -0
  76. data/lib/will_filter/containers/numeric_delimited.rb +50 -0
  77. data/lib/will_filter/containers/numeric_range.rb +60 -0
  78. data/lib/will_filter/containers/single_date.rb +57 -0
  79. data/lib/will_filter/containers/text.rb +45 -0
  80. data/lib/will_filter/containers/text_delimited.rb +51 -0
  81. data/lib/will_filter/engine.rb +11 -0
  82. data/lib/will_filter/filter_condition.rb +59 -0
  83. data/lib/will_filter/filter_container.rb +73 -0
  84. data/lib/will_filter/filter_exception.rb +27 -0
  85. data/lib/will_filter.rb +15 -0
  86. data/pkg/will_filter-0.1.0.gem +0 -0
  87. data/pkg/will_filter-0.1.1.gem +0 -0
  88. data/public/404.html +26 -0
  89. data/public/422.html +26 -0
  90. data/public/500.html +26 -0
  91. data/public/favicon.ico +0 -0
  92. data/public/robots.txt +5 -0
  93. data/public/will_filter/images/buttons.png +0 -0
  94. data/public/will_filter/images/calendar.png +0 -0
  95. data/public/will_filter/images/clock.png +0 -0
  96. data/public/will_filter/images/close.gif +0 -0
  97. data/public/will_filter/images/results_table_th_active.gif +0 -0
  98. data/public/will_filter/images/sort_arrow_all.gif +0 -0
  99. data/public/will_filter/images/sort_bg.gif +0 -0
  100. data/public/will_filter/images/spinner.gif +0 -0
  101. data/public/will_filter/javascripts/will_filter.js +568 -0
  102. data/public/will_filter/javascripts/will_filter_prototype_effects.js +15 -0
  103. data/public/will_filter/stylesheets/will_filter.css +168 -0
  104. data/script/rails +6 -0
  105. data/test/functional/models/will_filter/filter_test.rb +297 -0
  106. data/test/performance/browsing_test.rb +9 -0
  107. data/test/test_helper.rb +71 -0
  108. data/uninstall.rb +24 -0
  109. data/will_filter.gemspec +7 -0
  110. metadata +208 -0
data/public/500.html ADDED
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
data/public/robots.txt ADDED
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
Binary file
Binary file
@@ -0,0 +1,568 @@
1
+ /****************************************************************************
2
+ Copyright (c) 2011 Michael Berkovich
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ ****************************************************************************/
23
+
24
+ /****************************************************************************
25
+ **** Generic Helper Functions
26
+ ****************************************************************************/
27
+
28
+ var Wf = Wf || {
29
+ element:function(element_id) {
30
+ if (typeof element_id == 'string') return document.getElementById(element_id);
31
+ return element_id;
32
+ },
33
+ value:function(element_id) {
34
+ return Wf.element(element_id).value;
35
+ },
36
+ hide: function(element_id) {
37
+ Wf.element(element_id).style.display = "none";
38
+ },
39
+ visible: function(element_id) {
40
+ return (Wf.element(element_id).style.display != "none");
41
+ },
42
+ hidden: function(element_id) {
43
+ return (!Wf.visible(element_id));
44
+ },
45
+ show: function(element_id) {
46
+ var style = (Wf.element(element_id).tagName == "SPAN") ? "inline" : "block";
47
+ Wf.element(element_id).style.display = style;
48
+ },
49
+ submit: function(element_id) {
50
+ Wf.element(element_id).submit();
51
+ },
52
+ focus: function(element_id) {
53
+ Wf.element(element_id).focus();
54
+ },
55
+ scrollTo: function(element_id) {
56
+ var theElement = Wf.element(element_id);
57
+ var selectedPosX = 0;
58
+ var selectedPosY = 0;
59
+ while(theElement != null){
60
+ selectedPosX += theElement.offsetLeft;
61
+ selectedPosY += theElement.offsetTop;
62
+ theElement = theElement.offsetParent;
63
+ }
64
+ window.scrollTo(selectedPosX,selectedPosY);
65
+ }
66
+ };
67
+
68
+ /****************************************************************************
69
+ **** Effects Functions
70
+ **** The functions can be overloaded using a specific framework
71
+ ****************************************************************************/
72
+ Wf.Effects = {
73
+ blindUp: function(element_id) {
74
+ Wf.hide(element_id);
75
+ },
76
+ blindDown: function(element_id) {
77
+ Wf.show(element_id);
78
+ },
79
+ appear: function(element_id) {
80
+ Wf.show(element_id);
81
+ },
82
+ fade: function(element_id) {
83
+ Wf.hide(element_id);
84
+ },
85
+ };
86
+
87
+ /****************************************************************************
88
+ **** Filter Container
89
+ ****************************************************************************/
90
+
91
+ Wf.Filter = function(options){
92
+ var self = this;
93
+ this.original_form_action = null;
94
+ }
95
+
96
+ Wf.Filter.prototype = {
97
+ showSpinner: function() {
98
+ Wf.show("wf_loader");
99
+ },
100
+ hideSpinner: function() {
101
+ Wf.hide("wf_loader");
102
+ },
103
+ toggleDebugger: function() {
104
+ if (Wf.visible("wf_debugger")) {
105
+ new Wf.Effects.blindUp("wf_debugger");
106
+ } else {
107
+ new Wf.Effects.blindDown("wf_debugger");
108
+ }
109
+ },
110
+ markDirty: function() {
111
+ if (Wf.element("wf_key") && Wf.value("wf_id") == "") {
112
+ Wf.element("wf_key").value = "";
113
+ }
114
+ },
115
+ fieldChanged: function(fld) {
116
+ Wf.element(fld).style.border = "1px solid red";
117
+ this.markDirty();
118
+ },
119
+ saveFilter: function() {
120
+ var filter_name = prompt("Please provide a name for the new filter:", "");
121
+ if (filter_name == null) return;
122
+ Wf.element("wf_name").value = filter_name;
123
+ this.showSpinner();
124
+ this.updateFilterConditions('save_filter', Wf.Utils.serializeForm('wf_form'));
125
+ },
126
+ updateFilter: function() {
127
+ var filter_name = prompt("Please provide a name for this filter:", Wf.value("wf_name"));
128
+ if (filter_name == null) return;
129
+ Wf.element("wf_name").value = filter_name;
130
+ this.showSpinner();
131
+ this.updateFilterConditions('update_filter', Wf.Utils.serializeForm('wf_form'));
132
+ },
133
+ deleteFilter: function() {
134
+ if (!confirm("Are you sure you want to delete this filter?")) return;
135
+ this.showSpinner();
136
+ this.updateFilterConditions('delete_filter', Wf.Utils.serializeForm('wf_form'));
137
+ },
138
+ updateConditionAt: function(index) {
139
+ this.showSpinner();
140
+ this.markDirty();
141
+ var data_hash = Wf.Utils.serializeForm('wf_form');
142
+ data_hash["at_index"] = index;
143
+ this.updateFilterConditions('update_condition', data_hash);
144
+ },
145
+ removeConditionAt: function(index) {
146
+ this.showSpinner();
147
+ this.markDirty();
148
+ var data_hash = Wf.Utils.serializeForm('wf_form');
149
+ data_hash["at_index"] = index;
150
+ this.updateFilterConditions('remove_condition', data_hash);
151
+ },
152
+ removeAllConditions: function() {
153
+ this.showSpinner();
154
+ this.markDirty();
155
+ this.updateFilterConditions('remove_all_conditions', Wf.Utils.serializeForm('wf_form'));
156
+ },
157
+ addCondition: function() {
158
+ this.addConditionAfter(-1);
159
+ },
160
+ addConditionAfter: function(index) {
161
+ this.showSpinner();
162
+ this.markDirty();
163
+ var data_hash = Wf.Utils.serializeForm('wf_form');
164
+ data_hash["after_index"] = index;
165
+ this.updateFilterConditions('add_condition', data_hash);
166
+ },
167
+ updateFilterConditions: function(action, data_hash) {
168
+ Wf.Utils.update('wf_filter_conditions', '/will_filter/filter/' + action, {
169
+ parameters: data_hash,
170
+ evalScripts: true,
171
+ onComplete: function(transport) {
172
+ wfFilter.hideSpinner();
173
+ }
174
+ });
175
+ },
176
+ loadSavedFilter: function() {
177
+ if (Wf.value("wf_key") == "-1" || Wf.value("wf_key") == "-2")
178
+ return;
179
+
180
+ this.showSpinner();
181
+ var data_hash = Wf.Utils.serializeForm('wf_form');
182
+
183
+ Wf.Utils.update('wf_filter_conditions', '/will_filter/filter/load_filter', {
184
+ parameters: data_hash,
185
+ evalScripts: true,
186
+ onComplete: function(transport) {
187
+ wfFilter.submit();
188
+ }
189
+ });
190
+ },
191
+ submit: function() {
192
+ if (this.original_form_action != "")
193
+ Wf.element('wf_form').action = this.original_form_action;
194
+
195
+ Wf.element('wf_submitted').value = 'true';
196
+ Wf.submit('wf_form');
197
+ }
198
+ };
199
+
200
+ /****************************************************************************
201
+ **** Filter Calendar
202
+ ****************************************************************************/
203
+
204
+ Wf.Calendar = function(options) {
205
+ this.options = options || {};
206
+ this.trigger = null;
207
+ this.last_selected_cell = null;
208
+ this.selected_field_id = null;
209
+
210
+ this.container = document.createElement('div');
211
+ this.container.className = 'wf_calendar';
212
+ this.container.id = 'wf_calendar';
213
+ this.container.style.display = "none";
214
+
215
+ document.body.appendChild(this.container);
216
+ }
217
+
218
+ Wf.Calendar.prototype = {
219
+ show: function(fld_id, trigger, show_time) {
220
+ if (this.selected_field_id == fld_id) {
221
+ this.hide();
222
+ return;
223
+ }
224
+
225
+ this.trigger = trigger;
226
+
227
+ var form_hash = {};
228
+ form_hash["wf_calendar_selected_date"] = Wf.value(fld_id);
229
+ form_hash["wf_calendar_show_time"] = show_time;
230
+
231
+ this.selected_field_id = fld_id;
232
+ Wf.Utils.update('wf_calendar', '/will_filter/calendar', {
233
+ parameters: form_hash,
234
+ onComplete: function(transport) {
235
+ var trigger_position = Wf.Utils.cumulativeOffset(wfCalendar.trigger);
236
+ var calendar_container = Wf.element("wf_calendar");
237
+ calendar_container.style.left = (trigger_position[0] - 237) + "px";
238
+ calendar_container.style.top = trigger_position[1] + "px";
239
+ calendar_container.style.width = "230px";
240
+ Wf.Effects.appear("wf_calendar");
241
+ }
242
+ });
243
+ },
244
+ selectDate: function(fld_id, trigger){
245
+ this.show(fld_id, trigger, false);
246
+ },
247
+ selectDateTime: function(fld_id, trigger){
248
+ this.show(fld_id, trigger, true);
249
+ },
250
+ changeMode: function(mode) {
251
+ var form_hash = Wf.Utils.serializeForm('wf_calendar_form');
252
+ form_hash["wf_calendar_mode"] = mode;
253
+
254
+ if (mode == 'annual')
255
+ form_hash["wf_calendar_start_date"] = Wf.value("wf_calendar_year") + "-01-01";
256
+
257
+ Wf.Utils.update('wf_calendar', '/will_filter/calendar', {
258
+ parameters: form_hash,
259
+ onComplete: function(transport) {
260
+ var trigger_position = Wf.Utils.cumulativeOffset(wfCalendar.trigger);
261
+ var width = (mode=='annual' ? 760 : 400);
262
+ var calendar_container = Wf.element("wf_calendar");
263
+ calendar_container.style.left = (trigger_position[0] - width - 7) + "px";
264
+ calendar_container.style.top = trigger_position[1] + "px";
265
+ calendar_container.style.width = width + "px";
266
+ }
267
+ });
268
+ },
269
+ goToStartDate: function(start_date) {
270
+ var form_hash = Wf.Utils.serializeForm('wf_calendar_form');
271
+ if (start_date == '')
272
+ form_hash["wf_calendar_start_date"] = Wf.value("wf_calendar_year") + "-" + Wf.value("wf_calendar_month") + "-01";
273
+ else
274
+ form_hash["wf_calendar_start_date"] = start_date;
275
+
276
+ Wf.Utils.update('wf_calendar', '/will_filter/calendar', {
277
+ parameters: form_hash
278
+ });
279
+ },
280
+ setSelectedFieldValue: function(value) {
281
+ if (this.selected_field_id==null || Wf.element(this.selected_field_id)==null)
282
+ return;
283
+ Wf.element(this.selected_field_id).value = value;
284
+ wfFilter.fieldChanged(this.selected_field_id);
285
+ this.selected_field_id = null;
286
+ },
287
+ selectDateValue: function(elem_id, date) {
288
+ if (this.last_selected_cell)
289
+ Wf.Utils.removeClassName(Wf.element(this.last_selected_cell), "selected");
290
+
291
+ Wf.Utils.addClassName(Wf.element(elem_id), 'selected');
292
+ this.last_selected_cell = elem_id;
293
+
294
+ Wf.element("wf_calendar_selected_date").value = date;
295
+ },
296
+ setDate: function() {
297
+ this.setSelectedFieldValue(Wf.value("wf_calendar_selected_date"));
298
+ this.hide();
299
+ },
300
+ prepandZero: function(val) {
301
+ if (parseInt(val) >= 10)
302
+ return val;
303
+
304
+ return ("0" + val);
305
+ },
306
+ setDateTime: function() {
307
+ var val = Wf.value("wf_calendar_selected_date");
308
+ val += " " + this.prepandZero(Wf.value("wf_calendar_hour"));
309
+ val += ":" + this.prepandZero(Wf.value("wf_calendar_minute"));
310
+ val += ":" + this.prepandZero(Wf.value("wf_calendar_second"));
311
+
312
+ this.setSelectedFieldValue(val);
313
+ this.hide();
314
+ },
315
+ hide: function() {
316
+ this.selected_field_id = null;
317
+ Wf.Effects.fade("wf_calendar");
318
+ }
319
+ };
320
+
321
+ /****************************************************************************
322
+ **** Filter Exporter
323
+ ****************************************************************************/
324
+
325
+ Wf.Exporter = function(options) {
326
+ this.options = options || {};
327
+
328
+ this.container = document.createElement('div');
329
+ this.container.className = 'wf_exporter';
330
+ this.container.id = 'wf_exporter';
331
+ this.container.style.display = "none";
332
+
333
+ document.body.appendChild(this.container);
334
+ }
335
+
336
+ Wf.Exporter.prototype = {
337
+ show: function (trigger) {
338
+ Wf.Utils.update('wf_exporter', '/will_filter/exporter', {
339
+ parameters: Wf.Utils.serializeForm('wf_form'),
340
+ onComplete: function(transport) {
341
+ var trigger_position = Wf.Utils.cumulativeOffset(trigger);
342
+ var exporter_container = Wf.element("wf_exporter");
343
+ exporter_container.style.left = (trigger_position[0] - 240) + "px";
344
+ exporter_container.style.top = trigger_position[1] + "px";
345
+ Wf.Effects.appear("wf_exporter");
346
+ }
347
+ });
348
+ },
349
+ hide: function() {
350
+ Wf.Effects.fade("wf_exporter");
351
+ },
352
+ selectAllFields: function (fld) {
353
+ var i = 0;
354
+ var chkFld = Wf.element("wf_fld_chk_" + i);
355
+ while (chkFld != null) {
356
+ chkFld.checked = fld.checked;
357
+ i++;
358
+ chkFld = Wf.element("wf_fld_chk_" + i);
359
+ }
360
+ this.updateExportFields();
361
+ },
362
+ selectField: function (fld) {
363
+ if (!fld.checked) {
364
+ Wf.element("wf_fld_all").checked = false;
365
+ }
366
+ this.updateExportFields();
367
+ },
368
+ updateExportFields: function () {
369
+ var i = 0;
370
+ var chkFld = Wf.element("wf_fld_chk_" + i);
371
+ var fields = "";
372
+ while (chkFld != null) {
373
+ if (chkFld.checked) {
374
+ if (fields != "") fields += ",";
375
+ fields += Wf.value("wf_fld_name_" + i);
376
+ }
377
+ i++;
378
+ chkFld = Wf.element("wf_fld_chk_" + i);
379
+ }
380
+
381
+ Wf.element("wf_export_fields").value = fields;
382
+ },
383
+ exportFilter: function() {
384
+ if (wfFilter.original_form_action == "")
385
+ wfFilter.original_form_action = Wf.element('wf_form').action;
386
+
387
+ this.updateExportFields();
388
+
389
+ if (Wf.value("wf_export_fields") == "") {
390
+ alert("Please select st least one field to export");
391
+ return;
392
+ }
393
+
394
+ if (Wf.value('wf_export_format_selector') == "-1") {
395
+ alert("Please select an export format");
396
+ return;
397
+ }
398
+
399
+ Wf.element('wf_export_format').value = Wf.value('wf_export_format_selector');
400
+ Wf.element('wf_form').action = '/will_filter/exporter/export';
401
+ Wf.submit('wf_form');
402
+ }
403
+ };
404
+
405
+
406
+
407
+ /****************************************************************************
408
+ **** Utilities
409
+ ****************************************************************************/
410
+
411
+ Wf.Utils = {
412
+
413
+ addEvent: function(elm, evType, fn, useCapture) {
414
+ useCapture = useCapture || false;
415
+ if (elm.addEventListener) {
416
+ elm.addEventListener(evType, fn, useCapture);
417
+ return true;
418
+ } else if (elm.attachEvent) {
419
+ var r = elm.attachEvent('on' + evType, fn);
420
+ return r;
421
+ } else {
422
+ elm['on' + evType] = fn;
423
+ }
424
+ },
425
+
426
+ toQueryParams: function (obj) {
427
+ if (typeof obj == 'undefined' || obj == null) return "";
428
+ if (typeof obj == 'string') return obj;
429
+
430
+ var qs = [];
431
+ for(p in obj) {
432
+ qs.push(p + "=" + encodeURIComponent(obj[p]))
433
+ }
434
+ return qs.join("&")
435
+ },
436
+
437
+ serializeForm: function(form) {
438
+ var els = Wf.element(form).elements;
439
+ var form_obj = {}
440
+ for(i=0; i < els.length; i++) {
441
+ if (els[i].type == 'checkbox' && !els[i].checked) continue;
442
+ if (els[i].type == 'radio' && !els[i].checked) continue;
443
+ form_obj[els[i].name] = els[i].value;
444
+ }
445
+ return form_obj;
446
+ },
447
+
448
+ getRequest: function() {
449
+ var factories = [
450
+ function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
451
+ function() { return new XMLHttpRequest(); },
452
+ function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
453
+ ];
454
+ for(var i = 0; i < factories.length; i++) {
455
+ try {
456
+ var request = factories[i]();
457
+ if (request != null) return request;
458
+ } catch(e) {continue;}
459
+ }
460
+ },
461
+
462
+ ajax: function(url, options) {
463
+ options = options || {};
464
+ options.parameters = Wf.Utils.toQueryParams(options.parameters);
465
+ options.method = options.method || 'get';
466
+
467
+ var self=this;
468
+ if (options.method == 'get' && options.parameters != '') {
469
+ url = url + (url.indexOf('?') == -1 ? '?' : '&') + options.parameters;
470
+ }
471
+ var request = this.getRequest();
472
+
473
+ request.onreadystatechange = function() {
474
+ if(request.readyState == 4) {
475
+ if (request.status == 200) {
476
+ if(options.onSuccess) options.onSuccess(request);
477
+ if(options.onComplete) options.onComplete(request);
478
+ if(options.evalScripts) self.evalScripts(request.responseText);
479
+ } else {
480
+ if(options.onFailure) options.onFailure(request)
481
+ if(options.onComplete) options.onComplete(request)
482
+ }
483
+ }
484
+ }
485
+
486
+ request.open(options.method, url, true);
487
+ request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
488
+ request.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
489
+ request.send(options.parameters);
490
+ },
491
+
492
+ update: function(element_id, url, options) {
493
+ options.onSuccess = function(response) {
494
+ Wf.element(element_id).innerHTML = response.responseText;
495
+ };
496
+ Wf.Utils.ajax(url, options);
497
+ },
498
+
499
+ evalScripts: function(html){
500
+ var script_re = '<script[^>]*>([\\S\\s]*?)<\/script>';
501
+ var matchAll = new RegExp(script_re, 'img');
502
+ var matchOne = new RegExp(script_re, 'im');
503
+ var matches = html.match(matchAll) || [];
504
+ for(var i=0,l=matches.length;i<l;i++){
505
+ var script = (matches[i].match(matchOne) || ['', ''])[1];
506
+ // console.info(script)
507
+ // alert(script);
508
+ eval(script);
509
+ }
510
+ },
511
+
512
+ hasClassName: function(el, cls){
513
+ var exp = new RegExp("(^|\\s)"+cls+"($|\\s)");
514
+ return (el.className && exp.test(el.className))?true:false;
515
+ },
516
+
517
+ addClassName: function(el, cls) {
518
+ if (!Wf.Utils.hasClassName(el,cls)) el.className += " " + cls;
519
+ },
520
+
521
+ removeClassName: function(el,cls) {
522
+ if (Wf.Utils.hasClassName(el,cls)) {
523
+ var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
524
+ el.className=el.className.replace(reg, ' ');
525
+ }
526
+ },
527
+
528
+ findElement: function(e,selector,el) {
529
+ var event = e || window.event;
530
+ var target = el || event.target || event.srcElement;
531
+ if(target == document.body) return null;
532
+ var condition = (selector.match(/^\./)) ? this.hasClassName(target,selector.replace(/^\./,'')) : (target.tagName.toLowerCase() == selector.toLowerCase());
533
+ if(condition) {
534
+ return target;
535
+ } else {
536
+ return this.findElement(e,selector,target.parentNode);
537
+ }
538
+ },
539
+
540
+ cumulativeOffset: function(element) {
541
+ var valueT = 0, valueL = 0;
542
+ do {
543
+ valueT += element.offsetTop || 0;
544
+ valueL += element.offsetLeft || 0;
545
+ element = element.offsetParent;
546
+ } while (element);
547
+ return [valueL, valueT];
548
+ }
549
+
550
+ }
551
+
552
+ /****************************************************************************
553
+ **** Initialization
554
+ ****************************************************************************/
555
+
556
+ var wfFilter = null;
557
+ var wfCalendar = null;
558
+ var wfExporter = null;
559
+
560
+ function initializeWillFilter() {
561
+ var setup = function() {
562
+ wfFilter = new Wf.Filter();
563
+ wfCalendar = new Wf.Calendar();
564
+ wfExporter = new Wf.Exporter();
565
+ }
566
+
567
+ Wf.Utils.addEvent(window,'load',setup);
568
+ }
@@ -0,0 +1,15 @@
1
+ var Wf = Wf || {};
2
+ Wf.Effects = {
3
+ blindUp: function(element_id) {
4
+ Effect.BlindUp(element_id, { duration: 0.25 });
5
+ },
6
+ blindDown: function(element_id) {
7
+ Effect.BlindDown(element_id, { duration: 0.25 });
8
+ },
9
+ appear: function(element_id) {
10
+ Effect.Appear(element_id, { duration: 0.25 });
11
+ },
12
+ fade: function(element_id) {
13
+ Effect.Fade(element_id, { duration: 0.25 });
14
+ }
15
+ }