Skip to content

Commit

Permalink
Move action_preview widget from g2p_registry_document to g2p-document…
Browse files Browse the repository at this point in the history
…s base module
  • Loading branch information
Q-Niranjan committed Dec 10, 2024
1 parent ca403b4 commit b627f67
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
6 changes: 5 additions & 1 deletion g2p_documents/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"data/storage_backend.xml",
],
"external_dependencies": {"python": ["boto3<=1.15.18", "python_slugify"]},
"assets": {},
"assets": {
"web.assets_backend": [
"g2p_documents/static/src/js/preview_document.js",
],
},
"demo": [],
"images": [],
"application": True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Widgetpreview extends Component {
const slugElement = currentRow.querySelector('.o_data_cell[name="slug"]');
if (slugElement) {
const slugValue = slugElement.textContent.trim();
console.log("Slug Value:", slugValue);

let recordID = 0;
if (slugValue.includes("-")) {
Expand All @@ -45,22 +44,25 @@ class Widgetpreview extends Component {
kwargs: {},
});
const mimetype = result.mimetype;

const file = {
id: recordID,
displayName: result.name,
downloadUrl: result.url,
isViewable: mimetype.includes("image") || mimetype.includes("pdf"),
defaultSource: result.url,
isImage: mimetype.includes("image"),
isPdf: mimetype.includes("pdf"),
};
if (file.isViewable) {
this.fileViewer.open(file);
if (typeof mimetype === "string" && mimetype) {
const file = {
id: recordID,
displayName: result.name,
downloadUrl: result.url,
isViewable: mimetype.includes("image") || mimetype.includes("pdf"),
defaultSource: result.url,
isImage: mimetype.includes("image"),
isPdf: mimetype.includes("pdf"),
};
if (file.isViewable) {
this.fileViewer.open(file);
} else {
window.open(result.url, "_blank");
}
} else {
window.open(result.url, "_blank");
}
}
}

registry.category("view_widgets").add("action_preview_registry", {component: Widgetpreview});
registry.category("view_widgets").add("action_preview", {component: Widgetpreview});
6 changes: 1 addition & 5 deletions g2p_registry_documents/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
"data": [
"views/registrant_document_views.xml",
],
"assets": {
"web.assets_backend": [
"g2p_registry_documents/static/src/js/preview_document.js",
],
},
"assets": {},
"demo": [],
"images": [],
"application": True,
Expand Down
8 changes: 5 additions & 3 deletions g2p_registry_documents/views/registrant_document_views.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_registrant_documents_form_individual" model="ir.ui.view">
<record id="view_registrant_documents_form_individual" model="ir.ui.view">
<field name="name">view_registrant_documents_form_individual</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="g2p_registry_individual.view_individuals_form" />
Expand All @@ -13,7 +13,8 @@
<field name="slug" string="Name" />
<field name="file_size" />
<field name="file_type" />
<widget name="action_preview_registry" />
<!-- Widget provided by g2p_documents module for document preview and viewing -->
<widget name="action_preview" />
</tree>
</field>
</page>
Expand All @@ -34,7 +35,8 @@
<field name="slug" string="Name" />
<field name="file_size" />
<field name="file_type" />
<widget name="action_preview_registry" />
<!-- Widget provided by g2p_documents module for document preview and viewing -->
<widget name="action_preview" />
</tree>
</field>
</page>
Expand Down

0 comments on commit b627f67

Please sign in to comment.