[FIX] lot of stupid stuff in add to dashboard

bzr revid: nicolas.vanhoren@openerp.com-20120628121053-nct0zo9go1bzdjrs
This commit is contained in:
niv-openerp 2012-06-28 14:10:53 +02:00
parent e3473f1b6d
commit 3e30f54cbf
1 changed files with 17 additions and 38 deletions

View File

@ -640,6 +640,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
var drawer_started = $.when.apply(
null, _(this.select_for_drawer()).invoke(
'appendTo', this.$element.find('.oe_searchview_drawer')));
new instance.web.search.AddToDashboard(this).appendTo($('.oe_searchview_drawer', this.$element));
// load defaults
var defaults_fetched = $.when.apply(null, _(this.inputs).invoke(
@ -1637,7 +1639,7 @@ instance.web.search.Filters = instance.web.search.Input.extend({
}));
}
});
instance.web.search.AddToDashboard = instance.web.search.Input.extend({
instance.web.search.AddToDashboard = instance.web.Widget.extend({
template: 'SearchView.addtodashboard',
_in_drawer: true,
start: function () {
@ -1645,44 +1647,18 @@ instance.web.search.AddToDashboard = instance.web.search.Input.extend({
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();});
.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 self = this,dashboard_menu = instance.webclient.menu.data.data.children;
var ir_model_data = new instance.web.Model('ir.model.data',{},[['name','=','menu_reporting_dashboard']]).query(['res_id']);
var map_data = function(result){
_.detect(dashboard_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
@ -1700,8 +1676,10 @@ instance.web.search.AddToDashboard = instance.web.search.Input.extend({
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())
var self = this;
var getParent = this.getParent();
var view_parent = this.getParent().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() || []),
@ -1731,6 +1709,7 @@ instance.web.search.AddToDashboard = instance.web.search.Input.extend({
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,