Class: PaferaList

PaferaList(config)

The main widget for interfacing with the database, this displays a grid of cards or a table of database rows. To use this widget, create an instance of it under the temporary global object G, call paferalist.Display() to setup the controls, and then paferalist.List() to display the contents from the database. For a nicer looking display, you should override paferalist.OnRenderItem() to suit your own purposes. For hooks in derived classes, look at OnList, OnListParams(), OnSaveData(), and other such functions.

Constructor

new PaferaList(config)

Parameters:
Name Type Description
config object With so many options, please see the source to see what settings are available. The most commonly used ones are
apiurl
The URL for the JSON API. It should support the standard Pafera search, save, and delete commands.
div
a CSS selector to display the controls in
reference
a global reference to this object such as G.listctrl. It is used for buttons and actions to refer to itself.
displayfields
A list of arrays containing the fields that are shown in each card and the table columns with format [fieldname, fieldtype, fieldtitle]
editfields
The fields to pass to P.EditPopup(), with the same format. If you need specific fields or values for each object, override paferalist.GetEditFields()
limit
The number of items per page to display
cardstyles
Extra CSS styles for the cards displayed
tablestyles
Extra CSS styles for the table element
extrabuttons
A string containing HTML controls which are shown at the control bar at the top of the widget.
extraactions
A list of [displayname, funcname, colornum] shown on every row or card. You should define a method with funcname on a derived object. It will be passed the card element and the dbid of the row, thus ['Edit', 'editfunc', 3] will result in paferalist.editfunc(cardelement, dbid) being called. Note that if you want to support actions on multiple selected objects, use the GetSelectedIDs() function instead of just using dbid.
enableadd, enableedit, enablesearch, enableselect
Set these to true to enable their various actions.
Source:

Methods

Add()

Called to add a new object. Normally just calls Edit() with a blank object.
Source:

ConfirmDelete(dbids)

Calls P.ConfirmDeletePopup() before actually deleting the items from the database. Note that this will delete *all* selected cards
Parameters:
Name Type Description
dbids list The database IDs to be deleted
Source:

Delete(card, dbid)

Deletes the item from this widget and the database. Will show a confirm delete popup for one chance to cancel with ConfirmDelete() If multiple cards are selected, this function will delete all of them.
Parameters:
Name Type Description
card object The object clicked
dbid value The database ID of the object
Source:

DeleteSelected()

Deletes every currently displayed card or table row.
Source:

Display()

Displays the widget inside the div specified at construction and setups all handlers.
Source:

DisplayItems()

Called by List() to display the returned items from the server.
Source:

(async) Edit(card, dbid)

Shows an P.EditPopup() to edit an existing object or add a new object.
Parameters:
Name Type Description
card object The object to change, or an empty object if adding a new object.
dbid value The database ID of the existing object, or a blank id if adding a new object.
Source:

GetEditFields(obj)

Returns the edit fields for use in P.EditPopup(). If you want to have different fields for different objects, then override this function.
Parameters:
Name Type Description
obj object The original object to edit
Source:

GetItemByID(dbid)

Returns the item in self.items that matches dbid.
Parameters:
Name Type Description
dbid value
Source:

GetItemDisplayName(obj)

Returns the displayed name of an item, which by default is its first field. You may want to override this in a derived class if you want to make the name more meaningful.
Parameters:
Name Type Description
obj object
Source:

GetSelectedIDs()

Returns a list of all of the currently selected objects.
Source:

(async) List(start)

Calls the server to get the list of items and displays them.
Parameters:
Name Type Description
start int Leave undefined to use the last position, otherwise, specifies the starting position to display.
Source:

(async) LoadItem(dbid)

Loads all of the information for a particular object from the database and returns it as a JavaScript object.
Parameters:
Name Type Description
dbid value The database ID of the existing object.
Source:

(async) OnEditForm(obj)

Called after the editing form is displayed for custom fields.
Parameters:
Name Type Description
obj object The options passed to P.EditPopup()
Source:

OnFinished()

Called when the user clicks the finished button to signal that all changes have been made. Derived classes should override this for their own handling.
Source:

OnItemClicked(card, dbid)

Handler for when a card is clicked. Derived classes should not override this function, but the oncardclick(cardelement, dbid) handler instad.
Parameters:
Name Type Description
card object The object clicked
dbid value The database ID of the object
Source:

OnListParams()

Called before a list request is made to the server. Derived classes can add their own data to be sent.
Source:

(async) OnLoadItem(dbid)

Parameters:
Name Type Description
dbid value The database ID of the existing object.
Source:

OnRenderItem(r)

Called to return the HTML inside of a card or tr element. By default, it just loops through self.displayfields, but if you want a nicer display, feel free to customize this in a derived class.
Parameters:
Name Type Description
r object The object to display
Source:

(async) OnSave(formdiv, data, resultsdiv, e, saveandcontinue)

Custom save handler if you don't have an apiurl. This function should call await OnSaveComplete() and return true if it succeeds. If it does not succeed, then it should return false.
Parameters:
Name Type Description
formdiv string The selector for the whole form
data object The data to save to the server
resultsdiv string The div to display progress in
e event The event that trigged the save
saveandcontinue bool A flag indicating whether to return to the previous screen or to stay on this screen and allow further changes.
Source:

(async) OnSaveComplete(data, resultsdiv, saveandcontinue)

Called after an object has been saved with the returned data from the server. The normal behavior is to list new changes and remove the editing layer, so make sure that if you override this function, your own function must do the same.
Parameters:
Name Type Description
data object The data to save to the server
resultsdiv string The div to display progress in
saveandcontinue bool A flag indicating whether to return to the previous screen or to stay on this screen and allow further changes.
Source:

OnSaveData(obj)

Called before the changed object is sent to the server for last minute data changes.
Parameters:
Name Type Description
obj object The data to send to the server
Source:

RenderItem(r)

Returns the full HTML for a card or table row, calling OnRenderItem() to handle the inner portion. Derived classes normally should not override this method since this only takes care of the outer container and action buttons. Instead, override OnRenderItem() to customize your display.
Parameters:
Name Type Description
r object The object to display
Source:

SelectAll()

Selects every currently displayed card or table row.
Source:

SelectNone()

Deelects every currently selected card or table row.
Source:

ToggleTable()

Toggles between table and card displays.
Source: