X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifold%2Fjs%2Fmanifold-query.js;h=4da77da14679f4e6f069ea86e06c0bbe178ad30e;hb=55f628fd2398b231159c148e1dee8302e255640e;hp=7c5de9256fa96cc08ef5758647caf78dc31f4866;hpb=9e6b289bad3042093d0414ed90a336aaa5bfa09a;p=myslice.git diff --git a/manifold/js/manifold-query.js b/manifold/js/manifold-query.js index 7c5de925..4da77da1 100644 --- a/manifold/js/manifold-query.js +++ b/manifold/js/manifold-query.js @@ -42,9 +42,31 @@ INSERT INTO object VALUES(field=value) } this.clone = function() { - q = new ManifoldQuery(); - return jQuery.extend(true, q, this); + // + var q = new ManifoldQuery(); + q.action = this.action; + q.object = this.object; + q.timestamp = this.timestamp; + q.filters = this.filters.slice(); + q.fields = this.fields.slice(); + q.query_uuid = this.query_uuid; + + if (this.analyzed_query) + q.analyzed_query = this.analyzed_query.clone(); + else + q.analyzed_query = null; + + if (this.subqueries) { + q.subqueries = {} + for (method in this.subqueries) + q.subqueries[method] = this.subqueries[method].clone(); + } + + // deep extend not working for custom objects + // $.extend(true, q, this); + return q; } + this.add_filter = function(key, op, value) { this.filters.push(new Array(key, op, value)); } @@ -74,7 +96,7 @@ INSERT INTO object VALUES(field=value) } // FIXME These functions computing diff's between queries are meant to be shared - this.diff_fields = function (otherQuery) { + this.diff_fields = function(otherQuery) { var f1 = this.fields; var f2 = otherQuery.fields; @@ -87,7 +109,7 @@ INSERT INTO object VALUES(field=value) } // FIXME Modify filter to filters - this.diff_filter = function (otherQuery) { + this.diff_filter = function(otherQuery) { var f1 = this.filters; var f2 = otherQuery.filters; @@ -98,6 +120,35 @@ 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, parent_query) { + callback(query, data, parent_query); + jQuery.each(query.subqueries, function(object, subquery) { + rec(subquery, callback, data, query); + }); + }; + + if (this.analyzed_query !== undefined) + query = this.analyzed_query; + else + 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 // this.as_POST = function() { // return {'action': this.action, 'object': this.object, 'timestamp': this.timestamp,