[ADD] Added possibility to add actions to dashboards from searchviews filters

bzr revid: fme@openerp.com-20111123215356-wspyu61u6ad1vois
This commit is contained in:
Fabien Meghazi 2011-11-23 22:53:56 +01:00
parent 35edbcd90f
commit 66d11b95f4
3 changed files with 100 additions and 1 deletions

View File

@ -1064,6 +1064,44 @@ class SearchView(View):
}, context)
return to_return
@openerpweb.jsonrequest
def add_to_dashboard(self, req, menu_id, action_id, context_to_save, domain, view_mode, name=''):
ctx = web.common.nonliterals.CompoundContext(context_to_save)
ctx.session = req.session
ctx = ctx.evaluate()
domain = web.common.nonliterals.CompoundDomain(domain)
domain.session = req.session
domain = domain.evaluate()
dashboard_action = load_actions_from_ir_values(req, 'action', 'tree_but_open',
[('ir.ui.menu', menu_id)], False)
if dashboard_action:
action = dashboard_action[0][2]
if action['res_model'] == 'board.board' and action['views'][0][1] == 'form':
# Maybe should check the content instead of model board.board ?
view_id = action['views'][0][0]
board = req.session.model(action['res_model']).fields_view_get(view_id, 'form')
if board and 'arch' in board:
xml = ElementTree.fromstring(board['arch'])
column = xml.find('./board/column')
if column:
new_action = ElementTree.Element('action', {
'name' : str(action_id),
'string' : name,
'view_mode' : view_mode,
'context' : str(ctx),
'domain' : str(domain)
})
column.insert(0, new_action)
arch = ElementTree.tostring(xml, 'utf-8')
return req.session.model('ir.ui.view.custom').create({
'user_id': req.session._uid,
'ref_id': view_id,
'arch': arch
}, req.session.eval_context(req.context))
return False
class Binary(openerpweb.Controller):
_cp_path = "/web/binary"

View File

@ -139,6 +139,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
}
},
on_loaded: function(data) {
this.fields_view = data.fields_view;
if (data.fields_view.type !== 'search' ||
data.fields_view.arch.tag !== 'search') {
throw new Error(_.str.sprintf(
@ -241,6 +242,8 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
}}
]
});
} else if (val == "add_to_dashboard") {
this.on_add_to_dashboard();
} else { // manage_filters
select.val("_filters");
this.do_action({
@ -255,6 +258,53 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
});
}
},
on_add_to_dashboard: function() {
this.$element.find(".oe_search-view-filters-management")[0].selectedIndex = 0;
var self = this,
menu = openerp.webclient.menu,
$dialog = $(QWeb.render("SearchView.add_to_dashboard", {
dashboards : menu.data.data.children,
selected_menu_id : menu.$element.find('a.active').data('menu')
}));
$dialog.find('input').val(this.fields_view.name);
$dialog.dialog({
modal: true,
title: _t("Add to Dashboard"),
buttons: [
{text: _t("Cancel"), click: function() {
$(this).dialog("close");
}},
{text: _t("OK"), click: function() {
$(this).dialog("close");
var menu_id = $(this).find("select").val(),
title = $(this).find("input").val(),
data = self.build_search_data(),
context = new openerp.web.CompoundContext(),
domain = new openerp.web.CompoundDomain();
_.each(data.contexts, function(x) {
context.add(x);
});
_.each(data.domains, function(x) {
domain.add(x);
});
self.rpc('/web/searchview/add_to_dashboard', {
menu_id: menu_id,
action_id: self.widget_parent.action.id,
context_to_save: context,
domain: domain,
view_mode: self.widget_parent.active_view,
name: title
}, function(r) {
if (r === false) {
self.do_warn("Could not add filter to dashboard");
} else {
self.do_notify("Filter added to dashboard", '');
}
});
}}
]
});
},
/**
* Performs the search view collection of widget data.
*

View File

@ -1135,6 +1135,7 @@
</t>
<option value="_actions">-- Actions --</option>
<option value="save_filter">Save Filter</option>
<option value="add_to_dashboard">Add to Dashboard</option>
<option value="manage_filters">Manage Filters</option>
</t>
<t t-name="SearchView.managed-filters.add">
@ -1144,6 +1145,16 @@
<p>(Any existing filter with the same name will be replaced)</p>
</div>
</t>
<t t-name="SearchView.add_to_dashboard">
<div class="oe_forms">
<p><b>Select Dashboard to add this filter to:</b></p>
<select style="width: 100%; margin-right: 1em;">
<option t-foreach="dashboards" t-as="menu" t-att-value="menu.id" t-att-selected="(menu.id == selected_menu_id) || undefined"><t t-esc="menu.name"/></option>
</select>
<p><b>Title of new Dashboard item:</b></p>
<input type="text" style="width: 100%; margin-right: 1em;"/>
</div>
</t>
<t t-name="SearchView.render_lines">
<table class="oe-searchview-render-line" border="0" cellspacing="0" cellpadding="0"
t-foreach="lines" t-as="line">
@ -1711,4 +1722,4 @@
<t t-name="EmptyComponent">
<div></div>
</t>
</templates>
</templates>