]> git.llucax.com Git - z.facultad/75.52/sercom.git/blob - sercom/widgets.py
Hago que VOLVER sea un volver de verdad al punto de origen
[z.facultad/75.52/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 MultiSelectAjax = '''
23
24     function _on_alumno_get_result(lista, loading, results)
25     {
26         load = MochiKit.DOM.getElement(loading);
27         load.style.visibility = 'hidden';
28         if (results.error) {
29             alert(results.msg);
30             return;
31         }
32         /* Verifico si esta y no lo agrego si esta repetido */
33         l = MochiKit.DOM.getElement(lista);
34         esta = false;
35         for(i=0; i<l.options.length; i++) {
36             if (results.msg.id == l.options[i].value) {
37                 esta = true;
38                 break;
39             }
40         }
41         if (!esta)
42             MochiKit.DOM.appendChildNodes(lista, OPTION({'value':results.msg.id}, results.msg.value));
43     }
44
45     function _on_alumno_get_error(loading, results)
46     {
47         alert(results)
48         load = MochiKit.DOM.getElement(loading);
49         load.style.visibility = 'hidden';
50     }
51
52     function sacar_de_la_lista(lista)
53     {
54         replaceChildNodes(lista,
55             list(ifilterfalse(itemgetter('selected'), $(lista).options))
56         );
57     }
58
59     function _do_add(callback, texto, lista, loading)
60     {
61         url = callback(texto, lista);
62         t = MochiKit.DOM.getElement(texto);
63
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));
68         t.value = 'padron';
69         t.style.color = "#aaa";
70     }
71 '''
72
73 class AjaxMultiSelect(widgets.MultipleSelectField):
74     template = '''
75     <div style="width:250px" xmlns:py="http://purl.org/kid/ns#">
76     <div>
77     <input type="text" id="${field_id}_nuevo" size="10" value="padron"
78         style="color:#aaa;"
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'); " />
84     </div>
85     <div>
86     <select
87         multiple="multiple"
88         size="${size}"
89         name="${name}"
90         class="${field_class}"
91         id="${field_id}"
92         py:attrs="attrs"
93         style="width:250px;"
94     >
95         <optgroup py:for="group, options in grouped_options"
96             label="${group}"
97             py:strip="not group"
98         >
99         <option py:for="value, desc, attrs in options"
100             value="${value}"
101             py:attrs="attrs"
102             py:content="desc"
103         />
104         </optgroup>
105     </select>
106     </div>
107     <div align="center">
108     <input type="button" id="_sacar" value="Borrar" style="width:100%;"
109         onClick="sacar_de_la_lista('${field_id}'); " />
110     </div>
111     </div>
112     '''
113     javascript = [widgets.JSSource(MultiSelectAjax)]
114     on_add = "alert('Not defined action');"
115
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)
120
121 DosListasAjax = '''
122     function makeOption(option) {
123         return OPTION({"value": option.value}, option.text);
124     }
125
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))
133         );
134     }
135 '''
136
137 class AjaxDosListasSelect(widgets.MultipleSelectField):
138     template = '''
139     <div xmlns:py="http://purl.org/kid/ns#">
140     <table style="border:0; margin:0px; border-spacing:0px 0px">
141     <tr class="nada">
142         <td style="padding:0 0 0 0;" align="center">${title_from}</td>
143         <td>&nbsp;</td>
144         <td style="padding:0 0 0 0;" align="center">${title_to}</td>
145     </tr>
146     <tr class="nada">
147     <td style="padding:0 0 0 0;">
148     <select
149         multiple="multiple"
150         size="${size}"
151         class="${field_class}"
152         name="${name}_from"
153         id="${field_id}_from"
154         py:attrs="attrs"
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" />
158         </optgroup>
159     </select>
160     </td>
161     <td style="padding:0 10px 0 10px;" valign="center" align="center">
162         <input type="button" value="&gt;&gt;&gt;" style="font-size:90%;" onClick="moveOption('${field_id}_from', '${field_id}_to');" />
163         <br />
164         <br />
165         <input type="button" value="&lt;&lt;&lt;" style="font-size:90%;" onClick="moveOption('${field_id}_to', '${field_id}_from');" />
166     </td>
167     <td style="padding:0 0 0 0;">
168     <select
169         multiple="multiple"
170         size="${size}"
171         name="${name}_to"
172         class="${field_class}"
173         id="${field_id}_to"
174         py:attrs="attrs"
175         style="width:200px;">
176     </select>
177     </td>
178     </tr>
179     </table>
180     </div>
181     '''
182     javascript = [widgets.JSSource(DosListasAjax)]
183     title_from = ""
184     title_to = ""
185
186     def __init__(self, **kw):
187         self.params.append('title_from')
188         self.params.append('title_to')
189         self.title_from = "&nbsp;"
190         self.title_to = "&nbsp;"
191         widgets.MultipleSelectField.__init__(self, **kw)
192