</span>
'''
-AlumnoMultiSelectAjax = '''
- function agregar_a_la_lista(texto, lista)
+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);
+ for (i=0; i<l.options.length; i++) {
+ l.options[i].selected = true;
+ }
+ }
+
+ function _on_alumno_get_error(loading, results)
{
- t = MochiKit.DOM.getElement(texto);
- MochiKit.DOM.appendChildNodes(lista, OPTION(t.value));
- t.value = "";
+ 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];
}
'''
-class AlumnoMultiSelect(widgets.MultipleSelectField):
+class AjaxMultiSelect(widgets.MultipleSelectField):
template = '''
- <table xmlns:py="http://purl.org/kid/ns#" style="border:none; width:0%;">
- <tr><td>
- <input type="text" id="${field_id}_nuevo" /><input type="button" id="_agregar" value="Agregar"
- onClick=" agregar_a_la_lista('${field_id}_nuevo', '${field_id}'); " />
- </td></tr>
- <tr><td>
+ <div style="width:250px" xmlns:py="http://purl.org/kid/ns#">
+ <div>
+ <input type="text" id="${field_id}_nuevo" size="10" />
+ <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=" ${on_add}('${field_id}_nuevo', '${field_id}', '${name}_loading'); " />
+ </div>
+ <div>
<select
multiple="multiple"
size="${size}"
/>
</optgroup>
</select>
- </td></tr>
- <tr><td align="center">
- <input type="button" id="_sacar" value="Borrar"
+ </div>
+ <div align="center">
+ <input type="button" id="_sacar" value="Borrar" style="width:100%;"
onClick="sacar_de_la_lista('${field_id}'); " />
- </td></tr>
- </table>
+ </div>
+ </div>
'''
- javascript = [widgets.JSSource(AlumnoMultiSelectAjax)]
+ javascript = [widgets.JSSource(MultiSelectAjax)]
+ on_add = "alert('Not defined action');"
+ def __init__(self, **kw):
+ self.params.append('on_add')
+ self.on_add = "alert('Not defined action');"
+ widgets.MultipleSelectField.__init__(self, **kw)