Collection

class GroupListWidget(node_selector, options)

Group items of a list by class written in data attributes.

Note

Each list item must provide data-{{self.group_by_key}} and data-{{self.group_title_key}}. Those are needed to decide, in which group the item is placed and what title that group will get.

Extends:

ListWidget()

Arguments:
  • node_selector (string) – The selector of the DOM node where the widget should be rendered.
  • options (Object) – An object containing options for the widget.
  • options.group_by_key (Array) – By which data-key are items grouped.
  • options.group_title_key (Array) – Specify what key leads to the title of the group.
  • options.[collection_url] (string) – The url to a JSON View returning the data for the collection.
  • options.[form_options] (Object) – An object containing options for the edit Form() as described under load().
  • options.[item_actions] (Array) – Additional item_actions besides edit and del.
  • options.[default_item_actions] (Array) – Set to an empty Array to hide edit and del.
  • options.[form_actions] (Array) – Additional form_actions besides add.
  • options.[default_form_actions] (Array) – Set to an empty list to hide add.
Returns:

The widget instance.

Return type:

Object

$(body).append('<div id="my_list_widget"></div>');
var list_widget = new ajja.GroupListWidget(
    '#my_list_widget',
    {collection_url: '/list.json'}
);
get_collection(item)

Return the container DOM node of item.

Note

The grouping is done here on the fly.

Arguments:
  • item (Object) – An item as returned by the collection JSON view.
Returns:

jQuery DOM node to items container.

Return type:

Object

class ListWidget(node_selector, options)

Turn any DOM elements matched by node_selector into ListWidgets.

Extends:

TemplateHandler()

Arguments:
  • node_selector (string) – The selector of the DOM node where the widget should be rendered.
  • options (Object) – An object containing options for the widget.
  • options.collection_url (string) – The url to a JSON View returning the data for the collection.
  • options.form_options (Object) – An object containing options for the edit Form() as described under load().
  • options.[item_actions] (Array) – Additional item_actions besides edit and del.
  • options.[default_item_actions] (Array) – Set to an empty Array to hide edit and del.
  • options.[form_actions] (Array) – Additional form_actions besides add.
  • options.[default_form_actions] (Array) – Set to an empty list to hide add.
Returns:

The widget instance.

Return type:

Object

$(body).append('<div id="my_list_widget"></div>');
var list_widget = new ajja.ListWidget(
    '#my_list_widget',
    {collection_url: '/list.json'}
);
add_item()

Add an new item to the collection.

apply_item_actions(node)

Bind a click handler to each action of the given item.

Note

The callback, that was specified in item_actions, is binded here.

Arguments:
  • node (Object) – The jQuery DOM node of the item with the actions.
close_object_edit_form(ev, object_form, form_dialog)

Handler, that closes the edit form after save or cancel.

Arguments:
  • ev (Object) – The close event.
  • object_form (Object) – The Form() instance.
  • form_dialog (Object) – The jQuery DOM node of the form.
del_item(node)

Delete an item from the collection.

Arguments:
  • node (Object) – The jQuery DOM node of the item to be deleted.
edit_item(node)

Render an edit Form() and provide it to the user.

Note

The {FormOptions} object provided on initialization of the ListWidget is used to render the form.

Note

Only fields with a label (provided in {FormOptions}) are rendered in this form.

Arguments:
  • node (Object) – The jQuery DOM node pointing to the item.
get_collection(item)

Return the container DOM node of item.

Arguments:
  • item (Object) – An item as returned by the collection JSON view.
Returns:

jQuery DOM node to items container.

Return type:

Object

get_collection_head(items)

Return the rendered HTML of the widgets header.

Arguments:
  • items (Array) – The items as returned by the collection JSON view.
Returns:

HTML ready to be included into the DOM.

Return type:

string

reload()

Reload the widget. Retrieve data from the server and render items in DOM.

Returns:The widget instance.
Return type:Object
render(items)

Render items in the DOM.

Arguments:
  • items (Array) – The items as returned by the collection JSON view.
Return type:

eval

render_form_actions()

Render the form actions and bind a click handler to them.

render_item(item)

Render an item into the DOM.

Arguments:
  • item (Object) – An item as returned by the collection JSON view.
Returns:

jQuery DOM node to the rendered item.

Return type:

Object

render_item_content(node)

Render the content of an item (the part next to the actions in DOM).

Arguments:
  • node (Object) – The jQuery DOM node pointing to the item.
class TableWidget(node_selector, options)

Show list of items in a table.

Extends:

ListWidget()

Arguments:
  • node_selector (string) – The selector of the DOM node where the widget should be rendered.
  • options (Object) – An object containing options for the widget.
  • options.collection_url (string) – The url to a JSON View returning the data for the collection.
  • options.form_options (Object) – An object containing options for the edit Form() as described under load().
  • options.[omit] (Array) – Specifiy attributes taht should not be rendered as columns in the table.
  • options.[item_actions] (Array) – Additional item_actions besides edit and del.
  • options.[default_item_actions] (Array) – Set to an empty Array to hide edit and del.
  • options.[form_actions] (Array) – Additional form_actions besides add.
  • options.[default_form_actions] (Array) – Set to an empty list to hide add.
Returns:

The widget instance.

Return type:

Object

$(body).append('<div id="my_list_widget"></div>');
var list_widget = new ajja.TableWidget(
    '#my_list_widget',
    {collection_url: '/list.json'}
);
get_collection_head(items)

Return the rendered HTML of the widgets header.

Note

Only fields with a label (provided in {FormOptions}) are returned as columns of the table.

Arguments:
  • items (Array) – The items as returned by the collection JSON view.
Returns:

HTML ready to be included into the DOM.

Return type:

string

render_item(item)

Render an item into the DOM as a table row.

Arguments:
  • item (Object) – An item as returned by the collection JSON view.
Returns:

jQuery DOM node to the rendered item.

Return type:

Object

translate_boolean_cells(node)

Render boolean cells as proper glyphicons.

Arguments:
  • node (Object) – The jQuery DOM node pointing to the table row.