Filter status: All, Available, Unavailable, Unconfigured, Pending, Reserved
[myslice.git] / plugins / filter_status / static / js / filter_status.js
index 9c3fe4f..7a30100 100644 (file)
 
             /* Setup query and record handlers */
             this.listen_query(options.query_uuid);
+            this.listen_query(options.query_lease_uuid, 'leases');
 
             /* Setup click handlers */
             this.elts('list-group-item').click({'instance': this}, this._on_click);
 
             this.prev_filter_status = null;
+
+            /* Initialize tooltips */
+            $("[rel='tooltip']").tooltip();
+
         },
 
     /**************************************************************************
     // These functions are here to react on external filters, which we don't
     // use at the moment
 
-    on_filter_added: function(filter) {
+    on_filter_added: function(filter) 
+    {
         // XXX
     },
 
-    on_filter_removed: function(filter) {
+    on_filter_removed: function(filter) 
+    {
         // XXX
     },
 
+    on_leases_field_state_changed: function(data) 
+    {
+        console.log('leases_field_state_changed');
+        this.on_field_state_changed(data);
+    },
+    on_field_state_changed: function(data) 
+    {
+        var query_ext;
+        
+        switch (data.state) {
+            case STATE_SET:
+            case STATE_WARNINGS:
+                /* Get the number of pending / unconfigured resources */
+                /* Let's store it in query_ext */
+                query_ext = manifold.query_store.find_analyzed_query_ext(this.options.query_uuid);
+
+                $('#badge-pending').text(query_ext.num_pending);
+                if (query_ext.num_pending > 0) {
+                                       $('#badge-pending').show();
+                } else {
+                                       $('#badge-pending').hide();
+                }
+
+                $('#badge-unconfigured').text(query_ext.num_unconfigured);
+                if (query_ext.num_unconfigured > 0) {
+                                       $('#badge-unconfigured').show();
+                } else {
+                                       $('#badge-unconfigured').hide();
+                }
+            default:
+                break;
+        }
+    },
+
     /**************************************************************************
      *                            PRIVATE METHODS                             *
      **************************************************************************/
 
             // ... and communicate the appropriate filters to the manager
             // NOTE: we use the manifold namespace for internal filters 
-            if (self.prev_filter_status)
-                manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, self.prev_filter_status);
-
-            // XXX The datatables will be refreshed twice !
-            if (filter_status != 'all') {
-                // No filter for 'all'
-                var filter = ['manifold:status', '==', filter_status];
-                manifold.raise_event(self.options.query_uuid, FILTER_ADDED, filter);
+            if (self.prev_filter_status) {
+                var filter = ['manifold:status', '==', self.prev_filter_status];
+                manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, filter);
             }
+            // XXX The datatables will be refreshed twice !
+            //if (filter_status != 'all') {
+            // No filter for 'all'
+            // Changed since we have available/unavailable status
+            var filter = ['manifold:status', '==', filter_status];
+            manifold.raise_event(self.options.query_uuid, FILTER_ADDED, filter);
+            //}
 
             self.prev_filter_status = filter_status;
         },