(function($){
-
- var QUERYTABLE_MAP = {
- 'Facility': 'facility_name',
- 'Testbed': 'testbed_name',
- 'Resource name': 'hostname',
- 'Type': 'type',
- };
-
var debug=false;
// debug=true
sPaginationType: 'bootstrap',
// Handle the null values & the error : Datatables warning Requested unknown parameter
// http://datatables.net/forums/discussion/5331/datatables-warning-...-requested-unknown-parameter/p2
- aoColumnDefs: [{sDefaultContent: '', aTargets: [ '_all' ]}],
+ aoColumnDefs: [{sDefaultContent: '', aTargets: [ '_all' ], "sType": "mysort"}],
// WARNING: this one causes tables in a 'tabs' that are not exposed at the time this is run to show up empty
// sScrollX: '100%', /* Horizontal scrolling */
bProcessing: true, /* Loading */
});
/* Processing hidden_columns */
- arr = [];
- arr = $.map(Object.keys(QUERYTABLE_MAP), function(x, i) { return QUERYTABLE_MAP[x]; });
$.each(this.options.hidden_columns, function(i, field) {
- is_inarray = $.inArray(field,arr);
- if(is_inarray==-1){
- self.hide_column(field);
- }
+ self.hide_column(field);
});
$(".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>");
$(".dataTables_filter input").css("width","100%");
// resource info
var sTable = this.table;
+ var oSettings = this.table.fnSettings();
+ var cols = oSettings.aoColumns;
+ var self = this;
$('table.dataTable').delegate('a.resource-info','click',function() {
var aPos = sTable.fnGetPosition( this.parentNode );
var aData = sTable.fnGetData( aPos[0] );
- //console.log(aData);
-
- var network_hrn = aData[18];
+ console.log(aData);
+
+ var index = {}
+ // XXX Loic @ Hardcoded !!! Maybe a loop over all fields would be better
+ index['network_hrn'] = self.getColIndex('network_hrn',cols);
+ var network_hrn = aData[index['network_hrn']];
+
+ index['hostname'] = self.getColIndex('hostname',cols);
+ index['urn'] = self.getColIndex('urn',cols);
+ index['type'] = self.getColIndex('type',cols);
+ //index['status'] = self.getColIndex('boot_state',cols);
+ index['available'] = self.getColIndex('available',cols);
+ index['testbed'] = self.getColIndex('testbed_name',cols);
+ index['facility'] = self.getColIndex('facility_name',cols);
var resourceData = {
- 'hostname' : strip(aData[2]),
- 'urn' : aData[6],
- 'type' : aData[3],
- 'status' : aData[10],
- 'testbed' : aData[4],
- 'facility' : aData[5],
+ 'hostname' : strip(aData[index['hostname']]),
+ 'urn' : aData[index['urn']],
+ 'type' : aData[index['type']],
+ //'status' : aData[index['status']],
+ 'available' : aData[index['available']],
+ 'testbed' : aData[index['testbed']],
+ 'facility' : aData[index['facility']],
};
-
+ /*
//Greece: 37.6687092,22.2282404
if (network_hrn == 'omf.nitos') {
var logo = 'nitos';
};
var coordinates = resourceLocation['latitude']+','+resourceLocation['longitude'];
} else if (network_hrn == 'iotlab') {
+ */
+ if (network_hrn == 'iotlab') {
var logo = network_hrn;
var s = resourceData['hostname'].split(".");
var n = s[0].split("-");
resourceData['type'] = 'node ( Hardware: <a target="_blank" href="https://www.iot-lab.info/hardware/'+n[0]+'/">'+n[0]+'</a> )';
var coordinates = resourceData['testbed'];
} else {
- var logo = network_hrn;
+ var logo = resourceData['testbed'];
var resourceLocation = {
- 'longitude' : aData[13],
- 'latitude' : aData[23],
+ 'longitude' : aData[20],
+ 'latitude' : aData[17],
};
var coordinates = resourceLocation['latitude']+','+resourceLocation['longitude'];
+ console.log(coordinates);
}
var modal = $('#resource-info-modal');
modal.find('.modal-title').text(resourceData['testbed'] + ': ' +resourceData['hostname']);
table = modal.find('.modal-resource-info');
- table.html('<tr><td colspan="2"><img class="img-responsive" src="/static/img/testbeds/'+logo+'.png" alt="'+resourceData['facility']+' - '+resourceData['testbed']+'" /></td></tr>');
+ 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>');
for (var j in resourceData) {
table.append('<tr><td>' + j + '</td><td>' + resourceData[j] + '</td></tr>');
}
this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
break;
case STATE_SET_IN_PENDING:
- this.set_checkbox_from_data(data.key, true);
+ this.set_checkbox_from_data(data.value, true);
this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_ADDED);
break;
case STATE_SET_OUT_PENDING:
- this.set_checkbox_from_data(data.key, false);
+ this.set_checkbox_from_data(data.value, false);
this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_REMOVED);
break;
}
return result=$('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
});
};
+
+ // use sType: "mysort" for any columns you wish to use these routines
+ // http://datatables.net/forums/discussion/7546/alpha-numeric-sort
+ jQuery.fn.dataTableExt.oSort['mysort-asc'] = function(a,b) {
+ var r = new RegExp("<([a-zA-Z]+).*?>(.*?)</\\1>");
+ if (r.exec(a) != null){
+ a = r.exec(a)[2];
+ }
+ if (r.exec(b) != null){
+ b = r.exec(b)[2];
+ }
+ a = a.replace(/[^A-Za-z0-9]/, "");
+ b = b.replace(/[^A-Za-z0-9]/, "");
+ var re = new RegExp("^([a-zA-Z]*)(.*)");
+ var x = re.exec(a);
+ var y = re.exec(b);
+
+ // you might want to force the first portion to lowercase
+ // for case insensitive matching
+ // x[1] = x[1].toLowerCase();
+ // y[1] = y[1].toLowerCase();
+
+ if (x[1] > y[1]) return 1;
+ if (x[1] < y[1]) return -1;
+
+ // if you want to force the 2nd part to only be numeric:
+ x[2] = parseInt(x[2]);
+ y[2] = parseInt(y[2]);
+
+ return ((x[2] < y[2]) ? -1 : ((x[2] > y[2]) ? 1 : 0));
+ };
+
+ jQuery.fn.dataTableExt.oSort['mysort-desc'] = function(a,b) {
+ var r = new RegExp("<([a-zA-Z]+).*?>(.*?)</\\1>");
+ if (r.exec(a) != null){
+ a = r.exec(a)[2];
+ }
+ if (r.exec(b) != null){
+ b = r.exec(b)[2];
+ }
+ a = a.replace(/[^A-Za-z0-9]/, "");
+ b = b.replace(/[^A-Za-z0-9]/, "");
+ var re = new RegExp("^([a-zA-Z]*)(.*)");
+ var x = re.exec(a);
+ var y = re.exec(b);
+
+ // you might want to force the first portion to lowercase
+ // for case insensitive matching
+ // x[1] = x[1].toLowerCase();
+ // y[1] = y[1].toLowerCase();
+
+ if (x[1] > y[1]) return -1;
+ if (x[1] < y[1]) return 1;
+
+ // if you want to force the 2nd part to only be numeric:
+ x[2] = parseInt(x[2]);
+ y[2] = parseInt(y[2]);
+
+ return ((x[2] < y[2]) ? 1 : ((x[2] > y[2]) ? -1 : 0));
+ };