diff --git a/addons/board/static/src/js/dashboard.js b/addons/board/static/src/js/dashboard.js index 5fa7811b5a0..e24770f3b18 100644 --- a/addons/board/static/src/js/dashboard.js +++ b/addons/board/static/src/js/dashboard.js @@ -8,6 +8,16 @@ if (!instance.board) { } instance.web.form.DashBoard = instance.web.form.FormWidget.extend({ + events: { + 'click .oe_dashboard_link_reset': 'on_reset', + 'click .oe_dashboard_link_change_layout': 'on_change_layout', + 'click h2.oe_header span.oe_header_txt': function (ev) { + if(ev.target === ev.currentTarget) + self.on_header_string($(ev.target).parent()); + }, + 'click .oe_dashboard_column .oe_fold': 'on_fold_action', + 'click .oe_dashboard_column .oe_close': 'on_close_action', + }, init: function(view, node) { this._super(view, node); this.form_template = 'DashBoard'; @@ -27,16 +37,7 @@ instance.web.form.DashBoard = instance.web.form.FormWidget.extend({ var old_title = this.__parentedParent.get('title'); this.__parentedParent.on('load_record', self, function(){ self.__parentedParent.set({ 'title': old_title}); - }) - // Events - this.$('.oe_dashboard_link_reset').click(this.on_reset); - this.$('.oe_dashboard_link_change_layout').click(this.on_change_layout); - this.$('h2.oe_header span.oe_header_txt').click(function(ev){ - if(ev.target === ev.currentTarget) - self.on_header_string($(ev.target).parent()); }); - this.$el.delegate('.oe_dashboard_column .oe_fold', 'click', this.on_fold_action); - this.$el.delegate('.oe_dashboard_column .oe_close', 'click', this.on_close_action); // Init actions _.each(this.node.children, function(column, column_index) { @@ -332,10 +333,10 @@ instance.web.search.FavoriteMenu.include({ var self = this; this._super(filters); this.$('.favorites-menu').append(QWeb.render('SearchView.addtodashboard')); - this.$add_to_dashboard = this.$('.add-to-dashboard'); - this.$add_dashboard_btn = this.$add_to_dashboard.eq(2).find('button'); - this.$add_dashboard_input = this.$add_to_dashboard.eq(1).find('input'); - this.$add_dashboard_link = this.$add_to_dashboard.first().find('a'); + var $add_to_dashboard = this.$('.add-to-dashboard'); + this.$add_dashboard_btn = $add_to_dashboard.eq(2).find('button'); + this.$add_dashboard_input = $add_to_dashboard.eq(1).find('input'); + this.$add_dashboard_link = $add_to_dashboard.first().find('a'); var title = this.searchview.getParent().title; this.$add_dashboard_input.val(title); this.$add_dashboard_link.click(function () { @@ -344,12 +345,12 @@ instance.web.search.FavoriteMenu.include({ this.$add_dashboard_btn.click(this.proxy('add_dashboard')); }, toggle_dashboard_menu: function (is_open) { - this.$add_to_dashboard.first() + this.$add_dashboard_link .toggleClass('closed-menu', !is_open) .toggleClass('open-menu', is_open); this.$add_dashboard_btn.toggle(is_open); this.$add_dashboard_input.toggle(is_open); - if (this.$add_to_dashboard.first().hasClass('open-menu')) { + if (this.$add_dashboard_link.hasClass('open-menu')) { this.$add_dashboard_input.focus(); } }, @@ -358,12 +359,10 @@ instance.web.search.FavoriteMenu.include({ this._super(); }, add_dashboard: function () { - var self = this; - var view_manager = this.getParent(); - while (!(view_manager instanceof instance.web.ViewManager) && - view_manager && view_manager.getParent) { - view_manager = view_manager.getParent(); - } + var self = this, + view_manager = this.findAncestor(function (a) { + return a instanceof instance.web.ViewManager + }); if (!view_manager.action) { this.do_warn(_t("Can't find dashboard action")); return; @@ -401,10 +400,10 @@ instance.web.search.FavoriteMenu.include({ name: name, }); }).then(function (r) { - if (r === false) { - self.do_warn(_t("Could not add filter to dashboard")); + if (r) { + self.do_notify(_.str.sprintf(_t("'%s' added to dashboard"), name), ''); } else { - self.do_notify(_t("'"+name + "' added to dashboard"), ''); + self.do_warn(_t("Could not add filter to dashboard")); } }); }, diff --git a/addons/google_spreadsheet/static/src/js/search.js b/addons/google_spreadsheet/static/src/js/search.js index 45759bf3883..650eccdf619 100644 --- a/addons/google_spreadsheet/static/src/js/search.js +++ b/addons/google_spreadsheet/static/src/js/search.js @@ -1,51 +1,50 @@ openerp.google_spreadsheet = function(instance) { var _t = instance.web._t, - QWeb = instance.web.qweb; + QWeb = instance.web.qweb; instance.web.FormView.include({ - on_processed_onchange: function(result, processed) { - var self = this; - var fields = self.fields; - _(result.selection).each(function (selection, fieldname) { - var field = fields[fieldname]; - if (!field) { return; } - field.field.selection = selection; - field.values = selection; - field.renderElement(); - }); - return this._super(result, processed); - }, + on_processed_onchange: function(result, processed) { + var self = this; + var fields = self.fields; + _(result.selection).each(function (selection, fieldname) { + var field = fields[fieldname]; + if (!field) { return; } + field.field.selection = selection; + field.values = selection; + field.renderElement(); + }); + return this._super(result, processed); + }, }); instance.web.search.FavoriteMenu.include({ - prepare_dropdown_menu: function (filters) { - this._super(filters); - this.$('.favorites-menu').append(QWeb.render('SearchView.addtogooglespreadsheet')); - this.$('.add-to-spreadsheet').click(this.add_to_spreadsheet.bind(this)); - }, - add_to_spreadsheet: function () { - var data = this.searchview.build_search_data(), - model = this.searchview.dataset.model, - view_manager = this.searchview.getParent(), - list_view = view_manager.views.list, - list_view_id = list_view ? list_view.view_id : false, - context = this.searchview.dataset.get_context() || [], - domain = this.searchview.dataset.get_domain() || [], - compound_context = new instance.web.CompoundContext(context), - compound_domain = new instance.web.CompoundDomain(context), - groupbys = instance.web.pyeval.eval('groupbys', data.groupbys).join(" "), - ds = new instance.web.DataSet(this, 'google.drive.config'); + prepare_dropdown_menu: function (filters) { + this._super(filters); + this.$('.favorites-menu').append(QWeb.render('SearchView.addtogooglespreadsheet')); + this.$('.add-to-spreadsheet').click(this.add_to_spreadsheet.bind(this)); + }, + add_to_spreadsheet: function () { + var data = this.searchview.build_search_data(), + model = this.searchview.dataset.model, + view_manager = this.searchview.getParent(), + list_view = view_manager.views.list, + list_view_id = list_view ? list_view.view_id : false, + context = this.searchview.dataset.get_context() || [], + domain = this.searchview.dataset.get_domain() || [], + compound_context = new instance.web.CompoundContext(context), + compound_domain = new instance.web.CompoundDomain(context), + groupbys = instance.web.pyeval.eval('groupbys', data.groupbys).join(" "), + ds = new instance.web.DataSet(this, 'google.drive.config'); - _.each(data.contexts, compound_context.add, compound_context); - _.each(data.domains, compound_domain.add, compound_domain); + _.each(data.contexts, compound_context.add, compound_context); + _.each(data.domains, compound_domain.add, compound_domain); - compound_domain = JSON.stringify(compound_domain.eval()); - console.log('add_to_spreadsheet'); + compound_domain = JSON.stringify(compound_domain.eval()); ds.call('set_spreadsheet', [model, compound_domain, groupbys, list_view_id]) - .done(function (res) { - if (res['url']){ - window.open(res['url'], '_blank'); - } - }); - }, + .done(function (res) { + if (res['url']){ + window.open(res['url'], '_blank'); + } + }); + }, }); }; \ No newline at end of file diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index ef5cab96977..6c4d4609a20 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1968,11 +1968,9 @@ openerp.mail = function (session) { * @param {Object} defaults ?? */ load_searchview: function (defaults) { - var self = this; - var ds_msg = new session.web.DataSetSearch(this, 'mail.message'); - var options = { - $buttons: this.$('.oe-search-options') - }; + var self = this, + ds_msg = new session.web.DataSetSearch(this, 'mail.message'), + options = { $buttons: this.$('.oe-search-options') }; this.searchview = new session.web.SearchView(this, ds_msg, false, defaults || {}, options); this.searchview.on('search_data', this, this.do_searchview_search); this.searchview.appendTo(this.$('.oe-view-manager-search-view')).then(function () { diff --git a/addons/web/static/src/js/openerpframework.js b/addons/web/static/src/js/openerpframework.js index fd13bea49cb..b112783793f 100644 --- a/addons/web/static/src/js/openerpframework.js +++ b/addons/web/static/src/js/openerpframework.js @@ -287,7 +287,17 @@ openerp.ParentedMixin = { }); this.setParent(undefined); this.__parentedDestroyed = true; - } + }, + /** + * Find the closest ancestor matching predicate + */ + findAncestor: function (predicate) { + var ancestor = this; + while (!(predicate(ancestor)) && ancestor && ancestor.getParent) { + ancestor = ancestor.getParent(); + } + return ancestor; + }, }; /** diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index f55f9b4fe93..de839036d06 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -333,9 +333,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea }, 'click .oe_searchview_unfold_drawer': function (e) { e.stopImmediatePropagation(); - $(e.target).toggleClass('fa-caret-down') - .toggleClass('fa-caret-up'); - localStorage.visible_search_menu = !(localStorage.visible_search_menu === 'true'); + $(e.target).toggleClass('fa-caret-down fa-caret-up'); + localStorage.visible_search_menu = (localStorage.visible_search_menu !== 'true'); this.toggle_buttons(); }, 'keydown .oe_searchview_input, .oe_searchview_facet': function (e) { @@ -380,7 +379,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea this.search_fields = []; this.filters = []; this.groupbys = []; - this.visible_filters = !!(localStorage.visible_search_menu === 'true'); + this.visible_filters = (localStorage.visible_search_menu === 'true'); this.input_subviews = []; // for user input in searchbar this.defaults = defaults || {}; this.headless = this.options.hidden && _.isEmpty(this.defaults); @@ -410,8 +409,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea this.$('.oe_searchview_unfold_drawer') .toggleClass('fa-caret-down', !this.visible_filters) .toggleClass('fa-caret-up', this.visible_filters); - return $.when(this._super(), this.alive($.when(load_view)) - .then(this.view_loaded.bind(this))); + return this.alive($.when(this._super(), load_view.then(this.view_loaded.bind(this)))); }, view_loaded: function (r) { var self = this; @@ -433,7 +431,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea } return $.when(custom_filters_ready).then(this.proxy('set_default_filters')); }, - set_default_filters: function (a, b) { + set_default_filters: function () { var self = this, default_custom_filter = this.$buttons && this.favorite_menu.get_default_filter(); if (default_custom_filter) { @@ -523,8 +521,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea source: this.proxy('complete_global_search'), select: this.proxy('select_completion'), delay: 0, - get_search_string: function () { - return self.$('div.oe_searchview_input').text(); + get_search_string: function () { + return self.$('div.oe_searchview_input').text(); }, }); this.autocomplete.appendTo(this.$el); @@ -632,10 +630,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea this.$el.addClass('active'); }, childBlurred: function () { - var val = this.$el.val(); - this.$el.val(''); - this.$el.removeClass('active') - .trigger('blur'); + this.$el.val('').removeClass('active').trigger('blur'); this.autocomplete.close(); }, /** @@ -789,16 +784,6 @@ instance.web.search.Input = instance.web.Widget.extend( /** @lends instance.web. */ visible: function () { return !this.attrs.modifiers.invisible; - - // var parent = this; - // while ((parent = parent.getParent()) && - // ( (parent instanceof instance.web.search.Group) - // || (parent instanceof instance.web.search.Input))) { - // if (!parent.visible()) { - // return false; - // } - // } - // return true; }, }); instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends instance.web.search.FilterGroup# */{ @@ -1449,7 +1434,7 @@ instance.web.search.FilterMenu = instance.web.Widget.extend({ _.each(this.filters, function (group) { if (group.is_visible()) { group.insertBefore(self.$add_filter); - $('