1 # the supervisor for Plugins
2 # keeps a handle on all present plugins for managing their queries in a consistent way
3 # it is expected to exist one such object for a given page
5 from engine.prelude import Prelude
7 # decorator to deflect calls on this PluginSet to its prelude
8 def to_prelude (method):
9 def actual (self, *args, **kwds):
10 prelude_method=Prelude.__dict__[method.__name__]
11 return prelude_method(self.prelude,*args, **kwds)
20 self.prelude=Prelude(css_files='css/plugin.css')
21 # no queries yet, needed ?
23 # record known plugins hashed on their domid
24 def record_plugin (self, plugin):
25 self._plugins[plugin.domid]=plugin
27 def get_plugin (self, domid):
28 return self._plugins.get(domid,None)
30 def reset_queue (self):
33 # the js async methods (see manifold_async_success)
34 # offer the option to deliver the result to a specific DOM elt
35 # otherwise it goes through the pubsub using query's uuid
36 def enqueue_query (self, query, domid=None):
37 self._queue.append ( (query,domid,) )
39 # return the javascript that triggers all the queries
40 def exec_queue_asynchroneously (self):
42 js += "var manifold_query_array = new Array();\n"
43 for (query,domid) in self._queue:
45 id="'%s'"%domid if domid else 'undefined'
46 js += "manifold_query_array.push({'query':%(qjson)s, 'id':%(id)s});\n"%locals()
47 js += "onFunctionAvailable('manifold_async_exec', function() {manifold_async_exec(manifold_query_array);}, this, true);"
49 # run only once the document is ready
50 js = "$(document).ready(function(){%(js)s})"%locals()
51 self.add_js_chunks (js)
53 #################### requirements/prelude management
54 # just forward to self.pluginset - see decorator above
56 def add_js_files (self):pass
58 def add_css_files (self):pass
60 def add_js_chunks (self):pass
62 def add_css_chunks (self):pass
64 def template_env (self):pass