[FIX] put back the "Add to Dashboard" feature

bzr revid: nicolas.vanhoren@openerp.com-20120626145445-kym37wuxkaapdwe6
This commit is contained in:
niv-openerp
2012-06-26 16:54:45 +02:00
5 changed files with 121 additions and 59 deletions
+2 -1
View File
@@ -1286,7 +1286,8 @@ class SearchView(View):
del filter['context']
del filter['domain']
return filters
@openerpweb.jsonrequest
def add_to_dashboard(self, req, menu_id, action_id, context_to_save, domain, view_mode, name=''):
to_eval = common.nonliterals.CompoundContext(context_to_save)
+4
View File
@@ -1441,6 +1441,10 @@
top: 0;
right: 5px;
}
.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_dashboard form {
display: none;
margin-top: 2px;
}
.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced form {
display: none;
margin-top: 8px;
+5
View File
@@ -1131,6 +1131,11 @@ $colour4: #8a89ba
position: absolute
top: 0
right: 5px
.oe_searchview_dashboard
form
display: none
margin-top: 2px
.oe_searchview_advanced
form
display: none
+95 -47
View File
@@ -635,6 +635,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
(new instance.web.search.CustomFilters(this));
// add Advanced to this.inputs
(new instance.web.search.Advanced(this));
(new instance.web.search.AddToDashboard(this));
// build drawer
var drawer_started = $.when.apply(
@@ -692,53 +693,6 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
select.val('');
}
},
on_add_to_dashboard: function() {
this.$element.find(".oe_search-view-filters-management")[0].selectedIndex = 0;
var self = this,
menu = instance.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);
instance.web.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 instance.web.CompoundContext(),
domain = new instance.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.getParent().action.id,
context_to_save: context,
domain: domain,
view_mode: self.getParent().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", '');
}
});
}}
]
});
},
/**
* Extract search data from the view's facets.
*
@@ -1684,6 +1638,100 @@ instance.web.search.Filters = instance.web.search.Input.extend({
}));
}
});
instance.web.search.AddToDashboard = instance.web.search.Input.extend({
template: 'SearchView.addtodashboard',
_in_drawer: true,
start: function () {
var self = this;
this.data_loaded = $.Deferred();
this.dashboard_data =[];
this.$element
.on('click', 'h4', this.proxy('show_option'))
.on('submit', 'form', function (e) {e.preventDefault(); self.add_dashboard();});
return $.when(this.load_data(),this.data_loaded).pipe(this.proxy("render_data"));
},
load_data:function(){
// get from database if dashboard position change than also works(from Reporting to else).
/*var self = this,
ir_actions_act_window = new instance.web.Model('ir.actions.act_window',{},[['res_model','=',"board.board"],['view_id','!=',false]])
.query(['name','id']),
map_data = function(){
var ir_actions_values = arguments[0],ir_values = arguments[1];
_(ir_values).each(function(res){
var get_name = _.detect(ir_actions_values,function(name){ return name.id == parseInt((res.value).split(",")[1]);});
self.dashboard_data.push({"res_id":res.res_id,"name":get_name.name})
});
self.data_loaded.resolve();
},
make_domain = function(result){
var domain = [];
_(result).map(function(value,key){
domain.push(["value","=","ir.actions.act_window,"+value.id]);
((result.length)- 1 !== key)?domain.unshift("|"):false;
})
return domain;
};
return ir_actions_act_window._execute().then(function(ir_actions_values){
if(!ir_actions_values.length) {self.data_loaded.resolve();return;}
var ir_value = new instance.web.Model('ir.values',{},make_domain(ir_actions_values)).query(['res_id','value']);
ir_value._execute().done(function(ir_values){
map_data(ir_actions_values,ir_values);
})
});*/
//===============================get from instance.webclient.menu (with less rpc call)
var self = this,dashbaord_menu = instance.webclient.menu.data.data.children,
ir_model_data = new instance.web.Model('ir.model.data',{},[['name','=','menu_reporting_dashboard']]).query(['res_id']),
map_data = function(result){
_.detect(dashbaord_menu,function(dash){
var id = _.pluck(dash.children, "id"),indexof = _.indexOf(id, result.res_id);
if(indexof !== -1){
self.dashboard_data = dash.children[indexof].children
self.data_loaded.resolve();
return;
}
});
};
return ir_model_data._execute().done(function(result){map_data(result[0])});
},
render_data: function(){
var self = this;
var selection = instance.web.qweb.render("SearchView.addtodashboard.selection",{selections:this.dashboard_data});
this.$element.find("input").before(selection)
},
add_dashboard:function(){
var self = this,getParent = this.getParent(),view_parent = this.view.getParent();
if(!view_parent.action || !this.$element.find("select").val())
return this.do_warn("Can't find dashboard action");
data = getParent.build_search_data(),
context = new instance.web.CompoundContext(getParent.dataset.get_context() || []),
domain = new instance.web.CompoundDomain(getParent.dataset.get_domain() || []);
_.each(data.contexts, function(x) {context.add(x);});
_.each(data.domains, function(x) {domain.add(x);});
this.rpc('/web/searchview/add_to_dashboard', {
menu_id: this.$element.find("select").val(),
action_id: view_parent.action.id,
context_to_save: context,
domain: domain,
view_mode: view_parent.active_view,
name: this.$element.find("input").val()
}, function(r) {
if (r === false) {
self.do_warn("Could not add filter to dashboard");
} else {
self.$element.toggleClass('oe_opened');
self.do_notify("Filter added to dashboard", '');
}
});
},
show_option:function(){
this.$element.toggleClass('oe_opened');
if (! this.$element.hasClass('oe_opened'))
return;
this.$element.find("input").val(this.getParent().fields_view.name || "" );
}
});
instance.web.search.Advanced = instance.web.search.Input.extend({
template: 'SearchView.advanced',
_in_drawer: true,
+15 -11
View File
@@ -1238,7 +1238,6 @@
<optgroup label="-- Actions --">
<option value="advanced_filter">Add Advanced Filter</option>
<option value="save_filter">Save Filter</option>
<option value="add_to_dashboard">Add to Dashboard</option>
<option value="manage_filters">Manage Filters</option>
</optgroup>
</t>
@@ -1249,16 +1248,7 @@
<p>(Any existing filter with the same name will be replaced)</p>
</div>
</t>
<t t-name="SearchView.add_to_dashboard">
<div>
<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">
@@ -1397,6 +1387,20 @@
<div>
</div>
</div>
<div t-name="SearchView.addtodashboard" class="oe_searchview_dashboard">
<h4>Add to Dashboard</h4>
<form>
<input placeholder ="Title of new Dashboard item" title = "Title of new Dashboard item" type="text"/>
<button class="oe_apply" type="submit">save</button>
</form>
</div>
<t t-name="SearchView.addtodashboard.selection">
<select title = "Select Dashboard to add this filter to">
<t t-foreach="selections" t-as="element">
<option t-att-value="element.id || element.res_id "><t t-esc="element.name"/></option>
</t>
</select>
</t>
<div t-name="SearchView.advanced" class="oe_searchview_advanced">
<h4>Advanced Search</h4>
<form>