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 MochiKit.DOM.appendChildNodes(lista, OPTION({'value':results.msg.id}, results.msg.value));
33 l = MochiKit.DOM.getElement(lista);
36 function _on_alumno_get_error(loading, results)
39 load = MochiKit.DOM.getElement(loading);
40 load.style.visibility = 'hidden';
43 function sacar_de_la_lista(lista)
45 replaceChildNodes(lista,
46 list(ifilterfalse(itemgetter('selected'), $(lista).options))
50 function _do_add(callback, texto, lista, loading)
52 url = callback(texto, lista);
53 t = MochiKit.DOM.getElement(texto);
55 load = MochiKit.DOM.getElement(loading);
56 load.style.visibility = 'visible';
57 var d = loadJSONDoc(url);
58 d.addCallbacks(partial(_on_alumno_get_result, lista, loading), partial(_on_alumno_get_error, loading));
60 t.style.color = "#aaa";
64 class AjaxMultiSelect(widgets.MultipleSelectField):
66 <div style="width:250px" xmlns:py="http://purl.org/kid/ns#">
68 <input type="text" id="${field_id}_nuevo" size="10" value="padron"
70 onfocus="this.style.color='#000'; if (this.value =='padron') { this.value=''; }"
71 onblur="if (this.value == '') { this.style.color='#aaa'; this.value='padron'; }" />
72 <img src="/static/images/loading.gif" align="baseline" style="visibility:hidden;" id="${name}_loading" width="16px" height="16px" />
73 <input type="button" id="_agregar" value="Agregar"
74 onClick=" _do_add(${on_add}, '${field_id}_nuevo', '${field_id}', '${name}_loading'); " />
81 class="${field_class}"
86 <optgroup py:for="group, options in grouped_options"
90 <option py:for="value, desc, attrs in options"
99 <input type="button" id="_sacar" value="Borrar" style="width:100%;"
100 onClick="sacar_de_la_lista('${field_id}'); " />
104 javascript = [widgets.JSSource(MultiSelectAjax)]
105 on_add = "alert('Not defined action');"
107 def __init__(self, **kw):
108 self.params.append('on_add')
109 self.on_add = "alert('Not defined action');"
110 widgets.MultipleSelectField.__init__(self, **kw)
113 function makeOption(option) {
114 return OPTION({"value": option.value}, option.text);
117 function moveOption( fromSelect, toSelect) {
118 // add 'selected' nodes toSelect
119 appendChildNodes(toSelect,
120 map( makeOption,ifilter(itemgetter('selected'), $(fromSelect).options)));
121 // remove the 'selected' fromSelect
122 replaceChildNodes(fromSelect,
123 list(ifilterfalse(itemgetter('selected'), $(fromSelect).options))
128 class AjaxDosListasSelect(widgets.MultipleSelectField):
130 <div xmlns:py="http://purl.org/kid/ns#">
131 <table style="border:0; margin:0px; border-spacing:0px 0px">
133 <td style="padding:0 0 0 0;" align="center">${title_from}</td>
135 <td style="padding:0 0 0 0;" align="center">${title_to}</td>
138 <td style="padding:0 0 0 0;">
142 class="${field_class}"
144 id="${field_id}_from"
146 style="width:200px;">
147 <optgroup py:for="group, options in grouped_options" label="${group}" py:strip="not group">
148 <option py:for="value, desc, attrs in options" value="${value}" py:attrs="attrs" py:content="desc" />
152 <td style="padding:0 10px 0 10px;" valign="center" align="center">
153 <input type="button" value=">>>" style="font-size:90%;" onClick="moveOption('${field_id}_from', '${field_id}_to');" />
156 <input type="button" value="<<<" style="font-size:90%;" onClick="moveOption('${field_id}_to', '${field_id}_from');" />
158 <td style="padding:0 0 0 0;">
163 class="${field_class}"
166 style="width:200px;">
173 javascript = [widgets.JSSource(DosListasAjax)]
177 def __init__(self, **kw):
178 self.params.append('title_from')
179 self.params.append('title_to')
180 self.title_from = " "
181 self.title_to = " "
182 widgets.MultipleSelectField.__init__(self, **kw)