Commits

Ralph Bean committed 1cd7461

mako and genshi both working

  • Participants
  • Parent commits 66cd174

Comments (0)

Files changed (8)

tw2/jquery/plugins/jqplot/base.py

     modname='tw2.jquery.plugins.jqplot',
     subdir = '',
 )
+jqplot_utils_js = twc.JSLink(
+    modname='tw2.jquery.plugins.jqplot',
+    filename='static/js/jqplot-utils.js',
+)
+
 
 class JQPlotPluginJSLink(twjq_c.jQueryPluginJSLink):
     jqplugin = twc.Param('(string) Name of the jqplot plugin')
         subs.update(dict(jqplugin=self.jqplugin))
         return subs
 
-__all__ = ['jqplot_js', 'jqplot_css']
+__all__ = ['jqplot_js', 'jqplot_css', 'jqplot_utils_js']
 
 jqplugins = [
     'barRenderer',

tw2/jquery/plugins/jqplot/static/js/jqplot-utils.js

+/* Some workhorse functions for tw2.jquery.plugins.jqplot */
+
+function doJQPlotWidget(sel, data, options){
+        $.jqplot.config.enablePlugins = true;
+        $.jqplot(sel, data, options);
+}
+
+function doPollingJQPlotWidget(sel, data, options, url, url_kwargs, interval){
+        $.jqplot.config.enablePlugins = true;
+
+        // Setup our initial plot
+        var the_plot_thickens = $.jqplot(sel, data, options);
+
+        // Setup our callback function
+        callback = function (json) {
+                pl = the_plot_thickens;
+
+                for ( _i = 0; _i < json.data.length; _i++ ) {
+                        pl.series[_i].data = json.data[_i] ;
+                }
+                for (ax in json.options.axes) {
+                        pl.axes[ax]._ticks = []
+                        if ( 'axes' in json.options &&
+                                ax in json.options.axes &&
+                                'min' in json.options.axes[ax] ) {
+                                pl.axes[ax].min = json.options['axes'][ax].min;
+                                pl.axes[ax].max = json.options['axes'][ax].max;
+                        }
+                        pl.axes[ax].numberTicks = null
+                        pl.axes[ax].tickInterval = null
+                        pl.axes[ax]._tickInterval = null
+                }
+                pl.redraw();
+        };
+
+        // Finally make the JSON call
+        $.getJSON(url, url_kwargs, callback);
+
+        // And if we want to keep polling, do it
+        if ( interval > 0 ) {
+                setInterval( function() {
+                        $.getJSON(url, url_kwargs, callback);
+                }, interval );
+        }
+
+}
+

tw2/jquery/plugins/jqplot/templates/jqgrid.html

-<div xmlns:py="http://genshi.edgewall.org/">
-<table py:attrs="w.attrs" ></table>
-<div py:if="w.pager_id" id="${w.pager_id}" />
-<script type="text/javascript">
-$(document).ready(
-    function(){
-        var opts = ${w.options};
-        var grid = $("#${w.attrs['id']}");
-        grid.jqGrid(opts);
-        if ( 'pager' in opts ) {
-            opts['pager_selector'] = opts['pager'];
-            opts['pager'] = $(opts['pager'])
-            var pager_opts = ${w.pager_options}
-            grid.navGrid('#'+opts['pager_selector'], pager_opts);
-        }
-    }
-);
-</script>
-</div>

tw2/jquery/plugins/jqplot/templates/jqplot.html

+<div xmlns:py="http://genshi.edgewall.org/">
+  <div py:attrs="w.attrs" ></div>
+  <script type="text/javascript">
+    $(document).ready(
+      function(){
+        doJQPlotWidget(
+          '${w.selector}',
+          ${w._data},
+          ${w._options}
+        );
+      }
+    );
+  </script>
+</div>

tw2/jquery/plugins/jqplot/templates/jqplot.mak

 <script type="text/javascript">
 $(document).ready(
     function(){
-		$.jqplot.config.enablePlugins = true;
-		$.jqplot(
+		doJQPlotWidget(
 			'${w.selector}',
 			${w._data},
 			${w._options}

tw2/jquery/plugins/jqplot/templates/pollster.html

+<div xmlns:py="http://genshi.edgewall.org/">
+  <div py:attrs="w.attrs" ></div>
+  <script type="text/javascript">
+    $(document).ready(
+      function(){
+        doPollingJQPlotWidget(
+          // selector
+          '${w.selector}',
+          // data
+          ${w._data},
+          // options
+          ${w._options},
+          // url
+          '${w.url}',
+          // url_kwargs
+          ${w.url_kwargs},
+          // interval
+          ${w.interval}
+        );
+      }
+    );
+  </script>
+</div>

tw2/jquery/plugins/jqplot/templates/pollster.mak

 <div>
 <div ${tw.attrs(attrs=w.attrs)}></div>
 <script type="text/javascript">
-$(document).ready(
-    function(){
-		$.jqplot.config.enablePlugins = true;
-
-		// Setup our initial plot
-		var the_plot_thickens = $.jqplot(
-			'${w.selector}',
-			${w._data},
-			${w._options}
-		);
-
-		// Setup our callback function
-		callback = function (json) {
-		  pl = the_plot_thickens;
-		  
-          for ( _i = 0; _i < json.data.length; _i++ ) {
-                pl.series[_i].data = json.data[_i] ;
-          }
-          for (ax in json.options.axes) {
-                  pl.axes[ax]._ticks = []
-                  if ( 'axes' in json.options &&
-                        ax in json.options.axes &&
-                        'min' in json.options.axes[ax] ) {
-                        pl.axes[ax].min = json.options['axes'][ax].min;
-                        pl.axes[ax].max = json.options['axes'][ax].max;
-                  }
-                  pl.axes[ax].numberTicks = null
-                  pl.axes[ax].tickInterval = null
-                  pl.axes[ax]._tickInterval = null
-          }
-          pl.redraw();
-		};
-
-		// Finally make the JSON call
-		$.getJSON(
-			'${w.url}',
-			${w.url_kwargs},
-			callback
-		);
-
-		// And if we want to keep polling, do it
-		var interval = ${str(w.interval)};
-		if ( interval > 0 ) {
-			setInterval( function() {
-				$.getJSON(
-					'${w.url}',
-					${w.url_kwargs},
-					callback
-				);}, interval );
-		}
-    }
-);
+    $(document).ready(
+      function(){
+        doPollingJQPlotWidget(
+          // selector
+          '${w.selector}',
+          // data
+          ${w._data},
+          // options
+          ${w._options},
+          // url
+          '${w.url}',
+          // url_kwargs
+          ${w.url_kwargs},
+          // interval
+          ${str(w.interval)}
+        );
+      }
+    );
 </script>
 </div>

tw2/jquery/plugins/jqplot/widgets.py

 import formencode as fe
 import formencode.validators as fv
 
+
+
 class JQPlotWidget(tw2_jq_ui.JQueryUIWidget):
     resources = [
         tw2.jquery.jquery_js,
         tw2_jq_ui.jquery_ui_js, tw2_jq_ui.jquery_ui_css,
-        base.jqplot_js, base.jqplot_css,
+        base.jqplot_js, base.jqplot_css, base.jqplot_utils_js,
     ]
     template = "tw2.jquery.plugins.jqplot.templates.jqplot"
 
 
 class PollingJQPlotWidget(JQPlotWidget):
     template = "tw2.jquery.plugins.jqplot.templates.pollster"
+
     url = twc.Param("(string) A url to poll")
     url_kwargs = twc.Param("(dict) A dict for a query str", default={})
     interval = twc.Param("(int) milliseconds between pulls", default=0)