[IMP] dataset docstrings cleanups, remove traverser

Direct access to Dataset.ids was supposed to be superseeded by exposing a cleaner api named Traverser.
But as it never happened we keep the leaky dataset api for the moment.
Direct access to ids should be avoided whenever possible.
We might reintroduce Traverser in the future.

bzr revid: al@openerp.com-20121001223630-epxu4vad93i74lmd
This commit is contained in:
Antony Lesuisse 2012-10-02 00:36:30 +02:00
parent f025e07860
commit c4eafc859d
2 changed files with 6 additions and 161 deletions

View File

@ -349,85 +349,6 @@ instance.web.Model = instance.web.Class.extend({
},
});
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
@ -513,8 +434,7 @@ instance.web.StaticDataGroup = instance.web.DataGroup.extend({
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
@ -631,8 +551,6 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* 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) {
@ -655,8 +573,6 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* 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()});
@ -680,8 +596,6 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @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) {
@ -698,8 +612,6 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
*
* @param {String} method
* @param {Array} [args]
* @param {Function} callback
* @param {Function} error_callback
* @returns {$.Deferred}
*/
call_button: function (method, args) {
@ -709,7 +621,6 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* Fetches the "readable name" for records, based on intrinsic rules
*
* @param {Array} ids
* @param {Function} callback
* @returns {$.Deferred}
*/
name_get: function(ids) {
@ -735,7 +646,6 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
},
/**
* @param name
* @param callback
*/
name_create: function(name) {
return this._model.call('name_create', [name], {context: this._model.context()});
@ -795,6 +705,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
});
},
});
instance.web.DataSetStatic = instance.web.DataSet.extend({
init: function(parent, model, context, ids) {
this._super(parent, model, context);
@ -825,6 +736,7 @@ instance.web.DataSetStatic = instance.web.DataSet.extend({
this.set_ids(_.without.apply(null, [this.ids].concat(ids)));
}
});
instance.web.DataSetSearch = instance.web.DataSet.extend({
/**
* @constructs instance.web.DataSetSearch
@ -893,6 +805,7 @@ instance.web.DataSetSearch = instance.web.DataSet.extend({
return this._super();
}
});
instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
virtual_id_prefix: "one2many_v_id_",
debug_mode: true,
@ -964,7 +877,8 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
this.cache = [];
this.delete_all = false;
},
on_change: function() {},
on_change: function() {
},
read_ids: function (ids, fields, options) {
var self = this;
var to_get = [];

View File

@ -240,75 +240,6 @@ regular query for records):
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
---------------------------------------