X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=blobdiff_plain;f=plugins%2Flists%2Fstatic%2Fjs%2Fsimplelist.js;h=6df47cfc2d159db25ef8d2266fe8c251e451d7c1;hp=3d2c4b9c4322e124d339fb82470aba5e1a556e22;hb=df37189ffd08ea92ba19d6ecbfd9f14bf46c0550;hpb=9335bc06c9c946d1d1f9d545a59c9116c4be30b4 diff --git a/plugins/lists/static/js/simplelist.js b/plugins/lists/static/js/simplelist.js index 3d2c4b9c..6df47cfc 100644 --- a/plugins/lists/static/js/simplelist.js +++ b/plugins/lists/static/js/simplelist.js @@ -12,9 +12,16 @@ var SimpleList = Plugin.extend ({ init: function (options, element) { + this.classname = options.classname; this._super (options, element); - this.buffered_records=[]; - this.listen_query(options.query_uuid); + this.buffered_records = []; + this.listen_query(options.query_uuid); + /* Optional parameter warning_msg */ + if(options.warning_msg != "unknown-setting-warning_msg"){ + this.warning_msg = options.warning_msg; + }else{ + this.warning_msg = "No Result"; + } }, on_query_in_progress: function() { @@ -23,8 +30,11 @@ }, on_query_done: function() { - this._display_table(); + this._display_table(); this.unspin(); + console.log("query simple list done"); + console.log(this); + console.log(this.buffered_records); }, on_new_record: function(record) { @@ -35,41 +45,45 @@ _display_table: function() { var self=this; - var $plugindiv = this.elmt(); - var options = this.options; - var classname=options.classname; - // locate the element; with datatables in the way, - // this might not be a direct son of the div-plugin - var $table = $plugindiv.find("table."+classname).first(); - // also we may or may not have a header - var $tbody = $table.find("tbody."+classname).first(); - var use_datatables = $table.hasClass("with-datatables"); + var $plugindiv = this.elmt(); + var options = this.options; + // locate the
element; with datatables in the way, + // this might not be a direct son of the div-plugin + var $table = $plugindiv.find("table."+this.classname).first(); + // also we may or may not have a header + var $tbody = $table.find("tbody."+this.classname).first(); + var use_datatables = $table.hasClass("with-datatables"); var rows=self.buffered_records; self.buffered_records=[]; - if (debug) - messages.debug($plugindiv.attr('id') + " udt= " + use_datatables + " rows="+rows.length); - - if (rows.length == 0) { - if (use_datatables) - this._datatables_set_message ($table, $tbody, unfold.warning("No result")); - else - this._regular_set_message ($table, $tbody, unfold.warning("No result")); - return; + if (debug){ + messages.debug($plugindiv.attr('id') + " udt= " + use_datatables + " rows="+rows.length); + } + // check if rows contains results related to the object key + object_key = this.options.key.split('.'); + if (rows.length == 0 || rows[0][object_key[0]].length == 0) { + if (use_datatables){ + this._datatables_set_message ($table, $tbody, unfold.warning(self.warning_msg)); + }else{ + this._regular_set_message ($table, $tbody, unfold.warning(self.warning_msg)); } + return; + } - if (typeof rows[0].error != 'undefined') { - var error="ERROR: " + rows[0].error; - if (use_datatables) - this._datatables_set_message ($table, $tbody, unfold.error(error)); - else + if (typeof rows[0].error != 'undefined') { + var error="ERROR: " + rows[0].error; + if (use_datatables){ + this._datatables_set_message ($table, $tbody, unfold.error(error)); + }else{ this._regular_set_message ($table, $tbody, unfold.error(error)); - return; } + return; + } - if (use_datatables) - this._datatables_update_table($table, $tbody, rows, options.key); - else - this._regular_update_table($table, $tbody, rows, options.key, classname); + if (use_datatables){ + this._datatables_update_table($table, $tbody, rows, options.key); + }else{ + this._regular_update_table($table, $tbody, rows, options.key, this.classname); + } }, _regular_set_message: function ($table, $tbody, message) { @@ -78,7 +92,8 @@ _regular_update_table: function ($table, $tbody, rows, key, classname) { if (debug) - messages.debug('regular_update_table ' + rows.length + " rows" + " key=" + key + " classname=" + classname); + messages.debug('regular_update_table ' + rows.length + " rows" + + " key=" + key + " classname=" + this.classname); var self=this; var html=$.map(rows, function (row) { var value = row; @@ -91,10 +106,10 @@ }); if ($.isArray(value)) { return $.map(value, function(val, i) { - return self._html_row ( self._cell (key, val), classname); + return self._html_row ( self._cell (key, val), this.classname); }); } else { - return self._html_row ( self._cell (key, value), classname); + return self._html_row ( self._cell (key, value), this.classname); } }).join(); $tbody.html(html); @@ -110,7 +125,8 @@ if (debug) messages.debug('datatables_update_table ' + rows.length + " rows"); $table.dataTable().fnClearTable(); // the lambda here returns a [[]] because $.map is kind of broken; as per the doc: - // The function can return any value to add to the array. A returned array will be flattened into the resulting array. + // The function can return any value to add to the array. + // A returned array will be flattened into the resulting array. // this is wrong indeed so let's work around that var self=this; $table.dataTable().fnAddData( $.map(rows, function (row) { return [[ self._cell (key,row[key]) ]] }) );