new (require("nmodule/webEditors/rc/wb/mgr/model/MgrColumn"))()
API Status: Development
Column for use in a Manager
workflow. It functions both as a vanillaTableModel
column, and as a defined field for batch editing rows in a
manager view.
A MgrColumn
provides for the following workflow:
- Identify a number of components to edit at once.
- Coalesce corresponding values from those components into a single value.
- Load the coalesced value into a single editor for editing.
- Commit the entered value back to the edited components.
Extends:
Methods
-
<static> mixin(Ctor)
-
Applies
MgrColumn
functionality to an arbitraryColumn
subclass.Parameters:
Name Type Description Ctor
function -
buildCell(row, dom)
-
Creates the cell's contents by calling
toString
on the row's proposed value
or the current value if there is no proposal. HTML will be safely escaped.Parameters:
Name Type Description row
module:nmodule/webEditors/rc/wb/table/model/Row dom
JQuery Returns:
- Type
- Promise
-
coalesceRows(rows)
-
Given the set of rows to be edited, coalesce their values into one single
value to load into an editor.By default, this will simply read the proposed value from the first row.
This is appropriate for a use case where one value will be entered and
written back to all edited components.Parameters:
Name Type Description rows
Array.<module:nmodule/webEditors/rc/wb/table/model/Row> Throws:
-
if rows array not given, or values from rows are not all
of the same type - Type
- Error
Returns:
value coalesced from the given rows
- Type
- *
-
-
<abstract> commit(value, row [, params])
-
Should read the value and "officially" apply it back to the selected rows.
Ifparams.batch
is received, thenparams.progressCallback
must be
called withMgrColumn.COMMIT_READY
when this function is done using that
batch (even if no network calls are added to it).Note: sometimes you may want to abort the entire process of saving changes
to the Manager, for instance, if one of your columns requires the user to
confirm a dialog before committing. Returning a Promise that rejects will
show an error dialog to the user, which may not be what you want if you've
already shown a dialog. Another option is to return a Promise that never
resolves or rejects, which will drop the user back at the edit screen
without committing any changes (all commit calls must resolve for any
changes to post to the station). A more explicit API for this may be
provided in the future.Parameters:
Name Type Argument Description value
* the proposed value to commit to the row
row
module:nmodule/webEditors/rc/wb/table/model/Row params
Object <optional>
Properties
Name Type Argument Description editor
module:nmodule/webEditors/rc/fe/baja/BaseEditor <optional>
the editor from which the value was read. If the column is not editable,
this parameter will beundefined
, as no editor will have been created for
the value. This situation may occur when a value obtained via discovery is
set on row for a non-editable column.batch
baja.comm.Batch <optional>
a batch to use to commit changes
up to the stationprogressCallback
function <optional>
call this with
MgrColumn.COMMIT_READY
when this function is done adding network calls to
the batch.Returns:
- Type
- Promise
-
destroyCell(row, dom)
-
Called when the table is destroying the DOM element built for a cell in this column. This
gives aColumn
implementation the chance to clean up any resources that might have been
created during the earlier call to#buildCell
, perhaps destroying a widget in the cell,
for example. As with#buildCell
, if this completes synchronously and doesn't return a
Promise, the caller must wrap this in a call toPromise.resolve()
.Parameters:
Name Type Description row
module:nmodule/webEditors/rc/wb/table/model/Row dom
jQuery - Inherited From:
Returns:
- Type
- Promise | *
-
getColumnIcon()
-
Returns a URI for an icon representing this column. Returns
null
by
default; override as needed in subclasses.- Inherited From:
Returns:
a URI for an icon to be shown for this column.
- Type
- String
-
getConfigFor(rows)
-
After coalescing the selected rows into a single value, calculate a
config object to be given tofe.makeFor
that will determine how the
editor will be built to edit that value.This function will typically not be called directly but serves as an
override point. By default, it will simply get the coalesced value from
those rows and havefe.makeFor
build the default editor for that value.
Note that this means if the coalesced value is a non-Baja value, like an
array, this function must be overridden.Parameters:
Name Type Description rows
Array.<module:nmodule/webEditors/rc/wb/table/model/Row> Returns:
configuration object to be given to
fe.makeFor
- Type
- Object
-
getFlags()
-
Get the flags set on this column.
- Inherited From:
Returns:
- Type
- Number
-
getName()
-
Get the column name or
null
if none was given.- Inherited From:
Returns:
- Type
- String
-
getProposedValueFor(row)
-
Get the currently proposed value for the given row. If no value proposed
yet, will return the actual column value (getValueFor
).Parameters:
Name Type Description row
module:nmodule/webEditors/rc/wb/table/model/Row Returns:
- Type
- *
-
<abstract> getValueFor(row)
-
Override point; each column should define its own method of retrieving a
value from the given table row.Parameters:
Name Type Description row
module:nmodule/webEditors/rc/wb/table/model/Row - Inherited From:
Throws:
-
if not implemented
- Type
- Error
Returns:
the row value. Note that this is synchronous; if the row's
subject is not ready to provide a value, it should not be loaded into the
table.- Type
- *
-
hasFlags(flags)
-
Return true if the column has all of the given flags.
Parameters:
Name Type Description flags
Number flags to check for
- Inherited From:
Returns:
- Type
- Boolean
-
isEditable()
-
Return true if the column is editable.
- Inherited From:
Returns:
- Type
- Boolean
-
isEditorSuitable(editor, rows)
-
If an editor has already been built, it may be possible to reuse it,
simply loading in a new coalesced value rather than destroying and
rebuilding the existing editor.This function should return true if the editor is suitable to be reused
for the given rows. By default, will always return true.Parameters:
Name Type Description editor
module:nmodule/webEditors/rc/fe/baja/BaseEditor rows
Array.<module:nmodule/webEditors/rc/wb/table/model/Row> Returns:
- Type
- Boolean
-
isHidable()
-
Return true if the column should available in the table's show/hide context menu.
Defaults to true.- Inherited From:
Returns:
- Type
- Boolean
-
isReadonly()
-
Return true if the column is readonly.
- Inherited From:
Returns:
- Type
- Boolean
-
isSortable()
-
Returns a boolean indicating whether the column should not be sortable via the table headings.
Defaults to true.- Inherited From:
Returns:
- Type
- Boolean
-
isUnseen()
-
Return true if the column is unseen.
- Inherited From:
Returns:
- Type
- Boolean
-
mgrValidate(model, data [, params])
-
Allows this column to validate proposed changes.
Parameters:
Name Type Argument Description model
module:nmodule/webEditors/rc/wb/mgr/model/MgrModel the model to which we're about to apply changes.
data
Array an array of proposed changes to this column, one per
row in theMgrModel
. If a value in this array is null, no change has
been proposed for that row.params
Object <optional>
Properties
Name Type Argument Description editor
module:nmodule/webEditors/rc/fe/baja/BaseEditor <optional>
the editor from which the proposed values were read. Note that the editor
may have been used to edit other rows, so the editor's current value may
not match the proposed new values.Returns:
promise that resolves by default
- Type
- Promise
Example
Validating this column may require that I examine the changes I'm about to make to other columns as well.
MyMgrColumn.prototype.mgrValidate = function (model, data, params) { var that = this, rows = model.getRows(), otherColumn = model.getColumn('otherColumn'); //search through all MgrModel rows, and check to see that my proposed //change is compatible with the proposed change to another column. //say, i'm a "password" column, and the other column is a "password //scheme" column - i need to make sure that the proposed password is //considered valid by the proposed password scheme. for (var i = 0; i < rows.length; i++) { var row = rows[i], myValue = data[i], otherValue = otherColumn.getProposedValueFor(row); if (myValue === null) { //no changes proposed for this row, so nothing to validate. } if (!isCompatible(myValue, otherValue)) { return Promise.reject(new Error('incompatible values')); } } };
-
propose(value, row)
-
Should read the value and "tentatively" apply it to the
selected row. In most cases this will be setting some temporary data
for display-only purposes.By default, will set some temporary data on the row using the column's
name as a key.Parameters:
Name Type Description value
* row
module:nmodule/webEditors/rc/wb/table/model/Row Returns:
- Type
- Promise
-
setEditable(editable)
-
Set or unset the column's
EDITABLE
flag. Emits aflagsChanged
event.Parameters:
Name Type Description editable
boolean - Inherited From:
-
setFlags(flags)
-
Set the column's flags.
Parameters:
Name Type Description flags
Number - Inherited From:
Throws:
-
if a non-Number given
- Type
- Error
-
setHidable(hidable)
-
Set or unset whether the column should be allowed to be hidden or shown by the table's
show/hide context menu.Parameters:
Name Type Description hidable
boolean - Inherited From:
-
setReadonly(readonly)
-
Set or unset the column's
READONLY
flag. Emits aflagsChanged
event.Parameters:
Name Type Description readonly
boolean - Inherited From:
-
setSortable(sortable)
-
Set or unset whether the column should be allowed to be sorted by the table heading.
Parameters:
Name Type Description sortable
boolean - Inherited From:
-
setUnseen(unseen)
-
Set or unset the column's
UNSEEN
flag. Emits aflagsChanged
event.Parameters:
Name Type Description unseen
boolean - Inherited From:
-
toDisplayName()
-
Resolves a display name for this column.
- Inherited From:
Returns:
promise to be resolved when the element's display name
has been fully built. It's also acceptable for overrides of this function
to complete synchronously without returning a promise, so be sure to wrap
calls to this function inPromise.resolve()
when appropriate.- Type
- Promise | *