Filter not working when I extend it to another field

I have a filter that works with one field (‘event_type’)

When I add another (‘active’) it doesn’t work

Why is line 249 below coming back as undefined?

On line 251 e_pass is true when checked, a_pass is always false?

I’m stumped

Thanks in advance,

David


81 /* FILTER 1 */
82
83 .filters_wrapper {
84 line-height: 12px;
85 font-size: 12px;
86 }
87 .filters_wrapper span {
88 font-weight: bold;
89 padding-right: 5px;
90 }
91 .filters_wrapper label {
92 padding-right: 3px;
93 }
94

213 // FILTER array
214 var filters = {
215 other: true,
216 judgment: true,
217 special_set: true,
218 trial: true,
219 summary_judgment: true,
220 active: true, // not an event type but refers to another field called active with 0 or 1
222 };
223
224 var filter_inputs = document.getElementById(“filters_wrapper”).getElementsByTagName(“in
put”);
225 for (var i=0; i<filter_inputs.length; i++) {
226 var filter_input = filter_inputs[i];
227
228 filter_input.checked = filters[filter_input.name];
229
230 filter_input.onchange = function() {
231 filters[this.name] = !!this.checked;
232 scheduler.updateView();
233 }
234 }
235 /*
236 console.log(‘ec:’ + event.event_type );
237 console.log(‘fec:’ + filters[event.event_type] );
238 */
239 scheduler.filter_month = scheduler.filter_day = scheduler.filter_week = scheduler.filt
er_workweek = function(id, event) {
240
241 var e_pass = (filters[event.event_type] || event.event_type==scheduler.undefined);
242 var a_pass = (filters[event.active] || event.active==scheduler.undefined); // false ???
243
244 var filter_inputs = document.getElementById(“filters_wrapper”).getElementsByTagName(“in
put”);
245
246 //console.log(‘fi:’ + filter_inputs[0] );
247
248 //console.log(‘ac:’ + event.active ); // >>> correctly 1 or 0 depending on the event
249 console.log(‘fac:’ + filters[event.active] ); // >>> ??? always false
250 // return true;
251 if (e_pass && a_pass)
252 {
253 return true;
254 }
255 return false;
256 };

424
425


426

428
429
430
431 Other
432
433
434
435 Judgment
436
437
438
439 Summary Judgment
440
441
442
443 Special Set
444
445
446
447 Trial
448
449

450
451 Active
452
453

// >>> following records don’t work when I use a_pass

mysql> select * from events where event_name like ‘Test%’\G
*************************** 1. row ***************************
event_id: 16
start_date: 2013-11-18 11:10:00
end_date: 2013-11-18 14:00:00
event_name: Test 1
details:
division: AA
color: NULL
event_type: other
event_type_other:
media_type: T
is_private: 0
user_id: dgriffis
rec_type:
event_pid: 0
event_length: 0
active: 0
import_source_id: 1
cancel_reason:
*************************** 2. row ***************************
event_id: 12893
start_date: 2013-11-18 14:30:00
end_date: 2013-11-18 17:25:00
event_name: Test 2
details:
division: AA
color: NULL
event_type: other
event_type_other:
media_type: u
is_private: 0
user_id: dgriffis
rec_type:
event_pid: 0
event_length: 0
active: 1
import_source_id: 1
cancel_reason:
2 rows in set (0.00 sec)

RE: ‘cancelled’ checkbox not filtering (‘event_type’ filter is working)

Here’s my latest and less complicated approach that still doesn’t work

Not sure what I’m doing wrong?

Please note items - >>> 1), >>> 2) and >>>3) below

TIA

-D

  1. html

468


469

471
472
473
474 Cancelled
475
476

477

206 scheduler.templates.event_class=function(start, end, event){
207 if(event.color)
208 return “event_”+event.color;
209
210 return “”;
211 };
212
213 // FILTER array
214 var filters = {
215 other: true,
216 judgment: true,
217 special_set: true,
218 trial: true,
219 summary_judgment: true,
220 active: true,
221 };
222
223 var filter_inputs = document.getElementById(“filters_wrapper”).getElementsByTagName(“in
put”);
224 for (var i=0; i<filter_inputs.length; i++) {
225 var filter_input = filter_inputs[i];
226
227 filter_input.checked = filters[filter_input.name];
228
229 filter_input.onchange = function() {
230 filters[this.name] = !!this.checked;
231 scheduler.updateView();
232 }
233 }
234

235 var cancelled_filter = document.getElementById(“show_cancelled”);
236 cancelled_filter.onchange = function() {
237 show_cancelled = !!this.checked;
238 scheduler.updateView();
239 }
240 /*
241 console.log(‘ec:’ + event.event_type );
242 console.log(‘fec:’ + filters[event.event_type] );
243 */
244 scheduler.filter_month = scheduler.filter_day = scheduler.filter_week = scheduler.filt
er_workweek = function(id, event) {
245
246 var e_pass = (filters[event.event_type] || event.event_type==scheduler.undefined);

  1. this is pretty solid

247 var show_cancelled = ( document.getElementById(“show_cancelled”).value == ‘on’);
248 var is_cancelled = (event.active != 1);
249
250 a_pass = (show_cancelled && is_cancelled) ? 1 : 0;
251 if (e_pass && a_pass)
252 {
253 return true;
254 }
255 return false;
256 };

I added another filter and it worked. (division filter)

I can’t tell what doesn’t work with the ‘active’ filter. Maybe it’s a reserved word. Or it doesn’t appear as defined in the lightbox because it’s not viewable. Either way I solved it by prompting the user if they want active records at login. Other things to work on. Onward.

-D

I think that instead of

filters[event.event_type] filters[event.active]

you need to use

filters["event_type"] filters["active"]

No. The filter works. However, only for the checkboxes I have to refresh first.

Is there something I can add to the set_value, get_value functions so that the memory pointer for the event field gets update.

All the filters for the lightbox sections work without refresh, so that’s why I think I need to add additional code for our custom checkboxes…

Thanks,

David


I created a lightbox value for the checkbox and it still doesn’t work. So the edit section isn’t the problem.

Seems that the filter with division field, which is defined as text, works without reloading.

I wonder if it has something to do with the checkbox values being tinyint(1) and not varchar(999)?

-D

I’m debugging it with console. May not be a integer checkbox issue.

What I note is upon creation it hits the filter function two times. What’s strange is that when it’s saved I’m getting event.division but the object doesn’t show it. Which explains why the division filter appears to work but the is_private isn’t.

If you notice the refresh puts things back into a normal state and the filter works?

I shouldn’t have to refresh the page to get the filter to work.

-David

  1. created

“1402930960472 undefinedundefined” calendar:538
Object { start_date: Date 2014-06-17T12:35:00.000Z, end_date: Date 2014-06-17T12:40:00.000Z, text: “New event type”, id: 1402930960472, _timed: true, _sday: 1, _inner: false, _sorder: 0, _count: 1, _pid_time: NaN, 4 more… } calendar:539
“1402930960472 undefinedundefined” calendar:538
Object { start_date: Date 2014-06-17T12:35:00.000Z, end_date: Date 2014-06-17T12:40:00.000Z, text: “New event type”, id: 1402930960472, _timed: true, _sday: 1, _inner: false, _sorder: 0, _count: 1, _pid_time: NaN, 4 more… }

  1. saved

“1402930960472 undefinedAA” calendar:538
Object { start_date: Date 2014-06-17T12:35:00.000Z, end_date: Date 2014-06-17T12:40:00.000Z, text: “New event type”, id: 1402930960472, _timed: true, _sday: 1, _inner: false, _sorder: 0, _count: 1, _pid_time: NaN, 15 more… } calendar:539
“1402930960472 undefinedAA” calendar:538
Object { start_date: Date 2014-06-17T12:35:00.000Z, end_date: Date 2014-06-17T12:40:00.000Z, text: “New event type”, id: 1402930960472, _timed: true, _sday: 1, _inner: false, _sorder: 0, _count: 1, _pid_time: NaN, 15 more… } calendar:539
“1402930960472 undefinedAA” calendar:538
Object { start_date: Date 2014-06-17T12:35:00.000Z, end_date: Date 2014-06-17T12:40:00.000Z, text: “New event type”, id: “15153”, _timed: true, _sday: 1, _inner: false, _sorder: 0, _count: 1, _pid_time: NaN, 15 more… }7

  1. refreshed

“15153 is_privateAA” calendar:538
Object { id: “15153”, start_date: Date 2014-06-17T12:35:00.000Z, end_date: Date 2014-06-17T12:40:00.000Z, text: “New event type”, details: “”, division: “AA”, color: “”, event_type: “other”, media_type: “u”, is_private: “1”, 19 more… }

Code:

scheduler.filter_month = scheduler.filter_workweek =                                          
function(id, event) {                                                                         

console.log(event.id + ’ ’ + event.privacy + event.division);
console.log(event);

            var e_pass = (filters[event.event_type] || event.event_type==scheduler.undefined);
            var a_pass = (filters_div[event.division] || event.division==scheduler.undefined);
            var x_pass = (filters_status[event.status] || event.status==scheduler.undefined); 
            var p_pass = (filters_privacy[event.privacy] || event.privacy==scheduler.undefined

);

/*
var e_pass = (filters[“event_type”] || event.event_type==scheduler.undefined);
var a_pass = (filters_div[“division”] || event.division==scheduler.undefined);
var x_pass = (filters_status[“status”] || event.status==scheduler.undefined);
var p_pass = (filters_privacy[“privacy”] || event.privacy==scheduler.undefined);
*/

            if (e_pass && a_pass && x_pass && p_pass) {                                       
                return true;                                                                  
            }                                                                                 
                                                                                              
            return false;                                                                     
    };

When I save from the lightbox the database has been updated but the event object appears to have nothing from the filter function.

-D

mysql> select * from events where event_id = 15154\G
*************************** 1. row ***************************
event_id: 15154
start_date: 2014-06-17 09:25:00
end_date: 2014-06-17 09:30:00
event_name: New event type
details: NULL
division: AA
color:
event_type: other
media_type: u
is_private: 1
user_id: dgriffis
rec_type:
event_pid: 0
event_length: 0
canceled: 0
import_source_id: 1
cancel_reason:
import_source_name:
email_send: NULL
readonly: NULL
mediation_flag: 0
reminder_flag: NULL
cases_related: NULL
is_confirmed: 0

Sorry, but I don’t really understand how you are using filters and why you expect that filter values will be available on server side.

On client side, filter function called each time before repainting current view. So it can be called one or many times. When you adding new event, it can be sent to server side before “filter” was called, so if you setting some values in filter function - they may be not included in data saving call. ( there are separate handlers that can be used to customize newly created event )

I’m using filter exactly how it’s being used in the sample.

I have a field called division and when I click on AA or not it gets filter

But I also have a field called is_private which is a tinyint and not a character field which doesn’t work.

Is there any restriction in the filter code for non-text fields?

Thanks,

David




I’m seeing where the issue is. Will fix and re-post.

Thanks,

David

Figured it out. For boolean filter values you can do the following.

-D