Skip to content

Commit

Permalink
[FIX] sign_oca: fix errors accesing to pdf viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Nov 22, 2024
1 parent 75d32b5 commit d1ca0b4
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 252 deletions.
23 changes: 21 additions & 2 deletions sign_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,34 @@
"sign_oca/static/src/elements/elements.xml",
"sign_oca/static/src/scss/sign_oca.scss",
"sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common.esm.js",
"sign_oca/static/src/components/sign_oca_configure/sign_oca_configure_field_dialog.esm.js",
"sign_oca/static/src/components/sign_oca_configure/sign_oca_configure_field_dialog.xml",
"sign_oca/static/src/components/sign_oca_configure/sign_oca_configure.esm.js",
"sign_oca/static/src/components/sign_oca_preview/sign_oca_preview.esm.js",
"sign_oca/static/src/components/sign_oca_preview/sign_oca_preview.xml",
"sign_oca/static/src/elements/text.esm.js",
"sign_oca/static/src/elements/signature.esm.js",
"sign_oca/static/src/elements/check.esm.js",
"sign_oca/static/src/components/sign_oca_pdf/sign_oca_pdf.esm.js",
"sign_oca/static/src/components/" "sign_oca/static/src/js/*.js",
"sign_oca/static/src/js/*.js",
"sign_oca/static/src/xml/*.xml",
],
"web.assets_frontend": [
"oca_sign.assets_frontend_sign": [
# frontend needed imports
("include", "web._assets_helpers"),
("include", "web._assets_frontend_helpers"),
"web/static/lib/jquery/jquery.js",
"web/static/src/scss/pre_variables.scss",
"web/static/lib/bootstrap/scss/_variables.scss",
("include", "web._assets_bootstrap_frontend"),
("include", "web._assets_bootstrap_backend"),
"/web/static/lib/odoo_ui_icons/*",
"/web/static/lib/bootstrap/scss/_functions.scss",
"/web/static/lib/bootstrap/scss/_mixins.scss",
"/web/static/lib/bootstrap/scss/utilities/_api.scss",
"web/static/src/libs/fontawesome/css/font-awesome.css",
("include", "web._assets_core"),
# especific module frontend imports
"sign_oca/static/src/components/sign_oca_pdf_common/sign_oca_pdf_common.xml",
"sign_oca/static/src/components/sign_oca_configure/sign_oca_configure.xml",
"sign_oca/static/src/components/sign_oca_pdf/sign_oca_pdf.xml",
Expand Down
11 changes: 7 additions & 4 deletions sign_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -516,7 +517,9 @@ <h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/** @odoo-module QWeb **/

import {ControlPanel} from "@web/search/control_panel/control_panel";
import {Dialog} from "@web/core/dialog/dialog";
import {SignOcaConfigureFieldDialog} from "./sign_oca_configure_field_dialog.esm";
import {isMobileOS} from "@web/core/browser/feature_detection";
import SignOcaPdfCommon from "../sign_oca_pdf_common/sign_oca_pdf_common.esm.js";
import {_t} from "@web/core/l10n/translation";
import {registry} from "@web/core/registry";
import {renderToString} from "@web/core/utils/render";

export class SignOcaConfigureControlPanel extends ControlPanel {}
SignOcaConfigureControlPanel.template = "sign_oca.SignOcaConfigureControlPanel";
export default class SignOcaConfigure extends SignOcaPdfCommon {
setup() {
this.res_id =
this.props.action.params.res_id || this.props.action.context.active_id;
this.model =
this.props.action.params.res_model ||
this.props.action.context.active_model;
super.setup(...arguments);
this.field_template = "sign_oca.sign_iframe_field_configure";
this.contextMenu = undefined;
this.isMobile = isMobileOS;
this.isMobile = isMobileOS();
}
postIframeFields() {
super.postIframeFields(...arguments);
$.each(
this.iframe.el.contentDocument.getElementsByClassName("page"),
(page) => {
(index, page) => {
page.addEventListener("mousedown", (e) => {
e.preventDefault();
e.stopPropagation();
Expand Down Expand Up @@ -55,7 +55,10 @@ export default class SignOcaConfigure extends SignOcaPdfCommon {
"click",
(ev) => {
if (this.contextMenu && !this.creatingItem) {
if (this.contextMenu[0].contains(ev.target)) {
if (
this.contextMenu[0].contains(ev.target) &&
ev.target.dataset.page
) {
this.creatingItem = true;
this.orm
.call(this.model, "add_item", [
Expand Down Expand Up @@ -107,82 +110,40 @@ export default class SignOcaConfigure extends SignOcaPdfCommon {
}
var target = e.currentTarget;
// TODO: Open Dialog for configuration
var dialog = new Dialog(this, {
this.dialogService.add(SignOcaConfigureFieldDialog, {
title: _t("Edit field"),
$content: $(
renderToString("sign_oca.sign_oca_field_edition", {
item,
info: this.info,
})
),

buttons: [
{
text: _t("Save"),
classes: "btn-primary",
close: true,
click: () => {
var field_id = parseInt(
dialog.$el.find('select[name="field_id"]').val(),
10
);
var role_id = parseInt(
dialog.$el.find('select[name="role_id"]').val(),
10
);
var required = dialog.$el
.find("input[name='required']")
.prop("checked");
var placeholder = dialog.$el
.find("input[name='placeholder']")
.val();
this.orm
.call(this.model, "set_item_data", [
[this.res_id],
item.id,
{
field_id,
role_id,
required,
placeholder,
},
])
.then(() => {
item.field_id = field_id;
item.name = _.filter(
this.info.fields,
(field) => field.id === field_id
)[0].name;
item.role_id = role_id;
item.required = required;
item.placeholder = placeholder;
target.remove();
this.postIframeField(item);
});
},
},
{
text: _t("Delete"),
classes: "btn-danger",
close: true,
click: () => {
this.orm
.call(this.model, "delete_item", [
[this.res_id],
item.id,
])
.then(() => {
delete this.info.items[item.id];
target.remove();
});
item,
info: this.info,
confirm: async (field_id, role_id, required, placeholder) => {
await this.orm.call(this.model, "set_item_data", [
[this.res_id],
item.id,
{
field_id,
role_id,
required,
placeholder,
},
},
{
text: _t("Cancel"),
close: true,
},
],
}).open();
]);
item.field_id = field_id;
item.name = this.info.fields.filter(
(field) => field.id === field_id
)[0].name;
item.role_id = role_id;
item.required = required;
item.placeholder = placeholder;
target.remove();
this.postIframeField(item);
},
delete: async () => {
await this.orm.call(this.model, "delete_item", [
[this.res_id],
item.id,
]);
delete this.info.items[item.id];
target.remove();
},
});
},
true
);
Expand Down Expand Up @@ -245,7 +206,7 @@ export default class SignOcaConfigure extends SignOcaPdfCommon {
{once: true}
);
});
$.each(resizeItems, (resizeItem) => {
$.each(resizeItems, (index, resizeItem) => {
resizeItem.addEventListener(startFunction, (mousedownEvent) => {
mousedownEvent.preventDefault();
var parentPage = mousedownEvent.target.parentElement.parentElement;
Expand Down Expand Up @@ -354,6 +315,7 @@ export default class SignOcaConfigure extends SignOcaPdfCommon {
}
}
SignOcaConfigure.template = "sign_oca.SignOcaConfigure";
SignOcaConfigure.components = {...SignOcaPdfCommon.components, ControlPanel};
SignOcaConfigure.props = [];
SignOcaConfigure.props = {
action: Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div
class="o_sign_oca_button_header"
>Click on the field that you want to add</div>
<t t-foreach="info.fields" t-as="field">
<t t-foreach="info.fields" t-as="field" t-key="field.id">
<div
class="o_sign_oca_context_menu_item"
t-att-data-field="field.id"
Expand All @@ -59,56 +59,13 @@
</t>
</div>
</t>
<t t-name="sign_oca.sign_oca_field_edition">
<div class="o_sign_oca_field_edition">
<label for="field_id">Field</label>
<div class="o_sign_oca_field_edition_value">
<select name="field_id">
<t t-foreach="info.fields" t-as="field">
<option
t-att-value="field.id"
t-out="field.name"
t-att-selected="item.field_id === field.id ? 'selected': None"
/>
</t>
</select>
</div>
<label for="role_id">Filled by</label>
<div class="o_sign_oca_field_edition_value">
<select name="role_id">
<t t-foreach="info.roles" t-as="role">
<option
t-att-value="role.id"
t-out="role.name"
t-att-selected="item.role_id === role.id ? 'selected': None"
/>
</t>
</select>
</div>
<label for="required">Required</label>
<div class="o_sign_oca_field_edition_value">
<input
name="required"
type="checkbox"
t-att-checked="item.required? 'checked': undefined"
/>
</div>
<label for="placeholder">Placeholder</label>
<div class="o_sign_oca_field_edition_value">
<input
type="text"
name="placeholder"
t-att-value="item.placeholder || ''"
/>
</div>
</div>
</t>
<t
t-name="sign_oca.SignOcaConfigure"
t-inherit="sign_oca.SignOcaPdfCommon"
t-inherit-mode="primary"
>
<xpath expr="//iframe" position="before">
<ControlPanel display="{}" />
<div
class="alert alert-warning row"
role="alert"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/** @odoo-module */
/* Copyright 2024 Tecnativa - Carlos Roca
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */

import {Dialog} from "@web/core/dialog/dialog";
import {useChildRef} from "@web/core/utils/hooks";

import {Component} from "@odoo/owl";

export class SignOcaConfigureFieldDialog extends Component {
setup() {
this.env.dialogData.dismiss = () => this._cancel();
this.modalRef = useChildRef();
this.isProcess = false;
}

async _cancel() {
this.props.close();
}

async _confirm() {
const $el = $(this.modalRef.el);
await this.props.confirm(
parseInt($el.find('select[name="field_id"]').val(), 10),
parseInt($el.find('select[name="role_id"]').val(), 10),
$el.find("input[name='required']").prop("checked"),
$el.find("input[name='placeholder']").val()
);
this.props.close();
}

async _delete() {
this.props.delete();
this.props.close();
}
}
SignOcaConfigureFieldDialog.template = "sign_oca.SignOcaConfigureFieldDialog";
SignOcaConfigureFieldDialog.components = {Dialog};
SignOcaConfigureFieldDialog.props = {
close: Function,
title: {
validate: (m) => {
return (
typeof m === "string" ||
(typeof m === "object" && typeof m.toString === "function")
);
},
},
item: Object,
info: Object,
confirm: Function,
delete: Function,
};
Loading

0 comments on commit d1ca0b4

Please sign in to comment.