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