Mercurial > libervia-templates
comparison sat_templates/templates/default/input/xmlui.html @ 164:e9f0a4215e46
multi-sites handling (moved templates to "templates" sub-directory) + noscript styles handling.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 10 Sep 2018 08:53:33 +0200 |
parents | sat_templates/default/input/xmlui.html@33c7ce833d3f |
children | 4b5ad18f6ece |
comparison
equal
deleted
inserted
replaced
163:33f67228686a | 164:e9f0a4215e46 |
---|---|
1 {% import 'input/field.html' as field %} | |
2 | |
3 {# generate methods #} | |
4 | |
5 {% macro generate_container(cont, config) %} | |
6 {% if cont.type == 'vertical' %} | |
7 {{ vertical_container(cont, config) }} | |
8 {% elif cont.type == 'pairs' %} | |
9 {{ pairs_container(cont, config) }} | |
10 {% elif cont.type == 'label' %} | |
11 {{ label_container(cont, config) }} | |
12 {% endif %} | |
13 {% endmacro %} | |
14 | |
15 {% macro generate_widget(wid, config, id=none) %} | |
16 {% if wid.type == 'text' %} | |
17 {{ text_widget(wid, config, id=id) }} | |
18 {% elif wid.type == 'label' %} | |
19 {{ label_widget(wid, config) }} | |
20 {% elif wid.type == 'string' %} | |
21 {{ string_widget(wid, config, id=id) }} | |
22 {% elif wid.type == 'jid' %} | |
23 {# TODO: proper JID widget #} | |
24 {{ string_widget(wid, config, id=id) }} | |
25 {% elif wid.type == 'textbox' %} | |
26 {{ textbox_widget(wid, config, id=id) }} | |
27 {% elif wid.type == 'list' %} | |
28 {{ list_widget(wid, config, id=id) }} | |
29 {% endif %} | |
30 {% endmacro %} | |
31 | |
32 {% macro generate_children(cont, config) %} | |
33 {% for child in cont.children %} | |
34 {% if child.category == 'container' %} | |
35 {{ generate_container(child, config) }} | |
36 {% else %} | |
37 {{ generate_widget(child, config) }} | |
38 {% endif %} | |
39 {% endfor %} | |
40 | |
41 {% endmacro %} | |
42 | |
43 {% macro generate(xmlui, form=true, filters=none, attributes=none) %} | |
44 {# generate HTML from XMLUI | |
45 @param xmlui(template_xmlui.XMLUIPanel): xmlui to use | |
46 @param form(bool): if true will generate form elements | |
47 @param filters(dict,none): filters as expected by item_filter | |
48 @param attributes(dict,none): extra attributes to put on named widgets | |
49 #} | |
50 {% set config = {'form':form, 'filters':filters or {}, 'attrs': attributes or {}} %} | |
51 {{ generate_container(xmlui.main_cont, config) }} | |
52 {% endmacro %} | |
53 | |
54 {% macro generate_table(xmlui_items, fields, formatters, tr_class_fields, on_click) %} | |
55 {# generate a HTML table from requested widgets names | |
56 @param xmlui_items(iterable[unicode]): list of xmlui to show (one per row) | |
57 @param fields(tuple[unicode,unicode]): fields to show (name, label) | |
58 @param formatters(dict): dictionary of templates to format values: | |
59 field_name => template | |
60 if no formatter is set (or None is used) for a field, it will be used unmodified. | |
61 current xmlui items will be set as "item" key | |
62 @param tr_class_fields(iterable[unicode]): name of fields to use as class | |
63 class will be "{name}_{value}" where name is field name, and value field value | |
64 all lowercase/stripped | |
65 @param on_click(data_objects.OnClick): thing to do when clicking on a row | |
66 #} | |
67 {% if formatters is undefined %} | |
68 {% set formatters = {} %} | |
69 {% endif %} | |
70 {% if on_click is undefined %} | |
71 {% set on_click = {} %} | |
72 {% endif %} | |
73 <table> | |
74 <thead> | |
75 <tr> | |
76 {% for name,label in fields %} | |
77 <th>{{ label }}</th> | |
78 {% endfor %} | |
79 </tr> | |
80 </thead> | |
81 <tbody> | |
82 {% for xmlui in xmlui_items %} | |
83 {% set link=on_click.formatUrl(item=xmlui.widget_value) if on_click.url else none %} | |
84 <tr {{ {'class': xmlui|xmlui_class(tr_class_fields)}|xmlattr }}> | |
85 | |
86 {% for name,label in fields %} | |
87 <td {{ {'class': 'td_'+name}|xmlattr }}> | |
88 {% for value in xmlui.widgets[name].values %} | |
89 <a {{ {'href':link}|xmlattr }}>{{ value|adv_format(formatters.get(name),item=xmlui.widget_value) }}</a> | |
90 {% endfor %} | |
91 </td> | |
92 {% endfor %} | |
93 </tr> | |
94 {% endfor %} | |
95 </tbody> | |
96 </table> | |
97 {% endmacro %} | |
98 | |
99 | |
100 | |
101 | |
102 {% macro generate_list(xmlui_items, fields, formatters, item_class_fields, on_click) %} | |
103 {# generate a list of rendered XMLUI from requested widgets names | |
104 very similar to generate_table but generate a list instead of a tabme | |
105 @param xmlui_items(iterable[unicode]): list of xmlui to show | |
106 @param fields(tuple[unicode,unicode]): fields to show (name, label) | |
107 @param formatters(dict): dictionary of templates to format values: | |
108 field_name => template | |
109 if no formatter is set (or None is used) for a field, it will be used unmodified. | |
110 current xmlui items will be set as "item" key for the template | |
111 @param item_class_fields(iterable[unicode]): name of fields to use as class | |
112 class will be "{name}_{value}" where name is field name, and value field value | |
113 all lowercase/stripped | |
114 @param on_click(data_objects.OnClick): thing to do when clicking on a row | |
115 #} | |
116 {% if formatters is undefined %} | |
117 {% set formatters = {} %} | |
118 {% endif %} | |
119 {% if on_click is undefined %} | |
120 {% set on_click = {} %} | |
121 {% endif %} | |
122 <ul class="xmlui_list"> | |
123 {% for xmlui in xmlui_items %} | |
124 <li> | |
125 {% set link=on_click.formatUrl(item=xmlui.widget_value) if on_click.url else none %} | |
126 <a {{ {'class': xmlui|xmlui_class(item_class_fields), | |
127 'href':link}|xmlattr }}> | |
128 {% for name,label in fields %} | |
129 <span {{ {'class': 'xmlui_field__'+name}|xmlattr }}> | |
130 {% for label in xmlui.widgets.get(name, {}).labels %} | |
131 <span>{{ label|adv_format(formatters.get(name),item=xmlui.widget_value) }}</span> | |
132 {% endfor %} | |
133 </span> | |
134 {% endfor %} | |
135 </a> | |
136 </li> | |
137 {% endfor %} | |
138 </ul> | |
139 {% endmacro %} | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 {# containers #} | |
146 | |
147 {% macro vertical_container(cont, config) %} | |
148 <div class="xmlui_cont xmlui_cont_vertical"> | |
149 {{ generate_children(cont, config) }} | |
150 </div> | |
151 {% endmacro %} | |
152 | |
153 {% macro pairs_container(cont, config) %} | |
154 {# TODO: proper impelmentation (do the same as vertical container for now #} | |
155 <div class="xmlui_cont xmlui_cont_vertical"> | |
156 {{ generate_children(cont, config) }} | |
157 </div> | |
158 {% endmacro %} | |
159 | |
160 {% macro label_container(cont, config) %} | |
161 <div class="xmlui_cont xmlui_cont_vertical"> | |
162 {% for child in cont.children %} | |
163 {% if loop.index is odd %} | |
164 {# label #} | |
165 {% if child.type == 'label' %} | |
166 {% set for_ = ('wid_' + (child.for_name or child.name or '_noname'))|next_gidx %} | |
167 {{ label_widget(child, config, for=for_) }} | |
168 {% endif %} | |
169 {% else %} | |
170 {# widget #} | |
171 {% set id = ('wid_' + (child.name or '_noname'))|cur_gidx %} | |
172 {{ generate_widget(child, config, id=id) }} | |
173 {% endif %} | |
174 {% endfor %} | |
175 </div> | |
176 {% endmacro %} | |
177 | |
178 | |
179 {# widgets #} | |
180 | |
181 {% macro text_widget(wid, config, id=none) %} | |
182 <p class="xmlui_widget xmlui_text" {{ {'id':id}|xmlattr }}> | |
183 {{- wid|item_filter(config.filters)|default('\u00A0',true) -}} | |
184 </p> | |
185 {% endmacro%} | |
186 | |
187 {% macro label_widget(wid, config, for=none) %} | |
188 {% if config.form %} | |
189 <label class="xmlui_widget xmlui_label" {{ {'for':for}|xmlattr }}> | |
190 {{wid|item_filter(config.filters)}} | |
191 </label> | |
192 {% else %} | |
193 <span class="xmlui_widget xmlui_label" {{ {'id':none if not for else 'label_%s'|format(for)}|xmlattr }}>{{wid|item_filter(config.filters)}}</span> | |
194 {% endif %} | |
195 {% endmacro%} | |
196 | |
197 {% macro string_widget(wid, config, id=none) %} | |
198 {% if config.form %} | |
199 <input class="xmlui_widget xmlui_string" type="text" {{ {'name':wid.name, 'id':id, 'value':wid|item_filter(config.filters)}|dict_ext(config.attrs, wid.name)|xmlattr }}> | |
200 {% else %} | |
201 <div class="xmlui_widget xmlui_string" {{ {'id':id}|xmlattr }}> | |
202 {{- wid|item_filter(config.filters)|default('\u00A0',true) -}} | |
203 </div> | |
204 {% endif %} | |
205 {% endmacro%} | |
206 | |
207 {% macro textbox_widget(wid, config, id=none) %} | |
208 {% if config.form %} | |
209 <textarea class="xmlui_widget xmlui_textbox" rows="10" cols="50" {{ {'name':wid.name, 'id':id}|dict_ext(config.attrs, wid.name)|xmlattr }}> | |
210 {{- wid|item_filter(config.filters) -}} | |
211 </textarea> | |
212 {% else %} | |
213 <p class="xmlui_widget xmlui_textbox" {{ {'id':id}|xmlattr }}> | |
214 {{- wid|item_filter(config.filters) -}} | |
215 </p> | |
216 {% endif %} | |
217 {% endmacro%} | |
218 | |
219 {% macro list_widget(wid, config, id=none) %} | |
220 {% if config.form %} | |
221 <select class="xmlui_widget xmlui_list" {{ {'name':wid.name, 'id':id}|dict_ext(config.attrs, wid.name)|xmlattr }}> | |
222 {% for value,label in wid.options %} | |
223 <option {{ {'value':value}|xmlattr }} {{ 'selected' if value in wid.selected }}> | |
224 {{- label -}} | |
225 </option> | |
226 {% endfor %} | |
227 </select> | |
228 {% else %} | |
229 <div class="xmlui_widget xmlui_list" {{ {'id':id}|xmlattr }}> | |
230 {% for value,label in wid.items %} | |
231 <span class="xmlui_list_item value_{{value|attr_escape}}"> | |
232 {{- label -}} | |
233 </span> | |
234 {% endfor %} | |
235 </div> | |
236 {% endif %} | |
237 {% endmacro%} |