]> git.llucax.com Git - z.facultad/75.52/sercom.git/blob - sercom/widgets.py
070fb76eb316aed853f4eda5ac6ccb37b50ef95c
[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         MochiKit.DOM.appendChildNodes(lista, OPTION({'value':results.msg.id}, results.msg.value));
33         l = MochiKit.DOM.getElement(lista);
34     }
35
36     function _on_alumno_get_error(loading, results)
37     {
38         alert(results)
39         load = MochiKit.DOM.getElement(loading);
40         load.style.visibility = 'hidden';
41     }
42
43     function sacar_de_la_lista(lista)
44     {
45         replaceChildNodes(lista,
46             list(ifilterfalse(itemgetter('selected'), $(lista).options))
47         );
48     }
49
50     function _do_add(callback, texto, lista, loading)
51     {
52         url = callback(texto, lista);
53         t = MochiKit.DOM.getElement(texto);
54
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));
59     }
60 '''
61
62 class AjaxMultiSelect(widgets.MultipleSelectField):
63     template = '''
64     <div style="width:250px" xmlns:py="http://purl.org/kid/ns#">  
65     <div>
66     <input type="text" id="${field_id}_nuevo" size="10" value="padron"
67         style="color:#aaa;"
68         onfocus="this.style.color='#000'; if (this.value =='padron') { this.value=''; }"
69         onblur="if (this.value == '') { this.style.color='#aaa'; this.value='padron'; }" />
70     <img src="/static/images/loading.gif" align="baseline" style="visibility:hidden;" id="${name}_loading" width="16px" height="16px" />
71     <input type="button" id="_agregar" value="Agregar"
72         onClick=" _do_add(${on_add}, '${field_id}_nuevo', '${field_id}', '${name}_loading'); " />
73     </div>
74     <div>
75     <select  
76         multiple="multiple"  
77         size="${size}"  
78         name="${name}"  
79         class="${field_class}"  
80         id="${field_id}"  
81         py:attrs="attrs"  
82         style="width:250px;"
83     >
84         <optgroup py:for="group, options in grouped_options"  
85             label="${group}"  
86             py:strip="not group"  
87         >  
88         <option py:for="value, desc, attrs in options"  
89             value="${value}"  
90             py:attrs="attrs"  
91             py:content="desc"  
92         />  
93         </optgroup>  
94     </select>
95     </div>
96     <div align="center">
97     <input type="button" id="_sacar" value="Borrar" style="width:100%;"
98         onClick="sacar_de_la_lista('${field_id}'); " />
99     </div>
100     </div>
101     '''
102     javascript = [widgets.JSSource(MultiSelectAjax)]
103     on_add = "alert('Not defined action');"
104
105     def __init__(self, **kw):
106         self.params.append('on_add')
107         self.on_add = "alert('Not defined action');"
108         widgets.MultipleSelectField.__init__(self, **kw)