X-Git-Url: https://git.llucax.com/software/sercom.git/blobdiff_plain/2c23f36223624514f3ad84a7c629792a27e74a68..0b7fa756174b1d0014b030c0152e0be7f23c4fd4:/sercom/widgets.py diff --git a/sercom/widgets.py b/sercom/widgets.py index 218fb3a..53d9e4c 100644 --- a/sercom/widgets.py +++ b/sercom/widgets.py @@ -19,61 +19,61 @@ class CustomTextField(widgets.TextField): ''' -AlumnoMultiSelectAjax = ''' +MultiSelectAjax = ''' - function _on_alumno_get_result(lista, results) + 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(results.msg)); + MochiKit.DOM.appendChildNodes(lista, OPTION({'value':results.msg.id}, results.msg.value)); + l = MochiKit.DOM.getElement(lista); } - function _on_alumno_get_error(results) + function _on_alumno_get_error(loading, results) { alert(results) + load = MochiKit.DOM.getElement(loading); load.style.visibility = 'hidden'; } - function agregar_a_la_lista(texto, lista) + function sacar_de_la_lista(lista) { - load = MochiKit.DOM.getElement('loading'); - load.style.visibility = 'visible'; - t = MochiKit.DOM.getElement(texto); - url = "/grupo/get_inscripto?cursoid=1&padron="+t.value; - var d = loadJSONDoc(url); - d.addCallbacks(partial(_on_alumno_get_result, lista), _on_alumno_get_error); - t.value = ""; + replaceChildNodes(lista, + list(ifilterfalse(itemgetter('selected'), $(lista).options)) + ); } - function sacar_de_la_lista(lista) + function _do_add(callback, texto, lista, loading) { - 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; - } + url = callback(texto, lista); + t = MochiKit.DOM.getElement(texto); - for (i=l.selectedIndex; i - - - +
+
+ + - - + onClick=" _do_add(${on_add}, '${field_id}_nuevo', '${field_id}', '${name}_loading'); " /> +
+
- - - +
+ - +
+
+ ''' + 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) + +DosListasAjax = ''' + function makeOption(option) { + return OPTION({"value": option.value}, option.text); + } + + function moveOption( fromSelect, toSelect) { + // add 'selected' nodes toSelect + appendChildNodes(toSelect, + map( makeOption,ifilter(itemgetter('selected'), $(fromSelect).options))); + // remove the 'selected' fromSelect + replaceChildNodes(fromSelect, + list(ifilterfalse(itemgetter('selected'), $(fromSelect).options)) + ); + } +''' + +class AjaxDosListasSelect(widgets.MultipleSelectField): + template = ''' +
+ + + + + + + + + + +
${title_from} ${title_to}
+ + + +
+
+ +
+ +
+
''' - javascript = [widgets.JSSource(AlumnoMultiSelectAjax)] + javascript = [widgets.JSSource(DosListasAjax)] + title_from = "" + title_to = "" + + def __init__(self, **kw): + self.params.append('title_from') + self.params.append('title_to') + self.title_from = " " + self.title_to = " " + widgets.MultipleSelectField.__init__(self, **kw)