Initial commit: OCA Storage packages (17 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:06 +02:00
commit 7a380f05d3
659 changed files with 41828 additions and 0 deletions

View file

@ -0,0 +1,76 @@
/** @odoo-module */
/**
* Copyright 2023 ACSONE SA/NV
*/
import {Component, onWillUpdateProps, useState} from "@odoo/owl";
import {FileUploader} from "@web/views/fields/file_handler";
import {getDataURLFromFile} from "@web/core/utils/urls";
import {registry} from "@web/core/registry";
import {standardFieldProps} from "@web/views/fields/standard_field_props";
import {useService} from "@web/core/utils/hooks";
export class FSFileField extends Component {
setup() {
this.notification = useService("notification");
this.state = useState({
...this.props.value,
isValid: true,
});
onWillUpdateProps((nextProps) => {
this.state.isUploading = false;
const {filename, mimetype, url} = nextProps.value || {};
this.state.filename = filename;
this.state.mimetype = mimetype;
this.state.url = url;
});
}
async uploadFile(file) {
this.state.isUploading = true;
const data = await getDataURLFromFile(file);
this.props.record.update({
[this.props.name]: {
filename: file.name,
content: data.split(",")[1],
},
});
this.state.isUploading = false;
}
clear() {
this.props.record.update({[this.props.name]: false});
}
onFileRemove() {
this.state.isValid = true;
this.props.update(false);
}
onFileUploaded(info) {
this.state.isValid = true;
this.props.update({
filename: info.name,
content: info.data,
});
}
onLoadFailed() {
this.state.isValid = false;
this.notification.add(this.env._t("Could not display the selected image"), {
type: "danger",
});
}
}
FSFileField.template = "fs_file.FSFileField";
FSFileField.components = {
FileUploader,
};
FSFileField.props = {
...standardFieldProps,
acceptedFileExtensions: {type: String, optional: true},
};
FSFileField.defaultProps = {
acceptedFileExtensions: "*",
};
registry.category("fields").add("fs_file", FSFileField);

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="fs_file.FSFileField" owl="1">
<t t-if="!props.readonly">
<div class="w-100 d-inline-flex">
<FileUploader
acceptedFileExtensions="props.acceptedFileExtensions"
t-key="props.record.resId"
onUploaded.bind="onFileUploaded"
>
<t t-if="props.value">
<t t-if="state.url">
<a
class="o_form_uri fs_file_link"
t-att-href="state.url + '?download=1'"
>
<span class="fa fa-download me-2" />
<t t-if="state.filename" t-esc="state.filename" />
</a>
</t>
<t t-else="">
<t t-if="state.filename" t-esc="state.filename" />
</t>
</t>
<t t-set-slot="toggler">
<button
class="btn btn-secondary fa fa-pencil o_select_file_button py-0"
data-tooltip="Edit"
aria-label="Edit"
/>
</t>
<button
class="btn btn-secondary fa fa-trash o_clear_file_button py-0"
data-tooltip="Clear"
aria-label="Clear"
t-on-click="onFileRemove"
/>
</FileUploader>
</div>
</t>
<t t-elif="props.value">
<a class="o_form_uri fs_file_link" t-att-href="state.url">
<span class="fa fa-download me-2" />
<t t-if="state.filename" t-esc="state.filename" />
</a>
</t>
</t>
</templates>