175 Render list of items to delete. |
175 Render list of items to delete. |
176 |
176 |
177 visible - display list of items in addition the rendering the <input>'s |
177 visible - display list of items in addition the rendering the <input>'s |
178 """ |
178 """ |
179 |
179 |
180 def render_items (items, visible) : |
180 |
|
181 def render_items (items, with_list, with_input) : |
|
182 """ Item <ul> or <input>s """ |
|
183 |
181 if not items : |
184 if not items : |
182 # blank |
185 # blank |
183 return None |
186 return None |
184 |
187 |
185 elif visible : |
188 elif with_list : |
186 # nested list |
189 # nested list |
187 return html.ul( |
190 return html.ul( |
188 render_item(item, True) for item in items |
191 render_item(item, True, with_input) for item in items |
189 ) |
192 ) |
190 |
193 |
191 else : |
194 else : |
192 # just the controls |
195 # just the controls |
193 return [render_item(item, False) for item in items] |
196 return [render_item(item, False, with_input) for item in items] |
194 |
197 |
195 def render_item (item, visible) : |
198 |
196 # the form field |
199 def render_item (item, with_list, with_input) : |
197 field = html.input(type='hidden', name='items', value=item.id), |
200 """ Item <li> or <input> """ |
198 |
201 |
199 if visible : |
202 if with_input : |
|
203 # the form field |
|
204 input = html.input(type='hidden', name='items', value=item.id), |
|
205 else : |
|
206 # no field |
|
207 input = None |
|
208 |
|
209 if with_list : |
200 return html.li( |
210 return html.li( |
201 field, |
211 input, |
202 |
212 |
203 item.name if visible else None, |
213 item.name if visible else None, |
204 |
214 |
205 render_items(item.children, visible), |
215 # don't recurse inputs |
|
216 render_items(item.children, with_list, with_input=False), |
206 ) |
217 ) |
207 else : |
218 else : |
208 # just the input |
219 # just the input |
209 return field |
220 return input |
210 |
221 |
|
222 ## Render <div> or <input>s |
211 if visible : |
223 if visible : |
212 # div with nested <li>s |
224 # <div> with nested <li>s |
213 return html.div(class_='value')( |
225 return html.div(class_='value')( |
214 render_items(items, True), |
226 render_items(items, with_list=True, with_input=True), |
215 ) |
227 ) |
|
228 |
216 else : |
229 else : |
217 # just the <input>s |
230 # just the <input>s |
218 return render_items(items, False) |
231 return render_items(items, with_list=False, with_input=True) |
219 |
232 |
220 def render (self, legend=None, delete_action=None, confirm_action=None, return_url=None, item_listing=None) : |
233 def render (self, legend=None, delete_action=None, confirm_action=None, return_url=None, item_listing=None) : |
221 """ |
234 """ |
222 Render form with list of target items, and a confirm button |
235 Render form with list of target items, and a confirm button |
223 |
236 |
234 |
247 |
235 return html.form(action=action, method='POST')( |
248 return html.form(action=action, method='POST')( |
236 html.fieldset( |
249 html.fieldset( |
237 html.legend(legend), |
250 html.legend(legend), |
238 |
251 |
|
252 # raw field with just the <input>s |
|
253 (self.render_items_list('items', self.items, visible=False)) if not item_listing else None, |
|
254 |
239 html.ol( |
255 html.ol( |
240 ( |
256 # full UI field |
241 # full UI field |
257 (self.render_form_field('items', u"Poistettavat laitteet", u"Kaikki listatut laitteet poistetaan inventaarista", ( |
242 (self.render_form_field('items', u"Poistettavat laitteet", u"Kaikki listatut laitteet poistetaan inventaarista", ( |
258 self.render_items_list('items', self.items, visible=True) |
243 self.render_items_list('items', self.items, visible=True) |
259 )) if item_listing else None), |
244 ))) |
|
245 |
|
246 if item_listing else |
|
247 |
|
248 # raw field with just the <input>s |
|
249 (self.render_items_list('items', self.items, visible=False)) |
|
250 ), |
|
251 |
260 |
252 html.li( |
261 html.li( |
253 self.render_submit_button(u"Poista") if delete_action else None, |
262 self.render_submit_button(u"Poista") if delete_action else None, |
254 self.render_submit_button(u"Varmista", 'confirm') if confirm_action else None, |
263 self.render_submit_button(u"Varmista", 'confirm') if confirm_action else None, |
255 |
264 |