Filter status: All, Available, Unavailable, Unconfigured, Pending, Reserved
[myslice.git] / plugins / querytable / static / js / querytable.js
1 /**
2  * Description: display a query result in a datatables-powered <table>
3  * Copyright (c) 2012-2013 UPMC Sorbonne Universite - INRIA
4  * License: GPLv3
5  */
6
7 QUERYTABLE_BGCOLOR_RESET   = 0;
8 QUERYTABLE_BGCOLOR_ADDED   = 1;
9 QUERYTABLE_BGCOLOR_REMOVED = 2;
10
11 (function($){
12
13     var debug=false;
14 //    debug=true
15
16     var QueryTable = Plugin.extend({
17
18         init: function(options, element) {
19         this.classname="querytable";
20             this._super(options, element);
21
22             /* Member variables */
23             var query = manifold.query_store.find_analyzed_query(this.options.query_uuid);
24             this.object = query.object; // XXX
25
26             /* Events */
27             this.elmt().on('show', this, this.on_show);
28             this.elmt().on('shown.bs.tab', this, this.on_show);
29             this.elmt().on('resize', this, this.on_resize);
30
31             //// we need 2 different keys
32             // * canonical_key is the primary key as derived from metadata (typically: urn)
33             //   and is used to communicate about a given record with the other plugins
34             // * init_key is a key that both kinds of records 
35             //   (i.e. records returned by both queries) must have (typically: hrn or hostname)
36             //   in general query_all will return well populated records, but query
37             //   returns records with only the fields displayed on startup
38             var keys = manifold.metadata.get_key(this.object);
39             this.canonical_key = (keys && keys.length == 1) ? keys[0] : undefined;
40             // 
41             this.init_key = this.options.init_key;
42             // have init_key default to canonical_key
43             this.init_key = this.init_key || this.canonical_key;
44
45             /* sanity check */
46             if ( ! this.init_key ) 
47                 messages.warning ("QueryTable : cannot find init_key");
48             if ( ! this.canonical_key ) 
49                 messages.warning ("QueryTable : cannot find canonical_key");
50             if (debug)
51                 messages.debug("querytable: canonical_key="+this.canonical_key+" init_key="+this.init_key);
52
53             /* Setup query and record handlers */
54             this.listen_query(options.query_uuid);
55
56             /* GUI setup and event binding */
57             this.initialize_table();
58         },
59
60         /* PLUGIN EVENTS */
61
62         on_show: function(e) {
63         if (debug) messages.debug("querytable.on_show");
64             var self = e.data;
65             self.table.fnAdjustColumnSizing();
66     },        
67
68         on_resize: function(e) {
69         if (debug) messages.debug("querytable.on_resize");
70             var self = e.data;
71             self.table.fnAdjustColumnSizing();
72     },        
73
74         /* GUI EVENTS */
75
76         /* GUI MANIPULATION */
77
78         initialize_table: function() 
79         {
80             /* Transforms the table into DataTable, and keep a pointer to it */
81             var self = this;
82             var actual_options = {
83                 // Customize the position of Datatables elements (length,filter,button,...)
84                 // we use a fluid row on top and another on the bottom, making sure we take 12 grid elt's each time
85                 //sDom: "<'row'<'col-xs-5'l><'col-xs-1'r><'col-xs-6'f>>t<'row'<'col-xs-5'i><'col-xs-7'p>>",
86                 sDom: "<'row'<'col-xs-5'f><'col-xs-1'r><'col-xs-6 columns_selector'>>t<'row'<'col-xs-5'l><'col-xs-7'p>>",
87         // XXX as of sept. 2013, I cannot locate a bootstrap3-friendly mode for now
88         // hopefully this would come with dataTables v1.10 ?
89         // in any case, search for 'sPaginationType' all over the code for more comments
90                 sPaginationType: 'bootstrap',
91                 // Handle the null values & the error : Datatables warning Requested unknown parameter
92                 // http://datatables.net/forums/discussion/5331/datatables-warning-...-requested-unknown-parameter/p2
93                 aoColumnDefs: [{sDefaultContent: '', aTargets: [ '_all' ]}],
94                 // WARNING: this one causes tables in a 'tabs' that are not exposed at the time this is run to show up empty
95                 // sScrollX: '100%',       /* Horizontal scrolling */
96                 bProcessing: true,      /* Loading */
97                 fnDrawCallback: function() { self._querytable_draw_callback.call(self); },
98                 fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
99                     // This function is called on fnAddData to set the TR id. What about fnUpdate ?
100
101                     // Get the key from the raw data array aData
102                     var key = self.canonical_key;
103
104                     // Get the index of the key in the columns
105                     var cols = self._get_columns();
106                     var index = self.getColIndex(key, cols);
107                     if (index != -1) {
108                         // The key is found in the table, set the TR id after the data
109                         $(nRow).attr('id', self.id_from_key(key, aData[index]));
110                     }
111
112                     // That's the usual return value
113                     return nRow;
114                 }
115                 // XXX use $.proxy here !
116             };
117             // the intention here is that options.datatables_options as coming from the python object take precedence
118         // xxx DISABLED by jordan: was causing errors in datatables.js
119         // xxx turned back on by Thierry - this is the code that takes python-provided options into account
120         // check your datatables_options tag instead 
121         // however, we have to accumulate in aoColumnDefs from here (above) 
122         // and from the python wrapper (checkboxes management, plus any user-provided aoColumnDefs)
123         if ( 'aoColumnDefs' in this.options.datatables_options) {
124         actual_options['aoColumnDefs']=this.options.datatables_options['aoColumnDefs'].concat(actual_options['aoColumnDefs']);
125         delete this.options.datatables_options['aoColumnDefs'];
126         }
127         $.extend(actual_options, this.options.datatables_options );
128             this.table = this.elmt('table').dataTable(actual_options);
129
130             /* Setup the SelectAll button in the dataTable header */
131             /* xxx not sure this is still working */
132             var oSelectAll = $('#datatableSelectAll-'+ this.options.plugin_uuid);
133             oSelectAll.html("<span class='glyphicon glyphicon-ok' style='float:right;display:inline-block;'></span>Select All");
134             oSelectAll.button();
135             oSelectAll.css('font-size','11px');
136             oSelectAll.css('float','right');
137             oSelectAll.css('margin-right','15px');
138             oSelectAll.css('margin-bottom','5px');
139             oSelectAll.unbind('click');
140             oSelectAll.click(this._selectAll);
141
142             /* Add a filtering function to the current table 
143              * Note: we use closure to get access to the 'options'
144              */
145             $.fn.dataTableExt.afnFiltering.push(function( oSettings, aData, iDataIndex ) { 
146                 /* No filtering if the table does not match */
147                 if (oSettings.nTable.id != self.options.plugin_uuid + '__table')
148                     return true;
149                 return self._querytable_filter.call(self, oSettings, aData, iDataIndex);
150             });
151
152             /* Processing hidden_columns */
153             $.each(this.options.hidden_columns, function(i, field) {
154                 self.hide_column(field);
155             });
156             $(".dataTables_filter").append("<div style='display:inline-block;height:27px;width:27px;padding-left:6px;padding-top:4px;'><span class='glyphicon glyphicon-search'></span></div>");
157             $(".dataTables_filter input").css("width","100%");
158             
159             // resource info
160             var sTable = this.table;
161             var oSettings = this.table.fnSettings();
162             var cols = oSettings.aoColumns;
163             var self = this;
164             $('table.dataTable').delegate('a.resource-info','click',function() {
165                 var aPos = sTable.fnGetPosition( this.parentNode );
166                 var aData = sTable.fnGetData( aPos[0] );
167                 console.log(aData);
168
169                 var index = {}
170                 // XXX Loic @ Hardcoded !!! Maybe a loop over all fields would be better 
171                 index['network_hrn'] = self.getColIndex('network_hrn',cols);
172                 var network_hrn = aData[index['network_hrn']];
173
174                 index['hostname'] = self.getColIndex('hostname',cols);
175                 index['urn'] = self.getColIndex('urn',cols);
176                 index['type'] = self.getColIndex('type',cols);
177                 //index['status'] = self.getColIndex('boot_state',cols);
178                 index['available'] = self.getColIndex('available',cols);
179                 index['testbed'] = self.getColIndex('testbed_name',cols);
180                 index['facility'] = self.getColIndex('facility_name',cols);
181                 var resourceData = {
182                     'hostname' : strip(aData[index['hostname']]),
183                     'urn' : aData[index['urn']],
184                     'type' : aData[index['type']],
185                     //'status' : aData[index['status']],
186                     'available' : aData[index['available']],
187                     'testbed' : aData[index['testbed']],
188                     'facility' : aData[index['facility']],
189                 };
190                 
191                 /*
192                 //Greece: 37.6687092,22.2282404
193                 if (network_hrn == 'omf.nitos') {
194                     var logo = 'nitos';
195                     var resourceLocation = {
196                         'longitude' : '22.2282404',
197                         'latitude' : '37.6687092',
198                     };
199                     var coordinates = resourceLocation['latitude']+','+resourceLocation['longitude'];
200                 } else if (network_hrn == 'iotlab') {
201                 */
202                 if (network_hrn == 'iotlab') {
203                     var logo = network_hrn;
204                     var s = resourceData['hostname'].split(".");
205                     var n = s[0].split("-");
206                     resourceData['type'] = 'node ( Hardware: <a target="_blank" href="https://www.iot-lab.info/hardware/'+n[0]+'/">'+n[0]+'</a> )';
207                     var coordinates = resourceData['testbed'];
208                 } else {
209                     var logo = resourceData['testbed'];
210                     var resourceLocation = {
211                         'longitude' : aData[20],
212                         'latitude' : aData[17],
213                     };
214                     var coordinates = resourceLocation['latitude']+','+resourceLocation['longitude'];
215                     console.log(coordinates);
216                 }
217                 
218                 var modal = $('#resource-info-modal');
219                 modal.find('.modal-title').text(resourceData['testbed'] + ': ' +resourceData['hostname']);
220                 table = modal.find('.modal-resource-info');
221                 table.html('<tr><td colspan="2"><center><img class="img-responsive" src="/static/img/testbeds/'+logo+'.png" alt="'+resourceData['facility']+' - '+resourceData['testbed']+'" /></center></td></tr>');
222                 for (var j in resourceData) {
223                     table.append('<tr><td>' + j + '</td><td>' + resourceData[j] + '</td></tr>');
224                 }
225                 if (coordinates != '') {
226                     table.append('<tr><td colspan="2"><img src="http://maps.google.com/maps/api/staticmap?center='+coordinates+'&zoom=6&size=400x400&sensor=false&markers=color:red%7C'+coordinates+'" style="width:400px; height:400px;" /></td></tr>');
227                 }
228                 modal.modal();
229             });
230             
231         }, // initialize_table
232
233         /**
234          * @brief Determine index of key in the table columns 
235          * @param key
236          * @param cols
237          */
238         getColIndex: function(key, cols) {
239             var self = this;
240             var tabIndex = $.map(cols, function(x, i) { if (self._get_map(x.sTitle) == key) return i; });
241             return (tabIndex.length > 0) ? tabIndex[0] : -1;
242         }, // getColIndex
243
244     // create a checkbox <input> tag
245     // computes 'id' attribute from canonical_key
246     // computes 'init_id' from init_key for initialization phase
247     // no need to used convoluted ids with plugin-uuid or others, since
248     // we search using table.$ which looks only in this table
249         checkbox_html : function (record) {
250             var result="";
251             // Prefix id with plugin_uuid
252             result += "<input";
253             result += " class='querytable-checkbox'";
254      // compute id from canonical_key
255         var id = record[this.canonical_key]
256      // compute init_id form init_key
257         var init_id=record[this.init_key];
258      // set id - for retrieving from an id, or for posting events upon user's clicks
259         result += " id='"+record[this.canonical_key]+"'";
260      // set init_id
261         result += "init_id='" + init_id + "'";
262      // wrap up
263             result += " type='checkbox'";
264             result += " autocomplete='off'";
265             result += "></input>";
266             return result;
267         }, 
268
269
270         new_record: function(record)
271         {
272             var self = this;
273
274             // this models a line in dataTables, each element in the line describes a cell
275             line = new Array();
276      
277             // go through table headers to get column names we want
278             // in order (we have temporarily hack some adjustments in names)
279             var cols = this._get_columns();
280             var colnames = cols.map(function(x) {return self._get_map(x.sTitle)})
281             var nb_col = cols.length;
282             /* if we've requested checkboxes, then forget about the checkbox column for now */
283             //if (this.options.checkboxes) nb_col -= 1;
284             // catch up with the last column if checkboxes were requested 
285             if (this.options.checkboxes) {
286                 // Use a key instead of hostname (hard coded...)
287                 line.push(this.checkbox_html(record));
288             }
289             line.push('<span id="' + this.id_from_key('status', record[this.init_key]) + '"></span>'); // STATUS
290             
291             /* fill in stuff depending on the column name */
292             for (var j = 2; j < nb_col - 1; j++) { // nb_col includes status
293                 if (typeof colnames[j] == 'undefined') {
294                     line.push('...');
295                 } else if (colnames[j] == 'hostname') {
296                     if (record['type'] == 'resource,link')
297                         //TODO: we need to add source/destination for links
298                         line.push('');
299                     else
300                         //line.push(record['hostname']);
301                         line.push('<a class="resource-info" data-network_hrn="'+record['network_hrn']+'">' + record['hostname'] + '</a>');
302
303                 } else if (colnames[j] == this.init_key && typeof(record) != 'undefined') {
304                     obj = this.object
305                     o = obj.split(':');
306                     if(o.length>1){
307                         obj = o[1];
308                     }else{
309                         obj = o[0];
310                     }
311                     /* XXX TODO: Remove this and have something consistant */
312                     if(obj=='resource'){
313                         //line.push('<a href="../'+obj+'/'+record['urn']+'"><span class="glyphicon glyphicon-search"></span></a> '+record[this.init_key]);
314                     }else{
315                         //line.push('<a href="../'+obj+'/'+record[this.init_key]+'"><span class="glyphicon glyphicon-search"></span></a> '+record[this.init_key]);
316                     }
317                     line.push(record[this.init_key]);
318                 } else {
319                     if (record[colnames[j]])
320                         line.push(record[colnames[j]]);
321                     else
322                         line.push('');
323                 }
324             }
325     
326             // adding an array in one call is *much* more efficient
327             // this.table.fnAddData(line);
328             return line;
329         },
330
331         clear_table: function()
332         {
333             this.table.fnClearTable();
334         },
335
336         redraw_table: function()
337         {
338             this.table.fnDraw();
339         },
340
341         show_column: function(field)
342         {
343             var oSettings = this.table.fnSettings();
344             var cols = oSettings.aoColumns;
345             var index = this.getColIndex(field,cols);
346             if (index != -1)
347                 this.table.fnSetColumnVis(index, true);
348         },
349
350         hide_column: function(field)
351         {
352             var oSettings = this.table.fnSettings();
353             var cols = oSettings.aoColumns;
354             var index = this.getColIndex(field,cols);
355             if (index != -1)
356                 this.table.fnSetColumnVis(index, false);
357         },
358
359         set_checkbox_from_record_key: function (record_key, checked) 
360         {
361             if (checked === undefined) checked = true;
362
363             // using table.$ to search inside elements that are not visible
364             var element = this.table.$('[init_id="'+record_key+'"]');
365             element.attr('checked',checked);
366         },
367
368         // id relates to canonical_key
369         set_checkbox_from_data: function (id, checked) 
370         {
371             if (checked === undefined) checked = true;
372
373             // using table.$ to search inside elements that are not visible
374             var element = this.table.$("[id='"+id+"']");
375             element.attr('checked',checked);
376         },
377
378         /**
379          * Arguments
380          *
381          * key_value: the key from which we deduce the id
382          * request: STATUS_OKAY, etc.
383          * content: some HTML content
384          */
385         change_status: function(key_value, warnings)
386         {
387             var msg;
388             
389             if ($.isEmptyObject(warnings)) { 
390                 var state = manifold.query_store.get_record_state(this.options.query_uuid, key_value, STATE_SET);
391                 switch(state) {
392                     case STATE_SET_IN:
393                     case STATE_SET_IN_SUCCESS:
394                     case STATE_SET_OUT_FAILURE:
395                     case STATE_SET_IN_PENDING:
396                         // Checkmark sign if no warning for an object in the set
397                         msg = '&#10003;';
398                         break;
399                     default:
400                         // Nothing is the object is not in the set
401                         msg = '';
402                         break;
403                 }
404             } else {
405                 msg = '<ul class="nav nav-pills">';
406                 msg += '<li class="dropdown">';
407                 msg += '<a href="#" data-toggle="dropdown" class="dropdown-toggle nopadding"><b>&#9888</b></a>';
408                 msg += '  <ul class="dropdown-menu dropdown-menu-right" id="menu1">';
409                 $.each(warnings, function(i,warning) {
410                     msg += '<li><a href="#">' + warning + '</a></li>';
411                 });
412                 msg += '  </ul>';
413                 msg += '</li>';
414                 msg += '</ul>';
415             }
416
417             $(document.getElementById(this.id_from_key('status', key_value))).html(msg);
418             $('[data-toggle="tooltip"]').tooltip({'placement': 'bottom'});
419
420         },
421
422         set_bgcolor: function(key_value, class_name)
423         {
424             var elt = $(document.getElementById(this.id_from_key(this.canonical_key, key_value)))
425             if (class_name == QUERYTABLE_BGCOLOR_RESET)
426                 elt.removeClass('added removed');
427             else
428                 elt.addClass((class_name == QUERYTABLE_BGCOLOR_ADDED ? 'added' : 'removed'));
429         },
430
431         populate_table: function()
432         {
433             // Let's clear the table and only add lines that are visible
434             var self = this;
435             this.clear_table();
436
437             lines = Array();
438             var record_keys = [];
439             manifold.query_store.iter_records(this.options.query_uuid, function (record_key, record) {
440                 lines.push(self.new_record(record));
441                 record_keys.push(record_key);
442             });
443             this.table.fnAddData(lines);
444             $.each(record_keys, function(i, record_key) {
445                 var state = manifold.query_store.get_record_state(self.options.query_uuid, record_key, STATE_SET);
446                 var warnings = manifold.query_store.get_record_state(self.options.query_uuid, record_key, STATE_WARNINGS);
447                 switch(state) {
448                     // XXX The row and checkbox still does not exists !!!!
449                     case STATE_SET_IN:
450                     case STATE_SET_IN_SUCCESS:
451                     case STATE_SET_OUT_FAILURE:
452                         self.set_checkbox_from_record_key(record_key, true);
453                         break;
454                     case STATE_SET_OUT:
455                     case STATE_SET_OUT_SUCCESS:
456                     case STATE_SET_IN_FAILURE:
457                         //self.set_checkbox_from_record_key(record_key, false);
458                         break;
459                     case STATE_SET_IN_PENDING:
460                         self.set_checkbox_from_record_key(record_key, true);
461                         self.set_bgcolor(record_key, QUERYTABLE_BGCOLOR_ADDED);
462                         break;
463                     case STATE_SET_OUT_PENDING:
464                         //self.set_checkbox_from_record_key(record_key, false);
465                         self.set_bgcolor(record_key, QUERYTABLE_BGCOLOR_REMOVED);
466                         break;
467                 }
468                 self.change_status(record_key, warnings); // XXX will retrieve status again
469             });
470         },
471
472         /*************************** QUERY HANDLER ****************************/
473
474         on_filter_added: function(filter)
475         {
476             this.redraw_table();
477         },
478
479         on_filter_removed: function(filter)
480         {
481             this.redraw_table();
482         },
483         
484         on_filter_clear: function()
485         {
486             this.redraw_table();
487         },
488
489         on_field_added: function(field)
490         {
491             this.show_column(field);
492         },
493
494         on_field_removed: function(field)
495         {
496             this.hide_column(field);
497         },
498
499         on_field_clear: function()
500         {
501             alert('QueryTable::clear_fields() not implemented');
502         },
503
504         /*************************** RECORD HANDLER ***************************/
505
506         // Could be the default in parent
507         on_query_in_progress: function()
508         {
509             this.spin();
510         },
511
512         on_query_done: function()
513         {
514             this.populate_table();
515             this.unspin();
516         },
517         
518         on_field_state_changed: function(data)
519         {
520             // XXX We could get this from data.value
521             // var state = manifold.query_store.get_record_state(this.options.query_uuid, data.value, data.state);
522
523             switch(data.state) {
524                 case STATE_SET:
525                     switch(data.op) {
526                         case STATE_SET_IN:
527                         case STATE_SET_IN_SUCCESS:
528                         case STATE_SET_OUT_FAILURE:
529                             this.set_checkbox_from_data(data.value, true);
530                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
531                             break;  
532                         case STATE_SET_OUT:
533                         case STATE_SET_OUT_SUCCESS:
534                         case STATE_SET_IN_FAILURE:
535                             this.set_checkbox_from_data(data.value, false);
536                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
537                             break;
538                         case STATE_SET_IN_PENDING:
539                             this.set_checkbox_from_data(data.value, true);
540                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_ADDED);
541                             break;  
542                         case STATE_SET_OUT_PENDING:
543                             this.set_checkbox_from_data(data.value, false);
544                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_REMOVED);
545                             break;
546                     }
547                     break;
548
549                 case STATE_WARNINGS:
550                     this.change_status(data.key, data.value);
551                     break;
552             }
553         },
554
555         /************************** PRIVATE METHODS ***************************/
556
557         _get_columns: function()
558         {
559             return this.table.fnSettings().aoColumns;
560             // XXX return $.map(table.fnSettings().aoColumns, function(x, i) { return QUERYTABLE_MAP[x]; });
561         },
562
563         _get_map: function(column_title) {
564             return (column_title in QUERYTABLE_MAP) ? QUERYTABLE_MAP[column_title] : column_title;
565         },
566         /** 
567          * @brief QueryTable filtering function, called for every line in the datatable.
568          * 
569          * Return value:
570          *   boolean determining whether the column is visible or not.
571          */
572         _querytable_filter: function(oSettings, aData, iDataIndex)
573         {
574             var self = this;
575             var key_col, record_key_value;
576
577             /* Determine index of key in the table columns */
578             key_col = $.map(oSettings.aoColumns, function(x, i) {if (self._get_map(x.sTitle) == self.canonical_key) return i;})[0];
579
580             /* Unknown key: no filtering */
581             if (typeof(key_col) == 'undefined') {
582                 console.log("Unknown key");
583                 return true;
584             }
585
586             record_key_value = unfold.get_value(aData[key_col]);
587
588             return manifold.query_store.get_record_state(this.options.query_uuid, record_key_value, STATE_VISIBLE);
589         },
590
591         _querytable_draw_callback: function()
592         {
593             /* 
594              * Handle clicks on checkboxes: reassociate checkbox click every time
595              * the table is redrawn 
596              */
597             this.elts('querytable-checkbox').unbind('click').click(this, this._check_click);
598
599             if (!this.table)
600                 return;
601
602             /* Remove pagination if we show only a few results */
603             var wrapper = this.table; //.parent().parent().parent();
604             var rowsPerPage = this.table.fnSettings()._iDisplayLength;
605             var rowsToShow = this.table.fnSettings().fnRecordsDisplay();
606             var minRowsPerPage = this.table.fnSettings().aLengthMenu[0];
607
608             if ( rowsToShow <= rowsPerPage || rowsPerPage == -1 ) {
609                 $('.querytable_paginate', wrapper).css('visibility', 'hidden');
610             } else {
611                 $('.querytable_paginate', wrapper).css('visibility', 'visible');
612             }
613
614             if ( rowsToShow <= minRowsPerPage ) {
615                 $('.querytable_length', wrapper).css('visibility', 'hidden');
616             } else {
617                 $('.querytable_length', wrapper).css('visibility', 'visible');
618             }
619         },
620
621         _check_click: function(e) 
622         {
623             var data;
624             var self = e.data;
625
626             e.stopPropagation();
627
628             data = {
629                 state: STATE_SET,
630                 key  : null,
631                 op   : this.checked ? STATE_SET_ADD : STATE_SET_REMOVE,
632                 value: this.id
633             };
634             manifold.raise_event(self.options.query_uuid, FIELD_STATE_CHANGED, data);
635             //return false; // prevent checkbox to be checked, waiting response from manifold plugin api
636             
637         },
638
639         _selectAll: function() 
640         {
641             // requires jQuery id
642             var uuid=this.id.split("-");
643             var oTable=$("#querytable-"+uuid[1]).dataTable();
644             // Function available in QueryTable 1.9.x
645             // Filter : displayed data only
646             var filterData = oTable._('tr', {"filter":"applied"});   
647             /* TODO: WARNING if too many nodes selected, use filters to reduce nuber of nodes */        
648             if(filterData.length<=100){
649                 $.each(filterData, function(index, obj) {
650                     var last=$(obj).last();
651                     var key_value=unfold.get_value(last[0]);
652                     if(typeof($(last[0]).attr('checked'))=="undefined"){
653                         $.publish('selected', 'add/'+key_value);
654                     }
655                 });
656             }
657         },
658     });
659
660     $.plugin('QueryTable', QueryTable);
661
662   /* define the 'dom-checkbox' type for sorting in datatables 
663      http://datatables.net/examples/plug-ins/dom_sort.html
664      using trial and error I found that the actual column number
665      was in fact given as a third argument, and not second 
666      as the various online resources had it - go figure */
667     $.fn.dataTableExt.afnSortData['dom-checkbox'] = function  ( oSettings, _, iColumn ) {
668         return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
669             return result=$('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
670         });
671     };
672     
673     
674
675 })(jQuery);
676
677 function strip(html)
678 {
679    var tmp = document.createElement("DIV");
680    tmp.innerHTML = html;
681    return tmp.textContent || tmp.innerText || "";
682 }