define([
'viewmodel/js/api/Archetype'
], function(
Archetype) {
'use strict';
/**
* {@link viewmodel/js/api/Archetype Archetype} representing collection of
* records for a single businness object.
*
* Besides a data collection itself it provides also operations applicable
* on a collection of records, for example {@link viewmodel/js/api/CollectionArchetype#fetch retrieve data},
* {@link viewmodel/js/api/CollectionArchetype#delete delete one record} or
* {@link viewmodel/js/api/CollectionArchetype#getSelectedRecord get selected record}.
*
* ABCS table and list components are built on top of this archetype so any
* interaction with an existing <code>CollectionArchetype</code> also
* affects the owner component.
*
* @AbcsAPI stable
* @version 16.3.5
* @exports viewmodel/js/api/CollectionArchetype
* @constructor
* @private
* @augments viewmodel/js/api/Archetype
* @param {entity/js/api/Entity} entity
* @param {Object} descriptor JSON archetype descriptor
*/
var CollectionArchetype = function (entity, descriptor) {
AbcsLib.checkThis(this);
Archetype.call(this, entity, descriptor);
};
AbcsLib.extend(CollectionArchetype, Archetype);
/**
* (Re-)Fetch data into the collection. Calling this method triggers asynchronous
* refresh which will result into UI update when finished. Any data already
* loaded will be flushed and forgotten and the collection will be populated
* with fresh new data.
*
* @AbcsAPI stable
* @version 16.3.5
* @param {Object} [params] fetch parameters
* @param {operation/js/api/Condition} [params.condition] - Additional {@link operation/js/api/Condition Condition}
* that will be used together with any other {@link operation/js/api/Condition Condition} which may have been
* specified during configuration of this archetype.
* @example <caption>Fetch all customers with name equal to 'John' into a collection</caption>
* require([
* 'operation/js/api/Conditions',
* 'operation/js/api/Operator'
* ], function (Conditions, Operator) {
* // construct read condition for employee with name='John'
* var employee = Abcs.Entities().findById('my.custom.bop.Employee');
* var employeeName = employee.getProperty('name');
* var condition = Conditions.SIMPLE(employeeName, Operator.EQUALS, 'John');
*
* // fetch employee data into the collection
* employeeArchetype.fetch({
* condition: condition
* });
* });
*/
/*
* @param {Sorting} params.sorting
*/
CollectionArchetype.prototype.fetch = function (/*params*/) {};
/**
* Delete given {@link viewmodel/js/api/Record record} permanently from the
* underlying data source.
*
* Removes the record not only from the collection but also from any persistent
* data source feeding the collection with its data. Usually that means this
* calls a REST endpoint to remove the data.
*
* @AbcsAPI stable
* @version 16.3.5
* @param {Object} input data to delete
* @param {viewmodel/js/api/Record} input.record record instance to delete
* @returns {Promise} promise resolved when the record is successfully deleted
* or rejected in case of a failure.
* @example <caption>Delete the currently selected customer record</caption>
* var customerArchetype = pageViewModel.Archetypes.customerTableArchetype;
* // get the selected record
* var record = customerArchetype.getSelectedRecord();
* // if there is a selection delete the selected record
* if (record) {
* customerArchetype.delete({
* record: record
* }).then(function () {
* console.log('Record successfully deleted');
* });
* }
*/
CollectionArchetype.prototype.delete = function(/*input*/) {};
/**
* Returns currently selected {@link viewmodel/js/api/Record record}.
*
* @AbcsAPI stable
* @version 16.3.5
* @returns {viewmodel/js/api/Record|undefined} record with current row data
* or undefined if selection is empty at the moment.
* @example <caption>Delete the currently selected customer record</caption>
* var customerArchetype = pageViewModel.Archetypes.customerTableArchetype;
* // get the selected record
* var record = customerArchetype.getSelectedRecord();
* // if there is a selection delete the selected record
* if (record) {
* customerArchetype.delete({
* record: record
* }).then(function () {
* console.log('Record successfully deleted');
* });
* }
* @example <caption>Get the selected record and pass it to a detail page</caption>
* var customerArchetype = pageViewModel.Archetypes.customerTableArchetype;
* // get the selected record
* var record = customerArchetype.getSelectedRecord();
* // if there is a selection open it in a detail page
* if (record) {
* var customerToDisplay = ContextualData.createRecordToEditContext({
* // what business object are these data of:
* entityId: 'customer',
* // instance of a customer to edit
* data: record
* });
* // navigate to the detail page
* Abcs.Pages().navigateToPage('customerDetailPage', customerToDisplay);
* }
*/
CollectionArchetype.prototype.getSelectedRecord = function() {};
/**
* Returns an object that contains a set of fields and observables you can
* bind to in your components and use to communicate with other components on
* a page bound to the same fields.
*
* @AbcsAPI stable
* @version 16.3.5
* @returns {viewmodel/js/api/CollectionArchetype~CollectionObservables} observables exposed by the archetype
* @function
*/
CollectionArchetype.prototype.getObservables = Archetype.prototype.getObservables;
/**
* Return access to the data which this archetype represents, that is list
* of records.
*
* @AbcsAPI unstable
* @returns {Records} records accessor
*/
CollectionArchetype.prototype.getRecords = function() {};
/**
* Contains set of fields and observables you can bind to in your components
* and use to communicate with other components on a page bound to the same
* fields.
*
* At the moment there are no useful observables you could use for <code>CollectionArchetype</code>.
* To interact with a collection archetype you may use its public methods.
*
* @AbcsAPI stable
* @typedef viewmodel/js/api/CollectionArchetype~CollectionObservables
* @version 16.3.5
*/
return CollectionArchetype;
});