]> git.llucax.com Git - software/sercom.git/blob - sercom/widgets.py
Heredar CasoDePrueba de Comando (por conveniencia de atributos nomás).
[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 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         t.value = 'padron';
60         t.style.color = "#aaa";
61     }
62 '''
63
64 class AjaxMultiSelect(widgets.MultipleSelectField):
65     template = '''
66     <div style="width:250px" xmlns:py="http://purl.org/kid/ns#">  
67     <div>
68     <input type="text" id="${field_id}_nuevo" size="10" value="padron"
69         style="color:#aaa;"
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'); " />
75     </div>
76     <div>
77     <select  
78         multiple="multiple"  
79         size="${size}"  
80         name="${name}"  
81         class="${field_class}"  
82         id="${field_id}"  
83         py:attrs="attrs"  
84         style="width:250px;"
85     >
86         <optgroup py:for="group, options in grouped_options"  
87             label="${group}"  
88             py:strip="not group"  
89         >  
90         <option py:for="value, desc, attrs in options"  
91             value="${value}"  
92             py:attrs="attrs"  
93             py:content="desc"  
94         />  
95         </optgroup>  
96     </select>
97     </div>
98     <div align="center">
99     <input type="button" id="_sacar" value="Borrar" style="width:100%;"
100         onClick="sacar_de_la_lista('${field_id}'); " />
101     </div>
102     </div>
103     '''
104     javascript = [widgets.JSSource(MultiSelectAjax)]
105     on_add = "alert('Not defined action');"
106
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)
111
112 DosListasAjax = '''
113     function makeOption(option) {
114         return OPTION({"value": option.value}, option.text);
115     }
116
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))
124         );
125     }
126
127 '''
128
129 class AjaxDosListasSelect(widgets.MultipleSelectField):
130     template = '''
131     <div xmlns:py="http://purl.org/kid/ns#">  
132     <table style="border:0; margin:0px; border-spacing:0px 0px">
133     <tr class="nada">
134         <td style="padding:0 0 0 0;" align="center">${title_from}</td>
135         <td>&nbsp;</td>
136         <td style="padding:0 0 0 0;" align="center">${title_to}</td>
137     </tr>
138     <tr class="nada">
139     <td style="padding:0 0 0 0;">
140     <select  
141         multiple="multiple"
142         size="${size}"
143         class="${field_class}"
144         name="${name}_from"
145         id="${field_id}_from"
146         py:attrs="attrs"
147         style="width:200px;">
148         <optgroup py:for="group, options in grouped_options" label="${group}" py:strip="not group">
149         <option py:for="value, desc, attrs in options" value="${value}" py:attrs="attrs" py:content="desc" />  
150         </optgroup>  
151     </select>
152     </td>
153     <td style="padding:0 10px 0 10px;" valign="center" align="center">
154         <input type="button" value="&gt;&gt;&gt;" style="font-size:90%;" onClick="moveOption('${field_id}_from', '${field_id}_to');" />
155         <br />
156         <br />
157         <input type="button" value="&lt;&lt;&lt;" style="font-size:90%;" onClick="moveOption('${field_id}_to', '${field_id}_from');" />
158     </td>
159     <td style="padding:0 0 0 0;">
160     <select  
161         multiple="multiple"
162         size="${size}"
163         name="${name}_to"
164         class="${field_class}"
165         id="${field_id}_to"
166         py:attrs="attrs"
167         style="width:200px;">
168     </select>
169     </td>
170     </tr>
171     </table>
172     </div>
173     '''
174     javascript = [widgets.JSSource(DosListasAjax)]
175     title_from = ""
176     title_to = ""
177
178     def __init__(self, **kw):
179         self.params.append('title_from')
180         self.params.append('title_to')
181         self.title_from = "&nbsp;"
182         self.title_to = "&nbsp;"
183         widgets.MultipleSelectField.__init__(self, **kw)
184