4 from turbogears import widgets
6 class CustomTextField(widgets.TextField):
7 """Un input con un div al lado para ponerle info"""
9 <span xmlns:py="http://purl.org/kid/ns#">
13 class="${field_class}"
18 <span id="${field_id}_info" />
24 function _on_alumno_get_result(lista, loading, results)
26 load = MochiKit.DOM.getElement(loading);
27 load.style.visibility = 'hidden';
32 /* Verifico si esta y no lo agrego si esta repetido */
33 l = MochiKit.DOM.getElement(lista);
35 for(i=0; i<l.options.length; i++) {
36 if (results.msg.id == l.options[i].value) {
42 MochiKit.DOM.appendChildNodes(lista, OPTION({'value':results.msg.id}, results.msg.value));
45 function _on_alumno_get_error(loading, results)
48 load = MochiKit.DOM.getElement(loading);
49 load.style.visibility = 'hidden';
52 function sacar_de_la_lista(lista)
54 replaceChildNodes(lista,
55 list(ifilterfalse(itemgetter('selected'), $(lista).options))
59 function _do_add(callback, texto, lista, loading)
61 url = callback(texto, lista);
62 t = MochiKit.DOM.getElement(texto);
64 load = MochiKit.DOM.getElement(loading);
65 load.style.visibility = 'visible';
66 var d = loadJSONDoc(url);
67 d.addCallbacks(partial(_on_alumno_get_result, lista, loading), partial(_on_alumno_get_error, loading));
69 t.style.color = "#aaa";
73 class AjaxMultiSelect(widgets.MultipleSelectField):
75 <div style="width:250px" xmlns:py="http://purl.org/kid/ns#">
77 <input type="text" id="${field_id}_nuevo" size="10" value="padron"
79 onfocus="this.style.color='#000'; if (this.value =='padron') { this.value=''; }"
80 onblur="if (this.value == '') { this.style.color='#aaa'; this.value='padron'; }" />
81 <img src="/static/images/loading.gif" align="baseline" style="visibility:hidden;" id="${name}_loading" width="16px" height="16px" />
82 <input type="button" id="_agregar" value="Agregar"
83 onClick=" _do_add(${on_add}, '${field_id}_nuevo', '${field_id}', '${name}_loading'); " />
90 class="${field_class}"
95 <optgroup py:for="group, options in grouped_options"
99 <option py:for="value, desc, attrs in options"
108 <input type="button" id="_sacar" value="Borrar" style="width:100%;"
109 onClick="sacar_de_la_lista('${field_id}'); " />
113 javascript = [widgets.JSSource(MultiSelectAjax)]
114 on_add = "alert('Not defined action');"
116 def __init__(self, **kw):
117 self.params.append('on_add')
118 self.on_add = "alert('Not defined action');"
119 widgets.MultipleSelectField.__init__(self, **kw)
122 function makeOption(option) {
123 return OPTION({"value": option.value}, option.text);
126 function moveOption( fromSelect, toSelect) {
127 // add 'selected' nodes toSelect
128 appendChildNodes(toSelect,
129 map( makeOption,ifilter(itemgetter('selected'), $(fromSelect).options)));
130 // remove the 'selected' fromSelect
131 replaceChildNodes(fromSelect,
132 list(ifilterfalse(itemgetter('selected'), $(fromSelect).options))
137 class AjaxDosListasSelect(widgets.MultipleSelectField):
139 <div xmlns:py="http://purl.org/kid/ns#">
140 <table style="border:0; margin:0px; border-spacing:0px 0px">
142 <td style="padding:0 0 0 0;" align="center">${title_from}</td>
144 <td style="padding:0 0 0 0;" align="center">${title_to}</td>
147 <td style="padding:0 0 0 0;">
151 class="${field_class}"
153 id="${field_id}_from"
155 style="width:200px;">
156 <optgroup py:for="group, options in grouped_options" label="${group}" py:strip="not group">
157 <option py:for="value, desc, attrs in options" value="${value}" py:attrs="attrs" py:content="desc" />
161 <td style="padding:0 10px 0 10px;" valign="center" align="center">
162 <input type="button" value=">>>" style="font-size:90%;" onClick="moveOption('${field_id}_from', '${field_id}_to'); ${move_signal}; " />
165 <input type="button" value="<<<" style="font-size:90%;" onClick="moveOption('${field_id}_to', '${field_id}_from'); ${move_signal}; " />
167 <td style="padding:0 0 0 0;">
172 class="${field_class}"
175 style="width:200px;">
182 javascript = [widgets.JSSource(DosListasAjax)]
187 def __init__(self, **kw):
188 self.params.append('title_from')
189 self.params.append('title_to')
190 self.params.append('move_signal')
191 self.title_from = " "
192 self.title_to = " "
193 self.move_signal = ""
194 widgets.MultipleSelectField.__init__(self, **kw)