def central_station(endpoint, start=True): """ This function creates a JSSource widget which should be declared as dependency for all widgets that have java-script that relies on the existence of a "central_station". """ opts = dict( endpoint=endpoint, ) start = "true" if start else "false" return JSSource(""" $(function() { // one global window.central_station = new CentralStation(%(opts)s); if(%(start)s) { window.central_station.start(); } }); """ % dict(opts=dumps(opts), start=start), javascript = [centralstation_js] )
# Lil' chunk o' CSS for tasty eye-candy ;) # External css files can be wrapped with CSSLink css = CSSSource(""" label.required, .fielderror { font-weight: bold; color: red; }; """) # We define the source for some JS functions we're going to interface # External js files can be wrapped with JSLink functions = JSSource( """ var focus_element = function (elem) { var elem = document.getElementById(elem); elem.focus(); elem.select(); }; """, ) alert = js_function('alert') focus_element = js_function('focus_element') # This is needed because of the way TurboGears validates as it adds # spurious variables to the value being validated. class FilteringSchema(Schema): filter_extra_fields = True allow_extra_fields = True