Skip to content

Commit

Permalink
[MIG] fs_base_multi_image: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenminhchien committed Apr 26, 2024
1 parent 9ca3aa2 commit f7d0410
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
1 change: 1 addition & 0 deletions fs_base_multi_image/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Contributors
------------

- Laurent Mignon <laurent.mignon@acsone.eu>
- Nguyen Minh Chien <chien@trobz.com>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion fs_base_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Fs Base Multi Image",
"summary": """
Mulitple Images from External File System""",
"version": "16.0.1.1.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/storage",
Expand Down
1 change: 1 addition & 0 deletions fs_base_multi_image/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Laurent Mignon \<<laurent.mignon@acsone.eu>\>
- Nguyen Minh Chien \<<chien@trobz.com>\>
2 changes: 1 addition & 1 deletion fs_base_multi_image/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -441,6 +440,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Nguyen Minh Chien &lt;<a class="reference external" href="mailto:chien&#64;trobz.com">chien&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/** @odoo-module **/

import {blockUI, unblockUI} from "web.framework";
import {X2ManyField, x2ManyField} from "@web/views/fields/x2many/x2many_field";
import {onWillRender, useRef, useState} from "@odoo/owl";

import {X2ManyField} from "@web/views/fields/x2many/x2many_field";
import {registry} from "@web/core/registry";

export class FsImageRelationDndUploadField extends X2ManyField {
setup() {
super.setup();
this.options = this.activeField.options;
this.relationField = this.field.relation_field;
this.defaultTarget = this.options.target || "specific";
this.defaultTarget = this.props.crudOptions.target || "specific";
this.state = useState({
dragging: false,
target: this.defaultTarget,
Expand All @@ -38,7 +35,7 @@ export class FsImageRelationDndUploadField extends X2ManyField {

initDefaultSequence() {
let sequence = 0;
_.each(this.props.value.records, (record) => {
$.each(this.props.record.data[this.props.name].records, (i, record) => {
sequence = record.data.sequence;
if (sequence >= this.defaultSequence) {
this.defaultSequence = sequence + 1;
Expand Down Expand Up @@ -97,7 +94,7 @@ export class FsImageRelationDndUploadField extends X2ManyField {
.call("fs.image", "create", [imagesDesc])
.then((fsImageIds) => {
let values = {};
_.each(fsImageIds, (fsImageId) => {
$.each(fsImageIds, (i, fsImageId) => {
values = self.getFsImageRelationValues(fsImageId);
createValues.push(values);
});
Expand All @@ -111,7 +108,7 @@ export class FsImageRelationDndUploadField extends X2ManyField {
}

displayUploadError() {
unblockUI();
this.env.services.ui.unblock();
this.env.services.notification.add(
this.env._t("An error occurred during the images upload."),
{
Expand All @@ -133,7 +130,7 @@ export class FsImageRelationDndUploadField extends X2ManyField {
async uploadSpecificImage(imagesDesc) {
const self = this;
const createValues = [];
_.each(imagesDesc, (imageDesc) => {
$.each(imagesDesc, (i, imageDesc) => {
createValues.push(self.getSpecificImageRelationValues(imageDesc));
});
self.createFieldRelationRecords(createValues);
Expand All @@ -155,13 +152,13 @@ export class FsImageRelationDndUploadField extends X2ManyField {
const self = this;
const model = self.env.model;
model.orm
.call(self.activeField.relation, "create", [createValues])
.call(self.field.relation, "create", [createValues])
.then(() => {
model.root.load();
model.root.save();
})
.then(() => {
unblockUI();
self.env.services.ui.unblock();
})
.catch(() => {
self.displayUploadError();
Expand All @@ -171,8 +168,8 @@ export class FsImageRelationDndUploadField extends X2ManyField {
async uploadImages(files) {
const self = this;
const promises = [];
blockUI();
_.each(files, function (file) {
this.env.services.ui.block();
$.each(files, function (i, file) {
if (!file.type.includes("image")) {
return;
}
Expand All @@ -189,7 +186,7 @@ export class FsImageRelationDndUploadField extends X2ManyField {
});
return Promise.all(promises).then(function (fileContents) {
const imagesDesc = [];
_.each(fileContents, function (fileContent) {
$.each(fileContents, function (i, fileContent) {
imagesDesc.push(self.getFileImageDesc(fileContent));
});
if (imagesDesc.length > 0) {
Expand All @@ -201,10 +198,10 @@ export class FsImageRelationDndUploadField extends X2ManyField {
self.uploadSpecificImage(imagesDesc);
break;
default:
unblockUI();
self.env.services.ui.unblock();
}
} else {
unblockUI();
self.env.services.ui.unblock();
}
});
}
Expand All @@ -221,6 +218,11 @@ export class FsImageRelationDndUploadField extends X2ManyField {

FsImageRelationDndUploadField.template = "web.FsImageRelationDndUploadField";

export const fsImageRelationDndUploadField = {
...x2ManyField,
component: FsImageRelationDndUploadField,
};

registry
.category("fields")
.add("fs_image_relation_dnd_upload", FsImageRelationDndUploadField);
.add("fs_image_relation_dnd_upload", fsImageRelationDndUploadField);
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
display: table;
padding: 10px;
width: 90%;
margin: auto;
margin-top: 5px;
margin: 5px auto 10px;
min-height: 100px;
border: 1px solid transparent;
border-color: var(--notebook-link-border-color, transparent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
t-name="web.FsImageRelationDndUploadField"
t-inherit="web.X2ManyField"
t-inherit-mode="primary"
owl="1"
>
<xpath expr="//div[hasclass('o_x2m_control_panel')]" position="before">
<t t-if="displayDndZone">
Expand Down
9 changes: 3 additions & 6 deletions fs_base_multi_image/views/fs_image_relation_mixin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@
class="oe_avatar"
options="{'preview_image': 'image_medium', 'zoom': true}"
readonly="1"
attrs="{'invisible': [('link_existing', '=', False)]}"
invisible="not link_existing"
/>
<field
name="specific_image"
class="oe_avatar"
options="{'preview_image': 'image_medium', 'zoom': true}"
attrs="{'invisible': [('link_existing', '=', True)]}"
invisible="link_existing"
/>
<group>
<field name="link_existing" />
<field name="name" />
<field name="sequence" />
<field
name="image_id"
attrs="{'invisible': [('link_existing', '=', False)]}"
/>
<field name="image_id" invisible="not link_existing" />
</group>
<group name="extra">
<!-- Add here custom relation fields -->
Expand Down

0 comments on commit f7d0410

Please sign in to comment.