mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
add ui and widget
This commit is contained in:
@@ -89,7 +89,7 @@ msgstr "删除所有生产单"
|
||||
#. module: app_odoo_customize
|
||||
#: model:ir.ui.view,arch_db:app_odoo_customize.view_app_theme_config_settings
|
||||
msgid "Delete All Message"
|
||||
msgstr "删除所有消息"
|
||||
msgstr "删除所有消息与关注"
|
||||
|
||||
#. module: app_odoo_customize
|
||||
#: model:ir.ui.view,arch_db:app_odoo_customize.view_app_theme_config_settings
|
||||
|
||||
@@ -398,6 +398,7 @@ class AppThemeConfigSettings(models.TransientModel):
|
||||
to_removes = [
|
||||
# 清除消息数据
|
||||
['mail.message', ],
|
||||
['mail.followers', ],
|
||||
]
|
||||
try:
|
||||
for line in to_removes :
|
||||
|
||||
@@ -25,7 +25,27 @@
|
||||
'summary': 'UI Enhance for Odoo',
|
||||
'description': """
|
||||
|
||||
Search by date or number range in List view and Pivot view
|
||||
1.Search by date or number range in List view and Pivot view
|
||||
--------------------------------------------------
|
||||
2.Instructions for Activating List background color property
|
||||
|
||||
Just add tree attribute like style and colors with condition you want.
|
||||
|
||||
bg_colors="grey:state=='cancel';green:state=='draft';blue:state in ('done');red:state in ('waiting')"
|
||||
|
||||
|
||||
eg.
|
||||
|
||||
<record id="view_demo_tree" model="ir.ui.view">
|
||||
<field name="name">demo.tree</field>
|
||||
<field name="model">demo.model</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree bg_colors="grey:state=='cancel';green:state=='draft';blue:state in ('done');red:state in ('waiting')" name="demo_tree">
|
||||
<field name="name" string="Appointment" />
|
||||
<field name="state" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
--------------------------------------------------
|
||||
|
||||
""",
|
||||
@@ -33,6 +53,7 @@ Search by date or number range in List view and Pivot view
|
||||
'data': [
|
||||
'views/app_ui_config_settings_view.xml',
|
||||
'views/template_view.xml',
|
||||
'views/web_list_bg_color_view.xml',
|
||||
# data
|
||||
'data/ir_config_parameter.xml',
|
||||
],
|
||||
|
||||
@@ -62,6 +62,39 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="oe_container">
|
||||
<div class="oe_row oe_spaced" style="max-width: 800px;">
|
||||
<div class="oe_span12">
|
||||
<h2 class="oe_slogan">Web list View Background Color</h2>
|
||||
<div class="oe_demo" style=" margin: 30px auto 0; padding: 0 15px 0 0; border:none; width: 96%;">
|
||||
<p>This module changes the line color of records based on condition like state of a record and helps distinguish between different sets of
|
||||
records based on condition.</p>
|
||||
<a href="http://www.sunpop.cn" target="_blank">
|
||||
<img src="web_bg_color_change.png" width="100%">
|
||||
<p>Set Backgroud color to filed in list view based on condition same as colors and style attributes of tree view.</p>
|
||||
</a>
|
||||
<h3># Instructions for Activating List background color property</h3>
|
||||
<p>
|
||||
Just add tree attribute like style and colors with condition you want.
|
||||
</p>
|
||||
<pre>bg_colors="grey:state=='cancel';green:state=='draft';blue:state in ('done');red:state in ('waiting')"</pre>
|
||||
<h3>eg.</h3>
|
||||
<pre class="">
|
||||
<record id="view_demo_tree" model="ir.ui.view">
|
||||
<field name="name">demo.tree</field>
|
||||
<field name="model">demo.model</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree bg_colors="grey:state=='cancel';green:state=='draft';blue:state in ('done');red:state in ('waiting')" name="demo_tree">
|
||||
<field name="name" string="Appointment" />
|
||||
<field name="state" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="oe_container oe_dark">
|
||||
<div class="oe_row oe_spaced text-center">
|
||||
|
||||
BIN
app_ui_enhance/static/description/web_bg_color_change.png
Normal file
BIN
app_ui_enhance/static/description/web_bg_color_change.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
7
app_ui_enhance/static/src/css/web_list_bg_color.css
Normal file
7
app_ui_enhance/static/src/css/web_list_bg_color.css
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
.oe_list_field_bg_color div{
|
||||
display: inline-block;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
57
app_ui_enhance/static/src/js/web_list_bg_color.js
Normal file
57
app_ui_enhance/static/src/js/web_list_bg_color.js
Normal file
@@ -0,0 +1,57 @@
|
||||
odoo.define('app_ui_enhance.list_bg_color', function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var common = require('web.form_common');
|
||||
var Model = require('web.Model');
|
||||
var time = require('web.time');
|
||||
var ListView = require('web.ListView');
|
||||
var session = require('web.session');
|
||||
var compatibility = require('web.compatibility');
|
||||
|
||||
ListView.include({
|
||||
willStart: function() {
|
||||
if (this.fields_view.arch.attrs.bg_colors) {
|
||||
this.bg_colors = _(this.fields_view.arch.attrs.bg_colors.split(';')).chain()
|
||||
.compact()
|
||||
.map(function(color_pair) {
|
||||
var pair = color_pair.split(':'),
|
||||
color = pair[0],
|
||||
expr = pair[1];
|
||||
return [color, py.parse(py.tokenize(expr)), expr];
|
||||
}).value();
|
||||
|
||||
if (!this.colors) { this.colors = [] }
|
||||
}
|
||||
return this._super();
|
||||
},
|
||||
|
||||
style_for: function (record) {
|
||||
var len, style= '';
|
||||
|
||||
var context = _.extend({}, record.attributes, {
|
||||
uid: session.uid,
|
||||
current_date: moment().format('YYYY-MM-DD')
|
||||
// TODO: time, datetime, relativedelta
|
||||
});
|
||||
|
||||
var i;
|
||||
var pair;
|
||||
var expression;
|
||||
style = this._super(record);
|
||||
|
||||
if (!this.bg_colors) { return style; }
|
||||
for(i=0, len=this.bg_colors.length; i<len; ++i) {
|
||||
pair = this.bg_colors[i];
|
||||
var color = pair[0];
|
||||
expression = pair[1];
|
||||
if (py.PY_isTrue(py.evaluate(expression, context))) {
|
||||
return style += 'background-color: ' + color + ';';
|
||||
}
|
||||
}
|
||||
return style;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
11
app_ui_enhance/views/web_list_bg_color_view.xml
Normal file
11
app_ui_enhance/views/web_list_bg_color_view.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="assets_backend" name="web_field_bg_color assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<link rel="stylesheet" href="/app_ui_enhance/static/src/css/web_list_bg_color.css"/>
|
||||
<script type="text/javascript" src="/app_ui_enhance/static/src/js/web_list_bg_color.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
0
app_widget_extra/__init__.py
Normal file
0
app_widget_extra/__init__.py
Normal file
117
app_widget_extra/__manifest__.py
Normal file
117
app_widget_extra/__manifest__.py
Normal file
@@ -0,0 +1,117 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Created on 2017-11-05
|
||||
# author: 广州尚鹏,http://www.sunpop.cn
|
||||
# email: 300883@qq.com
|
||||
# resource of Sunpop
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
# Odoo在线中文用户手册(长期更新)
|
||||
# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html
|
||||
|
||||
# Odoo10离线中文用户手册下载
|
||||
# http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
# http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
# description:
|
||||
|
||||
# base on 'author': "Gilvan Leal",
|
||||
# website': "https://gilvanleal.github.io/odoowidgets/",
|
||||
{
|
||||
'name': "App widget extra(Inputmask Widget)",
|
||||
'author': "Sunpop.cn",
|
||||
'website': 'http://www.sunpop.cn',
|
||||
|
||||
'summary': """
|
||||
A Widget to make masks on form fields""",
|
||||
|
||||
'description': """
|
||||
================
|
||||
Inputmask Widget
|
||||
================
|
||||
|
||||
Based on jquery.inputmask 3.x `Docs in GitHub
|
||||
<http://robinherbots.github.io/Inputmask/>`_.
|
||||
|
||||
| An Inputmask Widget helps the user with the input by ensuring a predefined format.
|
||||
| This can be useful for dates, numerics, phone numbers, ...
|
||||
|
||||
Instructions:
|
||||
-------------
|
||||
|
||||
- Just add attribute *widget="mask"* and *data-inputmask[-<attribute>]="<value>"* to **<field />** on form, tree and kanban
|
||||
|
||||
Some examples::
|
||||
|
||||
<field widget="mask" data-inputmask="'alias': 'date'" name="name" />
|
||||
<field widget="mask" data-inputmask="'mask': '99/99/9999'" name="name" />
|
||||
<field widget="mask" data-inputmask="'mask': '99-aa-**-AA-&&-##'" name="name" />
|
||||
<field widget="mask" data-inputmask="'mask': '9', 'repeat': 10, 'greedy' : false" name="name" />
|
||||
|
||||
Or::
|
||||
|
||||
<field widget="mask" data-inputmask-alias="date" name="name" />
|
||||
<field widget="mask" data-inputmask-mask="99/99/9999" name="name" />
|
||||
<field widget="mask" data-inputmask-mask="99-aa-**-AA-&&-##" name="name" />
|
||||
<field widget="mask" data-inputmask-mask="9" data-inputmask-repeat="10" data-inputmask-greedy="false" name="name" />
|
||||
|
||||
**Note:** Use *contenteditable="true"* for apply mask in others HTML tags: span, div, etc. **Improve**
|
||||
|
||||
|
||||
- Just add attribute *widget="mask_regex"* and *data-inputmask[-regex]="<value>"* to **<field />**
|
||||
|
||||
With the regex extension you can use any regular expression as a mask. Currently this does only input restriction. There is no further masking visualization.
|
||||
|
||||
Example email validation::
|
||||
|
||||
<field widget="mask_regex" data-inputmask-regex="[a-zA-Z0-9._%-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}" name="name"/>
|
||||
|
||||
- Masking definition:
|
||||
|
||||
:9: Numeric value
|
||||
:a: Alphabetical value
|
||||
:\*: Alphanumeric value
|
||||
:A: Alphabetical uppercasing
|
||||
:&: Alfanumeric uppercasing - (Use **&** for escape **&** in XML file)
|
||||
:#: Hexadecimal
|
||||
|
||||
- Attributes:
|
||||
|
||||
:mask: The mask to use.
|
||||
:repeat: Mask repeat function. Repeat the mask definition x-times.
|
||||
:greedy: Toggle to allocate as much possible or the opposite. Non-greedy repeat function.
|
||||
:placeholder: Change the mask placeholder. Default: "_"
|
||||
:autounmask: Automatically unmask the value when retrieved. Default: false.
|
||||
:removemaskonsubmit: Remove the mask before submitting the form.Default: false
|
||||
:clearmaskonlostfocus: Remove the empty mask on blur or when not empty removes the optional trailing part Default: true
|
||||
:insertmode: Toggle to insert or overwrite input. Default: true.
|
||||
:clearincomplete: Clear the incomplete input on blur.
|
||||
:alias: The alias to use.
|
||||
|
||||
- Aliases:
|
||||
|
||||
Some aliases found in the extensions are: email, currency, decimal, integer, date, datetime, dd/mm/yyyy, url, ip, etc.
|
||||
|
||||
Docs:
|
||||
|
||||
* `Date and Datetime <https://github.com/RobinHerbots/Inputmask/blob/3.x/README_date.md>`_
|
||||
* `Numeric <https://github.com/RobinHerbots/Inputmask/blob/3.x/README_numeric.md>`_
|
||||
* `Regex <https://github.com/RobinHerbots/Inputmask/blob/3.x/README_regex.md>`_
|
||||
* `Phone <https://github.com/RobinHerbots/Inputmask/blob/3.x/README_phone.md>`_
|
||||
* `Other <https://github.com/RobinHerbots/Inputmask/blob/3.x/README_other.md>`_""",
|
||||
|
||||
|
||||
# Categories can be used to filter modules in modules listing
|
||||
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
|
||||
# for the full list
|
||||
'category': 'Extra Tools',
|
||||
'version': '1.0',
|
||||
|
||||
# any module necessary for this one to work correctly
|
||||
'depends': ['web'],
|
||||
|
||||
# always loaded
|
||||
"data": ['views/inputmask_templates.xml'],
|
||||
"qweb": ['static/src/xml/*.xml'],
|
||||
'images': ['static/description/main_screenshot.png']
|
||||
}
|
||||
BIN
app_widget_extra/static/description/icon.png
Normal file
BIN
app_widget_extra/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
BIN
app_widget_extra/static/description/main_screenshot.png
Normal file
BIN
app_widget_extra/static/description/main_screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
File diff suppressed because it is too large
Load Diff
113
app_widget_extra/static/src/js/inputmask_widget.js
Normal file
113
app_widget_extra/static/src/js/inputmask_widget.js
Normal file
@@ -0,0 +1,113 @@
|
||||
odoo.define('web.inputmask_widget', function (require) {
|
||||
"use strict";
|
||||
var core = require('web.core');
|
||||
var formats = require('web.formats');
|
||||
var form_widgets = require('web.form_widgets');
|
||||
var kanban_widgets = require('web_kanban.widgets');
|
||||
var utils = require('web.utils');
|
||||
var list_widget_registry = core.list_widget_registry;
|
||||
var QWeb = core.qweb;
|
||||
|
||||
function mask_attrs(attrs) {
|
||||
var keyMask = 'data-inputmask';
|
||||
var attributes = {};
|
||||
if (keyMask in attrs)
|
||||
attributes[keyMask] = attrs[keyMask];
|
||||
else
|
||||
attributes = Object.keys(attrs).reduce(function (filtered, key) {
|
||||
if (key.indexOf(keyMask) !== -1)
|
||||
filtered[key] = attrs[key];
|
||||
return filtered;
|
||||
}, {});
|
||||
if (!attributes)
|
||||
console.warn("The widget Mask expects the 'data-inputmask[-attribute]' attributes!")
|
||||
return attributes;
|
||||
}
|
||||
|
||||
var FieldMask = form_widgets.FieldChar.extend({
|
||||
template: "FieldMask",
|
||||
attributes: {},
|
||||
init: function (field_manager, node) {
|
||||
this._super(field_manager, node)
|
||||
this.attributes = mask_attrs(node.attrs);
|
||||
},
|
||||
render_value: function (mask) {
|
||||
this._super();
|
||||
if (this.attributes) {
|
||||
if (this.$input !== undefined)
|
||||
this.$input.inputmask(mask);
|
||||
else if ('contenteditable' in this.node.attrs)
|
||||
this.$el.inputmask(mask);
|
||||
}
|
||||
},
|
||||
//在前端验证输入值是否符合inputmask
|
||||
is_valid: function () {
|
||||
var musk = this.attributes['data-inputmask-regex'] ? this.attributes['data-inputmask-regex'] : this.attributes['data-inputmask'] ;
|
||||
var reg = new RegExp (musk,"g");
|
||||
var value = this.$input.val();
|
||||
if (!this.get('required') && this.is_false()) {
|
||||
return true;
|
||||
} else if (reg.test(value)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var FieldMaskRegex = FieldMask.extend({
|
||||
render_value: function () {
|
||||
this._super("Regex");
|
||||
}
|
||||
});
|
||||
|
||||
var ColumnMask = list_widget_registry.get('field.char').extend({
|
||||
attributes: {},
|
||||
$mask: undefined,
|
||||
init: function (id, tag, attrs) {
|
||||
this._super(id, tag, attrs);
|
||||
this.attributes = mask_attrs(attrs);
|
||||
if (this.attributes)
|
||||
this.$mask = $(jQuery.parseHTML(QWeb.render('Widget.mask', {widget: this}))).inputmask(undefined, {
|
||||
placeholder: '',
|
||||
greedy: false
|
||||
});
|
||||
},
|
||||
format: function (row_data, options) {
|
||||
var value = this._super(row_data, options);
|
||||
if (this.$mask) {
|
||||
this.$mask.val(value);
|
||||
value = this.$mask.val();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
});
|
||||
|
||||
var MaskWidget = kanban_widgets.AbstractField.extend({
|
||||
tagName: 'span',
|
||||
attributes: {},
|
||||
init: function (parent, field, $node) {
|
||||
this._super(parent, field, $node);
|
||||
this.attributes = mask_attrs(field.__attrs);
|
||||
if (this.attributes)
|
||||
this.$mask = $(jQuery.parseHTML(QWeb.render('Widget.mask', {widget: this}))).inputmask(undefined, {
|
||||
placeholder: '',
|
||||
greedy: false
|
||||
});
|
||||
},
|
||||
renderElement: function () {
|
||||
var value = this.field.raw_value;
|
||||
if (this.$mask)
|
||||
this.$mask.val(value);
|
||||
value = this.$mask.val();
|
||||
this.$el.text(value);
|
||||
}
|
||||
});
|
||||
|
||||
core.form_widget_registry.add('mask', FieldMask);
|
||||
core.form_widget_registry.add('mask_regex', FieldMaskRegex);
|
||||
list_widget_registry.add('field.mask', ColumnMask);
|
||||
kanban_widgets.registry.add("mask", MaskWidget);
|
||||
|
||||
return {FieldMask: FieldMask, FieldMaskRegex: FieldMaskRegex, MaskWidget: MaskWidget};
|
||||
});
|
||||
23
app_widget_extra/static/src/xml/inputmask_widget.xml
Normal file
23
app_widget_extra/static/src/xml/inputmask_widget.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="FieldMask">
|
||||
<span t-if="widget.get('effective_readonly')"
|
||||
t-att-contenteditable="widget.node.attrs.contenteditable"
|
||||
t-att="widget.node.attrs.contenteditable ? widget.attributes: undefined"/>
|
||||
|
||||
<input t-if="!widget.get('effective_readonly')" class="o_form_input"
|
||||
t-att-barcode_events="widget.options.barcode_events"
|
||||
type="text"
|
||||
t-att-id="widget.id_for_label"
|
||||
t-att-tabindex="widget.node.attrs.tabindex"
|
||||
t-att-autofocus="widget.node.attrs.autofocus"
|
||||
t-att-placeholder="widget.node.attrs.placeholder"
|
||||
t-att-autocomplete="widget.node.attrs.autocomplete"
|
||||
t-att-maxlength="widget.field.size"
|
||||
t-att="widget.attributes"
|
||||
/>
|
||||
</t>
|
||||
<span t-name="Widget.mask"
|
||||
t-att="widget.attributes"
|
||||
contenteditable="true"/>
|
||||
</templates>
|
||||
11
app_widget_extra/views/inputmask_templates.xml
Normal file
11
app_widget_extra/views/inputmask_templates.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<template id="assets_backend" name="inputmask_widget" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/app_widget_extra/static/lib/jquery.inputmask/jquery.inputmask.bundle.js"></script>
|
||||
<script type="text/javascript" src="/app_widget_extra/static/src/js/inputmask_widget.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user