},
});
-instance.web.Traverser = instance.web.Class.extend({
- /**
- * @constructs instance.web.Traverser
- * @extends instance.web.Class
- *
- * @param {instance.web.Model} model instance this traverser is bound to
- */
- init: function (model) {
- this._model = model;
- this._index = 0;
- },
-
- /**
- * Gets and sets the current index
- *
- * @param {Number} [idx]
- * @returns {Number} current index
- */
- index: function (idx) {
- if (idx) { this._index = idx; }
- return this._index;
- },
- /**
- * Returns the model this traverser is currently bound to
- *
- * @returns {openerp.web.Model}
- */
- model: function () {
- return this._model;
- },
- /**
- * Fetches the size of the backing model's match
- *
- * @returns {Deferred<Number>} deferred count
- */
- size: function () {
- return this._model.query().count();
- },
-
- /**
- * Record at the current index for the collection, fails if there is no
- * record at the current index.
- *
- * @returns {Deferred<>}
- */
- current: function (fields) {
- return this._model.query(fields).first().pipe(function (record) {
- if (record == null) {
- return $.Deferred()
- .reject('No record at index' + this._index)
- .promise();
- }
- return record;
- });
- },
- next: function (fields) {
- var self = this;
- this._index++;
- return this.size().pipe(function (s) {
- if (self._index >= s) {
- self._index = 0;
- }
- return self.current(fields);
- });
- },
- previous: function (fields) {
- var self = this;
- this._index--;
- if (this._index < 0) {
- return this.size().pipe(function (s) {
- self._index = s-1;
- return self.current(fields);
- });
- }
- return this.current(fields);
- }
-
-});
-
instance.web.DataGroup = instance.web.CallbackEnabled.extend({
/**
* Management interface between views and grouped collections of OpenERP
instance.web.DataSet = instance.web.CallbackEnabled.extend({
/**
- * DateaManagement interface between views and the collection of selected
- * OpenERP records (represents the view's state?)
+ * Collection of OpenERP records, used to share records and the current selection between views.
*
* @constructs instance.web.DataSet
* @extends instance.web.CallbackEnabled
* Creates a new record in db
*
* @param {Object} data field values to set on the new record
- * @param {Function} callback function called with operation result
- * @param {Function} error_callback function called in case of creation error
* @returns {$.Deferred}
*/
create: function(data) {
* Deletes an existing record from the database
*
* @param {Number|String} ids identifier of the record to delete
- * @param {Function} callback function called with operation result
- * @param {Function} error_callback function called in case of deletion error
*/
unlink: function(ids) {
return this._model.call('unlink', [ids], {context: this._model.context()});
* @param {Array} [args]
* @param {Number} [domain_index] index of a domain to evaluate in the args array
* @param {Number} [context_index] index of a context to evaluate in the args array
- * @param {Function} callback
- * @param {Function} error_callback
* @returns {$.Deferred}
*/
call_and_eval: function (method, args, domain_index, context_index) {
*
* @param {String} method
* @param {Array} [args]
- * @param {Function} callback
- * @param {Function} error_callback
* @returns {$.Deferred}
*/
call_button: function (method, args) {
* Fetches the "readable name" for records, based on intrinsic rules
*
* @param {Array} ids
- * @param {Function} callback
* @returns {$.Deferred}
*/
name_get: function(ids) {
},
/**
* @param name
- * @param callback
*/
name_create: function(name) {
return this._model.call('name_create', [name], {context: this._model.context()});
});
},
});
+
instance.web.DataSetStatic = instance.web.DataSet.extend({
init: function(parent, model, context, ids) {
this._super(parent, model, context);
this.set_ids(_.without.apply(null, [this.ids].concat(ids)));
}
});
+
instance.web.DataSetSearch = instance.web.DataSet.extend({
/**
* @constructs instance.web.DataSetSearch
return this._super();
}
});
+
instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
virtual_id_prefix: "one2many_v_id_",
debug_mode: true,
this.cache = [];
this.delete_all = false;
},
- on_change: function() {},
+ on_change: function() {
+ },
read_ids: function (ids, fields, options) {
var self = this;
var to_get = [];
The result of a (successful) :js:func:`~openerp.web.Query.group_by` is
an array of :js:class:`~openerp.web.data.Group`.
-Synchronizing views (provisional)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. note:: this API may not be final, and may not even remain
-
-While the high-level RPC API is mostly stateless, some objects in
-OpenERP Web need to share state information. One of those is OpenERP
-views, especially between "collection-based" views (lists, graphs) and
-"record-based" views (forms, diagrams), which gets its very own API
-for traversing collections of records, the aptly-named
-:js:class:`~openerp.web.Traverser`.
-
-A :js:class:`~openerp.web.Traverser` is linked to a
-:js:class:`~openerp.web.Model` and is used to iterate over it
-asynchronously (and using indexes).
-
-.. js:class:: openerp.web.Traverser(model)
-
- .. js:function:: openerp.web.Traverser.model()
-
- :returns: the :js:class:`~openerp.web.Model` this traverser
- instance is bound to
-
- .. js:function:: openerp.web.Traverser.index([idx])
-
- If provided with an index parameter, sets that as the new
- index for the traverser.
-
- :param Number idx: the new index for the traverser
- :returns: the current index for the traverser
-
- .. js:function:: openerp.web.Traverser.current([fields])
-
- Fetches the traverser's "current" record (that is, the record
- at the current index of the traverser)
-
- :param Array<String> fields: fields to return in the record
- :rtype: Deferred<>
-
- .. js:function:: openerp.web.Traverser.next([fields])
-
- Increases the traverser's internal index by one, the fetches
- the corresponding record. Roughly equivalent to:
-
- .. code-block:: javascript
-
- var idx = traverser.index();
- traverser.index(idx+1);
- traverser.current();
-
- :param Array<String> fields: fields to return in the record
- :rtype: Deferred<>
-
- .. js:function:: openerp.web.Traverser.previous([fields])
-
- Similar to :js:func:`~openerp.web.Traverser.next` but iterates
- the traverser backwards rather than forward.
-
- :param Array<String> fields: fields to return in the record
- :rtype: Deferred<>
-
- .. js:function:: openerp.web.Traverser.size()
-
- Shortcut to checking the size of the backing model, calling
- ``traverser.size()`` is equivalent to calling
- ``traverser.model().query([]).count()``
-
- :rtype: Deferred<Number>
-
Low-level API: RPC calls to Python side
---------------------------------------