odoo——Building Interface Extensions
来源:互联网 发布:爱另类软件 编辑:程序博客网 时间:2024/06/06 13:20
原教程地址:https://www.odoo.com/documentation/10.0/howtos/web.html#a-simple-module。
从github下载petstore项目,得到如下目录
oepetstore|-- images| |-- alligator.jpg| |-- ball.jpg| |-- crazy_circle.jpg| |-- fish.jpg| `-- mice.jpg|-- __init__.py|-- oepetstore.message_of_the_day.csv|-- __manifest__.py|-- petstore_data.xml|-- petstore.py|-- petstore.xml`-- static `-- src |-- css | `-- petstore.css |-- js | `-- petstore.js `-- xml `-- petstore.xml
我们主要操作static目录下的src/css,js,xml文件。
原始的petstore.js文件为:
odoo.oepetstore = function(instance, local) { var _t = instance.web._t, _lt = instance.web._lt; var QWeb = instance.web.qweb; local.HomePage = instance.Widget.extend({ start: function() { console.log("pet store home page loaded"); }, }); instance.web.client_actions.add( 'petstore.homepage', 'instance.oepetstore.HomePage');}
我们可以更新应用,点击petstore下的homepage,打开调试工具能看到控制台console.log了 “pet store home page loaded”.
我们可以在上面的start:function函数里写
this.$el.append("<div>Hello dear Odoo user!</div>");刷新页面,能看到petstore下的homepage页面有 "Hello dear odoo user!"的字样。这就是通过js往页面插入div的第一个简单尝试!
我们可以再建一个:
local.GreetingsWidget = instance.Widget.extend({ start: function() { this.$el.append("<div>We are so happy to see you again in this menu!</div>"); },});,但是要想在页面看到这个div,我们要把它加入到local.Homepage:
当然,我们也可以给这些div添加类名:local.HomePage = instance.Widget.extend({ start: function() { this.$el.append("<div>Hello dear Odoo user!</div>"); var greeting = new local.GreetingsWidget(this); return greeting.appendTo(this.$el); },});
local.HomePage = instance.Widget.extend({ className: 'oe_petstore_homepage', ...});local.GreetingsWidget = instance.Widget.extend({ className: 'oe_petstore_greetings', ...});
刷新页面我们系能看到相应的div多了类名。
Qweb被用作OpenERP的Web客户端模板引擎。它是一种基于XML的模板语言
我们可以在petstore.xml文件中写入:
<?xml version="1.0" encoding="UTF-8"?><templates xml:space="preserve"> <t t-name="HomePageTemplate"> <div style="background-color: red;">This is some simple HTML</div> </t></templates>
当然,需要告诉js 以让其识别xml,所以在js中写入:
local.HomePage = instance.Widget.extend({ start: function() { this.$el.append(QWeb.render("HomePageTemplate")); },});,或者用一种更简单的写法:
local.HomePage = instance.Widget.extend({ template: "HomePageTemplate", start: function() { ... },});
小部件的事件
可以在页面中添加两个按钮,一个为ok,一个位cancel,我们要实现的功能是点击ok,控制台打印一串英文m,点击cancel,打印另一段话,首先,我们添加这个小部件:
local.ConfirmWidget = instance.Widget.extend({ events: { 'click button.ok_button': function () { this.trigger('user_chose', true); }, 'click button.cancel_button': function () { this.trigger('user_chose', false); } }, start: function() { this.$el.append("<div>Are you sure you want to perform this action?</div>" + "<button class='ok_button'>Ok</button>" + "<button class='cancel_button'>Cancel</button>"); },});跟上面一样,我们要在local.Homepage中加入这个部件,然后,就要写这个打印的函数:
local.HomePage = instance.Widget.extend({ start: function() { var widget = new local.ConfirmWidget(this); widget.on("user_chose", this, this.user_chose); widget.appendTo(this.$el); }, user_chose: function(confirm) { if (confirm) { console.log("The user agreed to continue"); } else { console.log("The user refused to continue"); } },});
0 0
- odoo——Building Interface Extensions
- 《iOS Human Interface Guidelines》——App Extensions
- 19.odoo入门——odoo的session
- Reactive Extensions (Rx) 入门(1) —— Reactive Extensions 概要
- Reactive Extensions (Rx) 入门(2) —— 安装 Reactive Extensions
- 10.11.12.odoo入门——杂记
- 20.odoo入门——杂记
- 21.odoo入门——杂记
- 22.odoo入门——工作杂记
- 23.odoo入门——工作杂记
- 24.odoo入门——工作杂记
- Building a Simple User Interface
- 7.odoo入门——初探odoo后台启动过程(一)
- 8.odoo入门——初探odoo后台启动过程(二)
- 18.odoo入门——odoo权限控制(一)模型(数据表)级别权限控制
- Odoo
- 02Building a Simple User Interface
- 1.1.3 Building a Simple User Interface
- MySQL开启慢查询日志
- RAM or ROM
- Android技术网站
- 深度学习 10. cifar-10 介绍
- 调试和开发MTK源码
- odoo——Building Interface Extensions
- Qt实现读取显示obj文件——创建并绑定纹理
- android图片涂鸦——旋转与文字功能的实现原理
- java中可变对象与不可变对象
- TreeSet方法之一 当向TreeSet中添加Person对象 续 当有多个属性值时的自然排序
- which -find
- sigmoid和softmax函数的C++实现
- python 实现简单监控 windows版
- 设散列函数为H(k)=K MOD 13,给定的键值序列为13,41,15,44,06,68,12,25,38,64,19,49