From 15bbd76bedecea3ece64568f85530d9d3ae750c5 Mon Sep 17 00:00:00 2001
From: Thierry Parmentelat <thierry.parmentelat@inria.fr>
Date: Fri, 8 Mar 2013 09:45:24 +0100
Subject: [PATCH] various fixes - we now see the request sent on
 /manifold/api/json/ but there's nobody there yet

---
 engine/pluginset.py                | 10 +++---
 engine/static/js/manifold-async.js | 53 +++++-------------------------
 plugins/simplelist.py              |  7 +---
 trash/dashboard.py                 |  1 +
 4 files changed, 16 insertions(+), 55 deletions(-)

diff --git a/engine/pluginset.py b/engine/pluginset.py
index 01442dcd..1a0f54ed 100644
--- a/engine/pluginset.py
+++ b/engine/pluginset.py
@@ -33,21 +33,21 @@ class PluginSet:
     # the js async methods (see manifold_async_success)
     # offer the option to deliver the result to a specific DOM elt
     # otherwise it goes through the pubsub using query's uuid
-    def query_enqueue (self, query, domid=None):
+    def enqueue_query (self, query, domid=None):
         self._queue.append ( (query,domid,) )
 
     # return the javascript that triggers all the queries
     def exec_queue_asynchroneously (self):
         js = ""
-        js += "var manifold_query_array = new Array();"
+        js += "var manifold_query_array = new Array();\n"
         for (query,domid) in self._queue:
             qjson=query.to_json()
-            id="'%s'"%domid if domid else undefined
-            js += "manifold_query_array.push({'query':'%(qjson)s', 'id':%(id)s});"%locals()
+            id="'%s'"%domid if domid else 'undefined'
+            js += "manifold_query_array.push({'query':%(qjson)s, 'id':%(id)s});\n"%locals()
         js += "onFunctionAvailable('manifold_async_exec', function() {manifold_async_exec(manifold_query_array);}, this, true);"
         self.reset_queue()
         # run only once the document is ready
-        js = "jQuery(function(){%(js)s})"%locals()
+        js = "$(document).ready(function(){%(js)s})"%locals()
         self.add_js_chunks (js)
 
     #################### requirements/prelude management
diff --git a/engine/static/js/manifold-async.js b/engine/static/js/manifold-async.js
index 83a97a72..ae35630e 100644
--- a/engine/static/js/manifold-async.js
+++ b/engine/static/js/manifold-async.js
@@ -16,61 +16,24 @@ function manifold_array_size(obj) {
 //
 function manifold_async_exec(arr)
 {
-
+    console.log('manifold_async_exec length='+ arr.length);
     // start spinners
-    //onObjectAvailable('Spinners', function(){ Spinners.create('.loading').play(); }, this, true);
-    jQuery('.loading').spin();
+    // xxx todo - I don't have the spinner jquery plugin yet
+//    jQuery('.loading').spin();
 
     // We use js function closure to be able to pass the query (array) to the
     // callback function used when data is received
-    var manifold_async_success_wrapper = function(query, id) {
-        return function(data, textStatus) {
-            manifold_async_success(data, query, id);
-        };
+    var manifold_async_success_closure = function(query, id) {
+        return function(data, textStatus) {manifold_async_success(data, query, id);}
     };
 
     // Loop through query array and issue XML/RPC queries
     jQuery.each(arr, function(index, elt) {
-        // we do rendering by default
-        jQuery.post(api_url, {'query': elt.query.to_hash()}, manifold_async_success_wrapper(elt.query, elt.id));
+	console.log ('sending POST on ' + api_url + " iterating on " + elt);
+        jQuery.post(api_url, {'query': elt.query.to_hash()}, manifold_async_success_closure(elt.query, elt.id));
     })
 }
 
-function manifold_async_exec_render(arr)
-{
-
-    // start spinners
-    //onObjectAvailable('Spinners', function(){ Spinners.create('.loading').play(); }, this, true);
-    jQuery('.loading').spin();
-
-    // We use js function closure to be able to pass the query (array) to the
-    // callback function used when data is received
-    var manifold_async_success_wrapper = function(query, id) {
-        return function(data, textStatus) {
-            manifold_async_success(data, query, id);
-        };
-    };
-
-    // Loop through query array and issue XML/RPC queries
-    jQuery.each(arr, function(index, elt) {
-        // we do rendering by default
-        jQuery.post(api_render_url, {'query': elt.query.to_hash()}, manifold_async_success_wrapper(elt.query, elt.id));
-    })
-}
-
-function manifold_async_render(data, query)
-{
-    // We use js function closure to be able to pass the query (array) to the
-    // callback function used when data is received
-    var manifold_async_render_success_wrapper = function(query) {
-        return function(data, textStatus) {
-            manifold_async_render_success(data, query);
-        };
-    };
-
-    jQuery.post(api_render_url, {'data': data, 'query': query.to_hash()}, manifold_async_render_success_wrapper(data, query));
-}
-
 function manifold_async_error(str) {
     var out = '<div class="error"><h2>Error</h2><dl id="system-message"><dt class="error">Notice</dt><dd class="error message"><ul><li>' + jQuery('<div />').text(str).html() + '</li></ul></dd></dl></div>';
     jQuery('#manifold_message').html(out);
@@ -78,6 +41,7 @@ function manifold_async_error(str) {
     jQuery('.loading').spin();
 }
 
+/* what the hell is this doing here ?
 function apply_format(key, value, type, method) {
     // type = type, key = 
     var link = {
@@ -120,6 +84,7 @@ function apply_format(key, value, type, method) {
         return key;
     }
 }
+*/
 
 function manifold_html_a(key, value, type) {
     if (type == 'network_hrn') {
diff --git a/plugins/simplelist.py b/plugins/simplelist.py
index 19a77692..6eb0f44a 100644
--- a/plugins/simplelist.py
+++ b/plugins/simplelist.py
@@ -2,9 +2,7 @@ from engine.plugin import Plugin
 
 class SimpleList (Plugin) :
 
-    # it would make sense to *not* define any constructor here and let Plugin kick in
-    # however it feels nicer this way as we document the settings used in our own template
-    # plus it's less confusing for any subclass if they can be sure which constructor to call
+    # only deal with our own stuff here and let Plugin handle the rest
     def __init__ (self, list=[], with_datatables=False, **settings):
         Plugin.__init__ (self, **settings)
         self.list=list
@@ -22,9 +20,6 @@ class SimpleList (Plugin) :
             reqs['js_files'].append ("datatables/js/dataTables.js")
             reqs['js_files'].append ("js/with-datatables.js")
         return reqs
-# for tests
-#                 'js_chunks' : "/* a javascript chunk */",       
-#                 'css_chunks': "/* a css style */ ",
     
     def json_settings_list (self): return ['plugin_uuid', 'query','query_uuid','key','value']
 
diff --git a/trash/dashboard.py b/trash/dashboard.py
index 246536eb..e7ea8994 100644
--- a/trash/dashboard.py
+++ b/trash/dashboard.py
@@ -29,6 +29,7 @@ def dashboard_view (request):
                                   # we don't have the user's hrn yet
                                   # in addition this currently returns all slices anyways
                                   sort='slice_hrn',)
+    pluginset.enqueue_query (slices_query)
 
     main_plugin = SimpleList ( # setting visible attributes first
         pluginset=pluginset,
-- 
2.47.0