#!/usr/bin/env python # coding: utf8 from gluon.html import * from gluon.utils import * class AJAXSELECT(SELECT): def __init__(self, source, query, **attributes): SELECT.__init__( self, **attributes) self.source = source self.query = query def elements(self, *args, **kargs): matches = DIV.elements(self, *args, **kargs) if args and 'script' in args: matches.insert(0, self.hookScript() ) return matches def hookScript(self): scriptText = 'YAHOO.util.Event.onContentReady("' + self.attributes['_id'] + '", function() { \n' scriptText += '\tthis.ajax_selection = new YAHOO.Ext.AjaxSelect(this, {source : "' + self.source + '"});\n' scriptText += '\tthis.ajax_selection.update("' + ( self.query or '' ) + '");\n' scriptText += '}); \n' return SCRIPT( scriptText, _language='javascript' ) def xml(self): return self.hookScript().xml() + '\n' + SELECT.xml(self) def _postprocessing(self): if '_id' not in self.attributes: self.attributes['_id'] = 'ajax_select_' + web2py_uuid()