Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] fs_image: Add download button #429

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fs_image/static/src/scss/fsimage_field.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.fs_file_download_button {
top: 10% !important;
left: 50% !important;
position: absolute !important;
}
22 changes: 22 additions & 0 deletions fs_image/static/src/views/fields/fsimage_field.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {onWillUpdateProps, useState} from "@odoo/owl";

import {AltTextDialog} from "../dialogs/alttext_dialog.esm";
import {download, downloadFile} from "@web/core/network/download";
import {registry} from "@web/core/registry";
import {url} from "@web/core/utils/urls";
import {useService} from "@web/core/utils/hooks";
Expand Down Expand Up @@ -89,6 +90,27 @@ export class FSImageField extends ImageField {
};
this.dialogService.add(AltTextDialog, dialogProps);
}
async onFileDownload() {
if (this.props.value.content) {
const magic = fileTypeMagicWordMap[this.props.value.content[0]] || "png";
await downloadFile(
`data:image/${magic};base64,${this.props.value.content}`,
this.state.filename,
`image/${magic}`
);
} else {
await download({
data: {
model: this.props.record.resModel,
id: this.props.record.resId,
field: this.props.name,
filename: this.state.filename || "download",
download: true,
},
url: "/web/image",
});
}
}
}

FSImageField.template = "fs_image.FSImageField";
Expand Down
46 changes: 28 additions & 18 deletions fs_image/static/src/views/fields/fsimage_field.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@
<i class="fa fa-pencil fa-fw" />
</button>
</t>
<button
t-if="props.value and state.isValid"
class="o_clear_file_button btn btn-light border-0 rounded-circle m-1 p-1"
data-tooltip="Alt Text"
aria-label="Set Alt Text"
t-on-click="onAltTextEdit"
>
<i class="fa fa-blind fa-fw" />
</button>
<button
t-if="props.value and state.isValid"
class="o_clear_file_button btn btn-light border-0 rounded-circle m-1 p-1"
data-tooltip="Clear"
aria-label="Clear"
t-on-click="onFileRemove"
>
<i class="fa fa-trash-o fa-fw" />
</button>
<t t-if="props.value and state.isValid">
<button
class="o_alt_text_file_button btn btn-light border-0 rounded-circle m-1 p-1"
data-tooltip="Alt Text"
aria-label="Set Alt Text"
t-on-click="onAltTextEdit"
>
<i class="fa fa-blind fa-fw" />
</button>
<button
class="o_clear_file_button btn btn-light border-0 rounded-circle m-1 p-1"
data-tooltip="Clear"
aria-label="Clear"
t-on-click="onFileRemove"
>
<i class="fa fa-trash-o fa-fw" />
</button>
</t>
</FileUploader>
</t>
</div>
Expand All @@ -59,6 +59,16 @@
t-att-data-tooltip-info="hasTooltip and tooltipAttributes.info"
t-att-data-tooltip-delay="hasTooltip and props.zoomDelay"
/>
<button
t-if="props.value and state.isValid"
class="fs_file_download_button btn btn-light border-0 rounded-circle m-1 p-1 translate-middle opacity-0 opacity-100-hover"
data-tooltip="Download"
aria-label="Download"
t-on-click="onFileDownload"
>
<i class="fa fa-download fa-fw" />
</button>

</div>
</t>

Expand Down
Loading