444fe604f7d133df29694568eec643e88b2d2a2b
[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['testbed'] = self.getColIndex('testbed_name',cols);
179                 index['facility'] = self.getColIndex('facility_name',cols);
180                 var resourceData = {
181                     'hostname' : strip(aData[index['hostname']]),
182                     'urn' : aData[index['urn']],
183                     'type' : aData[index['type']],
184                     'status' : aData[index['status']],
185                     'testbed' : aData[index['testbed']],
186                     'facility' : aData[index['facility']],
187                 };
188                 
189                 /*
190                 //Greece: 37.6687092,22.2282404
191                 if (network_hrn == 'omf.nitos') {
192                     var logo = 'nitos';
193                     var resourceLocation = {
194                         'longitude' : '22.2282404',
195                         'latitude' : '37.6687092',
196                     };
197                     var coordinates = resourceLocation['latitude']+','+resourceLocation['longitude'];
198                 } else if (network_hrn == 'iotlab') {
199                 */
200                 if (network_hrn == 'iotlab') {
201                     var logo = network_hrn;
202                     var s = resourceData['hostname'].split(".");
203                     var n = s[0].split("-");
204                     resourceData['type'] = 'node ( Hardware: <a target="_blank" href="https://www.iot-lab.info/hardware/'+n[0]+'/">'+n[0]+'</a> )';
205                     var coordinates = resourceData['testbed'];
206                 } else {
207                     var logo = resourceData['testbed'];
208                     var resourceLocation = {
209                         'longitude' : aData[20],
210                         'latitude' : aData[17],
211                     };
212                     var coordinates = resourceLocation['latitude']+','+resourceLocation['longitude'];
213                     console.log(coordinates);
214                 }
215                 
216                 var modal = $('#resource-info-modal');
217                 modal.find('.modal-title').text(resourceData['testbed'] + ': ' +resourceData['hostname']);
218                 table = modal.find('.modal-resource-info');
219                 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>');
220                 for (var j in resourceData) {
221                     table.append('<tr><td>' + j + '</td><td>' + resourceData[j] + '</td></tr>');
222                 }
223                 if (coordinates != '') {
224                     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>');
225                 }
226                 modal.modal();
227             });
228             
229         }, // initialize_table
230
231         /**
232          * @brief Determine index of key in the table columns 
233          * @param key
234          * @param cols
235          */
236         getColIndex: function(key, cols) {
237             var self = this;
238             var tabIndex = $.map(cols, function(x, i) { if (self._get_map(x.sTitle) == key) return i; });
239             return (tabIndex.length > 0) ? tabIndex[0] : -1;
240         }, // getColIndex
241
242     // create a checkbox <input> tag
243     // computes 'id' attribute from canonical_key
244     // computes 'init_id' from init_key for initialization phase
245     // no need to used convoluted ids with plugin-uuid or others, since
246     // we search using table.$ which looks only in this table
247         checkbox_html : function (record) {
248             var result="";
249             // Prefix id with plugin_uuid
250             result += "<input";
251             result += " class='querytable-checkbox'";
252      // compute id from canonical_key
253         var id = record[this.canonical_key]
254      // compute init_id form init_key
255         var init_id=record[this.init_key];
256      // set id - for retrieving from an id, or for posting events upon user's clicks
257         result += " id='"+record[this.canonical_key]+"'";
258      // set init_id
259         result += "init_id='" + init_id + "'";
260      // wrap up
261             result += " type='checkbox'";
262             result += " autocomplete='off'";
263             result += "></input>";
264             return result;
265         }, 
266
267
268         new_record: function(record)
269         {
270             var self = this;
271
272             // this models a line in dataTables, each element in the line describes a cell
273             line = new Array();
274      
275             // go through table headers to get column names we want
276             // in order (we have temporarily hack some adjustments in names)
277             var cols = this._get_columns();
278             var colnames = cols.map(function(x) {return self._get_map(x.sTitle)})
279             var nb_col = cols.length;
280             /* if we've requested checkboxes, then forget about the checkbox column for now */
281             //if (this.options.checkboxes) nb_col -= 1;
282             // catch up with the last column if checkboxes were requested 
283             if (this.options.checkboxes) {
284                 // Use a key instead of hostname (hard coded...)
285                 line.push(this.checkbox_html(record));
286             }
287             line.push('<span id="' + this.id_from_key('status', record[this.init_key]) + '"></span>'); // STATUS
288             
289             /* fill in stuff depending on the column name */
290             for (var j = 2; j < nb_col - 1; j++) { // nb_col includes status
291                 if (typeof colnames[j] == 'undefined') {
292                     line.push('...');
293                 } else if (colnames[j] == 'hostname') {
294                     if (record['type'] == 'resource,link')
295                         //TODO: we need to add source/destination for links
296                         line.push('');
297                     else
298                         //line.push(record['hostname']);
299                         line.push('<a class="resource-info" data-network_hrn="'+record['network_hrn']+'">' + record['hostname'] + '</a>');
300
301                 } else if (colnames[j] == this.init_key && typeof(record) != 'undefined') {
302                     obj = this.object
303                     o = obj.split(':');
304                     if(o.length>1){
305                         obj = o[1];
306                     }else{
307                         obj = o[0];
308                     }
309                     /* XXX TODO: Remove this and have something consistant */
310                     if(obj=='resource'){
311                         //line.push('<a href="../'+obj+'/'+record['urn']+'"><span class="glyphicon glyphicon-search"></span></a> '+record[this.init_key]);
312                     }else{
313                         //line.push('<a href="../'+obj+'/'+record[this.init_key]+'"><span class="glyphicon glyphicon-search"></span></a> '+record[this.init_key]);
314                     }
315                     line.push(record[this.init_key]);
316                 } else {
317                     if (record[colnames[j]])
318                         line.push(record[colnames[j]]);
319                     else
320                         line.push('');
321                 }
322             }
323     
324             // adding an array in one call is *much* more efficient
325             // this.table.fnAddData(line);
326             return line;
327         },
328
329         clear_table: function()
330         {
331             this.table.fnClearTable();
332         },
333
334         redraw_table: function()
335         {
336             this.table.fnDraw();
337         },
338
339         show_column: function(field)
340         {
341             var oSettings = this.table.fnSettings();
342             var cols = oSettings.aoColumns;
343             var index = this.getColIndex(field,cols);
344             if (index != -1)
345                 this.table.fnSetColumnVis(index, true);
346         },
347
348         hide_column: function(field)
349         {
350             var oSettings = this.table.fnSettings();
351             var cols = oSettings.aoColumns;
352             var index = this.getColIndex(field,cols);
353             if (index != -1)
354                 this.table.fnSetColumnVis(index, false);
355         },
356
357         set_checkbox_from_record_key: function (record_key, checked) 
358         {
359             if (checked === undefined) checked = true;
360
361             // using table.$ to search inside elements that are not visible
362             var element = this.table.$('[init_id="'+record_key+'"]');
363             element.attr('checked',checked);
364         },
365
366         // id relates to canonical_key
367         set_checkbox_from_data: function (id, checked) 
368         {
369             if (checked === undefined) checked = true;
370
371             // using table.$ to search inside elements that are not visible
372             var element = this.table.$("[id='"+id+"']");
373             element.attr('checked',checked);
374         },
375
376         /**
377          * Arguments
378          *
379          * key_value: the key from which we deduce the id
380          * request: STATUS_OKAY, etc.
381          * content: some HTML content
382          */
383         change_status: function(key_value, warnings)
384         {
385             var msg;
386             
387             if ($.isEmptyObject(warnings)) { 
388                 var state = manifold.query_store.get_record_state(this.options.query_uuid, key_value, STATE_SET);
389                 switch(state) {
390                     case STATE_SET_IN:
391                     case STATE_SET_IN_SUCCESS:
392                     case STATE_SET_OUT_FAILURE:
393                     case STATE_SET_IN_PENDING:
394                         // Checkmark sign if no warning for an object in the set
395                         msg = '&#10003;';
396                         break;
397                     default:
398                         // Nothing is the object is not in the set
399                         msg = '';
400                         break;
401                 }
402             } else {
403                 msg = '<ul class="nav nav-pills">';
404                 msg += '<li class="dropdown">';
405                 msg += '<a href="#" data-toggle="dropdown" class="dropdown-toggle nopadding"><b>&#9888</b></a>';
406                 msg += '  <ul class="dropdown-menu dropdown-menu-right" id="menu1">';
407                 $.each(warnings, function(i,warning) {
408                     msg += '<li><a href="#">' + warning + '</a></li>';
409                 });
410                 msg += '  </ul>';
411                 msg += '</li>';
412                 msg += '</ul>';
413             }
414
415             $(document.getElementById(this.id_from_key('status', key_value))).html(msg);
416             $('[data-toggle="tooltip"]').tooltip({'placement': 'bottom'});
417
418         },
419
420         set_bgcolor: function(key_value, class_name)
421         {
422             var elt = $(document.getElementById(this.id_from_key(this.canonical_key, key_value)))
423             if (class_name == QUERYTABLE_BGCOLOR_RESET)
424                 elt.removeClass('added removed');
425             else
426                 elt.addClass((class_name == QUERYTABLE_BGCOLOR_ADDED ? 'added' : 'removed'));
427         },
428
429         populate_table: function()
430         {
431             // Let's clear the table and only add lines that are visible
432             var self = this;
433             this.clear_table();
434
435             lines = Array();
436             var record_keys = [];
437             manifold.query_store.iter_records(this.options.query_uuid, function (record_key, record) {
438                 lines.push(self.new_record(record));
439                 record_keys.push(record_key);
440             });
441             this.table.fnAddData(lines);
442             $.each(record_keys, function(i, record_key) {
443                 var state = manifold.query_store.get_record_state(self.options.query_uuid, record_key, STATE_SET);
444                 var warnings = manifold.query_store.get_record_state(self.options.query_uuid, record_key, STATE_WARNINGS);
445                 switch(state) {
446                     // XXX The row and checkbox still does not exists !!!!
447                     case STATE_SET_IN:
448                     case STATE_SET_IN_SUCCESS:
449                     case STATE_SET_OUT_FAILURE:
450                         self.set_checkbox_from_record_key(record_key, true);
451                         break;
452                     case STATE_SET_OUT:
453                     case STATE_SET_OUT_SUCCESS:
454                     case STATE_SET_IN_FAILURE:
455                         //self.set_checkbox_from_record_key(record_key, false);
456                         break;
457                     case STATE_SET_IN_PENDING:
458                         self.set_checkbox_from_record_key(record_key, true);
459                         self.set_bgcolor(record_key, QUERYTABLE_BGCOLOR_ADDED);
460                         break;
461                     case STATE_SET_OUT_PENDING:
462                         //self.set_checkbox_from_record_key(record_key, false);
463                         self.set_bgcolor(record_key, QUERYTABLE_BGCOLOR_REMOVED);
464                         break;
465                 }
466                 self.change_status(record_key, warnings); // XXX will retrieve status again
467             });
468         },
469
470         /*************************** QUERY HANDLER ****************************/
471
472         on_filter_added: function(filter)
473         {
474             this.redraw_table();
475         },
476
477         on_filter_removed: function(filter)
478         {
479             this.redraw_table();
480         },
481         
482         on_filter_clear: function()
483         {
484             this.redraw_table();
485         },
486
487         on_field_added: function(field)
488         {
489             this.show_column(field);
490         },
491
492         on_field_removed: function(field)
493         {
494             this.hide_column(field);
495         },
496
497         on_field_clear: function()
498         {
499             alert('QueryTable::clear_fields() not implemented');
500         },
501
502         /*************************** RECORD HANDLER ***************************/
503
504         // Could be the default in parent
505         on_query_in_progress: function()
506         {
507             this.spin();
508         },
509
510         on_query_done: function()
511         {
512             this.populate_table();
513             this.unspin();
514         },
515         
516         on_field_state_changed: function(data)
517         {
518             // XXX We could get this from data.value
519             // var state = manifold.query_store.get_record_state(this.options.query_uuid, data.value, data.state);
520
521             switch(data.state) {
522                 case STATE_SET:
523                     switch(data.op) {
524                         case STATE_SET_IN:
525                         case STATE_SET_IN_SUCCESS:
526                         case STATE_SET_OUT_FAILURE:
527                             this.set_checkbox_from_data(data.value, true);
528                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
529                             break;  
530                         case STATE_SET_OUT:
531                         case STATE_SET_OUT_SUCCESS:
532                         case STATE_SET_IN_FAILURE:
533                             this.set_checkbox_from_data(data.value, false);
534                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
535                             break;
536                         case STATE_SET_IN_PENDING:
537                             this.set_checkbox_from_data(data.value, true);
538                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_ADDED);
539                             break;  
540                         case STATE_SET_OUT_PENDING:
541                             this.set_checkbox_from_data(data.value, false);
542                             this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_REMOVED);
543                             break;
544                     }
545                     break;
546
547                 case STATE_WARNINGS:
548                     this.change_status(data.key, data.value);
549                     break;
550             }
551         },
552
553         /************************** PRIVATE METHODS ***************************/
554
555         _get_columns: function()
556         {
557             return this.table.fnSettings().aoColumns;
558             // XXX return $.map(table.fnSettings().aoColumns, function(x, i) { return QUERYTABLE_MAP[x]; });
559         },
560
561         _get_map: function(column_title) {
562             return (column_title in QUERYTABLE_MAP) ? QUERYTABLE_MAP[column_title] : column_title;
563         },
564         /** 
565          * @brief QueryTable filtering function, called for every line in the datatable.
566          * 
567          * Return value:
568          *   boolean determining whether the column is visible or not.
569          */
570         _querytable_filter: function(oSettings, aData, iDataIndex)
571         {
572             var self = this;
573             var key_col, record_key_value;
574
575             /* Determine index of key in the table columns */
576             key_col = $.map(oSettings.aoColumns, function(x, i) {if (self._get_map(x.sTitle) == self.canonical_key) return i;})[0];
577
578             /* Unknown key: no filtering */
579             if (typeof(key_col) == 'undefined') {
580                 console.log("Unknown key");
581                 return true;
582             }
583
584             record_key_value = unfold.get_value(aData[key_col]);
585
586             return manifold.query_store.get_record_state(this.options.query_uuid, record_key_value, STATE_VISIBLE);
587         },
588
589         _querytable_draw_callback: function()
590         {
591             /* 
592              * Handle clicks on checkboxes: reassociate checkbox click every time
593              * the table is redrawn 
594              */
595             this.elts('querytable-checkbox').unbind('click').click(this, this._check_click);
596
597             if (!this.table)
598                 return;
599
600             /* Remove pagination if we show only a few results */
601             var wrapper = this.table; //.parent().parent().parent();
602             var rowsPerPage = this.table.fnSettings()._iDisplayLength;
603             var rowsToShow = this.table.fnSettings().fnRecordsDisplay();
604             var minRowsPerPage = this.table.fnSettings().aLengthMenu[0];
605
606             if ( rowsToShow <= rowsPerPage || rowsPerPage == -1 ) {
607                 $('.querytable_paginate', wrapper).css('visibility', 'hidden');
608             } else {
609                 $('.querytable_paginate', wrapper).css('visibility', 'visible');
610             }
611
612             if ( rowsToShow <= minRowsPerPage ) {
613                 $('.querytable_length', wrapper).css('visibility', 'hidden');
614             } else {
615                 $('.querytable_length', wrapper).css('visibility', 'visible');
616             }
617         },
618
619         _check_click: function(e) 
620         {
621             var data;
622             var self = e.data;
623
624             e.stopPropagation();
625
626             data = {
627                 state: STATE_SET,
628                 key  : null,
629                 op   : this.checked ? STATE_SET_ADD : STATE_SET_REMOVE,
630                 value: this.id
631             };
632             manifold.raise_event(self.options.query_uuid, FIELD_STATE_CHANGED, data);
633             //return false; // prevent checkbox to be checked, waiting response from manifold plugin api
634             
635         },
636
637         _selectAll: function() 
638         {
639             // requires jQuery id
640             var uuid=this.id.split("-");
641             var oTable=$("#querytable-"+uuid[1]).dataTable();
642             // Function available in QueryTable 1.9.x
643             // Filter : displayed data only
644             var filterData = oTable._('tr', {"filter":"applied"});   
645             /* TODO: WARNING if too many nodes selected, use filters to reduce nuber of nodes */        
646             if(filterData.length<=100){
647                 $.each(filterData, function(index, obj) {
648                     var last=$(obj).last();
649                     var key_value=unfold.get_value(last[0]);
650                     if(typeof($(last[0]).attr('checked'))=="undefined"){
651                         $.publish('selected', 'add/'+key_value);
652                     }
653                 });
654             }
655         },
656     });
657
658     $.plugin('QueryTable', QueryTable);
659
660   /* define the 'dom-checkbox' type for sorting in datatables 
661      http://datatables.net/examples/plug-ins/dom_sort.html
662      using trial and error I found that the actual column number
663      was in fact given as a third argument, and not second 
664      as the various online resources had it - go figure */
665     $.fn.dataTableExt.afnSortData['dom-checkbox'] = function  ( oSettings, _, iColumn ) {
666         return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
667             return result=$('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
668         });
669     };
670     
671     
672
673 })(jQuery);
674
675 function strip(html)
676 {
677    var tmp = document.createElement("DIV");
678    tmp.innerHTML = html;
679    return tmp.textContent || tmp.innerText || "";
680 }