forked from Techsystech/web
Fix 'Add to Dashboard Tile' menu (MIG 9.0)
parent
87d3027020
commit
5ddf3688f9
|
@ -5,8 +5,8 @@
|
|||
}
|
||||
|
||||
.o_kanban_view.o_kanban_ungrouped .o_kanban_record.oe_dashboard_tile {
|
||||
/* override max-width rules */
|
||||
margin: 4px !important;
|
||||
/* override max-width rules */
|
||||
margin: 4px !important;
|
||||
/* flex width */
|
||||
-ms-flex: 1 1 150px;
|
||||
-moz-flex: 1 1 150px;
|
||||
|
@ -53,11 +53,8 @@
|
|||
display: block;
|
||||
}
|
||||
|
||||
/* SearchView Drawer */
|
||||
.oe_searchview_drawer .oe_searchview_dashboard .oe_dashboard_tile_form {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.oe_searchview_drawer .oe_opened .oe_dashboard_tile_form {
|
||||
display: block;
|
||||
/* Favorites menu in control panel */
|
||||
.o_add_to_dashboard_tile {
|
||||
/* hidden by default */
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
// 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
|
||||
|
@ -19,83 +20,122 @@
|
|||
//
|
||||
//#############################################################################
|
||||
|
||||
odoo.web_dashboard_tile = function (require)
|
||||
{
|
||||
var QWeb = require('web.qweb')
|
||||
var _t = require('web._t')
|
||||
var _lt = require('web._lt')
|
||||
odoo.define('web_dashboard_tile', function (require) {
|
||||
"use strict";
|
||||
|
||||
_.mixin({
|
||||
sum: function (obj) { return _.reduce(obj, function (a, b) { return a + b; }, 0); }
|
||||
});
|
||||
var module = instance.board.AddToDashboard;
|
||||
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;
|
||||
|
||||
module.include({
|
||||
start: function () {
|
||||
this._super();
|
||||
var self = this;
|
||||
this.$('#add_dashboard_tile').on('click', this, function (){
|
||||
self.save_tile();
|
||||
|
||||
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();
|
||||
});
|
||||
},
|
||||
render_data: function(dashboard_choices){
|
||||
var selection = instance.web.qweb.render(
|
||||
"SearchView.addtodashboard.selection", {
|
||||
selections: dashboard_choices});
|
||||
this.$("form input").before(selection);
|
||||
},
|
||||
save_tile: function () {
|
||||
var self = this;
|
||||
var view_parent = this.getParent().getParent();
|
||||
|
||||
var $name = this.$('#dashboard_tile_new_name');
|
||||
|
||||
this.tile = new instance.web.Model('tile.tile');
|
||||
|
||||
var private_filter = !this.$('#oe_searchview_custom_public').prop('checked');
|
||||
if (_.isEmpty($name.val())){
|
||||
this.do_warn(_t("Error"), _t("Filter name is required."));
|
||||
return false;
|
||||
}
|
||||
var search = this.view.build_search_data();
|
||||
var context = new instance.web.CompoundContext(view_parent.dataset.get_context() || []);
|
||||
var domain = new instance.web.CompoundDomain(view_parent.dataset.get_domain() || []);
|
||||
_.each(search.contexts, context.add, context);
|
||||
_.each(search.domains, domain.add, domain);
|
||||
|
||||
var c = instance.web.pyeval.eval('context', context);
|
||||
for(var k in c) {
|
||||
if (c.hasOwnProperty(k) && /^search_default_/.test(k)) {
|
||||
delete c[k];
|
||||
}
|
||||
}
|
||||
// TODO: replace this 6.1 workaround by attribute on <action/>
|
||||
c.dashboard_merge_domains_contexts = false;
|
||||
var d = instance.web.pyeval.eval('domain', domain);
|
||||
|
||||
context.add({
|
||||
group_by: instance.web.pyeval.eval('groupbys', search.groupbys || [])
|
||||
});
|
||||
// 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(instance.session.user_context)).each(function (key) {
|
||||
delete ctx[key];
|
||||
});
|
||||
var filter = {
|
||||
name: $name.val(),
|
||||
user_id: private_filter ? instance.session.uid : false,
|
||||
model_id: self.view.model,
|
||||
//context: context,
|
||||
domain: d,
|
||||
action_id: view_parent.action.id,
|
||||
};
|
||||
// FIXME: current context?
|
||||
return self.tile.call('add', [filter]).done(function (id) {
|
||||
self.do_warn(_t("Success"), _t("Tile is created"));
|
||||
});
|
||||
|
||||
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"));
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-extend="SearchView.addtodashboard">
|
||||
<t t-jquery="form" t-operation="after">
|
||||
<div class="oe_dashboard_tile_form">
|
||||
<label for="dashboard_tile_new_name">Tile:</label>
|
||||
<input id="dashboard_tile_new_name" />
|
||||
<button id="add_dashboard_tile">Create</button>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue