[MIG][12.0] web_dashboard_tile

- refactor tile category
- improve description
- add legalsylvain as maintainer
- update code and translation
This commit is contained in:
Sylvain LE GAL
2019-11-06 10:39:54 +01:00
parent b63327ef4b
commit 8128f242db
60 changed files with 1698 additions and 4184 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -0,0 +1,495 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Overview Dashboard (Tiles)</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="overview-dashboard-tiles">
<h1 class="title">Overview Dashboard (Tiles)</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/legalsylvain/web/tree/12.0-mig-web_dashboard_tile/web_dashboard_tile"><img alt="legalsylvain/web" src="https://img.shields.io/badge/github-legalsylvain%2Fweb-lightgray.png?logo=github" /></a></p>
<p>Adds a dashboard where you can configure tiles from any view and add them as short cut.</p>
<p>By default, the tile displays items count of a given model restricted to a given domain.</p>
<p>Optionally, the tile can display the result of a function on a field.</p>
<ul class="simple">
<li>Function is one of <tt class="docutils literal">sum</tt>, <tt class="docutils literal">avg</tt>, <tt class="docutils literal">min</tt>, <tt class="docutils literal">max</tt> or <tt class="docutils literal">median</tt>.</li>
<li>Field must be integer or float.</li>
</ul>
<p>Tile can be:</p>
<ul class="simple">
<li>Displayed only for a user.</li>
<li>Global for all users.</li>
<li>Restricted to some groups.</li>
</ul>
<p><em>Note: The tile will be hidden if the current user doesnt have access to the given model.</em></p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id3">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id7">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id8">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<p>First, you have to create tile categories.</p>
<ul class="simple">
<li>Go to “Dashboards &gt; Settings &gt; Dashboard Categories”</li>
<li>Click on Create</li>
<li>Set a name, and save.</li>
</ul>
<p>Odoo menu and action are automatically created.
You should refresh your browser to see new menu items.</p>
<img alt="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_category_form.png" src="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_category_form.png" />
<p>Then you can create tiles.</p>
<ul class="simple">
<li>go to “Dashboards &gt; Settings &gt; Dashboard Tiles”</li>
<li>create a new tile, set a name, a category and a model.</li>
<li>You can optionally define colors, domain a specific action to use.</li>
<li>Setting a user, or a group in “Security” tab will restrict the display of the tile.</li>
</ul>
<img alt="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_form.png" src="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_form.png" />
<p>You can optionanaly define a secondary value, for that purpose :</p>
<ul class="simple">
<li>Select a field, a function to apply.</li>
<li>You can define a specific format. (<tt class="docutils literal">.format()</tt> python syntax)</li>
</ul>
<img alt="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_form_secondary_value.png" src="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_form_secondary_value.png" />
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
<ul class="simple">
<li>Go to “Dashboard &gt; Overview” and select a category</li>
<li>The tile configured is displayed with the up to date count and average values of the selected domain.</li>
</ul>
<img alt="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_kanban.png" src="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_kanban.png" />
<ul class="simple">
<li>By clicking on the item, youll navigate to the tree view of the according model.</li>
</ul>
<img alt="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_2_tree_view.png" src="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/tile_tile_2_tree_view.png" />
<p><strong>Note</strong></p>
<p>When you are in a tree view, with a domain, you can save it in the favorite menu, but the configuration is limited.</p>
<img alt="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/favorite_menu_create_tile.png" src="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/favorite_menu_create_tile.png" />
<img alt="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/favorite_menu_create_tile_result.png" src="https://raw.githubusercontent.com/legalsylvain/web/12.0-mig-web_dashboard_tile/web_dashboard_tile/static/description/favorite_menu_create_tile_result.png" />
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
<p><strong>Known issues</strong></p>
<ul class="simple">
<li>Can not edit color from dashboard</li>
<li>Original context is ignored.</li>
<li>Original domain and filter are not restored.</li>
<li>To preserve a relative date domain, you have to manually edit the tiles domain from “Configuration &gt; User Interface &gt; Dashboard Tile”. You can use the same variables available in filters (<tt class="docutils literal">uid</tt>, <tt class="docutils literal">context_today()</tt>, <tt class="docutils literal">current_date</tt>, <tt class="docutils literal">time</tt>, <tt class="docutils literal">datetime</tt>, <cite>relativedelta</cite>).</li>
</ul>
<p><strong>Roadmap</strong></p>
<ul class="simple">
<li>Add icons.</li>
<li>Support client side action (like inbox).</li>
<li>Restore original Domain + Filter when an action is set.</li>
<li>Posibility to hide the tile based on a field expression.</li>
<li>Posibility to set the background color based on a field expression.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/legalsylvain/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/legalsylvain/web/issues/new?body=module:%20web_dashboard_tile%0Aversion:%2012.0-mig-web_dashboard_tile%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id5">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id6">Authors</a></h2>
<ul class="simple">
<li>initOS GmbH &amp; Co. KG</li>
<li>GRAP</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id7">Contributors</a></h2>
<ul class="simple">
<li>Markus Schneider &lt;markus.schneider at initos.com&gt;</li>
<li>Sylvain Le Gal (<a class="reference external" href="https://twitter.com/legalsylvain">https://twitter.com/legalsylvain</a>)</li>
<li>Iván Todorovich &lt;<a class="reference external" href="mailto:ivan.todorovich&#64;gmail.com">ivan.todorovich&#64;gmail.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<p>Current maintainer:</p>
<p><a class="reference external" href="https://github.com/legalsylvain"><img alt="legalsylvain" src="https://github.com/legalsylvain.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/legalsylvain/web/tree/12.0-mig-web_dashboard_tile/web_dashboard_tile">legalsylvain/web</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
</div>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 B

View File

@@ -1,141 +0,0 @@
// @@@ web_dashboard_tile custom JS @@@
//#############################################################################
//
// Copyright (C) 2010-2013 OpenERP s.a. (<http://www.openerp.com>)
// Copyright (C) 2014 initOS GmbH & Co. KG (<http://initos.com>)
// Copyright (C) 2018 Iván Todorovich (<ivan.todorovich@gmail.com>)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//#############################################################################
odoo.define('web_dashboard_tile', function (require) {
"use strict";
var core = require('web.core');
var data = require('web.data');
var FavoriteMenu = require('web.FavoriteMenu');
var ActionManager = require('web.ActionManager');
var ViewManager = require('web.ViewManager');
var Model = require('web.DataModel');
var session = require('web.session');
var pyeval = require('web.pyeval');
var _t = core._t;
var QWeb = core.qweb;
FavoriteMenu.include({
prepare_dropdown_menu: function (filters) {
var self = this;
this._super(filters);
var am = this.findAncestor(function (a) {
return a instanceof ActionManager;
});
if (am && am.get_inner_widget() instanceof ViewManager) {
this.view_manager = am.get_inner_widget();
this.add_to_dashboard_tile_available = true;
this.$('.o_favorites_menu').append(QWeb.render('SearchView.addtodashboardtile'));
this.$add_to_dashboard_tile = this.$('.o_add_to_dashboard_tile');
this.$add_dashboard_tile_btn = this.$add_to_dashboard_tile.eq(1).find('button');
this.$add_dashboard_tile_input = this.$add_to_dashboard_tile.eq(0).find('input');
this.$add_dashboard_tile_link = this.$('.o_add_to_dashboard_tile_link');
var title = this.searchview.get_title();
this.$add_dashboard_tile_input.val(title);
this.$add_dashboard_tile_link.click(function (e) {
e.preventDefault();
self.toggle_dashboard_tile_menu();
});
this.$add_dashboard_tile_btn.click(this.proxy('add_dashboard_tile'));
}
},
toggle_dashboard_tile_menu: function (is_open) {
this.$add_dashboard_tile_link
.toggleClass('o_closed_menu', !(_.isUndefined(is_open)) ? !is_open : undefined)
.toggleClass('o_open_menu', is_open);
this.$add_to_dashboard_tile.toggle(is_open);
if (this.$add_dashboard_tile_link.hasClass('o_open_menu')) {
this.$add_dashboard_tile_input.focus();
}
},
close_menus: function () {
if (this.add_to_dashboard_tile_available) {
this.toggle_dashboard_tile_menu(false);
}
this._super();
},
add_dashboard_tile: function () {
var self = this;
var search_data = this.searchview.build_search_data(),
context = new data.CompoundContext(this.searchview.dataset.get_context() || []),
domain = new data.CompoundDomain(this.searchview.dataset.get_domain() || []);
_.each(search_data.contexts, context.add, context);
_.each(search_data.domains, domain.add, domain);
context.add({
group_by: pyeval.eval('groupbys', search_data.groupbys || [])
});
context.add(this.view_manager.active_view.controller.get_context());
var c = pyeval.eval('context', context);
for(var k in c) {
if (c.hasOwnProperty(k) && /^search_default_/.test(k)) {
delete c[k];
}
}
this.toggle_dashboard_tile_menu(false);
c.dashboard_merge_domains_contexts = false;
var d = pyeval.eval('domain', domain),
tile = new Model('tile.tile'),
name = self.$add_dashboard_tile_input.val();
var private_filter = !this.$('#oe_searchview_custom_public').prop('checked');
if (_.isEmpty(name)){
this.do_warn(_t("Error"), _t("Filter name is required."));
return false;
}
// Don't save user_context keys in the custom filter, otherwise end
// up with e.g. wrong uid or lang stored *and used in subsequent
// reqs*
var ctx = context;
_(_.keys(session.user_context)).each(function (key) {
delete ctx[key];
});
var vals = {
name: name,
user_id: private_filter ? session.uid : false,
model_id: self.view_manager.active_view.controller.model,
//context: context,
domain: d,
action_id: self.action_id || false,
};
// FIXME: current context?
return tile.call('add', [vals]).done(function (id) {
self.do_notify(_t("Success"), _t("Tile is created"));
});
},
});
});

View File

@@ -0,0 +1,112 @@
/*
Copyright (C) 2010-2013 OpenERP s.a. (<http://www.openerp.com>)
Copyright (C) 2014 initOS GmbH & Co. KG (<http://initos.com>)
Copyright (C) 2018 Iván Todorovich (<ivan.todorovich@gmail.com>)
Copyright (C) 2019-Today GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define('web_dashboard_tile', function (require) {
'use strict';
var core = require('web.core');
var FavoriteMenu = require('web.FavoriteMenu');
var Domain = require('web.Domain');
var qweb = core.qweb;
var _t = core._t;
FavoriteMenu.include({
start: function () {
var self = this;
if (this.action_id === undefined) {
return this._super();
}
if (this.action.type === 'ir.actions.act_window') {
this.add_to_dashboard_available = true;
this.$('.o_favorites_menu').append(qweb.render('SearchView.addtodashboardtile'));
this.$add_to_dashboard_tile = this.$('.o_add_to_dashboard_tile');
this.$add_to_dashboard_tile_name = this.$('.o_add_to_dashboard_tile_name')[0];
// Add event on button and link clicks
this.$add_to_dashboard_tile_link = this.$('.o_add_to_dashboard_tile_link');
this.$add_to_dashboard_tile_link.click(function (e) {
e.preventDefault();
self._toggleDashboardTileMenu();
});
this.$add_to_dashboard_tile_button = this.$('.o_add_to_dashboard_tile_button');
this.$add_to_dashboard_tile_button.click(this.proxy('_addDashboardTile'));
// Add categories to the select list
this.$add_to_dashboard_tile_category = this.$('.o_add_to_dashboard_tile_category')[0];
this._rpc({
model: 'tile.category',
method: 'search_read',
args: [[], ['id', 'name']],
}).then(function (res) {
res.forEach(function(item){
var newOption = document.createElement("option");
newOption.text = item.name;
newOption.value = item.id;
self.$add_to_dashboard_tile_category.appendChild(newOption);
});
});
}
return this._super();
},
_toggleDashboardTileMenu: function (isOpen) {
this.$add_to_dashboard_tile_link
.toggleClass('o_closed_menu', !(_.isUndefined(isOpen)) ? !isOpen : undefined)
.toggleClass('o_open_menu', isOpen);
this.$add_to_dashboard_tile.toggle(isOpen);
if (this.$add_to_dashboard_tile_link.hasClass('o_open_menu')) {
this.$add_to_dashboard_tile_name.focus();
}
},
_addDashboardTile: function () {
var self = this;
var tile_name = this.$add_to_dashboard_tile_name.value;
var tile_category_id = this.$add_to_dashboard_tile_category.value;
if (!tile_name.length){
this.do_warn(_t("Error"), _t("Name Field is required."));
this.$add_to_dashboard_tile_name.focus();
return;
}
var search_data = this.searchview.build_search_data();
var domain = this.action.domain ? this.action.domain.slice(0) : [];
_.each(search_data.domains, function (d) {
domain.push.apply(domain, Domain.prototype.stringToArray(d));
});
return this._rpc({
route: '/web_dashboard_tile/create_tile',
params: {
model_name: self.action.res_model,
name: tile_name,
category_id: tile_category_id,
domain: domain,
action_id: this.action_id,
},
}).then(function (res) {
if (res) {
self.do_notify(
_.str.sprintf(_t("'%s' added to the overview dashboard"), tile_name),
_t('Please refresh your browser for the changes to take effect.')
);
self._toggleDashboardTileMenu(false);
} else {
self.do_warn(_t("Could not add new element to the overview dashboard"));
}
});
},
});
});

View File

@@ -1,13 +0,0 @@
<template>
<t t-name="SearchView.addtodashboardtile">
<li class="o_add_to_dashboard_tile_link o_closed_menu">
<a href="#">Add to Dashboard Tile</a>
</li>
<li class="o_add_to_dashboard_tile">
<input class="o_add_to_dashboard_input" type="text"/>
</li>
<li class="o_add_to_dashboard_tile">
<button type="button" class="btn btn-primary btn-sm o_add_to_dashboard_button">Add</button>
</li>
</t>
</template>

View File

@@ -0,0 +1,19 @@
<template>
<t t-name="SearchView.addtodashboardtile">
<a href="#" class="dropdown-item o_add_to_dashboard_tile_link o_closed_menu">Add to the Overview Dashboard</a>
<div class="dropdown-item-text o_add_to_dashboard_tile">
Name
<input class="o_input o_required_modifier o_add_to_dashboard_tile_name" type="text"/>
</div>
<div class="dropdown-item-text o_add_to_dashboard_tile">
Category
<select class="o_input o_required_modifier o_add_to_dashboard_tile_category">
</select>
</div>
<div class="dropdown-item-text o_add_to_dashboard_tile">
<button type="button" class="btn btn-primary o_add_to_dashboard_tile_button">Add</button>
</div>
</t>
</template>