2 openerp.web.data = function(instance) {
5 * Serializes the sort criterion array of a dataset into a form which can be
6 * consumed by OpenERP's RPC APIs.
8 * @param {Array} criterion array of fields, from first to last criteria, prefixed with '-' for reverse sorting
9 * @returns {String} SQL-like sorting string (``ORDER BY``) clause
11 instance.web.serialize_sort = function (criterion) {
12 return _.map(criterion,
14 if (criteria[0] === '-') {
15 return criteria.slice(1) + ' DESC';
17 return criteria + ' ASC';
21 instance.web.Query = instance.web.Class.extend({
22 init: function (model, fields) {
24 this._fields = fields;
31 clone: function (to_set) {
32 to_set = to_set || {};
33 var q = new instance.web.Query(this._model, this._fields);
34 q._context = this._context;
35 q._filter = this._filter;
36 q._limit = this._limit;
37 q._offset = this._offset;
38 q._order_by = this._order_by;
40 for(var key in to_set) {
41 if (!to_set.hasOwnProperty(key)) { continue; }
44 q._filter = new instance.web.CompoundDomain(
45 q._filter, to_set.filter);
48 q._context = new instance.web.CompoundContext(
49 q._context, to_set.context);
54 q['_' + key] = to_set[key];
59 _execute: function () {
61 return instance.session.rpc('/web/dataset/search_read', {
62 model: this._model.name,
63 fields: this._fields || false,
64 domain: instance.web.pyeval.eval('domains',
65 [this._model.domain(this._filter)]),
66 context: instance.web.pyeval.eval('contexts',
67 [this._model.context(this._context)]),
70 sort: instance.web.serialize_sort(this._order_by)
71 }).then(function (results) {
72 self._count = results.length;
73 return results.records;
77 * Fetches the first record matching the query, or null
79 * @returns {jQuery.Deferred<Object|null>}
83 return this.clone({limit: 1})._execute().then(function (records) {
85 if (records.length) { return records[0]; }
90 * Fetches all records matching the query
92 * @returns {jQuery.Deferred<Array<>>}
95 return this._execute();
98 * Fetches the number of records matching the query in the database
100 * @returns {jQuery.Deferred<Number>}
103 if (this._count != undefined) { return $.when(this._count); }
104 return this._model.call(
105 'search_count', [this._filter], {
106 context: this._model.context(this._context)});
109 * Performs a groups read according to the provided grouping criterion
111 * @param {String|Array<String>} grouping
112 * @returns {jQuery.Deferred<Array<openerp.web.QueryGroup>> | null}
114 group_by: function (grouping) {
115 var ctx = instance.web.pyeval.eval(
116 'context', this._model.context(this._context));
118 // undefined passed in explicitly (!)
119 if (_.isUndefined(grouping)) {
123 if (!(grouping instanceof Array)) {
124 grouping = _.toArray(arguments);
126 if (_.isEmpty(grouping) && !ctx['group_by_no_leaf']) {
131 return this._model.call('read_group', {
133 fields: _.uniq(grouping.concat(this._fields || [])),
134 domain: this._model.domain(this._filter),
136 offset: this._offset,
138 orderby: instance.web.serialize_sort(this._order_by) || false
139 }).then(function (results) {
140 return _(results).map(function (result) {
141 // FIX: querygroup initialization
142 result.__context = result.__context || {};
143 result.__context.group_by = result.__context.group_by || [];
144 _.defaults(result.__context, ctx);
145 return new instance.web.QueryGroup(
146 self._model.name, grouping[0], result);
151 * Creates a new query with the union of the current query's context and
154 * @param context context data to add to the query
155 * @returns {openerp.web.Query}
157 context: function (context) {
158 if (!context) { return this; }
159 return this.clone({context: context});
162 * Creates a new query with the union of the current query's filter and
165 * @param domain domain data to AND with the current query filter
166 * @returns {openerp.web.Query}
168 filter: function (domain) {
169 if (!domain) { return this; }
170 return this.clone({filter: domain});
173 * Creates a new query with the provided limit replacing the current
176 * @param {Number} limit maximum number of records the query should retrieve
177 * @returns {openerp.web.Query}
179 limit: function (limit) {
180 return this.clone({limit: limit});
183 * Creates a new query with the provided offset replacing the current
186 * @param {Number} offset number of records the query should skip before starting its retrieval
187 * @returns {openerp.web.Query}
189 offset: function (offset) {
190 return this.clone({offset: offset});
193 * Creates a new query with the provided ordering parameters replacing
194 * those of the current query
196 * @param {String...} fields ordering clauses
197 * @returns {openerp.web.Query}
199 order_by: function (fields) {
200 if (fields === undefined) { return this; }
201 if (!(fields instanceof Array)) {
202 fields = _.toArray(arguments);
204 if (_.isEmpty(fields)) { return this; }
205 return this.clone({order_by: fields});
209 instance.web.QueryGroup = instance.web.Class.extend({
210 init: function (model, grouping_field, read_group_group) {
211 // In cases where group_by_no_leaf and no group_by, the result of
212 // read_group has aggregate fields but no __context or __domain.
213 // Create default (empty) values for those so that things don't break
214 var fixed_group = _.extend(
215 {__context: {group_by: []}, __domain: []},
219 _(fixed_group).each(function (value, key) {
220 if (key.indexOf('__') === 0
221 || key === grouping_field
222 || key === grouping_field + '_count') {
225 aggregates[key] = value || 0;
228 this.model = new instance.web.Model(
229 model, fixed_group.__context, fixed_group.__domain);
231 var group_size = fixed_group[grouping_field + '_count'] || fixed_group.__count || 0;
232 var leaf_group = fixed_group.__context.group_by.length === 0;
234 folded: !!(fixed_group.__fold),
235 grouped_on: grouping_field,
236 // if terminal group (or no group) and group_by_no_leaf => use group.__count
238 value: fixed_group[grouping_field],
239 // A group is open-able if it's not a leaf in group_by_no_leaf mode
240 has_children: !(leaf_group && fixed_group.__context['group_by_no_leaf']),
242 aggregates: aggregates
245 get: function (key) {
246 return this.attributes[key];
248 subgroups: function () {
249 return this.model.query().group_by(this.model.context().group_by);
252 return this.model.query.apply(this.model, arguments);
256 instance.web.Model = instance.web.Class.extend({
258 * @constructs instance.web.Model
259 * @extends instance.web.Class
261 * @param {String} model_name name of the OpenERP model this object is bound to
262 * @param {Object} [context]
263 * @param {Array} [domain]
265 init: function (model_name, context, domain) {
266 this.name = model_name;
267 this._context = context || {};
268 this._domain = domain || [];
271 * @deprecated does not allow to specify kwargs, directly use call() instead
273 get_func: function (method_name) {
276 return self.call(method_name, _.toArray(arguments));
280 * Call a method (over RPC) on the bound OpenERP model.
282 * @param {String} method name of the method to call
283 * @param {Array} [args] positional arguments
284 * @param {Object} [kwargs] keyword arguments
285 * @param {Object} [options] additional options for the rpc() method
286 * @returns {jQuery.Deferred<>} call result
288 call: function (method, args, kwargs, options) {
290 kwargs = kwargs || {};
291 if (!_.isArray(args)) {
292 // call(method, kwargs)
296 instance.web.pyeval.ensure_evaluated(args, kwargs);
297 var debug = instance.session.debug ? '/'+this.name+':'+method : '';
298 return instance.session.rpc('/web/dataset/call_kw' + debug, {
306 * Fetches a Query instance bound to this model, for searching
308 * @param {Array<String>} [fields] fields to ultimately fetch during the search
309 * @returns {instance.web.Query}
311 query: function (fields) {
312 return new instance.web.Query(this, fields);
315 * Executes a signal on the designated workflow, on the bound OpenERP model
317 * @param {Number} id workflow identifier
318 * @param {String} signal signal to trigger on the workflow
320 exec_workflow: function (id, signal) {
321 return instance.session.rpc('/web/dataset/exec_workflow', {
328 * Fetches the model's domain, combined with the provided domain if any
330 * @param {Array} [domain] to combine with the model's internal domain
331 * @returns {instance.web.CompoundDomain} The model's internal domain, or the AND-ed union of the model's internal domain and the provided domain
333 domain: function (domain) {
334 if (!domain) { return this._domain; }
335 return new instance.web.CompoundDomain(
336 this._domain, domain);
339 * Fetches the combination of the user's context and the domain context,
340 * combined with the provided context if any
342 * @param {Object} [context] to combine with the model's internal context
343 * @returns {instance.web.CompoundContext} The union of the user's context and the model's internal context, as well as the provided context if any. In that order.
345 context: function (context) {
346 return new instance.web.CompoundContext(
347 instance.session.user_context, this._context, context || {});
350 * Button action caller, needs to perform cleanup if an action is returned
351 * from the button (parsing of context and domain, and fixup of the views
352 * collection for act_window actions)
354 * FIXME: remove when evaluator integrated
356 call_button: function (method, args) {
357 instance.web.pyeval.ensure_evaluated(args, {});
358 return instance.session.rpc('/web/dataset/call_button', {
361 // Should not be necessary anymore. Integrate remote in this?
363 context_id: args.length - 1,
369 instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, {
371 * Collection of OpenERP records, used to share records and the current selection between views.
373 * @constructs instance.web.DataSet
375 * @param {String} model the OpenERP model this dataset will manage
377 init: function(parent, model, context) {
378 instance.web.PropertiesMixin.init.call(this);
380 this.context = context || {};
383 this._model = new instance.web.Model(model, context);
385 previous: function () {
387 if (!this.ids.length) {
389 } else if (this.index < 0) {
390 this.index = this.ids.length - 1;
396 if (!this.ids.length) {
398 } else if (this.index >= this.ids.length) {
403 select_id: function(id) {
404 var idx = this.get_id_index(id);
412 get_id_index: function(id) {
413 for (var i=0, ii=this.ids.length; i<ii; i++) {
414 // Here we use type coercion because of the mess potentially caused by
415 // OpenERP ids fetched from the DOM as string. (eg: dhtmlxcalendar)
416 // OpenERP ids can be non-numeric too ! (eg: recursive events in calendar)
417 if (id == this.ids[i]) {
426 * @param {Array} ids identifiers of the records to read
427 * @param {Array} fields fields to read and return, by default all fields are returned
428 * @returns {$.Deferred}
430 read_ids: function (ids, fields, options) {
432 return $.Deferred().resolve([]);
434 options = options || {};
437 var context = this.get_context(options.context);
438 if (options.check_access_rule === true){
439 method = 'search_read';
440 ids_arg = [['id', 'in', ids]];
441 context = new instance.web.CompoundContext(context, {active_test: false});
443 return this._model.call(method,
444 [ids_arg, fields || false],
446 .then(function (records) {
447 if (records.length <= 1) { return records; }
449 for (var i = 0; i < ids.length; i++) {
452 records.sort(function (a, b) {
453 return indexes[a.id] - indexes[b.id];
459 * Read a slice of the records represented by this DataSet, based on its
460 * domain and context.
462 * @param {Array} [fields] fields to read and return, by default all fields are returned
463 * @params {Object} [options]
464 * @param {Number} [options.offset=0] The index from which selected records should be returned
465 * @param {Number} [options.limit=null] The maximum number of records to return
466 * @returns {$.Deferred}
468 read_slice: function (fields, options) {
470 options = options || {};
471 return this._model.query(fields)
472 .limit(options.limit || false)
473 .offset(options.offset || 0)
474 .all().done(function (records) {
475 self.ids = _(records).pluck('id');
479 * Reads the current dataset record (from its index)
481 * @params {Array} [fields] fields to read and return, by default all fields are returned
482 * @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context
483 * @returns {$.Deferred}
485 read_index: function (fields, options) {
486 options = options || {};
487 return this.read_ids([this.ids[this.index]], fields, options).then(function (records) {
488 if (_.isEmpty(records)) { return $.Deferred().reject().promise(); }
493 * Reads default values for the current model
495 * @param {Array} [fields] fields to get default values for, by default all defaults are read
496 * @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context
497 * @returns {$.Deferred}
499 default_get: function(fields, options) {
500 options = options || {};
501 return this._model.call('default_get',
502 [fields], {context: this.get_context(options.context)});
505 * Creates a new record in db
507 * @param {Object} data field values to set on the new record
508 * @param {Object} options Dictionary that can contain the following keys:
509 * - readonly_fields: Values from readonly fields that were updated by
510 * on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
511 * @returns {$.Deferred}
513 create: function(data, options) {
515 return this._model.call('create', [data], {
516 context: this.get_context()
517 }).done(function () {
518 self.trigger('dataset_changed', data, options)
522 * Saves the provided data in an existing db record
524 * @param {Number|String} id identifier for the record to alter
525 * @param {Object} data field values to write into the record
526 * @param {Object} options Dictionary that can contain the following keys:
527 * - context: The context to use in the server-side call.
528 * - readonly_fields: Values from readonly fields that were updated by
529 * on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
530 * @returns {$.Deferred}
532 write: function (id, data, options) {
533 options = options || {};
535 return this._model.call('write', [[id], data], {
536 context: this.get_context(options.context)
537 }).done(function () {
538 self.trigger('dataset_changed', id, data, options)
542 * Deletes an existing record from the database
544 * @param {Number|String} ids identifier of the record to delete
546 unlink: function(ids) {
548 return this._model.call('unlink', [ids], {
549 context: this.get_context()
550 }).done(function () {
551 self.trigger('dataset_changed', ids)
555 * Calls an arbitrary RPC method
557 * @param {String} method name of the method (on the current model) to call
558 * @param {Array} [args] arguments to pass to the method
559 * @param {Function} callback
560 * @param {Function} error_callback
561 * @returns {$.Deferred}
563 call: function (method, args) {
564 return this._model.call(method, args);
567 * Calls a button method, usually returning some sort of action
569 * @param {String} method
570 * @param {Array} [args]
571 * @returns {$.Deferred}
573 call_button: function (method, args) {
574 return this._model.call_button(method, args);
577 * Fetches the "readable name" for records, based on intrinsic rules
580 * @returns {$.Deferred}
582 name_get: function(ids) {
583 return this._model.call('name_get', [ids], {context: this.get_context()});
587 * @param {String} name name to perform a search for/on
588 * @param {Array} [domain=[]] filters for the objects returned, OpenERP domain
589 * @param {String} [operator='ilike'] matching operator to use with the provided name value
590 * @param {Number} [limit=0] maximum number of matches to return
591 * @param {Function} callback function to call with name_search result
592 * @returns {$.Deferred}
594 name_search: function (name, domain, operator, limit) {
595 return this._model.call('name_search', {
597 args: domain || false,
598 operator: operator || 'ilike',
599 context: this._model.context(),
606 name_create: function(name) {
607 return this._model.call('name_create', [name], {context: this.get_context()});
609 exec_workflow: function (id, signal) {
610 return this._model.exec_workflow(id, signal);
612 get_context: function(request_context) {
613 return this._model.context(request_context);
616 * Reads or changes sort criteria on the dataset.
618 * If not provided with any argument, serializes the sort criteria to
619 * an SQL-like form usable by OpenERP's ORM.
621 * If given a field, will set that field as first sorting criteria or,
622 * if the field is already the first sorting criteria, will reverse it.
624 * @param {String} [field] field to sort on, reverses it (toggle from ASC to DESC) if already the main sort criteria
625 * @param {Boolean} [force_reverse=false] forces inserting the field as DESC
626 * @returns {String|undefined}
628 sort: function (field, force_reverse) {
630 return instance.web.serialize_sort(this._sort);
632 var reverse = force_reverse || (this._sort[0] === field);
633 this._sort.splice.apply(
634 this._sort, [0, this._sort.length].concat(
635 _.without(this._sort, field, '-' + field)));
637 this._sort.unshift((reverse ? '-' : '') + field);
641 return this.ids.length;
643 alter_ids: function(n_ids) {
646 remove_ids: function (ids) {
647 this.alter_ids(_(this.ids).difference(ids));
649 add_ids: function(ids, at) {
650 var args = [at, 0].concat(_.difference(ids, this.ids));
651 this.ids.splice.apply(this.ids, args);
654 * Resequence records.
656 * @param {Array} ids identifiers of the records to resequence
657 * @returns {$.Deferred}
659 resequence: function (ids, options) {
660 options = options || {};
661 return instance.session.rpc('/web/dataset/resequence', {
664 context: instance.web.pyeval.eval(
665 'context', this.get_context(options.context)),
666 }).then(function (results) {
672 instance.web.DataSetStatic = instance.web.DataSet.extend({
673 init: function(parent, model, context, ids) {
675 this._super(parent, model, context);
677 this.ids = ids || [];
679 read_slice: function (fields, options) {
680 options = options || {};
681 fields = fields || {};
682 var offset = options.offset || 0,
683 limit = options.limit || false;
684 var end_pos = limit && limit !== -1 ? offset + limit : this.ids.length;
685 return this.read_ids(this.ids.slice(offset, end_pos), fields);
687 set_ids: function (ids) {
689 if (ids.length === 0) {
691 } else if (this.index >= ids.length - 1) {
692 this.index = ids.length - 1;
695 unlink: function(ids) {
696 this.set_ids(_.without.apply(null, [this.ids].concat(ids)));
697 this.trigger('unlink', ids);
698 return $.Deferred().resolve({result: true});
702 instance.web.DataSetSearch = instance.web.DataSet.extend({
704 * @constructs instance.web.DataSetSearch
705 * @extends instance.web.DataSet
707 * @param {Object} parent
708 * @param {String} model
709 * @param {Object} context
710 * @param {Array} domain
712 init: function(parent, model, context, domain) {
713 this._super(parent, model, context);
714 this.domain = domain || [];
717 this._model = new instance.web.Model(model, context, domain);
720 * Read a slice of the records represented by this DataSet, based on its
721 * domain and context.
723 * @params {Object} options
724 * @param {Array} [options.fields] fields to read and return, by default all fields are returned
725 * @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context
726 * @param {Array} [options.domain] domain data to add to the request payload, ANDed with the dataset's domain
727 * @param {Number} [options.offset=0] The index from which selected records should be returned
728 * @param {Number} [options.limit=null] The maximum number of records to return
729 * @returns {$.Deferred}
731 read_slice: function (fields, options) {
732 options = options || {};
734 var q = this._model.query(fields || false)
735 .filter(options.domain)
736 .context(options.context)
737 .offset(options.offset || 0)
738 .limit(options.limit || false);
739 q = q.order_by.apply(q, this._sort);
741 return q.all().done(function (records) {
742 // FIXME: not sure about that one, *could* have discarded count
743 q.count().done(function (count) { self._length = count; });
744 self.ids = _(records).pluck('id');
747 get_domain: function (other_domain) {
748 return this._model.domain(other_domain);
750 alter_ids: function (ids) {
752 if (this.index !== null && this.index >= this.ids.length) {
753 this.index = this.ids.length > 0 ? this.ids.length - 1 : 0;
756 remove_ids: function (ids) {
757 var before = this.ids.length;
760 this._length -= (before - this.ids.length);
763 unlink: function(ids, callback, error_callback) {
765 return this._super(ids).done(function(result) {
766 self.remove_ids( ids);
767 self.trigger("dataset_changed", ids, callback, error_callback);
771 if (this._length != null) {
774 return this._super();
778 instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
779 virtual_id_prefix: "one2many_v_id_",
782 this._super.apply(this, arguments);
784 this.last_default_get = {};
785 this.running_reads = [];
787 default_get: function(fields, options) {
789 return this._super(fields, options).done(function(res) {
790 self.last_default_get = res;
793 create: function(data, options) {
795 id:_.uniqueId(this.virtual_id_prefix),
796 values: _.extend({}, data, (options || {}).readonly_fields || {}),
797 defaults: this.last_default_get
799 this.to_create.push(_.extend(_.clone(cached), {values: _.clone(data)}));
800 this.cache.push(cached);
801 return $.Deferred().resolve(cached.id).promise();
803 write: function (id, data, options) {
805 var record = _.detect(this.to_create, function(x) {return x.id === id;});
806 record = record || _.detect(this.to_write, function(x) {return x.id === id;});
809 for (var k in data) {
810 if (record.values[k] === undefined || record.values[k] !== data[k]) {
815 $.extend(record.values, data);
818 record = {id: id, values: data};
819 self.to_write.push(record);
821 var cached = _.detect(this.cache, function(x) {return x.id === id;});
823 cached = {id: id, values: {}};
824 this.cache.push(cached);
826 $.extend(cached.values, _.extend({}, record.values, (options || {}).readonly_fields || {}));
828 this.trigger("dataset_changed", id, data, options);
829 return $.Deferred().resolve(true).promise();
831 unlink: function(ids, callback, error_callback) {
833 _.each(ids, function(id) {
834 if (! _.detect(self.to_create, function(x) { return x.id === id; })) {
835 self.to_delete.push({id: id})
838 this.to_create = _.reject(this.to_create, function(x) { return _.include(ids, x.id);});
839 this.to_write = _.reject(this.to_write, function(x) { return _.include(ids, x.id);});
840 this.cache = _.reject(this.cache, function(x) { return _.include(ids, x.id);});
841 this.set_ids(_.without.apply(_, [this.ids].concat(ids)));
842 this.trigger("dataset_changed", ids, callback, error_callback);
843 return $.async_when({result: true}).done(callback);
845 reset_ids: function(ids) {
851 this.delete_all = false;
852 _.each(_.clone(this.running_reads), function(el) {
856 read_ids: function (ids, fields, options) {
859 _.each(ids, function(id) {
860 var cached = _.detect(self.cache, function(x) {return x.id === id;});
861 var created = _.detect(self.to_create, function(x) {return x.id === id;});
863 _.each(fields, function(x) {if (cached.values[x] === undefined)
864 cached.values[x] = created.defaults[x] || false;});
866 if (!cached || !_.all(fields, function(x) {return cached.values[x] !== undefined}))
870 var return_records = function() {
871 var records = _.map(ids, function(id) {
872 var c = _.find(self.cache, function(c) {return c.id === id;});
873 return _.isUndefined(c) ? c : _.extend({}, c.values, {"id": id});
875 if (self.debug_mode) {
876 if (_.include(records, undefined)) {
877 throw "Record not correctly loaded";
880 var sort_fields = self._sort,
881 compare = function (v1, v2) {
882 return (v1 < v2) ? -1
886 // Array.sort is not necessarily stable. We must be careful with this because
887 // sorting an array where all items are considered equal is a worst-case that
888 // will randomize the array with an unstable sort! Therefore we must avoid
889 // sorting if there are no sort_fields (i.e. all items are considered equal)
890 // See also: http://ecma262-5.com/ELS5_Section_15.htm#Section_15.4.4.11
891 // http://code.google.com/p/v8/issues/detail?id=90
892 if (sort_fields.length) {
893 records.sort(function (a, b) {
894 return _.reduce(sort_fields, function (acc, field) {
895 if (acc) { return acc; }
897 if (field[0] === '-') {
899 field = field.slice(1);
901 if(!a[field] && a[field] !== 0){ return sign}
902 if(!b[field] && b[field] !== 0){ return (sign == -1) ? 1 : -1}
903 //m2o should be searched based on value[1] not based whole value(i.e. [id, value])
904 if(_.isArray(a[field]) && a[field].length == 2 && _.isString(a[field][1])){
905 return sign * compare(a[field][1], b[field][1]);
907 return sign * compare(a[field], b[field]);
911 return $.when(records);
913 if(to_get.length > 0) {
914 var def = $.Deferred();
915 self.running_reads.push(def);
916 def.always(function() {
917 self.running_reads = _.without(self.running_reads, def);
919 this._super(to_get, fields, options).then(function() {
920 def.resolve.apply(def, arguments);
922 def.reject.apply(def, arguments);
924 return def.then(function(records) {
925 _.each(records, function(record, index) {
926 var id = to_get[index];
927 var cached = _.detect(self.cache, function(x) {return x.id === id;});
929 self.cache.push({id: id, values: record});
931 // I assume cache value is prioritary
932 cached.values = _.defaults(_.clone(cached.values), record);
935 return return_records();
938 return return_records();
942 * Invalidates caching of a record in the dataset to ensure the next read
943 * of that record will hit the server.
945 * Of use when an action is going to remote-alter a record which will then
946 * need to be reloaded, e.g. action button.
948 * @param {Object} id record to remove from the BDS's cache
950 evict_record: function (id) {
951 // Don't evict records which haven't yet been saved: there is no more
952 // recent data on the server (and there potentially isn't any data),
953 // and this breaks the assumptions of other methods (that the data
954 // for new and altered records is both in the cache and in the to_write
955 // or to_create collection)
956 if (_(this.to_create.concat(this.to_write)).find(function (record) {
957 return record.id === id; })) {
960 for(var i=0, len=this.cache.length; i<len; ++i) {
961 var record = this.cache[i];
962 // if record we call the button upon is in the cache
963 if (record.id === id) {
964 // evict it so it gets reloaded from server
965 this.cache.splice(i, 1);
970 call_button: function (method, args) {
971 this.evict_record(args[0][0]);
972 return this._super(method, args);
974 exec_workflow: function (id, signal) {
975 this.evict_record(id);
976 return this._super(id, signal);
978 alter_ids: function(n_ids) {
980 this.trigger("dataset_changed", n_ids);
983 instance.web.BufferedDataSet.virtual_id_regex = /^one2many_v_id_.*$/;
985 instance.web.ProxyDataSet = instance.web.DataSetSearch.extend({
987 this._super.apply(this, arguments);
988 this.create_function = null;
989 this.write_function = null;
990 this.read_function = null;
991 this.default_get_function = null;
992 this.unlink_function = null;
994 read_ids: function (ids, fields, options) {
995 if (this.read_function) {
996 return this.read_function(ids, fields, options, this._super);
998 return this._super.apply(this, arguments);
1001 default_get: function(fields, options) {
1002 if (this.default_get_function) {
1003 return this.default_get_function(fields, options, this._super);
1005 return this._super.apply(this, arguments);
1008 create: function(data, options) {
1009 if (this.create_function) {
1010 return this.create_function(data, options, this._super);
1012 return this._super.apply(this, arguments);
1015 write: function (id, data, options) {
1016 if (this.write_function) {
1017 return this.write_function(id, data, options, this._super);
1019 return this._super.apply(this, arguments);
1022 unlink: function(ids) {
1023 if (this.unlink_function) {
1024 return this.unlink_function(ids, this._super);
1026 return this._super.apply(this, arguments);
1031 instance.web.CompoundContext = instance.web.Class.extend({
1033 this.__ref = "compound_context";
1034 this.__contexts = [];
1035 this.__eval_context = null;
1037 _.each(arguments, function(x) {
1041 add: function (context) {
1042 this.__contexts.push(context);
1045 set_eval_context: function (eval_context) {
1046 this.__eval_context = eval_context;
1049 get_eval_context: function () {
1050 return this.__eval_context;
1053 return instance.web.pyeval.eval('context', this, undefined, {no_user_context: true});
1057 instance.web.CompoundDomain = instance.web.Class.extend({
1059 this.__ref = "compound_domain";
1060 this.__domains = [];
1061 this.__eval_context = null;
1063 _.each(arguments, function(x) {
1067 add: function(domain) {
1068 this.__domains.push(domain);
1071 set_eval_context: function(eval_context) {
1072 this.__eval_context = eval_context;
1075 get_eval_context: function() {
1076 return this.__eval_context;
1079 return instance.web.pyeval.eval('domain', this);
1083 instance.web.DropMisordered = instance.web.Class.extend({
1085 * @constructs instance.web.DropMisordered
1086 * @extends instance.web.Class
1088 * @param {Boolean} [failMisordered=false] whether mis-ordered responses should be failed or just ignored
1090 init: function (failMisordered) {
1091 // local sequence number, for requests sent
1093 // remote sequence number, seqnum of last received request
1095 this.failMisordered = failMisordered || false;
1098 * Adds a deferred (usually an async request) to the sequencer
1100 * @param {$.Deferred} deferred to ensure add
1101 * @returns {$.Deferred}
1103 add: function (deferred) {
1104 var res = $.Deferred();
1106 var self = this, seq = this.lsn++;
1107 deferred.done(function () {
1108 if (seq > self.rsn) {
1110 res.resolve.apply(res, arguments);
1111 } else if (self.failMisordered) {
1114 }).fail(function () {
1115 res.reject.apply(res, arguments);
1118 return res.promise();
1124 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: