|
| 1 | +/** @odoo-module */ |
| 2 | + |
| 3 | +import { KeepLast } from "@web/core/utils/concurrency"; |
| 4 | +import { url } from "@web/core/utils/urls"; |
| 5 | + |
| 6 | +export class GalleryModel { |
| 7 | + constructor(orm, resModel, archInfo, fields) { |
| 8 | + this.orm = orm; |
| 9 | + this.resModel = resModel; |
| 10 | + const { imageField, limit, fieldsForTooltip } = archInfo; |
| 11 | + this.imageField = imageField; |
| 12 | + this.fieldsForTooltip = fieldsForTooltip; |
| 13 | + this.limit = limit; |
| 14 | + this.keepLast = new KeepLast(); |
| 15 | + this.fields = fields; |
| 16 | + this.pager = { offset: 0, limit: limit }; |
| 17 | + } |
| 18 | + |
| 19 | + async loadImages(domain) { |
| 20 | + const specification = { |
| 21 | + [this.imageField]: {}, |
| 22 | + write_date: {}, |
| 23 | + } |
| 24 | + for (const field of this.fieldsForTooltip) { |
| 25 | + specification[field] = {}; |
| 26 | + } |
| 27 | + const { length, records } = await this.keepLast.add( |
| 28 | + this.orm.webSearchRead(this.resModel, domain, { |
| 29 | + limit: this.pager.limit, |
| 30 | + offset: this.pager.offset, |
| 31 | + specification, |
| 32 | + context: { |
| 33 | + bin_size: true, |
| 34 | + } |
| 35 | + }) |
| 36 | + ); |
| 37 | + this.records = records; |
| 38 | + this.recordsLength = length; |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | + async uploadImage(record_id, image_binary, domain) { |
| 43 | + await this.orm.webSave( |
| 44 | + this.resModel, |
| 45 | + [record_id], |
| 46 | + { |
| 47 | + [this.imageField]: image_binary, |
| 48 | + }, |
| 49 | + { |
| 50 | + specification: {}, |
| 51 | + } |
| 52 | + ) |
| 53 | + await this.loadImages(domain); |
| 54 | + } |
| 55 | +} |
0 commit comments