Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

publicWidget.Widget.extend example

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
frontendWidgets
1 Balas
13298 Tampilan
Avatar
Francesco Ballerini

I want to make an rpc call using the helper this._rpc but I only want to execute this on 'my/account' route. I think there are serveral ways to achieve this task in js side, I like this one because I found this comment on PublicWidget 'class':

/**
* The selector attribute, if defined, allows to automatically create an
* instance of this widget on page load for each DOM element which
* matches this selector. The `PublicWidget.$target` element will then be
* that particular DOM element. This should be the main way of instantiating
* `PublicWidget` elements.
*
*/

There are PLENTY of examples on source code, so and I created a js module and outside the scope of widget.extend is working properly (can load js-module and can read console log instructions) but when I go into the scope of widget.extend I cannot see my custom widget properties and handlers are not executed anymore, but the console does not show any errors.

I declared assets_xml (module is loading properly), created js file that is logging infos correctly and extended '/my/account' form to append the selector. Can some one give me a good advice to make my instructions execute ? What am I missing to make this work?


Update: I tried to console.log the registry itself instead of a generic string, it log and I see that my widget is correctly added to prototype object, as I stated in updated comment, also, the selector seems ok, the only thing it comes to my mind is the 'momentum' when my js code is executed, maybe it should be loaded after template is rendered (that would make sense to me) but I'm not sure if that's the matter and I'm not sure what I should do here. I defined assets.xml before the template with id "portal_details_extend_widget" , but even if I switch the position in the manifest I don't see relevant changes, meaning that code inside widget still not executed.


JS MODULE:

odoo.define("idro_portal.my_account_extend", function (require) {
"use strict";

var publicWidget = require('web.public.widget');
var core = require('web.core');
var ServicesMixin = require('web.ServicesMixin');
var webSession = require('web.session');
var rootWidget = require('root.widget');

console.log('logging') //CAN see in console
publicWidget.registry.PublicWidgetMyAccountExtend = publicWidget.Widget.extend({
selector: '.custom_public_widget_extend',

start: function () {
var res = this._super.apply(this, arguments);
console.log('publicwidget'); // CANNOT see in console
this.do_notify('Success', 'Start function notify'); // does NOT work, but also NOT raise any error
return res
},
});
console.log(publicWidget)
//This console.log show object 'registry' in console, if I expand
//I can find 'PublicWidgetMyAccountExtend' in 'registry' key, so it's added
return publicWidget.registry.PublicWidgetMyAccountExtend;});

LOAD SCRIPT IN THE ASSET BUNDLE FRONTEND:

​
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend" inherit_id="web.assets_frontend" name="Portal Extend JS">
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/idro_portal/static/src/js/my_account_extend.js"/>
</xpath>
</template>
</odoo>


DEFINE SELECTOR IN THE FORM:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- ADD SELECTOR CLASS TO RUN THE JS WIDGET SCRIPT -->
<template id="portal_details_extend_widget" inherit_id="portal.portal_my_details" name="User Profile Extend">
<xpath expr="//form" position="attributes">
<attribute name="class" add="custom_public_widget_extend" separator=" "/>
</xpath>
</template></odoo>
0
Avatar
Buang
Avatar
Francesco Ballerini
Penulis Jawaban Terbai

I figured out: selector is not enough to make publicWidget work on website. 

It just create an istance of the widget for each element matched by the selector but then you need to render the widget to make use of it. One way to achieve this task is by using the following code to initialize, render, and put the widget in the DOM:

*     var myWidget = new MyWidget(this);
* myWidget.appendTo($(".some-div"));

The following snippet works well in the website

odoo.define("idro_portal.my_account_extend", function (require) {
"use strict";

var core = require('web.core');
var publicWidget = require('web.public.widget');

publicWidget.registry.PublicWidgetMyAccountExtend = publicWidget.Widget.extend({
selector: '.custom_public_widget_extend',

start: function () {
var res = this._super.apply(this, arguments);
this.do_notify('Success', 'Widget start notify');
return res
},
});
var PublicWidgetMyAccountExtend = new publicWidget.registry.PublicWidgetMyAccountExtend(this);
PublicWidgetMyAccountExtend.appendTo($(".custom_public_widget_extend"));
return publicWidget.registry.PublicWidgetMyAccountExtend;
});


0
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
widget many2many_list not working v13 Diselesaikan
Widgets
Avatar
2
Des 22
1291
Front-end Odoo language
frontend
Avatar
Avatar
1
Agu 22
7841
What is we-button, we-collapse like things?
frontend
Avatar
0
Jul 20
4116
how to reload widget on every product form view? Diselesaikan
Widgets
Avatar
Avatar
3
Apr 17
10751
URL
url frontend
Avatar
0
Nov 23
2231
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now