You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

  1. odoo.define('web_timeline.TimelineModel', function (require) {
  2. "use strict";
  3. var AbstractModel = require('web.AbstractModel');
  4. var TimelineModel = AbstractModel.extend({
  5. /**
  6. * @constructor
  7. */
  8. init: function () {
  9. this._super.apply(this, arguments);
  10. },
  11. /**
  12. * @override
  13. */
  14. load: function (params) {
  15. var self = this;
  16. this.modelName = params.modelName;
  17. this.fieldNames = params.fieldNames;
  18. if (!this.preload_def) {
  19. this.preload_def = $.Deferred();
  20. $.when(
  21. this._rpc({model: this.modelName, method: 'check_access_rights', args: ["write", false]}),
  22. this._rpc({model: this.modelName, method: 'check_access_rights', args: ["unlink", false]}),
  23. this._rpc({model: this.modelName, method: 'check_access_rights', args: ["create", false]}))
  24. .then(function (write, unlink, create) {
  25. self.write_right = write;
  26. self.unlink_right = unlink;
  27. self.create_right = create;
  28. self.preload_def.resolve();
  29. });
  30. }
  31. this.data = {
  32. domain: params.domain,
  33. context: params.context,
  34. };
  35. return this.preload_def.then(this._loadTimeline.bind(this));
  36. },
  37. /**
  38. * Read the records for the timeline.
  39. *
  40. * @private
  41. * @returns {jQuery.Deferred}
  42. */
  43. _loadTimeline: function () {
  44. var self = this;
  45. return self._rpc({
  46. model: self.modelName,
  47. method: 'search_read',
  48. context: self.data.context,
  49. fields: self.fieldNames,
  50. domain: self.data.domain,
  51. })
  52. .then(function (events) {
  53. self.data.data = events;
  54. self.data.rights = {
  55. 'unlink': self.unlink_right,
  56. 'create': self.create_right,
  57. 'write': self.write_right,
  58. };
  59. });
  60. },
  61. });
  62. return TimelineModel;
  63. });