X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fquerytable%2Fstatic%2Fjs%2Fquerytable.js;h=9d7bced0716ff2d6f51ceedb3a0ff05c5e1c9fab;hb=265fd105b18cfa17791352c04a8da976b2c4826f;hp=e0ac3fd0d6f7be1fdf6cff73035f3c7c50559013;hpb=6e53114f25d1511e1c72a243da5bc5077ebc5aa0;p=myslice.git diff --git a/plugins/querytable/static/js/querytable.js b/plugins/querytable/static/js/querytable.js index e0ac3fd0..9d7bced0 100644 --- a/plugins/querytable/static/js/querytable.js +++ b/plugins/querytable/static/js/querytable.js @@ -41,8 +41,18 @@ var query = manifold.query_store.find_analyzed_query(this.options.query_uuid); this.method = query.object; - var keys = manifold.metadata.get_key(this.method); - this.key = (keys && keys.length == 1) ? keys[0] : null; + // xxx beware that this.key needs to contain a key that all records will have + // in general query_all will return well populated records, but query + // returns records with only the fields displayed on startup. + this.key = (this.options.id_key); + if (! this.key) { + // if not specified by caller, decide from metadata + var keys = manifold.metadata.get_key(this.method); + this.key = (keys && keys.length == 1) ? keys[0] : null; + } + if (! this.key) messages.warning("querytable.init could not kind valid key"); + + messages.debug("querytable: key="+this.key); /* Setup query and record handlers */ this.listen_query(options.query_uuid); @@ -250,27 +260,27 @@ /* Default: checked = true */ if (checked === undefined) checked = true; - var key_value; + var id; /* The function accepts both records and their key */ switch (manifold.get_type(record)) { - case TYPE_VALUE: - key_value = record; - break; - case TYPE_RECORD: - /* XXX Test the key before ? */ - key_value = record[this.key]; - break; - default: - throw "Not implemented"; - break; + case TYPE_VALUE: + id = record; + break; + case TYPE_RECORD: + /* XXX Test the key before ? */ + id = record[this.key]; + break; + default: + throw "Not implemented"; + break; } - if (key_value === undefined) { - messages.warning("querytable.set_checkbox has no value to figure which line to tick"); + if (id === undefined) { + messages.warning("querytable.set_checkbox record has no id to figure which line to tick"); return; } - var checkbox_id = this.flat_id(this.id('checkbox', key_value)); + var checkbox_id = this.flat_id(this.id('checkbox', id)); // function escape_id(myid) is defined in portal/static/js/common.functions.js checkbox_id = escape_id(checkbox_id); // using dataTables's $ to search also in nodes that are not currently displayed