global helper functions need to have grep-able names, i.e. a little bit longer
[myslice.git] / plugins / hazelnut / static / js / hazelnut.js
index 91fe152..13bc5d8 100644 (file)
@@ -7,7 +7,6 @@
 (function($){
 
     // TEMP
-    var ELEMENT_KEY = 'resource_hrn';
     var debug=false;
     debug=true
 
  // UNUSED ? //         
  // UNUSED ? //         }, // update_plugin
 
-        checkbox: function (plugin_uuid, header, field) //, selected_str, disabled_str)
+        checkbox: function (key, value)
         {
             var result="";
-            if (header === null)
-                header = '';
             // Prefix id with plugin_uuid
             result += "<input";
             result += " class='hazelnut-checkbox'";
-            result += " id='" + this.id('checkbox', this.id_from_key(this.key, unfold.get_value(header))) + "'";
-             //hazelnut-checkbox-" + plugin_uuid + "-" + unfold.get_value(header).replace(/\\/g, '')  + "'";
-            result += " name='" + unfold.get_value(field) + "'";
+            result += " id='" + this.id('checkbox', this.id_from_key(key, value)) + "'";
+            result += " name='" + key + "'";
             result += " type='checkbox'";
-            //result += selected_str;
-            //result += disabled_str;
             result += " autocomplete='off'";
-            result += " value='" + unfold.get_value(header) + "'";
+            result += " value='" + value + "'";
             result += "></input>";
             return result;
         }, // checkbox
             if (this.options.checkboxes)
                 // Use a key instead of hostname (hard coded...)
                 // XXX remove the empty checked attribute
-                line.push(this.checkbox(this.options.plugin_uuid, record[ELEMENT_KEY], record['type']));
+                line.push(this.checkbox(this.key, record[this.key]));
     
             // XXX Is adding an array of lines more efficient ?
             this.table.fnAddData(line);
 
         set_checkbox: function(record, checked)
         {
+            /* Default: checked = true */
+            if (typeof checked === 'undefined')
+                checked = true;
+
             var key_value;
             /* The function accepts both records and their key */
             switch (manifold.get_type(record)) {
 
             var element = $(checkbox_id, this.table.fnGetNodes());
 
-            /* Default: swap check status */
-            if (typeof checked === 'undefined')
-                checked = !(element.is(':checked'));
-
             element.attr('checked', checked);
         },
 
         {
             switch(data.request) {
                 case FIELD_REQUEST_ADD:
+                case FIELD_REQUEST_ADD_RESET:
                     this.set_checkbox(data.value, true);
                     break;
                 case FIELD_REQUEST_REMOVE:
+                case FIELD_REQUEST_REMOVE_RESET:
                     this.set_checkbox(data.value, false);
                     break;
-                case FIELD_REQUEST_RESET:
-                    this.set_checkbox(data.value); // swap
-                    break;
                 default:
                     break;
             }
              * Handle clicks on checkboxes: reassociate checkbox click every time
              * the table is redrawn 
              */
-            this.els('hazelnut-checkbox').unbind('click').click(this, this._check_click);
+            this.elts('hazelnut-checkbox').unbind('click').click(this, this._check_click);
 
             if (!this.table)
                 return;
 
         _check_click: function(e) 
         {
+            e.stopPropagation();
 
             var self = e.data;