+'''
+
+MultiSelectAjax = '''
+
+ function _on_alumno_get_result(lista, loading, results)
+ {
+ load = MochiKit.DOM.getElement(loading);
+ load.style.visibility = 'hidden';
+ if (results.error) {
+ alert(results.msg);
+ return;
+ }
+ MochiKit.DOM.appendChildNodes(lista, OPTION({'value':results.msg.id}, results.msg.value));
+ l = MochiKit.DOM.getElement(lista);
+ }
+
+ function _on_alumno_get_error(loading, results)
+ {
+ alert(results)
+ load = MochiKit.DOM.getElement(loading);
+ load.style.visibility = 'hidden';
+ }
+
+ function sacar_de_la_lista(lista)
+ {
+ l = MochiKit.DOM.getElement(lista);
+ if (l.selectedIndex < 0) return;
+
+ /* caso especial, 1 solo item */
+ if (l.options.length == 1) {
+ l.options.length = 0
+ return;
+ }
+
+ for (i=l.selectedIndex; i<l.options.length-1;i++)
+ l.options[i] = l.options[i+1];
+ }
+
+ function _do_add(callback, texto, lista, loading)
+ {
+ url = callback(texto, lista);
+ t = MochiKit.DOM.getElement(texto);
+
+ load = MochiKit.DOM.getElement(loading);
+ load.style.visibility = 'visible';
+ var d = loadJSONDoc(url);
+ d.addCallbacks(partial(_on_alumno_get_result, lista, loading), partial(_on_alumno_get_error, loading));
+ }
+'''
+
+class AjaxMultiSelect(widgets.MultipleSelectField):
+ template = '''
+ <div style="width:250px" xmlns:py="http://purl.org/kid/ns#">
+ <div>
+ <input type="text" id="${field_id}_nuevo" size="10" value="padron"
+ style="color:#aaa;"
+ onfocus="this.style.color='#000'; if (this.value =='padron') { this.value=''; }"
+ onblur="if (this.value == '') { this.style.color='#aaa'; this.value='padron'; }" />
+ <img src="/static/images/loading.gif" align="baseline" style="visibility:hidden;" id="${name}_loading" width="16px" height="16px" />
+ <input type="button" id="_agregar" value="Agregar"
+ onClick=" _do_add(${on_add}, '${field_id}_nuevo', '${field_id}', '${name}_loading'); " />
+ </div>
+ <div>
+ <select
+ multiple="multiple"
+ size="${size}"
+ name="${name}"
+ class="${field_class}"
+ id="${field_id}"
+ py:attrs="attrs"
+ style="width:250px;"
+ >
+ <optgroup py:for="group, options in grouped_options"
+ label="${group}"
+ py:strip="not group"
+ >
+ <option py:for="value, desc, attrs in options"
+ value="${value}"
+ py:attrs="attrs"
+ py:content="desc"
+ />
+ </optgroup>
+ </select>
+ </div>
+ <div align="center">
+ <input type="button" id="_sacar" value="Borrar" style="width:100%;"
+ onClick="sacar_de_la_lista('${field_id}'); " />
+ </div>
+ </div>