]> git.llucax.com Git - software/sercom.git/blob - sercom/widgets.py
309adc0e9d1a2296b99ae8ee236b80373e362675
[software/sercom.git] / sercom / widgets.py
1 # Custom useful widget
2 #
3
4 from turbogears import widgets
5
6 class CustomTextField(widgets.TextField):
7     """Un input con un div al lado para ponerle info"""
8     template = '''
9         <span xmlns:py="http://purl.org/kid/ns#">
10         <input  
11             type="text"  
12             name="${name}"  
13             class="${field_class}"  
14             id="${field_id}"  
15             value="${value}"  
16             py:attrs="attrs"  
17          />
18          <span id="${field_id}_info" />
19         </span>
20 '''
21
22 AlumnoMultiSelectAjax = '''
23     function agregar_a_la_lista(texto, lista)
24     {
25         t = MochiKit.DOM.getElement(texto);
26         MochiKit.DOM.appendChildNodes(lista, OPTION(t.value));
27         t.value = "";
28     }
29
30     function sacar_de_la_lista(lista)
31     {
32         l = MochiKit.DOM.getElement(lista);
33         if (l.selectedIndex < 0) return;
34
35         for (i=l.selectedIndex; i<l.options.length-1;i++)
36             l.options[i] = l.options[i+1];
37     }
38 '''
39
40 class AlumnoMultiSelect(widgets.MultipleSelectField):
41     template = '''
42     <table xmlns:py="http://purl.org/kid/ns#" style="border:none; width:0%;">  
43     <tr><td>
44     <input type="text" id="${field_id}_nuevo" /><input type="button" id="_agregar" value="Agregar"
45         onClick=" agregar_a_la_lista('${field_id}_nuevo', '${field_id}'); " />
46     </td></tr>
47     <tr><td>
48     <select  
49         multiple="multiple"  
50         size="${size}"  
51         name="${name}"  
52         class="${field_class}"  
53         id="${field_id}"  
54         py:attrs="attrs"  
55         style="width:250px;"
56     >
57         <optgroup py:for="group, options in grouped_options"  
58             label="${group}"  
59             py:strip="not group"  
60         >  
61         <option py:for="value, desc, attrs in options"  
62             value="${value}"  
63             py:attrs="attrs"  
64             py:content="desc"  
65         />  
66         </optgroup>  
67     </select>
68     </td></tr>
69     <tr><td align="center">
70     <input type="button" id="_sacar" value="Borrar"
71         onClick="sacar_de_la_lista('${field_id}'); " />
72     </td></tr>
73     </table>
74     '''
75     javascript = [widgets.JSSource(AlumnoMultiSelectAjax)]
76