t-on-click 傳遞引數

CrossPython發表於2024-07-09

xml:

<button class="btn btn-outline-primary m-1" t-on-click="()=>this.runtask('MM離線檔案')">MM離線檔案</button>

js

/** @odoo-module **/
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { getDefaultConfig } from "@web/views/view";
import { useService } from "@web/core/utils/hooks";
const { Component, useSubEnv, useState } = owl;

class SAPBOTSupportView extends Component {
    "use strict";

    setup(){
        useSubEnv({
            config: {
                ...getDefaultConfig(),
                ...this.env.config,
            },
        });

    this.rpc = useService("rpc");
    this.action = useService('action');
    this.display = {
        controlPanel: { "top-right": false, "bottom-right": false },
        };
    }

    async runtask(y){
        var x = this.rpc('/runtask', {name: y});
        if(x){
                    this.action.doAction({
                        type: 'ir.actions.client',
                        tag: 'display_notification',
                        params:{
                            'title': "提醒",
                            'message':"等待一小會兒, 會收到任務郵件.",
                            'sticky': false,}})
                            ;
        }else{
            this.action.doAction({
                        type: 'ir.actions.client',
                        tag: 'display_notification',
                        params:{
                            'title': "提醒",
                            'message':"執行失敗, 請聯絡Grant.",
                            'sticky': false,
                            }}
                            );
        }
    }
}

SAPBOTSupportView.components = { Layout };
SAPBOTSupportView.template = "saobot_support_template";
registry.category("actions").add("sapbot.sapbot_support_view", SAPBOTSupportView);

  

相關文章