framework now supports displaying the results of queries
[myslice.git] / manifold / js / manifold-query.js
index c6ebaab..6036c38 100644 (file)
@@ -45,6 +45,7 @@ INSERT INTO object VALUES(field=value)
         q = new ManifoldQuery();
         return jQuery.extend(true, q, this);
     }
+
     this.add_filter = function(key, op, value) {
         this.filters.push(new Array(key, op, value));
     }
@@ -99,19 +100,32 @@ INSERT INTO object VALUES(field=value)
         return {'added':added, 'removed':removed};
     } 
 
+    // Callaback received 3 parameters: query, data, parent_query
     this.iter_subqueries = function(callback, data)
     {
-        rec = function(query, callback, data) {
+        rec = function(query, callback, data, parent_query) {
+            callback(query, data, parent_query);
             jQuery.each(query.subqueries, function(object, subquery) {
-                rec(subquery, callback);
+                rec(subquery, callback, data, query);
             });
-            callback(query, data);
         };
+
         if (this.analyzed_query !== undefined)
             query = this.analyzed_query;
         else
-            query = this
-        rec(query, callback, data);
+            query = this;
+
+        rec(query, callback, data, null);
+    }
+
+    this.select = function(field)
+    {
+        this.fields.push(field);
+    }
+
+    this.unselect = function(field)
+    {   
+        this.fields = $.grep(this.fields, function(x) { return x != field; });
     }
 
 // we send queries as a json string now