- var $plugindiv=e.data;
- if (debug) console.log("entering hazelnut.update_plugin on id '" + $plugindiv.attr('id') + "'");
- // clear the spinning wheel: look up an ancestor that has the need-spin class
- // do this before we might return
- $plugindiv.closest('.need-spin').spin(false);
+ // e.data is what we passed in second argument to subscribe
+ // so here it is the jquery object attached to the plugin
+ var $plugindiv=e.data;
+ if (debug) messages.debug("entering hazelnut.update_plugin on id '" + $plugindiv.attr('id') + "'");
+ // clear the spinning wheel: look up an ancestor that has the need-spin class
+ // do this before we might return
+ $plugindiv.closest('.need-spin').spin(false);
var options = this.options;
var hazelnut = this;
+ /* if we get no result, or an error, try to make that clear, and exit */
if (rows.length==0) {
- if (debug) console.l ("empty result");
- this.table.html(unfold.errorDisplay("No Result"));
+ if (debug) messages.debug("Empty result on hazelnut " + this.options.domid);
+ var placeholder=$(this.table).find("td.dataTables_empty");
+ console.log("placeholder "+placeholder);
+ if (placeholder.length==1) placeholder.html(unfold.warning("Empty result"));
+ else this.table.html(unfold.warning("Empty result"));
return;
} else if (typeof(rows[0].error) != 'undefined') {
- if (debug) console.log ("undefined result");
- this.table.html(unfold.errorDisplay(rows[0].error));
+ // we now should have another means to report errors that this inline/embedded hack
+ if (debug) messages.error ("undefined result on " + this.options.domid + " - should not happen anymore");
+ this.table.html(unfold.error(rows[0].error));
return;
}
- newlines = new Array();
+
+ /*
+ * fill the dataTables object
+ * we cannot set html content directly here, need to use fnAddData
+ */
+ var lines = new Array();
this.current_resources = Array();
- $.each(rows, function(index, obj) {
- newline = new Array();
-
+ $.each(rows, function(index, row) {
+ // this models a line in dataTables, each element in the line describes a cell
+ line = new Array();
+
// go through table headers to get column names we want
// in order (we have temporarily hack some adjustments in names)
var cols = hazelnut.table.fnSettings().aoColumns;
var colnames = cols.map(function(x) {return x.sTitle})
- var nb_col = colnames.length;
- if (options.checkboxes)
- nb_col -= 1;
+ var nb_col = cols.length;
+ /* if we've requested checkboxes, then forget about the checkbox column for now */
+ if (options.checkboxes) nb_col -= 1;
+
+ /* fill in stuff depending on the column name */
for (var j = 0; j < nb_col; j++) {
if (typeof colnames[j] == 'undefined') {
- newline.push('...');
+ line.push('...');
} else if (colnames[j] == 'hostname') {
- if (obj['type'] == 'resource,link')
+ if (row['type'] == 'resource,link')
//TODO: we need to add source/destination for links
- newline.push('');
+ line.push('');
else
- newline.push(obj['hostname']);
+ line.push(row['hostname']);
} else {
- if (obj[colnames[j]])
- newline.push(obj[colnames[j]]);
+ if (row[colnames[j]])
+ line.push(row[colnames[j]]);
else
- newline.push('');
+ line.push('');
}
}
+ /* catch up with the last column if checkboxes were requested */
if (options.checkboxes) {
var checked = '';
- if (typeof(obj['sliver']) != 'undefined') { /* It is equal to null when is present */
+ // xxx problem is, we don't get this 'sliver' thing set apparently
+ if (typeof(row['sliver']) != 'undefined') { /* It is equal to null when is present */
checked = 'checked ';
- hazelnut.current_resources.push(obj['urn']);
+ hazelnut.current_resources.push(row['urn']);
}
// Use a key instead of hostname (hard coded...)
- newline.push(hazelnut.checkbox(options.plugin_uuid, obj['urn'], obj['type'], checked, false));
+ line.push(hazelnut.checkbox(options.plugin_uuid, row['urn'], row['type'], checked, false));
}
- newlines.push(newline);
-
+ lines.push(line);
});
- this.table.fnClearTable();
- if (debug) console.log("hazelnut.update_plugin: total of " + newlines.length + " rows");
- this.table.fnAddData(newlines);
+ this.table.fnClearTable();
+ if (debug) messages.debug("hazelnut.update_plugin: total of " + lines.length + " rows");
+ this.table.fnAddData(lines);
};
this.checkbox = function (plugin_uuid, header, field, selected_str, disabled_str) {
- var result="";
- /* Prefix id with plugin_uuid */
- result += "";
- return result;
+ var result="";
+ // Preafix id with plugin_uuid
+ result += "";
+ return result;
};
} // constructor
/***************************************************************************
* Private methods
+ * xxx I'm not sure why this should not be methods in the Hazelnut class above
***************************************************************************/
/**
@@ -351,6 +394,7 @@
*/
function hazelnut_filter (oSettings, aData, iDataIndex) {
var cur_query = this.current_query;
+ if (!cur_query) return true;
var ret = true;
/* We have an array of filters : a filter is an array (key op val)