239
241
def __init__(self, context, exported_field, default_html,
240
242
content_box_id=None, header='Select an item',
241
step_title='Search', assign_button_text='Pick Me',
242
remove_button_text='Remove Person',
243
244
null_display_value='None',
244
245
edit_view="+edit", edit_url=None, edit_title=''):
245
246
"""Create a widget wrapper.
252
253
Automatically generated if this is not provided.
253
254
:param header: The large text at the top of the picker.
254
255
:param step_title: Smaller line of text below the header.
255
:param assign_button_text: Override default button text: "Pick Me"
256
:param remove_button_text: Override default button text: "Remove"
257
256
:param null_display_value: This will be shown for a missing value
258
257
:param edit_view: The view name to use to generate the edit_url if
259
258
one is not specified.
278
275
self.exported_field.vocabularyName)
278
def picker_type(self):
282
def selected_value_metadata(self):
286
def selected_value(self):
287
""" String representation of field value associated with the picker.
289
Default implementation is to return the 'name' attribute.
291
if self.context is None:
293
val = getattr(self.context, self.exported_field.__name__)
294
if val is not None and safe_hasattr(val, 'name'):
295
return getattr(val, 'name')
281
299
def config(self):
300
return self.getConfig()
304
picker_type=self.picker_type,
283
305
header=self.header, step_title=self.step_title,
284
assign_button_text=self.assign_button_text,
285
remove_button_text=self.remove_button_text,
306
selected_value=self.selected_value,
307
selected_value_metadata=self.selected_value_metadata,
286
308
null_display_value=self.null_display_value,
287
show_remove_button=self.optional_field,
288
show_assign_me_button=self.show_assign_me_button,
289
309
show_search_box=self.show_search_box)
302
322
def show_search_box(self):
303
323
return IHugeVocabulary.providedBy(self.vocabulary)
326
class InlinePersonEditPickerWidget(InlineEditPickerWidget):
327
def __init__(self, context, exported_field, default_html,
328
content_box_id=None, header='Select an item',
329
step_title='Search', assign_me_text='Pick me',
330
remove_person_text='Remove person',
331
remove_team_text='Remove team',
332
null_display_value='None',
333
edit_view="+edit", edit_url=None, edit_title=''):
334
"""Create a widget wrapper.
336
:param context: The object that is being edited.
337
:param exported_field: The attribute being edited. This should be
338
a field from an interface of the form ISomeInterface['fieldname']
339
:param default_html: Default display of attribute.
340
:param content_box_id: The HTML id to use for this widget.
341
Automatically generated if this is not provided.
342
:param header: The large text at the top of the picker.
343
:param step_title: Smaller line of text below the header.
344
:param assign_me_text: Override default button text: "Pick me"
345
:param remove_person_text: Override default link text: "Remove person"
346
:param remove_team_text: Override default link text: "Remove team"
347
:param null_display_value: This will be shown for a missing value
348
:param edit_view: The view name to use to generate the edit_url if
349
one is not specified.
350
:param edit_url: The URL to use for editing when the user isn't logged
351
in and when JS is off. Defaults to the edit_view on the context.
352
:param edit_title: Used to set the title attribute of the anchor.
354
super(InlinePersonEditPickerWidget, self).__init__(
355
context, exported_field, default_html, content_box_id, header,
356
step_title, null_display_value,
357
edit_view, edit_url, edit_title)
359
self.assign_me_text = assign_me_text
360
self.remove_person_text = remove_person_text
361
self.remove_team_text = remove_team_text
364
def picker_type(self):
368
def selected_value_metadata(self):
369
val = getattr(self.context, self.exported_field.__name__)
370
return get_person_picker_entry_metadata(val)
306
373
def show_assign_me_button(self):
307
374
# show_assign_me_button is true if user is in the vocabulary.
309
376
user = getUtility(ILaunchBag).user
310
377
return user and user in vocabulary
380
config = super(InlinePersonEditPickerWidget, self).getConfig()
382
show_remove_button=self.optional_field,
383
show_assign_me_button=self.show_assign_me_button,
384
assign_me_text=self.assign_me_text,
385
remove_person_text=self.remove_person_text,
386
remove_team_text=self.remove_team_text))
313
390
class InlineMultiCheckboxWidget(WidgetBase):
314
391
"""Wrapper for the lazr-js multicheckbox widget."""
366
443
self.label_close_tag = "</%s>" % label_tag
367
444
self.items = selected_items
368
445
self.items_open_tag = ("<%s id='%s'>" %
369
(items_tag, self.content_box_id+"-items"))
446
(items_tag, self.content_box_id + "-items"))
370
447
self.items_close_tag = "</%s>" % items_tag
371
448
self.linkify_items = linkify_items