d.addCallbacks(procesar, err);
}
- function onsubmit()
+ function doSubmit()
{
/* TODO : Validar datos y evitar el submit si no esta completo */
l.options[i].selected = true;
}
/* Selecciono todos los miembros si no, no llegan al controllere*/
- l = MochiKit.DOM.getElement('form_docentes_curso');
+ l = MochiKit.DOM.getElement('form_docentes_to');
for (i=0; i<l.options.length; i++) {
l.options[i].selected = true;
}
help_text=_(u'Descripcion.'),
validator=V.UnicodeString(not_empty=False, strip=True))
- docentes = W.MultipleSelectField(name="docentes",
- label=_(u'Docentes'),
- attrs=dict(style='width:300px'),
+ #docentes = W.MultipleSelectField(name="docentes",
+ # label=_(u'Docentes'),
+ # attrs=dict(style='width:300px'),
+ # options=get_docentes,
+ # validator=V.Int(not_empty=True))
+ #addDocente = W.Button(default='Asignar', label='',
+ # attrs=dict( onclick='mover("form_docentes","form_docentes_curso")'))
+ #remDocente = W.Button(default='Remover', label='',
+ # attrs=dict( onclick='remover("form_docentes_curso","form_docentes")'))
+ #docentes_curso = W.MultipleSelectField(name="docentes_curso",
+ # label=_(u'Docentes del curso'),
+ # attrs=dict(style='width:300px'),
+# # options=get_docentes_curso,
+ # validator=V.Int(not_empty=True))
+ docentes = AjaxDosListasSelect(label=_(u'Docentes'),
+ title_from="Docentes",
+ title_to="Docentes del Curso",
options=get_docentes,
validator=V.Int(not_empty=True))
- addDocente = W.Button(default='Asignar', label='',
- attrs=dict( onclick='mover("form_docentes","form_docentes_curso")'))
- remDocente = W.Button(default='Remover', label='',
- attrs=dict( onclick='remover("form_docentes_curso","form_docentes")'))
- docentes_curso = W.MultipleSelectField(name="docentes_curso",
- label=_(u'Docentes del curso'),
- attrs=dict(style='width:300px'),
-# options=get_docentes_curso,
- validator=V.Int(not_empty=True))
alumnos = AjaxMultiSelect(label=_(u'Alumnos'),
validator=V.Int(),
fields = Fields()
javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('anio');"),
W.JSSource(ajax)]
- form_attrs = dict(onsubmit='return onsubmit()')
+ form_attrs = dict(onsubmit='return doSubmit();')
form = CursoForm()
#}}}
def create(self, **kw):
"""Save or create record to model"""
print "--KW--"
- print kw
- docentes = kw.get('docentes_curso', [])
+ docentes = kw.get('docentes_to', [])
alumnos = kw.get('alumnos', [])
- del(kw['remDocente'])
- del(kw['addDocente'])
- del(kw['docentes_curso'])
+ del(kw['docentes_to'])
del(kw['alumnos'])
r = validate_new(kw)
""" Agrego la nueva seleccion de docentes """
values.cursoID = r.id
values.descripcion = r.descripcion
# cargo la lista con los docentes asignados al curso
- values.docentes_curso = [{"id":d.docente.id, "label":d.docente.shortrepr()} for d in DocenteInscripto.selectBy(curso=r.id)]
+ values.docentes_to = [{"id":d.docente.id, "label":d.docente.shortrepr()} for d in DocenteInscripto.selectBy(curso=r.id)]
values.alumnos_inscriptos = [{"id":a.alumno.id, "label":a.alumno.shortrepr()} for a in AlumnoInscripto.selectBy(curso=r.id)]
return dict(name=name, namepl=namepl, record=values, form=form)
params = dict([(k,v) for (k,v) in kw.iteritems() if k in Curso.sqlmeta.columns.keys()])
r = validate_set(id, params)
- docentes = kw.get('docentes_curso', [])
+ docentes = kw.get('docentes_to', [])
alumnos = kw.get('alumnos', [])
alumnos_inscriptos = AlumnoInscripto.selectBy(curso=id)
""" levanto los doncentes del curso para ver cuales tengo que agregar """
function init_data() {
// MochiKit.DOM.getElement('form_responsable').focus();
MochiKit.DOM.getElement('form_anio').focus();
- <span py:for="d in record.docentes_curso" py:strip="True">
- MochiKit.DOM.appendChildNodes("form_docentes_curso", OPTION({"value":${d['id']}}, '${d['label']}'))
+ <span py:for="d in record.docentes_to" py:strip="True">
+ MochiKit.DOM.appendChildNodes("form_docentes_to", OPTION({"value":${d['id']}}, '${d['label']}'))
</span>
<span py:for="a in record.alumnos_inscriptos" py:strip="True">
</span>
}
MochiKit.DOM.addLoadEvent(init_data)
-
- 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)));
- }
-
- function mover( src, dest ) {
- moveOption(src, dest)
- }
-
- function remover (src, dest) {
- replaceChildNodes(src,list(ifilterfalse(itemgetter('selected'), $(src).options)))
- }
-
</script>
<body>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
py:extends="'../../../templates/master.kid'">
<head>
-
-<script type="text/javascript">
- 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))
- );
- }
-
- function mover(src, dest) {
- moveOption(src, dest)
- }
-
- function remover( src, dest ) {
- moveOption(src, dest)
- }
-</script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
<title>new</title>
</head>
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 = '''
+ <div xmlns:py="http://purl.org/kid/ns#">
+ <table style="border:0; margin:0px; border-spacing:0px 0px">
+ <tr class="nada">
+ <td style="padding:0 0 0 0;" align="center">${title_from}</td>
+ <td> </td>
+ <td style="padding:0 0 0 0;" align="center">${title_to}</td>
+ </tr>
+ <tr class="nada">
+ <td style="padding:0 0 0 0;">
+ <select
+ multiple="multiple"
+ size="${size}"
+ class="${field_class}"
+ name="${name}_from"
+ id="${field_id}_from"
+ py:attrs="attrs"
+ style="width:200px;">
+ <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>
+ </td>
+ <td style="padding:0 10px 0 10px;" valign="center" align="center">
+ <input type="button" value=">>>" style="font-size:90%;" onClick="moveOption('${field_id}_from', '${field_id}_to');" />
+ <br />
+ <br />
+ <input type="button" value="<<<" style="font-size:90%;" onClick="moveOption('${field_id}_to', '${field_id}_from');" />
+ </td>
+ <td style="padding:0 0 0 0;">
+ <select
+ multiple="multiple"
+ size="${size}"
+ name="${name}_to"
+ class="${field_class}"
+ id="${field_id}_to"
+ py:attrs="attrs"
+ style="width:200px;">
+ </select>
+ </td>
+ </tr>
+ </table>
+ </div>
+ '''
+ 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)
+