ugly hack to use hrn instead of urn for now
[myslice.git] / plugins / querytable / static / js / querytable.js
index 30c727b..12232c8 100644 (file)
             var keys = manifold.metadata.get_key(this.method);
             this.key = (keys && keys.length == 1) ? keys[0] : null;
 
+           // xxx temporary hack
+           // as of nov. 28 2013 we have here this.key='urn', but in any place where
+           // the code tries to access record[this.key] the records only have
+           // keys=type,hrn,network_hrn,hostname
+           // so for now we force using hrn instead
+           // as soon as record have their primary key set this line can be removed
+           // see also same hack in googlemap
+           this.key= (this.key == 'urn') ? 'hrn' : this.key;
+
             /* Setup query and record handlers */
             this.listen_query(options.query_uuid);
             this.listen_query(options.query_all_uuid, 'all');
 
         checkbox_html : function (key, value)
         {
+//         if (debug) messages.debug("checkbox_html, value="+value);
             var result="";
             // Prefix id with plugin_uuid
             result += "<input";
             result += " name='" + key + "'";
             result += " type='checkbox'";
             result += " autocomplete='off'";
-            result += " value='" + value + "'";
+           if (value === undefined) {
+               messages.warning("querytable.checkbox_html - undefined value");
+           } else {
+               result += " value='" + value + "'";
+           }
             result += "></input>";
             return result;
-        }, // checkbox
+        }, 
 
 
         new_record: function(record)
             /* 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;
             }
 
 
-            var checkbox_id = this.flat_id(this.id('checkbox', key_value));
+           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', 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
+            // using dataTables's $ to search also in nodes that are not currently displayed
             var element = this.table.$(checkbox_id);
-               if (debug) messages.debug("set_checkbox checked=" + checked + " id=" + checkbox_id + " matches=" + element.length);
+            if (debug) 
+                messages.debug("set_checkbox checked=" + checked
+                               + " id=" + checkbox_id + " matches=" + element.length);
             element.attr('checked', checked);
         },
 
         on_new_record: function(record)
         {
             if (this.received_all_query) {
-                       // if the 'all' query has been dealt with already we may turn on the checkbox
-                       if (debug) messages.debug("turning on checkbox for record "+record[this.key]);
+               // if the 'all' query has been dealt with already we may turn on the checkbox
                 this.set_checkbox(record, true);
-               } else {
-                       // otherwise we need to remember that and do it later on
-                       if (debug) messages.debug("Remembering record to check " + record[this.key]);
+            } else {
+               // otherwise we need to remember that and do it later on
+               if (debug) messages.debug("Remembering record to check " + record[this.key]);
                 this.buffered_records_to_check.push(record);
-               }
+            }
         },
 
         on_clear_records: function()