cv-dialog-sdk
Version:
Catavolt Dialog Javascript API
98 lines (97 loc) • 3.37 kB
JavaScript
import { Dialog } from './Dialog';
import { QueryMarkerOption, QueryScroller } from './QueryScroller';
import { ActionIdsEnum, TypeNames } from './types';
/**
* Dialog Subtype that represents a 'Query Dialog'.
* A 'Query' represents and is backed by a list of Records and a single Record definition.
* See {@link Record} and {@link RecordDef}.
*/
export class QueryDialog extends Dialog {
get defaultActionId() {
return this.view.defaultActionId;
}
initScroller(pageSize, firstRecordId = null, markerOptions = [QueryMarkerOption.None]) {
this._scroller = new QueryScroller(this, pageSize, firstRecordId, markerOptions);
}
isBinary(column) {
const propDef = this.propDefAtName(column.propertyName);
return propDef && (propDef.isLargePropertyType || (propDef.isURLType && propDef.isInlineMediaStyle));
}
performMenuActionWithId(actionId, targets) {
return this.invokeMenuActionWithId(actionId, {
targets,
type: TypeNames.ActionParametersTypeName
}).then(result => {
return result;
});
}
/**
* Get a redirection to the search dialog for this query dialog
*/
openSearch() {
return this.performMenuActionWithId(ActionIdsEnum.SEARCH_ACTION_ID, []);
}
/**
* Perform this action associated with the given Menu on this dialog.
* The targets array is expected to be an array of object ids.
* @param {Menu} menu
* @param {Array<string>} targets
* @returns {Promise<{actionId: string} | Redirection>}
*/
performMenuAction(menu, targets) {
return this.invokeMenuAction(menu, {
targets,
type: TypeNames.ActionParametersTypeName
}).then(result => {
return result;
});
}
/**
* Perform a query
*
* @param {number} maxRows
* @param {QueryDirection} direction
* @param {string} fromRecordId
* @returns {Promise<RecordSet>}
*/
query(maxRows, direction, fromRecordId) {
const queryParams = fromRecordId
? {
fetchDirection: direction,
fetchMaxRecords: maxRows,
fromRecordId,
type: TypeNames.QueryParametersTypeName
}
: {
fetchDirection: direction,
fetchMaxRecords: maxRows,
type: TypeNames.QueryParametersTypeName
};
return this.catavolt.dialogApi
.getRecords(this.catavolt.session.tenantId, this.catavolt.session.id, this.id, queryParams)
.then((recordSet) => {
this.lastRefreshTime = new Date();
return recordSet;
});
}
/**
* Get the associated QueryScroller
* @returns {QueryScroller}
*/
get scroller() {
if (!this._scroller) {
this._scroller = this.defaultScroller();
}
return this._scroller;
}
getProperty(params, propertyName) {
return this.catavolt.dialogApi.getQueryProperty(this.tenantId, this.sessionId, this.id, propertyName, params);
}
/**
* Creates a new QueryScroller with default buffer size of 50
* @returns {QueryScroller}
*/
defaultScroller() {
return new QueryScroller(this, 50, null, [QueryMarkerOption.None]);
}
}