add ui and widget

This commit is contained in:
ivan deng
2017-12-13 13:09:05 +08:00
parent b544e06262
commit a009219026
16 changed files with 3106 additions and 2 deletions

View File

@@ -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',
],

View File

@@ -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="">
&lt;record id="view_demo_tree" model="ir.ui.view"&gt;
&lt;field name="name"&gt;demo.tree&lt;/field&gt;
&lt;field name="model"&gt;demo.model&lt;/field&gt;
&lt;field name="arch" type="xml"&gt;
&lt;tree bg_colors="grey:state=='cancel';green:state=='draft';blue:state in ('done');red:state in ('waiting')" name="demo_tree"&gt;
&lt;field name="name" string="Appointment" /&gt;
&lt;field name="state" /&gt;
&lt;/tree&gt;
&lt;/field&gt;
&lt;/record&gt;
</pre>
</div>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced text-center">

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View File

@@ -0,0 +1,7 @@
.oe_list_field_bg_color div{
display: inline-block;
height: 100%;
position: relative;
width: 100%;
}

View 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;
},
});
});

View 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>