Initial commit

This commit is contained in:
Hubert Van De Walle
2026-06-05 16:57:09 +02:00
commit 3b93bbc43f
5 changed files with 141 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
import { registry } from "@web/core/registry";
import mobile from "@web_mobile/js/services/core";
import { Component, useState, useRef } from "@odoo/owl";
class MobileDebug extends Component {
static template = owl.xml`<div class="p-4">
<details>
<summary t-esc="'Mobile methods (' + this.methods.length + ')'">Mobile methods</summary>
<ul t-foreach="this.methods" t-key="method_index" t-as="method">
<li t-esc="method"></li>
</ul>
</details>
<hr/>
<span class="d-flex">
<h2 t-esc="'mode: ' + this.state.mode"/>
<button class="btn btn-primary" t-on-click="() => this.onNext()">next</button>
</span>
<input
type="file"
name="fileInput"
t-att-multiple="this.modes[this.state.mode].multiple ? 'multiple' : false"
t-att-accept="this.modes[this.state.mode].accept"
t-on-change="() => this.onFileChange()"
t-ref="fileInput"
/>
<h2>Files:</h2>
<ul t-foreach="this.state.files" t-key="file_index" t-as="file">
<li t-esc="file.name + ' ' + file.type"></li>
</ul>
<hr/>
</div>`;
setup() {
this.fileInputRef = useRef("fileInput");
this.state = useState({
"mode": "all",
"files": [],
});
this.modes = {
"all": {
accept: "*",
multiple: false,
},
"image": {
accept: "image/*",
multiple: false,
},
"multiple images": {
accept: "image/*",
multiple: true,
},
"pdf": {
accept: "application/pdf",
multiple: false,
}
};
}
onNext() {
this.fileInputRef.el.value = "";
this.state.files = [];
const keys = Object.keys(this.modes);
const idx = keys.indexOf(this.state.mode);
const nextIdx = (idx + 1) % keys.length;
this.state.mode = keys[nextIdx];
}
onFileChange() {
/** @type{HTMLInputElement} **/
const el = this.fileInputRef.el;
if (!el) {
this.state.files = [];
return;
}
const files = el.files;
this.state.files = Array.from(files).map(e => ({
name: e.name,
type: e.type,
}));
}
get methods() {
return [...Object.keys(mobile.methods)];
}
}
registry.category("actions").add("mobile_debug.action_mobile_debug", MobileDebug);