Cleans up Black Cherry, fixes query passing bug in SDK
diff --git a/asterix-app/src/main/resources/sdk/static/cherry/js/cherry.js b/asterix-app/src/main/resources/sdk/static/cherry/js/cherry.js
index b3a8f62..0e35865 100755
--- a/asterix-app/src/main/resources/sdk/static/cherry/js/cherry.js
+++ b/asterix-app/src/main/resources/sdk/static/cherry/js/cherry.js
@@ -1,5 +1,8 @@
 $(function() {	
-	   
+	
+	// Connection to AsterixDB   
+	var A = new AsterixDBConnection().dataverse("twitter");
+	
     APIqueryTracker = {};
     drilldown_data_map = {};
     drilldown_data_map_vals = {};
@@ -225,55 +228,48 @@
         };
 
 		var build_cherry_mode = "synchronous";
-		if ($('#asbox').is(":checked")) {
-		    build_cherry_mode = "asynchronous";
-		}
+		
+		// FIXME
+		//if ($('#asbox').is(":checked")) {
+		//    build_cherry_mode = "asynchronous";
+		//}
 	
         var f = new FLWOGRExpression()
-            .bind(new ForClause("$t", null, new AQLClause().set("dataset TweetMessages")))
-            .bind(new LetClause("keyword", new AQLClause().set('"' + formData["keyword"] + '"')))
-            .bind(new LetClause("region", new AQLClause().set(temporary_rectangle(formBounds))))
-            .bind(new WhereClause(new AExpression().set(
-                [
-		            'spatial-intersect($t.sender-location, $region)',
-		            '$t.send-time > datetime("' + formData["startdt"] + '")',
-		            '$t.send-time < datetime("' + formData["enddt"] + '")',
-		            'contains($t.message-text, $keyword)'
-                ].join(" and ")
-            )))
-            .bind(new AQLClause().set("group by $c := spatial-cell($t.sender-location, create-point(24.5,-125.5), " + formData["gridlat"].toFixed(1) + ", " + formData["gridlng"].toFixed(1) + ") with $t"))
-            .bind(new ReturnClause({ "cell" : "$c", "count" : "count($t)" }));
+            .bind(new ForClause("$t", new AExpression().set("dataset TweetMessages")))
+            .bind(new LetClause("$keyword", new AQLClause().set('"' + formData["keyword"] + '"')))
+            .bind(new LetClause("$region", new AQLClause().set(temporary_rectangle(formBounds))))
+            .bind(new WhereClause().and(
+                new AExpression().set('spatial-intersect($t.sender-location, $region)'),
+                new AExpression().set('$t.send-time > datetime("' + formData["startdt"] + '")'),
+                new AExpression().set('$t.send-time < datetime("' + formData["enddt"] + '")'),
+                new AExpression().set('contains($t.message-text, $keyword)')
+            ))
+            .bind(new GroupClause(
+                "c", 
+                new AExpression().set("spatial-cell($t.sender-location, create-point(24.5,-125.5), " + formData["gridlat"].toFixed(1) + ", " + formData["gridlng"].toFixed(1) + ")"),
+                "with", 
+                "t"
+            ))
+            .ReturnClause({ "cell" : "$c", "count" : "count($t)" });
         
-        var extra = {
-            "payload" : formData,
-            "query_string" : "use dataverse twitter;\n" + f.val()
-        };
+        param_placeholder["payload"] = formData;
+        param_placeholder["query_string"] = "use dataverse twitter;\n" + f.val();
         
-        f.run(
-            "http://localhost:19002/query",
-             {
-                "query" : "use dataverse twitter;\n" + f.val(),
-                "mode" : build_cherry_mode // "synchronous"
-             },
-             {
-                "sync" : cherryQuerySyncCallback,
-                "async" : cherryQueryAsyncCallback
-             },
-             extra
-        );
-        
+        A.run(f.val(), cherryQuerySyncCallback);
+    
 		APIqueryTracker = {
 		    "query" : "use dataverse twitter;\n" + f.val(),
 		    "data" : formData
 		};
 		
-		$('#dialog').html(APIqueryTracker["query"]);//.replace("\n", '<br />'));
+		$('#dialog').html(APIqueryTracker["query"]);
 
-        if (!$('#asbox').is(":checked")) {
-		    $('#show-query-button').attr("disabled", false);
-        } else {
-            $('#show-query-button').attr("disabled", true);
-        }
+        // FIXME
+        //if (!$('#asbox').is(":checked")) {
+		//    $('#show-query-button').attr("disabled", false);
+        //} else {
+        //    $('#show-query-button').attr("disabled", true);
+        //}
     });
     
 });
@@ -436,9 +432,7 @@
 * @param    {Object}    res, a result object from a cherry geospatial query
 * @param    {Object}    extra, extra data passed from the API call - legacy stuff
 */
-function cherryQuerySyncCallback(res, extra) {
-    
-    //alert(JSON.stringify(res));
+function cherryQuerySyncCallback(res) {
     
     records = res["results"];
     if (typeof res["results"][0] == "object") {
@@ -454,7 +448,7 @@
         coordinates.push(coordinate);
     }
     
-    triggerUIUpdate(coordinates, extra["payload"], weights);
+    triggerUIUpdate(coordinates, param_placeholder["payload"], weights);
 }
 
 /**
diff --git a/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js b/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js
index dedc76e..bb7bc5f 100644
--- a/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js
+++ b/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js
@@ -28,7 +28,7 @@
         statements = [ statements ];
     }
     
-    var query = "use dataverse " + this._properties["dataverse"] + "\n;" + statements.join("\n");
+    var query = "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n");
     var mode = this._properties["mode"];
     
     $.ajax({
@@ -307,10 +307,10 @@
 function ForClause(for_variable, at_variable, expression) {
     AQLClause.call(this);
   
-    this._properties["clause"] = "for $" + arguments[0];
+    this._properties["clause"] = "for " + arguments[0];
     
     if (arguments.length == 3) {
-        this._properties["clause"] += " at $" + arguments[1];
+        this._properties["clause"] += " at " + arguments[1];
         this._properties["clause"] += " in " + arguments[2].val();
     } else if (arguments.length == 2) {
         this._properties["clause"] += " in " + arguments[1].val();
@@ -335,7 +335,7 @@
 function LetClause(let_variable, expression) {
     AQLClause.call(this);
     
-    this._properties["clause"] = "let $" + let_variable + " := ";
+    this._properties["clause"] = "let " + let_variable + " := ";
     this._properties["clause"] += expression.val();
     
     return this;